2023-07-22 08:02 PM - edited 2023-07-22 08:02 PM
Hard fault with DMA on TIM3_CH2 (but on TIM1_CH1) for WS2812B LEDs
I am trying to control WS2812 addressable LEDs. This example (Interface WS2812 with STM32) works great using TIM1_CH1 to generate a PWM signal on output PA8. It uses DMA to adjust he duty cycle after each pulse to flip between the logical "on" and "off" signal for each color of each LED. (DMA request TIM1_CH1, DMA1 Channel 2.)
In my actual hardware, I need to drive the LEDs using PA7. This is done using TIM3_CH2. I modified the example in the link to use TIM3_CH2. This uses DMA request TIM3_CH4/up, DMA1 channel 3. There are no other changes. Unfortunately, I get a hard fault using the new configuration.
Processor is STM32103C8T6. I am using the STM32CubeIDE to setup the the hardware, timers, DMA, etc.
The code changes, in addition to the configuration changes in the STM32Cube .ioc and the generated configuration code are:
From:
HAL_TIM_PWM_Stop_DMA(&htim1, TIM_CHANNEL_1);
to:
HAL_TIM_PWM_Stop_DMA(&htim3, TIM_CHANNEL_2);
and
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)pwmData, indx);
to:
HAL_TIM_PWM_Start_DMA(&htim3, TIM_CHANNEL_2, (uint32_t *)pwmData, indx);
Any ideas on why I'm getting a hard fault here?
Thank you!
2023-07-22 10:26 PM
Investigate further details about your hard fault, may be there you can find informations:
https://developer.arm.com/documentation/dui0552/a/cortex-m3-peripherals/system-control-block/hardfault-status-register
BTW: You can use MOSI (SPI) output to generate bitstream for WS2812 and reduce RAM footprint and DMA traffic.
2024-03-21 03:31 AM
you can use my pack.
https://github.com/nimaltd/ws28xx
please watch the video how to install and use.