mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-22 04:13:39 +08:00
[stm32] spektrum for F4
Not tested on an actual F4 board! Using some of the new gpio helper functions. Also removed seemingly useless DebugInit.
This commit is contained in:
@@ -33,7 +33,7 @@ GPS_LED ?= none
|
||||
SYS_TIME_LED ?= 1
|
||||
|
||||
#
|
||||
# default MODEM and GPS configuration
|
||||
# default UART configuration (modem, gps, spektrum)
|
||||
#
|
||||
|
||||
MODEM_PORT ?= UART1
|
||||
@@ -42,6 +42,8 @@ MODEM_BAUD ?= B57600
|
||||
GPS_PORT ?= UART4
|
||||
GPS_BAUD ?= B38400
|
||||
|
||||
RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT ?= UART2
|
||||
|
||||
|
||||
#
|
||||
# default actuator configuration
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "subsystems/radio_control.h"
|
||||
#include "subsystems/radio_control/spektrum_arch.h"
|
||||
#include "mcu_periph/uart.h"
|
||||
#include "mcu_periph/gpio.h"
|
||||
|
||||
#include BOARD_CONFIG
|
||||
|
||||
@@ -79,8 +80,11 @@ struct SpektrumStateStruct {
|
||||
typedef struct SpektrumStateStruct SpektrumStateType;
|
||||
|
||||
SpektrumStateType PrimarySpektrumState = {1,0,0,0,0,0,0,0,0,{0}};
|
||||
PRINT_CONFIG_VAR(RADIO_CONTROL_SPEKTRUM_PRIMARY_PORT)
|
||||
|
||||
#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
|
||||
PRINT_CONFIG_MSG("Using secondary spektrum receiver.")
|
||||
PRINT_CONFIG_VAR(RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT)
|
||||
SpektrumStateType SecondarySpektrumState = {1,0,0,0,0,0,0,0,0,{0}};
|
||||
#else
|
||||
PRINT_CONFIG_MSG("NOT using secondary spektrum receiver.")
|
||||
@@ -114,8 +118,7 @@ static uint8_t ExpectedFrames = 0;
|
||||
void SpektrumUartInit(void);
|
||||
/* initialise the timer used by the parser to ensure sync */
|
||||
void SpektrumTimerInit(void);
|
||||
/* sets a GPIO pin as output for debugging */
|
||||
void DebugInit(void);
|
||||
|
||||
void tim6_irq_handler(void);
|
||||
/* wait busy loop, microseconds */
|
||||
static void DelayUs( uint16_t uSecs );
|
||||
@@ -139,7 +142,6 @@ void radio_control_impl_init(void) {
|
||||
#endif
|
||||
|
||||
SpektrumTimerInit();
|
||||
// DebugInit();
|
||||
SpektrumUartInit();
|
||||
}
|
||||
|
||||
@@ -478,8 +480,14 @@ void SpektrumTimerInit( void ) {
|
||||
timer_set_prescaler(TIM6, ((AHB_CLK / TIM_FREQ_1000000) - 1));
|
||||
|
||||
/* Enable TIM6 interrupts */
|
||||
#ifdef STM32F1
|
||||
nvic_set_priority(NVIC_TIM6_IRQ, 2);
|
||||
nvic_enable_irq(NVIC_TIM6_IRQ);
|
||||
#elif defined STM32F4
|
||||
/* the define says DAC IRQ, but it is also the global TIM6 IRQ*/
|
||||
nvic_set_priority(NVIC_TIM6_DAC_IRQ, 2);
|
||||
nvic_enable_irq(NVIC_TIM6_DAC_IRQ);
|
||||
#endif
|
||||
|
||||
/* Enable TIM6 Update interrupt */
|
||||
timer_enable_irq(TIM6, TIM_DIER_UIE);
|
||||
@@ -494,7 +502,11 @@ void SpektrumTimerInit( void ) {
|
||||
* TIM6 interrupt request handler updates times used by SpektrumParser
|
||||
*
|
||||
*****************************************************************************/
|
||||
#ifdef STM32F1
|
||||
void tim6_isr( void ) {
|
||||
#elif defined STM32F4
|
||||
void tim6_dac_isr( void ) {
|
||||
#endif
|
||||
|
||||
timer_clear_flag(TIM6, TIM_SR_UIF);
|
||||
|
||||
@@ -513,7 +525,7 @@ void tim6_isr( void ) {
|
||||
*****************************************************************************/
|
||||
void SpektrumUartInit(void) {
|
||||
/* init RCC */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, PrimaryUart(_RCC_GPIO));
|
||||
gpio_enable_clock(PrimaryUart(_BANK));
|
||||
rcc_peripheral_enable_clock(PrimaryUart(_RCC_REG), PrimaryUart(_RCC_DEV));
|
||||
|
||||
/* Enable USART interrupts */
|
||||
@@ -522,10 +534,7 @@ void SpektrumUartInit(void) {
|
||||
|
||||
/* Init GPIOS */
|
||||
/* Primary UART Rx pin as floating input */
|
||||
gpio_set_mode(PrimaryUart(_BANK), GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_FLOAT, PrimaryUart(_PIN));
|
||||
|
||||
PrimaryUart(_REMAP);
|
||||
gpio_setup_pin_af(PrimaryUart(_BANK), PrimaryUart(_PIN), PrimaryUart(_AF), FALSE);
|
||||
|
||||
/* Configure Primary UART */
|
||||
usart_set_baudrate(PrimaryUart(_DEV), 115200);
|
||||
@@ -543,7 +552,7 @@ void SpektrumUartInit(void) {
|
||||
|
||||
#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
|
||||
/* init RCC */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, SecondaryUart(_RCC_GPIO));
|
||||
gpio_enable_clock(SecondaryUart(_BANK));
|
||||
rcc_peripheral_enable_clock(SecondaryUart(_RCC_REG), SecondaryUart(_RCC_DEV));
|
||||
|
||||
/* Enable USART interrupts */
|
||||
@@ -552,10 +561,7 @@ void SpektrumUartInit(void) {
|
||||
|
||||
/* Init GPIOS */;
|
||||
/* Secondary UART Rx pin as floating input */
|
||||
gpio_set_mode(SecondaryUart(_BANK), GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_FLOAT, SecondaryUart(_PIN));
|
||||
|
||||
SecondaryUart(_REMAP);
|
||||
gpio_setup_pin_af(SecondaryUart(_BANK), SecondaryUart(_PIN), SecondaryUart(_AF), FALSE);
|
||||
|
||||
/* Configure secondary UART */
|
||||
usart_set_baudrate(SecondaryUart(_DEV), 115200);
|
||||
@@ -618,19 +624,6 @@ void SecondaryUart(_ISR)(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Use pin to output debug information.
|
||||
*
|
||||
*****************************************************************************/
|
||||
void DebugInit(void) {
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
|
||||
|
||||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, GPIO5);
|
||||
gpio_clear(GPIOC, GPIO5);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
@@ -649,13 +642,9 @@ void DebugInit(void) {
|
||||
*****************************************************************************/
|
||||
void radio_control_spektrum_try_bind(void) {
|
||||
|
||||
/* init RCC */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, SPEKTRUM_BIND_PIN_RCC_IOP);
|
||||
|
||||
/* Init GPIO for the bind pin */
|
||||
gpio_set(SPEKTRUM_BIND_PIN_PORT, SPEKTRUM_BIND_PIN);
|
||||
gpio_set_mode(SPEKTRUM_BIND_PIN_PORT, GPIO_MODE_INPUT,
|
||||
GPIO_CNF_INPUT_PULL_UPDOWN, SPEKTRUM_BIND_PIN);
|
||||
gpio_setup_input(SPEKTRUM_BIND_PIN_PORT, GPIO_MODE_INPUT);
|
||||
|
||||
/* exit if the BIND_PIN is high, it needs to
|
||||
be pulled low at startup to initiate bind */
|
||||
if (gpio_get(SPEKTRUM_BIND_PIN_PORT, SPEKTRUM_BIND_PIN) != 0)
|
||||
@@ -665,22 +654,20 @@ void radio_control_spektrum_try_bind(void) {
|
||||
SpektrumDelayInit();
|
||||
|
||||
/* initialise the uarts rx pins as GPIOS */
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, PrimaryUart(_RCC_GPIO));
|
||||
gpio_enable_clock(PrimaryUart(_BANK));
|
||||
|
||||
/* Master receiver Rx push-pull */
|
||||
gpio_set_mode(PrimaryUart(_BANK), GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, PrimaryUart(_PIN));
|
||||
gpio_setup_output(PrimaryUart(_BANK), PrimaryUart(_PIN));
|
||||
|
||||
/* Master receiver RX line, drive high */
|
||||
gpio_set(PrimaryUart(_BANK), PrimaryUart(_PIN));
|
||||
|
||||
#ifdef RADIO_CONTROL_SPEKTRUM_SECONDARY_PORT
|
||||
|
||||
rcc_peripheral_enable_clock(&RCC_APB2ENR, SecondaryUart(_RCC_GPIO));
|
||||
gpio_enable_clock(SecondaryUart(_BANK));
|
||||
|
||||
/* Slave receiver Rx push-pull */
|
||||
gpio_set_mode(SecondaryUart(_BANK), GPIO_MODE_OUTPUT_50_MHZ,
|
||||
GPIO_CNF_OUTPUT_PUSHPULL, SecondaryUart(_PIN));
|
||||
gpio_setup_output(SecondaryUart(_BANK), SecondaryUart(_PIN));
|
||||
|
||||
/* Slave receiver RX line, drive high */
|
||||
gpio_set(SecondaryUart(_BANK), SecondaryUart(_PIN));
|
||||
|
||||
@@ -287,6 +287,14 @@
|
||||
/* The line that is pulled low at power up to initiate the bind process */
|
||||
#define SPEKTRUM_BIND_PIN GPIO8
|
||||
#define SPEKTRUM_BIND_PIN_PORT GPIOA
|
||||
#define SPEKTRUM_BIND_PIN_RCC_IOP RCC_AHB1ENR_IOPAEN
|
||||
|
||||
#define SPEKTRUM_UART2_RCC_REG &RCC_APB1ENR
|
||||
#define SPEKTRUM_UART2_RCC_DEV RCC_APB1ENR_USART2EN
|
||||
#define SPEKTRUM_UART2_BANK GPIOA
|
||||
#define SPEKTRUM_UART2_PIN GPIO3
|
||||
#define SPEKTRUM_UART2_AF GPIO_AF7
|
||||
#define SPEKTRUM_UART2_IRQ NVIC_USART2_IRQ
|
||||
#define SPEKTRUM_UART2_ISR usart2_isr
|
||||
#define SPEKTRUM_UART2_DEV USART2
|
||||
|
||||
#endif /* CONFIG_APOGEE_0_99_H */
|
||||
|
||||
@@ -388,6 +388,5 @@
|
||||
/* The line that is pulled low at power up to initiate the bind process */
|
||||
#define SPEKTRUM_BIND_PIN GPIO8
|
||||
#define SPEKTRUM_BIND_PIN_PORT GPIOA
|
||||
#define SPEKTRUM_BIND_PIN_RCC_IOP RCC_AHB1ENR_IOPAEN
|
||||
|
||||
#endif /* CONFIG_KROOZ_1_0_H */
|
||||
|
||||
@@ -75,9 +75,7 @@
|
||||
/* The line that is pulled low at power up to initiate the bind process */
|
||||
#define SPEKTRUM_BIND_PIN GPIO3
|
||||
#define SPEKTRUM_BIND_PIN_PORT GPIOC
|
||||
#define SPEKTRUM_BIND_PIN_RCC_IOP RCC_APB2ENR_IOPCEN
|
||||
|
||||
#define SPEKTRUM_UART1_RCC_GPIO RCC_APB2ENR_IOPAEN
|
||||
#define SPEKTRUM_UART1_RCC_REG &RCC_APB2ENR
|
||||
#define SPEKTRUM_UART1_RCC_DEV RCC_APB2ENR_USART1EN
|
||||
#define SPEKTRUM_UART1_BANK GPIO_BANK_USART1_RX
|
||||
@@ -87,7 +85,6 @@
|
||||
#define SPEKTRUM_UART1_DEV USART1
|
||||
#define SPEKTRUM_UART1_REMAP {}
|
||||
|
||||
#define SPEKTRUM_UART3_RCC_GPIO RCC_APB2ENR_IOPCEN
|
||||
#define SPEKTRUM_UART3_RCC_REG &RCC_APB1ENR
|
||||
#define SPEKTRUM_UART3_RCC_DEV RCC_APB1ENR_USART3EN
|
||||
#define SPEKTRUM_UART3_BANK GPIO_BANK_USART3_PR_RX
|
||||
@@ -97,7 +94,6 @@
|
||||
#define SPEKTRUM_UART3_DEV USART3
|
||||
#define SPEKTRUM_UART3_REMAP {AFIO_MAPR |= AFIO_MAPR_USART3_REMAP_PARTIAL_REMAP;}
|
||||
|
||||
#define SPEKTRUM_UART5_RCC_GPIO RCC_APB2ENR_IOPDEN
|
||||
#define SPEKTRUM_UART5_RCC_REG &RCC_APB1ENR
|
||||
#define SPEKTRUM_UART5_RCC_DEV RCC_APB1ENR_UART5EN
|
||||
#define SPEKTRUM_UART5_BANK GPIO_BANK_UART5_RX
|
||||
|
||||
@@ -58,37 +58,33 @@
|
||||
/* The line that is pulled low at power up to initiate the bind process */
|
||||
#define SPEKTRUM_BIND_PIN GPIO3
|
||||
#define SPEKTRUM_BIND_PIN_PORT GPIOC
|
||||
#define SPEKTRUM_BIND_PIN_RCC_IOP RCC_APB2ENR_IOPCEN
|
||||
|
||||
#define SPEKTRUM_UART1_RCC_GPIO RCC_APB2ENR_IOPAEN
|
||||
#define SPEKTRUM_UART1_RCC_REG &RCC_APB2ENR
|
||||
#define SPEKTRUM_UART1_RCC_DEV RCC_APB2ENR_USART1EN
|
||||
#define SPEKTRUM_UART1_BANK GPIO_BANK_USART1_RX
|
||||
#define SPEKTRUM_UART1_PIN GPIO_USART1_RX
|
||||
#define SPEKTRUM_UART1_AF 0
|
||||
#define SPEKTRUM_UART1_IRQ NVIC_USART1_IRQ
|
||||
#define SPEKTRUM_UART1_ISR usart1_isr
|
||||
#define SPEKTRUM_UART1_DEV USART1
|
||||
#define SPEKTRUM_UART1_REMAP {}
|
||||
|
||||
#define SPEKTRUM_UART3_RCC_GPIO RCC_APB2ENR_IOPCEN
|
||||
#define SPEKTRUM_UART3_RCC_REG &RCC_APB1ENR
|
||||
#define SPEKTRUM_UART3_RCC_DEV RCC_APB1ENR_USART3EN
|
||||
#define SPEKTRUM_UART3_BANK GPIO_BANK_USART3_PR_RX
|
||||
#define SPEKTRUM_UART3_PIN GPIO_USART3_PR_RX
|
||||
#define SPEKTRUM_UART3_AF AFIO_MAPR_USART3_REMAP_PARTIAL_REMAP
|
||||
#define SPEKTRUM_UART3_IRQ NVIC_USART3_IRQ
|
||||
#define SPEKTRUM_UART3_ISR usart3_isr
|
||||
#define SPEKTRUM_UART3_DEV USART3
|
||||
#define SPEKTRUM_UART3_REMAP {AFIO_MAPR |= AFIO_MAPR_USART3_REMAP_PARTIAL_REMAP;}
|
||||
|
||||
#define SPEKTRUM_UART5_RCC_GPIO RCC_APB2ENR_IOPDEN
|
||||
#define SPEKTRUM_UART5_RCC_REG &RCC_APB1ENR
|
||||
#define SPEKTRUM_UART5_RCC_DEV RCC_APB1ENR_UART5EN
|
||||
#define SPEKTRUM_UART5_BANK GPIO_BANK_UART5_RX
|
||||
#define SPEKTRUM_UART5_PIN GPIO_UART5_RX
|
||||
#define SPEKTRUM_UART5_AF 0
|
||||
#define SPEKTRUM_UART5_IRQ NVIC_UART5_IRQ
|
||||
#define SPEKTRUM_UART5_ISR uart5_isr
|
||||
#define SPEKTRUM_UART5_DEV UART5
|
||||
#define SPEKTRUM_UART5_REMAP {}
|
||||
|
||||
|
||||
/* PPM
|
||||
|
||||
Reference in New Issue
Block a user