0
votes

I've been trying for a couple of days now, to create a simple DMA program for the G4. But without HAL (using libopencm3). The goal is to configure DMA to read data (in circular mode) from buffer and send them to TIM17_CCR1. I've made the code work in HAL previously, but have no luck with libopencm3. I've managed to transfer data from buffer to the OCR in mem2mem mode (even though i need mem2perif) just to try. But I have no idea on how to start with mem2perif. Configuring DMA is no big deal, but I'm lost in the DMAMUX part.

Do you even have to configure it? How do you configure it the right way? I'm totally lost in ST's documentation and can't find any existing code using DMAMUX without HAL. Do any of you have any examples I could look at? Best would be some bare metal C so I could check out the registers. Anything that would help some documents (else than STs own)? It would be much appreciated.

Thanks a lot!

1
using libopencm3 do it register level. Do not use magic libraries. I bet you will be ready in 2-3 hours assuming that you never did it before.0___________
if you struggle to do it with a library noone knows, maybe start using the STM32 HAL and ask for some support herehendrikschnack
as I said, I've succesfully done it with HAL before, no help needed there ;)Wojta

1 Answers

0
votes

I've got it working even with the library, just needed one more day of testing :(

Here is the code for anybody interesrted:

gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_FRONT_LED | GPIO_BACK_LED);
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_FRONT_LED | GPIO_BACK_LED);
gpio_set_af(GPIOB, GPIO_AF10, GPIO_BACK_LED);

//Setup for back led
dma_set_priority(DMA1, DMA_CHANNEL1, DMA_CCR_PL_LOW);
dma_set_memory_size(DMA1, DMA_CHANNEL1, DMA_CCR_MSIZE_8BIT);
dma_set_peripheral_size(DMA1, DMA_CHANNEL1, DMA_CCR_PSIZE_16BIT);
dma_enable_memory_increment_mode(DMA1, DMA_CHANNEL1);
dma_enable_circular_mode(DMA1, DMA_CHANNEL1);
dma_set_read_from_memory(DMA1, DMA_CHANNEL1);

dmamux_set_dma_channel_request(DMAMUX1, DMA_CHANNEL1, DMAMUX_CxCR_DMAREQ_ID_TIM17_CH1);

dma_set_peripheral_address(DMA1, DMA_CHANNEL1, (uint32_t)&TIM17_CCR1);
dma_set_memory_address(DMA1, DMA_CHANNEL1, (uint32_t)&ledBackBuffer);
dma_set_number_of_data(DMA1, DMA_CHANNEL1, LED_BACK_BUFFER_SIZE);

timer_enable_preload(TIM17);
timer_update_on_overflow(TIM17);
timer_set_dma_on_update_event(TIM17);
timer_enable_irq(TIM17, TIM_DIER_CC1DE);
timer_generate_event(TIM17, TIM_EGR_CC1G);
timer_set_oc_mode(TIM17, TIM_OC1, TIM_OCM_PWM1);
timer_enable_oc_output(TIM17, TIM_OC1);
timer_enable_break_main_output(TIM17);
timer_set_period(TIM17, 179);

timer_enable_counter(TIM17);
dma_enable_channel(DMA1, DMA_CHANNEL1);

ledBackBuffer is basic uint8_t array filled with data to be transmitted to all the LEDs.