3

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
Bence Kaulics
  • 633
  • 1
  • 6
  • 26
user2967920
  • 399
  • 2
  • 10
  • So if you uncomment both uartStartSend(&UARTD2, 7, "Soom!\r\n"); and uartStartSend(&UARTD1, 7, "Boom!\r\n");, you get both outputs on UART1? – Ian Jan 04 '16 at 21:48
  • USART2 also available on PA14 and PA15 pins, you should try those too. – Bence Kaulics May 04 '16 at 08:44
  • The best option was to use a custom proto board to avoid all those conflicts. Thanks for the suggestion. CHeers – user2967920 May 10 '16 at 09:39
  • 1
    @user2967920, you can add a new answer with more details, and later accept it! That would help others with similar problem in the future. – Shahbaz Jun 03 '16 at 20:37
  • @user2967920 - Did you ever resolve this? – Chuck Dec 21 '18 at 19:19
  • We made our own dev board and proceeded, the Nucleo board was conflicting with some pins we needed to use as well. – user2967920 Jan 17 '19 at 04:14

1 Answers1

1

Perhaps try UART3? UART2 might be in use for something else as the manual says,

"By default the USART2 communication between the target MCU and ST-LINK MCU is enabled..." on page 23, section 5.8.

Manual for reference

Matt Brown
  • 328
  • 1
  • 7
  • UART2 Is shared with the STLnk BUS, so i am trying to get UART3 to work. I am stuck in a unhandled exception phase now need to sort out the vector tables and isr numbers. – user2967920 Jul 03 '15 at 13:31