STM32F3 - Fix LED Strip hardware initialisation.

This commit is contained in:
Dominic Clifton 2015-01-12 22:01:45 +00:00
parent 4e0cdf5e86
commit b6ac9204d3
6 changed files with 58 additions and 8 deletions

View File

@ -35,13 +35,16 @@ void ws2811LedStripHardwareInit(void)
#ifdef CC3D
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
#else
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* GPIOA Configuration: TIM3 Channel 1 as alternate function push-pull */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
@ -52,6 +55,7 @@ void ws2811LedStripHardwareInit(void)
/* Compute the prescaler value */
prescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 29; // 800kHz
TIM_TimeBaseStructure.TIM_Prescaler = prescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
@ -59,6 +63,7 @@ void ws2811LedStripHardwareInit(void)
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration: Channel1 */
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
@ -75,6 +80,7 @@ void ws2811LedStripHardwareInit(void)
/* DMA1 Channel6 Config */
DMA_DeInit(DMA1_Channel6);
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&TIM3->CCR1;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ledStripDMABuffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;

View File

@ -27,9 +27,11 @@
#include "drivers/light_ws2811strip.h"
#ifndef WS2811_GPIO
#define USE_LED_STRIP_ON_DMA1_CHANNEL3
#define WS2811_GPIO GPIOB
#define WS2811_GPIO_AHB_PERIPHERAL RCC_AHBPeriph_GPIOB
#define WS2811_PIN Pin_8 // TIM16_CH1
#define WS2811_GPIO_AF GPIO_AF_1
#define WS2811_PIN GPIO_Pin_8 // TIM16_CH1
#define WS2811_PIN_SOURCE GPIO_PinSource8
#define WS2811_TIMER TIM16
#define WS2811_TIMER_APB2_PERIPHERAL RCC_APB2Periph_TIM16
@ -48,9 +50,10 @@ void ws2811LedStripHardwareInit(void)
RCC_AHBPeriphClockCmd(WS2811_GPIO_AHB_PERIPHERAL, ENABLE);
GPIO_PinAFConfig(WS2811_GPIO, WS2811_PIN_SOURCE, GPIO_AF_1);
GPIO_PinAFConfig(WS2811_GPIO, WS2811_PIN_SOURCE, WS2811_GPIO_AF);
/* Configuration alternate function push-pull */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = WS2811_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
@ -60,9 +63,11 @@ void ws2811LedStripHardwareInit(void)
RCC_APB2PeriphClockCmd(WS2811_TIMER_APB2_PERIPHERAL, ENABLE);
/* Compute the prescaler value */
prescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 29; // 800kHz
TIM_TimeBaseStructure.TIM_Prescaler = prescalerValue;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
@ -70,6 +75,7 @@ void ws2811LedStripHardwareInit(void)
TIM_TimeBaseInit(WS2811_TIMER, &TIM_TimeBaseStructure);
/* PWM1 Mode configuration */
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
@ -87,6 +93,7 @@ void ws2811LedStripHardwareInit(void)
/* DMA1 Channel Config */
DMA_DeInit(WS2811_DMA_CHANNEL);
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&WS2811_TIMER->CCR1;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ledStripDMABuffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
@ -117,6 +124,7 @@ void ws2811LedStripHardwareInit(void)
ws2811UpdateStrip();
}
#ifdef USE_LED_STRIP_ON_DMA1_CHANNEL3
void DMA1_Channel3_IRQHandler(void)
{
if (DMA_GetFlagStatus(DMA1_FLAG_TC3)) {
@ -125,8 +133,20 @@ void DMA1_Channel3_IRQHandler(void)
DMA_ClearFlag(DMA1_FLAG_TC3); // clear DMA1 Channel transfer complete flag
}
}
#endif
#if 0
#ifdef USE_LED_STRIP_ON_DMA1_CHANNEL2
void DMA1_Channel2_IRQHandler(void)
{
if (DMA_GetFlagStatus(DMA1_FLAG_TC2)) {
ws2811LedDataTransferInProgress = 0;
DMA_Cmd(DMA1_Channel2, DISABLE); // disable DMA channel
DMA_ClearFlag(DMA1_FLAG_TC2); // clear DMA1 Channel transfer complete flag
}
}
#endif
#ifdef USE_LED_STRIP_ON_DMA1_CHANNEL7
void DMA1_Channel7_IRQHandler(void)
{
if (DMA_GetFlagStatus(DMA1_FLAG_TC7)) {

View File

@ -337,8 +337,8 @@ pwmOutputConfiguration_t *pwmInit(drv_pwm_config_t *init)
if (init->useLEDStrip) {
if (timerHardwarePtr->tim == LED_STRIP_TIMER)
continue;
#if defined(WS2811_GPIO) && defined(WS2811_PIN)
if (timerHardwarePtr->gpio == WS2811_GPIO && timerHardwarePtr->pin == WS2811_PIN)
#if defined(STM32F303xC) && defined(WS2811_GPIO) && defined(WS2811_PIN_SOURCE)
if (timerHardwarePtr->gpio == WS2811_GPIO && timerHardwarePtr->gpioPinSource == WS2811_PIN_SOURCE)
continue;
#endif
}

View File

@ -338,6 +338,7 @@ void DMA1_Channel7_IRQHandler(void)
#endif
// USART3 Tx DMA Handler
#ifdef USE_USART2_TX_DMA
void DMA1_Channel2_IRQHandler(void)
{
uartPort_t *s = &uartPort3;
@ -345,6 +346,8 @@ void DMA1_Channel2_IRQHandler(void)
DMA_Cmd(DMA1_Channel2, DISABLE);
handleUsartTxDma(s);
}
#endif
void usartIrqHandler(uartPort_t *s)
{

View File

@ -69,7 +69,23 @@
#define GPS
#define LED_STRIP
#if 1
#define LED_STRIP_TIMER TIM16
#else
// alternative LED strip configuration, tested working.
#define LED_STRIP_TIMER TIM1
#define USE_LED_STRIP_ON_DMA1_CHANNEL2
#define WS2811_GPIO GPIOA
#define WS2811_GPIO_AHB_PERIPHERAL RCC_AHBPeriph_GPIOA
#define WS2811_GPIO_AF GPIO_AF_6
#define WS2811_PIN GPIO_Pin_8
#define WS2811_PIN_SOURCE GPIO_PinSource8
#define WS2811_TIMER TIM1
#define WS2811_TIMER_APB2_PERIPHERAL RCC_APB2Periph_TIM1
#define WS2811_DMA_CHANNEL DMA1_Channel2
#define WS2811_IRQ DMA1_Channel2_IRQn
#endif
#define BLACKBOX
#define TELEMETRY

View File

@ -97,9 +97,11 @@
// LED strip configuration using PWM motor output pin 5.
#define LED_STRIP_TIMER TIM16
#define USE_LED_STRIP_ON_DMA1_CHANNEL3
#define WS2811_GPIO GPIOA
#define WS2811_GPIO_AHB_PERIPHERAL RCC_AHBPeriph_GPIOA
#define WS2811_PIN Pin_6 // TIM16_CH1
#define WS2811_GPIO_AF GPIO_AF_1
#define WS2811_PIN GPIO_Pin_6 // TIM16_CH1
#define WS2811_PIN_SOURCE GPIO_PinSource6
#define WS2811_TIMER TIM16
#define WS2811_TIMER_APB2_PERIPHERAL RCC_APB2Periph_TIM16
@ -108,12 +110,15 @@
#endif
#if 0
// Alternate LED strip pin - FIXME for some reason the DMA IRQ Transfer Complete is never called.
// Alternate LED strip pin
// FIXME DMA IRQ Transfer Complete is never called because the TIM17_DMA_RMP needs to be set in SYSCFG_CFGR1
#define LED_STRIP_TIMER TIM17
#define USE_LED_STRIP_ON_DMA1_CHANNEL7
#define WS2811_GPIO GPIOA
#define WS2811_GPIO_AHB_PERIPHERAL RCC_AHBPeriph_GPIOA
#define WS2811_PIN Pin_7 // TIM17_CH1
#define WS2811_GPIO_AF GPIO_AF_1
#define WS2811_PIN GPIO_Pin_7 // TIM17_CH1
#define WS2811_PIN_SOURCE GPIO_PinSource7
#define WS2811_TIMER TIM17
#define WS2811_TIMER_APB2_PERIPHERAL RCC_APB2Periph_TIM17