PWM on non PWM pin
I need to generate PWM on a non-PWM pin
I know one method is to use an ISR triggered by a timer, but because I need to run the PWM at 10kHz, this will put a huge load on the CPU just to toggle 1 pin.
I've seen examples of using DMA to send data to the BSRR e.g.
https://github.com/mnemocron/STM32_PatternDriver
But following this example, on my STM32F407, the DMA does not seem to send a single transfer to the BSRR register, as the pin does not change
const int dimingTableSize = 100;
uint32_t dimingPattern[dimingTableSize];
memset(dimingPattern,0x00, dimingTableSize * sizeof(uint32_t));
dimingPattern[0] = GPIO_PIN_8;// set pin 8
dimingPattern[50] = GPIO_PIN_8 << 16;// reset pin 8
HAL_DMA_Start(&hdma_tim2_ch2_ch4, (uint32_t)dimingPattern, (uint32_t)&(GPIOD->BSRR), dimingTableSize);
HAL_TIM_Base_Start(&htim2);
HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_2);
//TIM2->DIER |= (1 << 8); // set UDE bit (update dma request enable)
__HAL_TIM_ENABLE_DMA(&htim2, TIM_DMA_CC2);
I've tested the array and BSRR part simply using a for() loop to send the array, and the pin clearly toggles.
However using DMA, even if I set the first index in the array to set the pin, the pin remains reset, which indicates the DMA has done a single transfer
Can anyone see what I've done wrong.
BTW. I've tried other timers and other channels, but it didn't make any difference