Live data from Hacker News

Bare Metal STM32 Programming and a Quadcopters Awakening

timakro.de

21–30 of 58 posts

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#21

Hi, interesting article, but I would like to suggest you something. While it's OK to do bare metal just using the memory locations like you did: *(uint32_t *)0x40021018 = 0x00000004; after a few days, it will become tiresome to read and to remember all those addresses. I suggest you to use the header [0] that the ST provides for STM32F1, which is included in packages such as STMCubeF1 [1], STMCubeF0, etc. For instanc…

>but you won't be using the API/drivers ST provides (such as HAL and LL), just the header. As I understand, the STM32 community kind of rejects this API as "bloated".

If you're not making millions of something (cost sensitive), and not running into performance issues with the HAL, just pick a microcontroller with more than enough flash and use the HAL provided by ST. It's faster to develop with, relatively robust, good performance, and it will make your code more portable. Writing directly to registers is the perfect example of premature optimization.

I've spent the last ~7 years writing firmware on the NXP LPC8xx/18xx and the STM32 L0/L4/F7/H7. In that time I've only found a couple of errors in the HALs provided, and only once or twice needed to re-write some HAL code to increase performance. Using the HALs from the vendor saved me an immense amount of development time and made porting code between chips trivial.

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#22

Ok, this drives me nuts ARGH! Seriously? The STM32F103? Crazy (or should that be Craze) hobbyists using "blue pill" boards because they are cheap (and they are, like $3 on ebay) which use this bastard chip of the ST Cortex-M line and they say "gee, its a really simple circuit and since they sell for so cheap on ebay it should be a good idea to use this chip!" BZZZZZZT! ST Micro makes much better CPUs that would be id…

Shoot the Crazepony people an email and ask about the PCB design files for their 'open source' quadcopter?

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#23
post #6

Keil has a completely free version of their compiler for STM32F0, STM32G0, and STM32L0 micros: https://www2.keil.com/stmicroelectronics-stm32/mdk

With regards to tooling, if you like Visual Studio and are working on ARM processors, I can't recommend VisualGDB enough: https://visualgdb.com/

It's not free ($189), but it removes so much friction from the embedded development process.

I'm not affiliated with the company, just a happy customer.

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#24
post #22

Ok, this drives me nuts ARGH! Seriously? The STM32F103? Crazy (or should that be Craze) hobbyists using "blue pill" boards because they are cheap (and they are, like $3 on ebay) which use this bastard chip of the ST Cortex-M line and they say "gee, its a really simple circuit and since they sell for so cheap on ebay it should be a good idea to use this chip!" BZZZZZZT! ST Micro makes much better CPUs that would be id…

Shoot the Crazepony people an email and ask about the PCB design files for their 'open source' quadcopter?

I did one better than that, I shot my ST Micro rep an email and asked them if they would like a open source design on the web that showcased their new STM32F4 series with built in Wireless support and their new STSPIN BLDC controllers with built in Cortex-M0s. He was quite taken with the idea :-)

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#25
post #22

Earlier quoted context omitted.

Shoot the Crazepony people an email and ask about the PCB design files for their 'open source' quadcopter?

I did one better than that, I shot my ST Micro rep an email and asked them if they would like a open source design on the web that showcased their new STM32F4 series with built in Wireless support and their new STSPIN BLDC controllers with built in Cortex-M0s. He was quite taken with the idea :-)

Quadcopter pilots have been using STM32F3 for years. Check out: https://github.com/betaflight/betaflight one of the more popular flight control projects. They've been supporting STM32F4 and STM32F7 for quite some time.

A typical quad flight controller with an STM32F4 and a decent MPU will set you back less than $30.

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#26
post #18
post #2

