I am trying to use the USB port of STM32F103C8T6 as it is a Serial port but I did not have any success until know. This question seams to be simple but it is not. What I want is that a command like Serial.print("...") send the data to USB and Serial.read(...) get the data from USB. Google does not know how. Existing Arduino forums neither. Does anybody have some idea about how to do that ? Thanks
You have to be very careful in setting the options correctly in the Tools tab when you upload. USB support must be set to "CDC (generic Serial supercede USART)", for that to work. I use this all the time, it works fine.
Thanks aarg. With your suggestion the compiler issues a lot of error messages such "undefined reference to `Serial2" ... I would like to have just one serial remaped to USB, such Serial1. The Roger Clark core underestand Serial1, 2 and 3 normally but I think the ST core version 1.9.0 do not. Would you please help ? Thanks
Great news... I have found in API - STM32duino wiki the following information about this issue:
------------------------------------------------------
Serial & USB Serial
Serial USB is enabled for all F103 boards when uploading using the bootloader, it is also available when uploading by ST-Link (SWD) In these cases:
** Serial.print("Hello world"); will print via Serial USB (CDC).**
- Serial1 prints to hardware USART 1*
- Serial2 prints to hardware USART 2*
- etc*
When uploading via "Serial" (external USB to Serial adaptor connected to PA9 and PA10 (USART1) on the STM32): - Serial.print("Hello world"); will print to hardware USART1 (the one the code was uploaded using)*
- Serial1 prints to hardware USART 2*
- etc*
Note. Some boards, e.g. Nucleo F103RB have special serial mapping, because these boards need to have hardware modification to make Serial usable.
The Serial <-> USART mapping is defined in file "variants//board.cpp".
------------------------------------------------------
It works does not matter which core are you using !!! I am using Roger Clark's core with 20K bootloader. I do not know if it works with the smaller bootloaders such 7k.
Bye bye
I'm usually using the ST core, and when USB serial is enabled, the other USART ports definitely work normally. I know that because I've used it for GPS while the USB serial provided a control interface.
As far as I know, you can upload using USB with the CDC serial enabled, I never had that problem. Really, it shouldn't make any difference except that there has to be a bootloader already loaded that supports it. If you are having problems with that, I don't know. I would have to try it.