5 years, 6 months ago.

Serial2 is not working.

Hi

I want use Serial1 and Serial2 at the same time to control two UART device. On NUCLEO-F042K6, Below code was working when gps pin is PB_6, PB_7 or PA_9, PA_10 as Serial1. But it won't work when PA_2, PA_3 as Serial2.

There is only one difference is Pin Assign. Can you think of any reasons?

thanks.

include the mbed library with this snippet

#include "mbed.h"

Serial gps(PA_2, PA_3);       // TX, RX
Serial pc(USBTX, USBRX);    // TX, RX

int main() {
    gps.baud(9600);
    pc.baud(115200);
    pc.printf("START DEMO\n");
    while (1) {
         char c = gps.getc();
        pc.printf(c);
    }
}

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F042K6T6 microcontroller.

1 Answer

5 years, 6 months ago.

Hello Sako-san,

It's because USBTX = PA_2 (USBTX and PA_2 are actually the same pin) and this pin is physically (over a solder bridge) connected to the STM32F103CBT6 chip, which provides the virtual serial port functionality over the USB connector with your PC. If you connect three serial lines one another (STM32F046K6, STM32F103CBT6 and the GPS) the serial communication will stop working.
See also https://os.mbed.com/questions/82683/How-can-I-use-UART2-on-Mbed-with-F030R8/#answer15433.

Thanks, Zoltan!

Well, you reply means until using USB, I cannot use PA_2, right? if it the case that how I can debug it when debug on using Serial 1 and Serial 2? Do I should use JTAG/SWD device?

Can you please explain this problem in further detail?

And thank you for reply #answer15433.

posted by sako sako 16 Oct 2018
  • One option is exporting your project to an external tool which supports debugging and then debug offline. The USB connection with your PC provides three functions:
    • Programming
    • Virtual serial port
    • Debugging.
      So you will not need an additional external JTAG/SWD device for debugging because that is already built into your NUCLEO-F030R8 board and connected to the MCU. You can then simply debug over the USB cable connected to your PC.
  • Another alternative is to use a software serial port (for example this one) either for the GPS or for the BLE device.
posted by Zoltan Hudak 16 Oct 2018