Little bit off topic, but if anyone is on the fence about STM32, I strongly suggest trying out STM32 Black pill 3.3V version ( https://wiki.stm32duino.com/images/5/52/Black_Pill_Schematic... ). It's an amazing board, Arduino-compatible, 72MHz, i/o, adc and pwm pins, uart and i2c. You can get it cheaper and just solder the header yourself. Even has a micro USB support. Truly remarkable board.

I'm not an expert wrt. the clocking of these boards, how does it achieve the 72MHz? In that datasheet it looks like the onboard crystal is just 8MHz. Does it use some kind of internal clock multiplier to achieve 72MHz? Would such a magnified 8MHz to 72MHz provide a good stable clock?

Pretty much all clocks in modern electronics above a few MHz are generated by PLL synthesis. The synthesizers are referenced to a slower clock crystal or something along those lines. You can go way beyond just multiplication, as well, with fractional synthesis. Check out the Si5351 for a chip that packs a couple of these synthesizers.

https://www.silabs.com/documents/public/data-sheets/Si5351-B...

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#27

Hi, interesting article, but I would like to suggest you something. While it's OK to do bare metal just using the memory locations like you did: *(uint32_t *)0x40021018 = 0x00000004; after a few days, it will become tiresome to read and to remember all those addresses. I suggest you to use the header [0] that the ST provides for STM32F1, which is included in packages such as STMCubeF1 [1], STMCubeF0, etc. For instanc…

    *(uint32_t *)0x40021018 = 0x00000004;

Actually that line is not ok. But for another reason. Without "volatile" in there, the compiler may reorder this access with others, or remove it, or combine it with others. None of that is good.

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#28
post #6

Keil has a completely free version of their compiler for STM32F0, STM32G0, and STM32L0 micros: https://www2.keil.com/stmicroelectronics-stm32/mdk

I cannot reccomend against Kiel, iar, and atollic enough. They are garbage ide's (can only do string based auto complete, no dark theme, very poor window management), yet still cost a small fortune if you want to go above 32KB of flash usage or whatever other the free versions do. They also have their version of a linker script which is even worse than normal linker scripts, and if you are forced to use their compiler then often it doesn't even handle c++11. Or if it does have c++, the auto complete doesn't.

Go for gcc or clang with cmake (or even just make) and use qt creator or visual studio code or others. You will get cmake based auto complete, access to a proper IDE color scheme of your choice, get to use your own compiler (clang, gcc, etc), and it's much more flexible. And for debugging be able to use a much more capable ozone from segger, or even gdb enabled backend in qt creator or clion.

My work flow for example is cmake and gcc regarding tooling, qt creator or visual studio code which works with cmake to give me proper context aware auto complete, and clang-tidy as a linter running in the background. I am incredibly productive with this, and am able to make use of c++17's features to go for true zero cost abstractions, while shifting checks from runtime to the compiler via types and static asserts and whatnot.

Plus, this is far more portable. No longer having to worry about project files working across diffirent versions of keil (this bit me in the ass at my last company). It's just a simple text file.

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#29

Hi, interesting article, but I would like to suggest you something. While it's OK to do bare metal just using the memory locations like you did: *(uint32_t *)0x40021018 = 0x00000004; after a few days, it will become tiresome to read and to remember all those addresses. I suggest you to use the header [0] that the ST provides for STM32F1, which is included in packages such as STMCubeF1 [1], STMCubeF0, etc. For instanc…

*(uint32_t *)0x40021018 = 0x00000004; Actually that line is not ok. But for another reason. Without "volatile" in there, the compiler may reorder this access with others, or remove it, or combine it with others. None of that is good.

That's a very important call-out. This is the kind of tear-your-hair-out stuff that's going to be very difficult to track down unless you get it exactly right. I echo that using the definitions makes the code infinitely more readable and writeable, and makes zero difference in terms of performance.

Re: Bare Metal STM32 Programming and a Quadcopters Awakening

#30

Ok, this drives me nuts ARGH! Seriously? The STM32F103? Crazy (or should that be Craze) hobbyists using "blue pill" boards because they are cheap (and they are, like $3 on ebay) which use this bastard chip of the ST Cortex-M line and they say "gee, its a really simple circuit and since they sell for so cheap on ebay it should be a good idea to use this chip!" BZZZZZZT! ST Micro makes much better CPUs that would be id…

I'm fairly certain all the blue pills that are cheap have a GD32F103 and not a ST chip.
Post reply on HN