I am trying to control two lines of digital LEDs (WS2812b) with my STM32F103 using Timers with DMA and PWM. LED strips data lines are connected to PB5
and PB6
of the MC. I used STM32CumeMX to create the inital code for my project.
I click channel 1 and set it to "PWM Generation CH1". PB6
tuns green and in DMA settings it says TIM4_CH1
and DMA1 Channel1
. Looks OK, and it works.
But when I try to configure PB5 weird stuff happens: I select TIM3 and Channel2. PA7
turns green(!?). I click PB5
and select TIM3_CH2 manually. The black pin appears next to it. In DMA settings it says TIM3_CH4/UP
(!??) and DMA1 channel 3
(!???). What is the logic here? What does /UP
even mean? Where are all possible combinations of Timer/DMA channel are listed?
As the result PB5
does not work.
Also I noticed that CubeMX produces this:
/* Several peripheral DMA handle pointers point to the same DMA handle.
Be aware that there is only one channel to perform all the requested DMAs. */
__HAL_LINKDMA(tim_baseHandle, hdma[TIM_DMA_ID_CC4], hdma_tim3_ch4_up);
__HAL_LINKDMA(tim_baseHandle, hdma[TIM_DMA_ID_UPDATE], hdma_tim3_ch4_up);
I deleted the last line, but it didn't help. I just want to configure PB5
similarly to PB6
. What am I missing here?
Is it possible to use DMA on PB5
at all?
Answer
TIM3_CH2 can be connected to one of two pins: PA7 or PB5. When you select TIM3 & PWM Generation CH2 in CubeMX, it assigns it to PA7. You can CTRL+Click (and hold both) to PA7 and see that PB5 highlighted. Then you can drag & drop it while holding the CTRL key. The black pin means that it's manually assigned and CubeMX won't move it if you try to enable another peripheral which uses the same pin.
If you refer to the Table 78 in the reference manual, you see that DMA1 Channel 3 is shared by TIM3_CH4 and TIM3_UP (update event, basically timer overflow). That's why it's named that way in CubeMX. When a DMA channel is shared by more than one sources, you shouldn't enable more than one at a time.
Update:
After the OP's comment, I realized that I overlooked Table 78. It appears that TIM3_CH2 is unable to make a Capture & Compare DMA request as it's not present in the table.
However, I also realized that what you actually need is a DMA request tied to the update event. This allows you to update CCRx registers every time TIM3 overflows. You can even update all the CCRx registers at once by using the DMA Burst Mode of the timer.
BTW, DMA capabilities are not related to the pins that peripherals use. So, it doesn't matter if it's PA7 or PB5. CubeMX shows TIM3_CH4/UP option because the update event is not related to any timer channel and that DMA request is available even if no CH pin is used.
No comments:
Post a Comment