STM32F103 USB powered AIO simpleFOC board bringup

hi, my boards arrived, they look great! figured I would make a forum post for visibility of process in bringing another community board up.
here is the project:

bringup is going OK so far, power is OK, programming is good, and I got the motor spinning (open loop) today.
I am having trouble with a few things:

  • working serial via STlink
  • working serial via USB

the problems are not simpleFOC issues but I am not familiar with stm32duino core, and we can’t use the STM32cube output so I’m hoping someone here knows. I can’t tell at this point how the serial USB is supposed to work. In my platformio.ini I have these build flags:

build_flags = 

monitor_dtr = 1

If instead of trying to use USB serial, I use the uart available on STlink, this is the output I get (115200 baud rate). So it is talking, but something is wrong. I am not sure what sort of parity to expect, I didn’t see any documents specifying what the standard HardwareSerial object uses.

1 Like

this is from STMcube and should set up the clock so that we have the 48MHz for USB. I am still not seeing any USB device. Maybe this has to do with missing some kind of bootloader? I’m not sure if I should put the maple core or what on here.

Oops! Looking at this I just found that I was previously using 8MHz but changed HSE to 12MHz for cheaper parts when ordering.

Fixing this does not seem to have done anything?

OK, trying to load the HID bootloader for STM32F103 GitHub - Serasidis/STM32_HID_Bootloader: Driverless USB HID bootloader and flashing tool for STM32F10X devices

but CLI flashing of board is not working, because it can’t find programmer … but STMcube finds it and also platformIO finds it…

st-info --probe
2023-03-29T19:13:34 WARN usb.c: skipping ST device : 0x483:0x3754)
Found 0 stlink programmers 

not sure why it would ignore ??

1 Like

How are you pulling the serial through the USB? Are you using a library?

Try lowering the baud rate, try matching the baud with the baud from the serial window. Usually this type of gibberish is speed/parity mismatch.

To be honest, I don’t know. With STMCube you can just configure this, and it sets everything up. For stm32duino, I have 0 idea how it is processing this. From what I saw around, I’m under impression that the build flags will enable USB as a virtual com port, which is what I’m after.

They are matching in that screenshot, but I will try lowering it. This is with HardwareSerial interface, not the USB one, which I’m still fine with for now because I’m just trying to verify all the hardware works.

When calling Serial.begin(speed,parity) you can add SERIAL_8N1 but this didn’t resolve the errors I had, I will slow it down. 9600 does not help. I’m confused why, because I’m the one in charge of the speed, I set platformIO and the driver to the same speed.

Let me know if you manage to do it since I’m not sure that’s how it works, without a fairly involved library. Usually I use a third party serial to USB component for that, such as CP2104 or something similar.

If you manage to make that one work, too, let us know. I haven’t tried this.


1 Like

I think some people have figured it out, especially since all of the “blue pill” and other various cheap devboards are doing direct USB to STM32:

But this is just UART, nothing fancy - but this is all I need. I was thinking about using CP2104 but I wanted to save some BOM cost since a primary goal for the project was to pinch pennies :stuck_out_tongue:

I guess I will brute force check all the standard UART speeds.

Yes, the maple core does it but that’s completely different and built directly into the maple core.

ah, I didn’t realize it’s a separate core. I thought it’s just an isolated bootloader. So maple core is incompatible with Arduino_STM_Core?

I thought this also would give you a COM port but after reading the page closer it doesn’t say that anywhere, although being able to flash new code over USB would suggest it is opening some kind of port.

No, this should give you a COM port too.

It doesn’t seem like any baud rate gives me good results…
I will take a look with my oscilloscope tomorrow and see if the serial decoding on that is any good.

OK, so development for st-link on macos has stopped, before they added support for stlink v3 minie (the programmer I’m using). hrm… maybe time to dust off the thinkpad. Or maybe I should just go buy a v2.

If you have an old nucleo board, use the V2 SWD STLink on the nucleo.

I’m confused. I use the STLink V3 Mini all the time on my Mac. It’s not a problem. You can use it from Arduino IDE, PlatformIO or of course STM32CubeProgrammer…

That’s for flashing the device, using the “stlink” connection/protocol, and with the STLink connected to the SWD pins of the target MCU.

For Serial IO, this is not automatic. The STLink (also the Mini V3) has an integrated virtual com port, which you can use if you route the RX/TX of your serial to the ST-Links inputs.

For Serial-USB, this also depends on the setup and all the #defines that control serial and USB support, but if you have set them up correctly, and the USB port is connected correctly, then the USB Serial should also work. I am not sure, but I don’t remember installing extra drivers for this on the Mac.

Yes, sorry - I meant to refer to the stlink-org/stlink open source programmer software. This is not supported with v3 minie (support added 1.7.1) (v3set is supported in their latest release 1.7.0) (macos support end with 1.7.0)

I can program via STMCube, arduino, and PlatformIO, but I can’t find a way to get those to just flash a specific bootloader. Do you know if it’s possible? I just wanted this other software to load the .bin provided in the HID bootloader project, but maybe that is the wrong way to go.

Yes, I have them routed out on my board to the STlink connector, my mac can find the USB device under /dev/tty.usbmodem102 so it is open as a com port, but the data that comes through is garbled. I will look with oscilloscope to see if the baud rate matches what I am setting and if I can decode real messages.

Yes, all the resources I saw say there should be no additional drivers on mac, this is why I was thinking it’s an issue with my board not opening the port right or anything - hoping that the bootloader would fix it.

hmm, I see. That’s strange. Normally this works without any additional circuitry. I’m not 100% sure, but I think the lines are Target_RX, and Target_TX, e.g. the lines aren’t crossed before connecting to the ST-Link…

I am not sure if the built-in boot loader on the F103 supports USB. I think maybe it doesn’t. So then you would have to flash a custom boot loader, or find one for the F103 that supports it and flash that. But you can’t mix maple boot loader with stm32duino for example. And you need a custom ldscript to handle flashing programs so that you don’t overwrite the boot loader each time… So it all gets complicated quickly.

You don’t need a custom boot loader for USB Serial comms. You can just flash via SWD and then use USB for Serial, normally.

Of course if Serial is working via the ST-Link, then you don’t really need to bother with USB. More convenient to just have one cable.

I put a little hack with 0R resistor to swap in case they are installed backwards, I might do that and see if it works…

It does not, it just supports UART upload over UART1 pins, the USB is not doing anything.

OK, good to know. I was worried that maybe this was why USB serial was not working. I will play with it a bit more later. Could you confirm if the DUSB_CON=1 and DPLATFORMIO_ARDUINO_ENABLE_CDC build flags are enough to use the USB as serial?
If you use these flags when you call Serial.begin does it just know to identify the USB as the interface port?


But I almost always use the STLink, so that might not be up-to-date info.

Hey, are you on a nightly version of KiCad? I just installed the newest MacOS version but I still can’t open your KiCad files :frowning:

1 Like

Maybe this can bring some help to solve your issue.

PS: I have tried to open you project using Kicked 7.0 on a MacOS and it is not possible .