Forum > Embedded - ARM

STM32, startup and enable USB as Virtual COM port

(1/4) > >>

SymbolicFrank:
I think I can build a bootable image with the embedded version as installed through fpcupdeluxe.  :D

I checked the device and cpu configuration files, and they look pretty good, but they're only available for the common STM32F controllers. The ones I had weren't available.

I installed Arduino and the STM32 support, the devices I had were available and the simple program (flash the led) worked right away. But Arduino isn't a real development platform, it's for light hobby usage only.

I installed the (brand new) official STM32 development platform. At the start you have to run the STM32CubeMX tool, which generates the startup and initialization code. This is a mess of lots of .h files, with either a HAL (the default) or a Low Level interface. And I am talking about the LL interface, the HAL one is a maze. This generates a project with a lot of source files with in total about 20 lines of C code to initialize the clock sources. To enable the USB you have to use the HAL.

I hated that, so I installed the Open Source STM32 development platform, which allows you to program to the bare metal. When you create a project, it basically generates a single file with the startup code in assembly. I hunted down, translated and added the configuration of the clock sources from the CubeMX project.

This does work, and the debugging is flawless. But getting the USB to work like this is far too complex.

Next up, as I knew what I needed, I looked closer at the free pascal / Lazarus interface. It was not complete. For starters, all the FPUs are defined as: "fputype:fpu_soft". And while the larger controllers can have multiple banks of RAM and Flash (with different starting addresses), only continuous chunks seem to be supported. Fortunately, all the register names and addresses are there.  :)

The FPU should work if you fill in the right value, the startup code is there, and the supplied device files look like they are from before ST chopped them up and packaged them into LL and HAL chunks. But I would have to make my own for the devices I had.

I bought some new, supported devices and when they finally arrived, I could start programming them. Well, after generating and translating the CubeMX code that configures the clock sources. And activating the USB...

Ok, let me put it like this: a quarter of the Reference Manual for the STM32F401 is about the USB. It's complex. DIY is going to take a lot of time. Especially because the ST Virtual COM Port Driver has to recognize and understand it.

What would be the simplest way to get this to work? I'm going to try to generate the CubeMX project and see if I can get the IDE to compile it to assembly, and import that, but that will still be very time-consuming.

SymbolicFrank:
I now have 5 different kinds of STM32 boards, but it seems the board I was most enthusiastic about is already depreciated.

https://www.aliexpress.com/item/33014539711.html

They make a much improved, green "blue pill" board, and then they replace it with a black one that confirms to the much worse "official" specs.  :(

lucamar:
USB programming is complex. With normal OSs this complexity is hidden besides succesive layers of system code: device drivers, kernel libs, mid-layer libs, etc. but for embedded code w/out OS DIY is the way ... unless someone happens to have done it before for your particular platform, which you can google for.

Bare metal (and "almost-bare metal") programming has always been like this. Thank the gods for "the internets" and the acumulated expertise therein. ;)

SymbolicFrank:

--- Quote from: lucamar on June 24, 2019, 12:23:57 am ---USB programming is complex. With normal OSs this complexity is hidden besides succesive layers of system code: device drivers, kernel libs, mid-layer libs, etc. but for embedded code w/out OS DIY is the way ... unless someone happens to have done it before for your particular platform, which you can google for.

Bare metal (and "almost-bare metal") programming has always been like this. Thank the gods for "the internets" and the acumulated expertise therein. ;)

--- End quote ---

I wrote a low-level USB interface (Windows) and an USB driver (Linux) for some devices, and it was not a fun or fast experience. But I was hoping the microcontroller part would be better organized.

ST/Philips/Microchip: just !@#$%^& give us one assembly file for each complex device to configure, instead of a really hard to understand, use and massive library and documentation for each and every one that only works with C!

Edit: and I tend to always write a mini-OS with command-line interface for microcontrollers to make larger projects manageable.

Atmel did it right: turn on the power, and it actually works right away. And Microchip is the worst.

avra:

--- Quote from: SymbolicFrank on June 23, 2019, 11:41:06 pm ---What would be the simplest way to get this to work?
--- End quote ---
The simplest way would be to forget STM32 internal USB and use something external, like FTDI or CP210x. Or use MikroElektronika Pascal for STM32 and use their USB CDC implementation.


--- Quote from: SymbolicFrank on June 23, 2019, 11:41:06 pm ---I'm going to try to generate the CubeMX project and see if I can get the IDE to compile it to assembly, and import that, but that will still be very time-consuming.
--- End quote ---
Chances for incorporating generated asm and making it work properly with your pascal code are very slim, and even worse tied to a specific MCU. It is not a simple copy of generated asm for a single function. It is a whole framework. If there is a USB lib for some STM32 GCC based compiler then you might want to try to translate headers and link to it, but on STM32 embedded target you are on uncharted territory. You could also read all the USB docs and try to do it yourself, but some 15 years ago when I checked such an effort for an AVR would be 6+ months so STM32 would probably be similar. What I would do would be to find a STM32 USB CDC lib with acceptable license an try to convert it to FPC. Also lots of work, but doable. Quick search pointed me to something like this: https://github.com/ayushgaud/USB_Serial_Bridge/tree/master/Src. It would need some adaptation, but looks doable.

Since I am new to STM32, this link introduced me to USB CDC on it: https://damogranlabs.com/2018/02/stm32-usb-cdc/

Navigation

[0] Message Index

[#] Next page

Go to full version