I am trying to use 2x UARTs with ChibiOS on the STM32F072RB Nucleo Board.
I initialized UART2 but I am still getting output on UART1 pins, which is totally weird.
#include "ch.h"
#include "hal.h"
/*
* UART driver configuration structure.
*/
static UARTConfig uart_cfg_1 = {
NULL, //txend1,
NULL, //txend2,
NULL, //rxend,
NULL, //rxchar,
NULL, //rxerr,
800000,
0,
0, //USART_CR2_LINEN,
0
};
static UARTConfig uart_cfg_2 = {
NULL, //txend1,
NULL, //txend2,
NULL, //rxend,
NULL, //rxchar,
NULL, //rxerr,
800000,
0,
0,
0
};
/*
* Application entry point.
*/
int main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
/*
* Activates the serial driver 1, PA9 and PA10 are routed to USART1.
*/
//uartStart(&UARTD1, &uart_cfg_1);
uartStart(&UARTD2, &uart_cfg_2);
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1)); // USART1 TX.
palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(1)); // USART1 RX.
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(1)); // USART2 TX.
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(1)); // USART2 RX.
/*
* Starts the transmission, it will be handled entirely in background.
*/
//uartStartSend(&UARTD1, 13, "Starting...\r\n");
uartStartSend(&UARTD2, 13, "Starting...\r\n");
/*
* Normal main() thread activity, in this demo it does nothing.
*/
while (true) {
chThdSleepMilliseconds(500);
uartStartSend(&UARTD2, 7, "Soom!\r\n");
//uartStartSend(&UARTD1, 7, "Boom!\r\n");
}
}
The line uartStartSend(&UARTD2, 7, "Soom!\r\n");
gives output on UART1.
Is there anything else I need to do?
mcuconfig.h reads
#define STM32_UART_USE_USART1 TRUE
#define STM32_UART_USE_USART2 TRUE
#define STM32_UART_USART1_IRQ_PRIORITY 3
#define STM32_UART_USART2_IRQ_PRIORITY 3
#define STM32_UART_USART1_DMA_PRIORITY 0
#define STM32_UART_USART2_DMA_PRIORITY 0
uartStartSend(&UARTD2, 7, "Soom!\r\n");
anduartStartSend(&UARTD1, 7, "Boom!\r\n");
, you get both outputs on UART1? $\endgroup$