Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 8 Replies) Getting SerialUSB to work on stm32 (Read 3240 times)
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Getting SerialUSB to work on stm32
Dec 29th, 2021 at 6:43pm
Print Post  
I have been using stm32f103 and stm32f4 series of boards successfully using stlink v2. (Blue Pill and Black Pill boards)

I would like to use the USB port as a serial coms port, using SerialUSB and the stm32duino tools.

Playing around with platformio, adding the build flag -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC got SerialUSB working. I was able to send messages out of the USB connector to the PC.

However, I can't work out where to add this build_flag in Visual Micro. I have played with project properties, but can't be doing it correctly.

What is the best way of adding this flag/option in Visual Micro?

Regards,

David
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 11676
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Getting SerialUSB to work on stm32
Reply #1 - Dec 30th, 2021 at 5:04am
Print Post  
Yes there are project properties for both defines and extra compiler flags. with extra compiler flags you can use exact same syntax.
  
Back to top
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Getting SerialUSB to work on stm32
Reply #2 - Dec 30th, 2021 at 2:00pm
Print Post  
I tried again today and I think the attached entry is working. 

I still get an error
"stm32_testblink.ino: In function void setup()
 
stm32_testblink.ino: 26:5: error: 'SerialUSB' was not declared in this scope; did you mean 'Serial6'?
   26 |     SerialUSB.begin()
   |     ^~~~~~~~~
   |     Serial6

So need to work out which include, other than Arduino.h is required.

Regards,

David
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 11676
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Getting SerialUSB to work on stm32
Reply #3 - Dec 30th, 2021 at 4:38pm
Print Post  
Well done. If you click vMicro>Show/Hide Hidden Files, that will add short cuts to the project for the underlying core. That does not affect compilation but it does make finding/exploring the underlying code easier.
  
Back to top
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Getting SerialUSB to work on stm32
Reply #4 - Dec 30th, 2021 at 5:00pm
Print Post  
For some reason I can't get it to work in Visual Micro. I think PlatformIO and Arduino use the same stm32duino core.

In platformio the Comport comes up immediately after uploading. In ArduinoIDE and Visual Micro nothing.

I upgraded to the latest stm32 core library in Arduino, but still nothing.

So not sure what the difference is.
Attached is my output log from VM to see if anything is obvious.

It compiles ok with Serial.begin(baudrate), but SerialUSB fails with the not defined message.

Regards,

David
« Last Edit: Dec 30th, 2021 at 5:01pm by davidbal »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 11676
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Getting SerialUSB to work on stm32
Reply #5 - Dec 30th, 2021 at 5:24pm
Print Post  
Did you look at the vMicro menu to see what board options are designed for the board you are using? There does look to be some built in support? This config shows in the output you posted which relates to the menu items provided by the core.

menu.xserial.generic=Enabled (generic 'Serial')
menu.xserial.none=Enabled (no generic 'Serial')
menu.xserial.none.build.xSerial=-DHAL_UART_MODULE_ENABLED -DHWSERIAL_NONE
menu.xserial.disabled=Disabled (no Serial support)
menu.xserial.disabled.build.xSerial=
menu.usb.none=None
menu.usb.CDCgen=CDC (generic 'Serial' supersede U(S)ART)
menu.usb.CDCgen.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC
menu.usb.CDC=CDC (no generic 'Serial')
menu.usb.CDC.build.enable_usb={build.usb_flags} -DUSBD_USE_CDC -DDISABLE_GENERIC_SERIALUSB
  
Back to top
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Getting SerialUSB to work on stm32
Reply #6 - Dec 30th, 2021 at 5:40pm
Print Post  
I have now got it to work in the Arduino IDE after some digging around I found the attached options in the Arduino IDE that I had not noticed.

Presumably there are similar in VM?

Regards,

David
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Getting SerialUSB to work on stm32
Reply #7 - Dec 30th, 2021 at 5:50pm
Print Post  
Found the setting in VM for the board Option 4 set to USBCDC. Easy when you know how. 

Serial.USB() is now working fine and I have removed the compiler flag as that isn't needed.

