USB Serial as a diagnostic channel

Post Reply
User avatar
AndySymons
Posts: 33
Joined: Tue Sep 25, 2018 6:34 pm

USB Serial as a diagnostic channel

Post by AndySymons » Wed Nov 14, 2018 6:30 pm

I am working with a 'bare board' STM32F103C8T chip, so with the original ST boot loader, and can download programs OK using STLink preceded by a manual reset. I would however like to set up a serial channel to my Mac computer so that I can send diagnostic messages using Serial.print(...) etc.

I have tried various cores -- STM32_Arduino, STM32GENERIC and STM32_Core_Arduino -- but have had no success. There is a message after download saying "Waiting for /dev/cu.usbmodem1411 serial ... Done", so it looks as if the chip thinks it is finished, but I cannot see a live USB channel from the Mac (using SerialTools as a terminal) and the oscilloscope is showing no signal on PA11 or PA12. I have a feeling I am missing something in the configuration of the STM32F1?

Does anyone have experience of using a diagnostic Serial channel with an STM32F1 and a Mac with SerialTools?

Cheers,

Andy

User avatar
mrburnette
Posts: 3001
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: USB Serial as a diagnostic channel

Post by mrburnette » Wed Nov 14, 2018 9:30 pm

I try to steer clear of the MacIntosh machines as I try to avoid Microsoft windows 10...
But using a Maple Mini on Linux, I have no issues using the serial console for debug... In fact, I leave the console "open" under Mint 18.3, make code changes, upload, and the serial console will automatically restart. Nice.

But, you may find this of interest:
http://stm32duinoforum.com/forum/index.php?title=API
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".
Ray

User avatar
AndySymons
Posts: 33
Joined: Tue Sep 25, 2018 6:34 pm

Re: USB Serial as a diagnostic channel

Post by AndySymons » Fri Nov 16, 2018 12:42 am

Mmm, thanks, I'm not quite ready to switch to Linux yet... ;)

I checked out the API link (assuming it describes the API applicable to Arduino_Core_STM32) but it describes it exactly as I am using it.

Arduino_Core_STM32 does not have a boards.cpp file like Arduino_STM32. UART seems to be configured in stm32f1xx_hal_uart.c, which is in ... system ... drivers ... It is defined for each processor and I have not touched it. Whether this also configures USB is not clear to me.

Everything compiles OK and the program is running setup() and loop(). I verify this by flashing an LED. The lack of any signal at all on the PA11 and PA12 pins, as shown by the oscilloscope, suggests to me some kind of pin mode initialisation error, or a failure to start the clock, but visual inspection has not thrown up any anomalies and the GPIO pin used for the LED, PC13, is clearly OK. So I am not sure about how to progress debugging any further!

BTW, I have the same problem with SPI, but I was going to try debugging that with Serial.print() !

Regards, Andy

fpiSTM
Posts: 722
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France
Contact:

Re: USB Serial as a diagnostic channel

Post by fpiSTM » Fri Nov 16, 2018 8:42 am

USB Serial is not release yet on Arduino_Core_STM32....

User avatar
RogerClark
Posts: 8416
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB Serial as a diagnostic channel

Post by RogerClark » Fri Nov 16, 2018 10:30 am

The libmaple core has USB serial, but its only enabled for certain types of uploads.

Its enabled if you select the stm32duino bootloader, or the STLink, but its not enabled for Serial upload (built in bootloader) or the BlackMagic Probe (as the BMP has its own hardware serial)

I can't remember how the drivers work on the Mac. But its all documented via links in the FAQ.

Post Reply