From 5eaebac8d8dce7060a91bf115f61afcdde0e2be2 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Fri, 2 Sep 2011 15:58:05 -0500 Subject: [PATCH] INS: Get the aux uart working. All F2 GPIO pins need to be remapped to work. Good thing to remember. --- flight/INS/inc/pios_config.h | 2 +- flight/INS/pios_board.c | 37 ++++++++++++++++++------------ flight/PiOS/Boards/STM32F2xx_INS.h | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/flight/INS/inc/pios_config.h b/flight/INS/inc/pios_config.h index 3526b48cb..2ce0d71db 100644 --- a/flight/INS/inc/pios_config.h +++ b/flight/INS/inc/pios_config.h @@ -45,7 +45,7 @@ #define PIOS_INCLUDE_SYS #define PIOS_INCLUDE_USART #define PIOS_INCLUDE_COM -//#define PIOS_INCLUDE_COM_AUX +#define PIOS_INCLUDE_COM_AUX #define PIOS_INCLUDE_GPS #define PIOS_INCLUDE_BMA180 #define PIOS_INCLUDE_HMC5883 diff --git a/flight/INS/pios_board.c b/flight/INS/pios_board.c index 90c2d643d..bc2a342ba 100644 --- a/flight/INS/pios_board.c +++ b/flight/INS/pios_board.c @@ -289,6 +289,7 @@ void PIOS_SPI_accel_irq_handler(void) */ static const struct pios_usart_cfg pios_usart_gps_cfg = { .regs = USART1, + .remap = GPIO_AF_USART1, .init = { .USART_BaudRate = 57600, .USART_WordLength = USART_WordLength_8b, @@ -328,6 +329,11 @@ static const struct pios_usart_cfg pios_usart_gps_cfg = { }, }; +#define PIOS_COM_AUX_TX_BUF_LEN 255 +static uint8_t pios_com_aux_tx_buffer[PIOS_COM_AUX_TX_BUF_LEN]; +#define PIOS_COM_AUX_RX_BUF_LEN 255 +static uint8_t pios_com_aux_rx_buffer[PIOS_COM_AUX_RX_BUF_LEN]; + #endif /* PIOS_INCLUDE_GPS */ #ifdef PIOS_INCLUDE_COM_AUX @@ -335,7 +341,8 @@ static const struct pios_usart_cfg pios_usart_gps_cfg = { * AUX USART */ static const struct pios_usart_cfg pios_usart_aux_cfg = { - .regs = USART4, + .regs = UART4, + .remap = GPIO_AF_UART4, .init = { .USART_BaudRate = 57600, .USART_WordLength = USART_WordLength_8b, @@ -347,14 +354,14 @@ static const struct pios_usart_cfg pios_usart_aux_cfg = { }, .irq = { .init = { - .NVIC_IRQChannel = USART4_IRQn, + .NVIC_IRQChannel = UART4_IRQn, .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH, .NVIC_IRQChannelSubPriority = 0, .NVIC_IRQChannelCmd = ENABLE, }, }, .rx = { - .gpio = GPIOB, + .gpio = GPIOC, .init = { .GPIO_Pin = GPIO_Pin_11, .GPIO_Speed = GPIO_Speed_2MHz, @@ -364,7 +371,7 @@ static const struct pios_usart_cfg pios_usart_aux_cfg = { }, }, .tx = { - .gpio = GPIOB, + .gpio = GPIOC, .init = { .GPIO_Pin = GPIO_Pin_10, .GPIO_Speed = GPIO_Speed_2MHz, @@ -375,6 +382,11 @@ static const struct pios_usart_cfg pios_usart_aux_cfg = { }, }; +#define PIOS_COM_GPS_TX_BUF_LEN 192 +static uint8_t pios_com_gps_tx_buffer[PIOS_COM_GPS_TX_BUF_LEN]; +#define PIOS_COM_GPS_RX_BUF_LEN 96 +static uint8_t pios_com_gps_rx_buffer[PIOS_COM_GPS_RX_BUF_LEN]; + #endif /* PIOS_COM_AUX */ @@ -382,15 +394,6 @@ static const struct pios_usart_cfg pios_usart_aux_cfg = { #include -#if 0 -#define PIOS_COM_AUX_TX_BUF_LEN 192 -static uint8_t pios_com_aux_tx_buffer[PIOS_COM_AUX_TX_BUF_LEN]; -#endif - -#define PIOS_COM_GPS_RX_BUF_LEN 96 -static uint8_t pios_com_gps_rx_buffer[PIOS_COM_GPS_RX_BUF_LEN]; - - #endif /* PIOS_INCLUDE_COM */ #if defined(PIOS_INCLUDE_I2C) @@ -732,16 +735,20 @@ void PIOS_Board_Init(void) { } if (PIOS_COM_Init(&pios_com_gps_id, &pios_usart_com_driver, pios_usart_gps_id, pios_com_gps_rx_buffer, sizeof(pios_com_gps_rx_buffer), - NULL, 0)) { + pios_com_gps_tx_buffer, sizeof(pios_com_gps_tx_buffer))) { PIOS_DEBUG_Assert(0); } #endif /* PIOS_INCLUDE_GPS */ #if defined(PIOS_INCLUDE_COM_AUX) + uint32_t pios_usart_aux_id; + if (PIOS_USART_Init(&pios_usart_aux_id, &pios_usart_aux_cfg)) { PIOS_DEBUG_Assert(0); } - if (PIOS_COM_Init(&pios_com_aux_id, &pios_usart_com_driver, pios_usart_aux_id)) { + if (PIOS_COM_Init(&pios_com_aux_id, &pios_usart_com_driver, pios_usart_aux_id, + pios_com_aux_rx_buffer, sizeof(pios_com_aux_rx_buffer), + pios_com_aux_tx_buffer, sizeof(pios_com_aux_tx_buffer))) { PIOS_DEBUG_Assert(0); } #endif /* PIOS_INCLUDE_COM_AUX */ diff --git a/flight/PiOS/Boards/STM32F2xx_INS.h b/flight/PiOS/Boards/STM32F2xx_INS.h index b0ac59b6c..cabf1b921 100644 --- a/flight/PiOS/Boards/STM32F2xx_INS.h +++ b/flight/PiOS/Boards/STM32F2xx_INS.h @@ -117,7 +117,7 @@ extern uint32_t pios_i2c_gyro_adapter_id; // See also pios_board.c //------------------------- #define PIOS_COM_MAX_DEVS 2 - +extern uint32_t pios_com_gps_id; extern uint32_t pios_com_aux_id; #define PIOS_COM_AUX (pios_com_aux_id) #define PIOS_COM_DEBUG PIOS_COM_AUX