So I now have it Stm32f103 Serial USB working in VM, PlatformIO and Arduino.

Many thanks,

David
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 11676
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Getting SerialUSB to work on stm32
Reply #8 - Dec 30th, 2021 at 5:51pm
Print Post  
Exactly, that is why I asked this question in my last post

Did you look at the vMicro menu to see what board options are designed for the board you are using? 

The image shows three ways to see the board options. Two of them via the vMicro button either on menu or tool bar + right click the bar strip and there is a board options tool bar that can be displayed.
« Last Edit: Dec 30th, 2021 at 6:01pm by Tim@Visual Micro »  

Please Register or Login to the Forum to see File Attachments
Back to top
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Getting SerialUSB to work on stm32
Reply #9 - Dec 30th, 2021 at 6:10pm
Print Post  
Sure, but I wasn't aware of those options until now and that was the place to see USB settings.

You have to know what you are looking for to find it!

Anyway, after three months of wondering how to do this, it is now working.

Regards,

David
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 11676
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Getting SerialUSB to work on stm32
Reply #10 - Dec 30th, 2021 at 6:21pm
Print Post  
Good to hear you got it working. 

That is the place for any/all options that the tool chain provides. The options differ for every board, in the case of the stm32 package you have used they do include some usb settings but most other boards do not. 

The names of the options are read from the core/package config, they are unknown to the visual micro code other than option1, option2 etc.

As you can see, both Visual Micro and the Arduino IDE use the same configuration because the author of the stm32 package has adhered to the Arduino standard. 

This means that the github wiki page of the stm32 core that you installed will provide the documentation for the board options presented by their package. 

In short, the board options are different for every board/package, it is the authors of the board packages that decide what appears on the menus in the Arduino IDE and Visual Micro.

I hope this information helps you find the documentation more easily in the future.
  
Back to top
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Getting SerialUSB to work on stm32
Reply #11 - Dec 30th, 2021 at 9:49pm
Print Post  
I have looked at the stm32wiki and other places and couldn't find any details about this or the board options.

There is stuff about hardware serial, which I used to map pins to the serial ports for stm32f1 and stm32f4 boards. But nothing about using serial usb. Most of the blogs talk about using the USB in dfu mode for downloading.

I might write up my adventure for others to benefit.

Regards,

David
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 11676
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Getting SerialUSB to work on stm32
Reply #12 - Dec 30th, 2021 at 10:47pm
Print Post  
If you can give the url of the .json index file you registered for board manager I can take a look. The .json file will either be in arduino ide file>preferences or visual micro Ide Locations dialog.
  
Back to top
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Getting SerialUSB to work on stm32
Reply #13 - Dec 31st, 2021 at 12:27pm
Print Post  
« Last Edit: Dec 31st, 2021 at 12:29pm by davidbal »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 11676
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Getting SerialUSB to work on stm32
Reply #14 - Jan 1st, 2022 at 2:52am
Print Post  
Yes visual micro combines them. I agree there isn't much documentation, I guess they just expect people to know to look on the menu for options.
  
Back to top
WWW  
IP Logged
 
davidbal
Junior Member
**
Offline


Posts: 29
Joined: Dec 20th, 2015
Re: Getting SerialUSB to work on stm32
Reply #15 - Jan 1st, 2022 at 8:20am
Print Post  
And the forums are full of people having problems getting it to work. But you see no one saying use the menu selections. If you are used to the arduino you probably don't look at the menus. I haven't looked at them when using esp8266 either.

I might look at what is needed to add to the wiki.

Regards,

David
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 11676
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Getting SerialUSB to work on stm32
Reply #16 - Jan 1st, 2022 at 5:21pm
Print Post  
A lot of arduino boards have menus, especially teensy, esp8266 and esp32 but many others also. 

The board options have been in place for many years and are a big part of what makes arduino easier than other solutions. You will see that for the esp boards the file system (spiffs) is also controlled via the same options.

It is interesting to hear your experience and point of view. We will give some thought as to how we can reinforce the message thanks.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint