3
$\begingroup$

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
$\endgroup$
6
  • $\begingroup$ So if you uncomment both uartStartSend(&UARTD2, 7, "Soom!\r\n"); and uartStartSend(&UARTD1, 7, "Boom!\r\n");, you get both outputs on UART1? $\endgroup$
    – Ian
    Jan 4 '16 at 21:48
  • $\begingroup$ USART2 also available on PA14 and PA15 pins, you should try those too. $\endgroup$ May 4 '16 at 8:44
  • $\begingroup$ The best option was to use a custom proto board to avoid all those conflicts. Thanks for the suggestion. CHeers $\endgroup$ May 10 '16 at 9:39
  • 1
    $\begingroup$ @user2967920, you can add a new answer with more details, and later accept it! That would help others with similar problem in the future. $\endgroup$
    – Shahbaz
    Jun 3 '16 at 20:37
  • $\begingroup$ @user2967920 - Did you ever resolve this? $\endgroup$
    – Chuck
    Dec 21 '18 at 19:19
1
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Jul 3 '15 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.