Author Topic: STM32 where to start?  (Read 497 times)

0 Members and 1 Guest are viewing this topic.

Online bd139

  • Super Contributor
  • ***
  • Posts: 13564
  • Country: gb
STM32 where to start?
« on: March 21, 2020, 10:59:51 pm »
Ok I’m not new to STM32. I got a nucleo32-412KB board and managed to build something not totally insignificant so far (FreeRTOS/I2C/LED mux etc) but it has been quite frankly horrible. I come from an AVR-gcc background and I need more grunt and a decent debugger.

Problem so far have been mostly related to the CubeMX stuff which periodically just toasts everything I have done when I change pin config. Also the board itself is an arduino compatible unit which has solder links and stuff all over it and some damn weird behaviour which took me ages to work out. Also HAL is horrible.

So the question is where can I find something with the following requirements;

1. Not too big STM32. Something that FreeRTOS will be happy on. Five tasks, 64k or so flash (mostly LUT), not much stack. I2C, 24 GPIO pins, not a lot more. Long lifetime so I don’t have to throw everything in the bin in the near future.
2. On a dead simple breakout board with crystals and external ST Link that doesn’t pretend to be arduino friendly.
3. Command line tool chain for Linux.

If anyone has any references or pointers or better ideas I’d appreciate it.  :-+
 

Online krish2487

  • Frequent Contributor
  • **
  • Posts: 441
  • Country: dk
Re: STM32 where to start?
« Reply #1 on: March 25, 2020, 10:31:29 am »
Ok I’m not new to STM32. I got a nucleo32-412KB board and managed to build something not totally insignificant so far (FreeRTOS/I2C/LED mux etc) but it has been quite frankly horrible. I come from an AVR-gcc background and I need more grunt and a decent debugger.

Problem so far have been mostly related to the CubeMX stuff which periodically just toasts everything I have done when I change pin config. Also the board itself is an arduino compatible unit which has solder links and stuff all over it and some damn weird behaviour which took me ages to work out. Also HAL is horrible.

So the question is where can I find something with the following requirements;

1. Not too big STM32. Something that FreeRTOS will be happy on. Five tasks, 64k or so flash (mostly LUT), not much stack. I2C, 24 GPIO pins, not a lot more. Long lifetime so I don’t have to throw everything in the bin in the near future.
2. On a dead simple breakout board with crystals and external ST Link that doesn’t pretend to be arduino friendly.
3. Command line tool chain for Linux.

If anyone has any references or pointers or better ideas I’d appreciate it.  :-+

Hello, I have seen this thread a couple of days and made note mentally to get back to it.. but got distracted with something else.

I do not have any specific advice except for the STM32cube nuking user code part.

The CubeMX software has
Code: [Select]
// User code here

//Exit user code here

sections in the boilerplate code generated. If your code is present in there.. then any regeneration after modification should preserve the user code.
It has been a while since I worked with CubeMX but this is what I recall was the behaviour!
Hope this helps..
If god made us in his image,
and we are this stupid
then....
 

Online bd139

  • Super Contributor
  • ***
  • Posts: 13564
  • Country: gb
Re: STM32 where to start?
« Reply #2 on: March 25, 2020, 11:35:34 am »
Thanks for the reply. I got that far. Occasionally it nukes stuff inside the marked up blocks which is annoying.  :(
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2024
  • Country: au
Re: STM32 where to start?
« Reply #3 on: March 25, 2020, 12:04:06 pm »
So the question is where can I find something with the following requirements;

1. Not too big STM32. Something that FreeRTOS will be happy on. Five tasks, 64k or so flash (mostly LUT), not much stack. I2C, 24 GPIO pins, not a lot more. Long lifetime so I don’t have to throw everything in the bin in the near future.
2. On a dead simple breakout board with crystals and external ST Link that doesn’t pretend to be arduino friendly.
3. Command line tool chain for Linux.

1&2. I've used the f4's with FReeRTOS without a problem in particular the f407 and f429. You can get the STM32F4DISCOVERY dev boards for cheap, they're going for around $20 and have an on board stlink which can be used for the onboard MCU and for external mcu's

3. GNU ARM Toolchain should do the trick. It's a gcc fork by ARM. I originally set up a command line environment on windows so it should be a breeze on a linux machine. Some loathe gdb but I find it works well both on the cmd line and through eclipse, which is now my main setup.

Unfortunately, for me at least, all of the stuff I've developed is based on the old std peripherals libraries and newer chips such as the f7's don't have the std periph libs so you have to bite the bullet and go with cubemx.
Apparently you can just use the low level funcs and avoid all the abstracted stuff. Having said that the last time I looked people were saying cubemx had improved. At any rate if you want to use some of the more complex peripherals you're probably going to have to suffer hal unless you want to roll your own libs
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 4688
  • Country: fr
Re: STM32 where to start?
« Reply #4 on: March 25, 2020, 03:19:53 pm »
As I repeatedly say - don't use CubeMX. Done. You may have a slightly steeper learning curve at first, but you'll quickly be glad you made the switch.
 

Online bd139

  • Super Contributor
  • ***
  • Posts: 13564
  • Country: gb
Re: STM32 where to start?
« Reply #5 on: March 25, 2020, 03:31:13 pm »
Yeah I'm done with that now. I've managed to get some stuff up from bare metal now compiling with GCC and makefile. Thanks for help so far everyone. Much appreciated.

Now onto working out how to program / debug the device!

 

Online krish2487

  • Frequent Contributor
  • **
  • Posts: 441
  • Country: dk
Re: STM32 where to start?
« Reply #6 on: March 25, 2020, 04:18:20 pm »
Also,
just look into libopencm3.
It is fairly mature and supports a lot of STM32 families. And the learning curve is not too steep.
:-)
If god made us in his image,
and we are this stupid
then....
 
The following users thanked this post: bd139

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 4688
  • Country: fr
Re: STM32 where to start?
« Reply #7 on: March 25, 2020, 05:22:05 pm »
Yeah I'm done with that now. I've managed to get some stuff up from bare metal now compiling with GCC and makefile. Thanks for help so far everyone. Much appreciated.

Now onto working out how to program / debug the device!

Have fun! :-+
 
The following users thanked this post: bd139

Offline Karel

  • Super Contributor
  • ***
  • Posts: 1466
  • Country: 00
Re: STM32 where to start?
« Reply #8 on: March 25, 2020, 08:41:29 pm »
I guess you'll need also this:

Code: [Select]
git clone --depth 1 --no-checkout https://github.com/STMicroelectronics/STM32CubeF4.git

git checkout HEAD Drivers/CMSIS/Core/Include

git checkout HEAD Drivers/CMSIS/Device/ST/STM32F4xx/Include

Those are the header files that describes the internal of the MCU.

You'll also need some minimal startup code and a linker file.

I use the ones generated by System Workbench and adapted them to my needs.

I also use a modified makefile that once was generated by it as well. It speeds up things a lot.
 
The following users thanked this post: krish2487, bd139

Online krish2487

  • Frequent Contributor
  • **
  • Posts: 441
  • Country: dk
Re: STM32 where to start?
« Reply #9 on: March 25, 2020, 09:06:48 pm »
@karel
It looks very very interesting and promising. If it is not too much trouble, can you post a simple Blinky example using the files you have mentioned??
I would like to go more bare metal than libopencm3, and this looks like the way. But I am not so much proficient with linker scripts and makefiles.
I am looking for a barebones example that I can adapt to other families that I use and work with.
:-)

Thank you and my apologies for hijacking the thread.

I guess you'll need also this:

Code: [Select]
git clone --depth 1 --no-checkout https://github.com/STMicroelectronics/STM32CubeF4.git

git checkout HEAD Drivers/CMSIS/Core/Include

git checkout HEAD Drivers/CMSIS/Device/ST/STM32F4xx/Include

Those are the header files that describes the internal of the MCU.

You'll also need some minimal startup code and a linker file.

I use the ones generated by System Workbench and adapted them to my needs.

I also use a modified makefile that once was generated by it as well. It speeds up things a lot.
If god made us in his image,
and we are this stupid
then....
 
The following users thanked this post: bd139

Offline Doctorandus_P

  • Frequent Contributor
  • **
  • Posts: 625
  • Country: nl
Re: STM32 where to start?
« Reply #10 on: March 25, 2020, 11:24:09 pm »
If you want to get down to the absolute minimum, then "pandafruits" is a really excellent tutorial. It's a small website, with about 4 pages of text, and it handles stuff like writing your own linker script, statup code  and makefile to getting GDB working from the commandline.

Even if you normally work with those bigger frameworks, but are curious about the underlying mechanisms it is an excellent tutorial for the nitty gritty details most people just take for granted.

Another nice tutorial to get started with the Blue Pill is from:
https://jeelabs.org/2018/getting-started-bp/


Mini Davey Jones (long time no see) made a youtube vid about working with C++ templates for I/O. The video is quite nice although not complete, but it does show some of the power of templates.


Other experiments with templates for STM32 are from XPCC, Kvasir and Bmptk, and Jeenode already mentioned above.

 
The following users thanked this post: krish2487, Mortymore, bd139

Offline Karel

  • Super Contributor
  • ***
  • Posts: 1466
  • Country: 00
Re: STM32 where to start?
« Reply #11 on: March 26, 2020, 09:36:15 am »
I attached a "boilerplate" project with a blinky led and serial port example.
The serial port uses dma for rx, interrupts for tx.

For some unknown reason, the forum board does not accept tar.gz files so I renamed it to tar.zip.
After downloading the file, rename it back to tar.gz before trying to extract.

This example is made for the STM NUCLEO-L452RE evaluation board (Digikey: 497-17008-ND).
It comes with an STlink programmer on a break-out board connected to the dev board.
It costs only $15 so I strongly recommend to buy it and make sure this boilerplate works before
you start to modify it for your particular project and MCU.

You need the compiler toolchain which comes with the installation of the free System Workbench,
you can download it here (registration required):

https://www.openstm32.org

After installation of System Workbench, install the latest updates: in Eclips go to Help -> Check for Updates

Check if the following rules have been added to your /etc/udev/rules.d/ directory: (they are needed for the STlink programmer)

49-stlinkv1.rules
49-stlinkv2-1.rules
49-stlinkv2.rules
49-stlinkv3.rules

Restart your pc to make sure they are active.

Edit the files environment.txt and programmer/program_target.sh and adapt the path so that they point to the correct location.
(replace all instances of "<put your path here>") (it depends on where you have installed System Workbench)

Now you can start!

Usage:

open a terminal and cd to the boilerplate directory

source environment.txt   (to add the toolchain bin directory to the PATH variable)

make

./programmer/program_target.sh


now the green led of the devboard will blink


use "make clean" to remove all files generated by the make command



You will need the following documentation:

datasheet: STM32l452RE.pdf

errata: ES0388 STM32L452xx device limitations.pdf

programming, register descriptions, peripherals etc.: RM0394 STM32L43xxx STM32L44xxx STM32L45xxx STM32L46xxx advanced ARM-based 32-bit MCUs.pdf

UM1724 User manual STM32 Nucleo-64 boards

You can download them here: https://www.st.com and search for STM32l452RE and NUCLEO-L452RE


 
The following users thanked this post: krish2487

Online krish2487

  • Frequent Contributor
  • **
  • Posts: 441
  • Country: dk
Re: STM32 where to start?
« Reply #12 on: March 26, 2020, 09:51:16 am »
Thank you.
That is very nice and helpful of you @karel! :-)
If god made us in his image,
and we are this stupid
then....
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 1466
  • Country: 00
Re: STM32 where to start?
« Reply #13 on: March 26, 2020, 10:13:48 am »
I tried also the ARM reference compiler which can be found here

https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm

but the linker script and startup code are not compatibel.

Is there some GNU tool-chain wizzard here who can fix this?
 

Online Canis Dirus Leidy

  • Regular Contributor
  • *
  • Posts: 146
  • Country: ru
Re: STM32 where to start?
« Reply #14 on: March 26, 2020, 11:05:06 am »
So the question is where can I find something with the following requirements;
1. Not too big STM32. Something that FreeRTOS will be happy on. Five tasks, 64k or so flash (mostly LUT), not much stack. I2C, 24 GPIO pins, not a lot more. Long lifetime so I don’t have to throw everything in the bin in the near future.
2. On a dead simple breakout board with crystals and external ST Link that doesn’t pretend to be arduino friendly.
3. Command line tool chain for Linux.
ChibiOS (Can run even on STM32F030F4)? It has it's own HAL, so you don't need any CubeMX. Here is some tutorials: https://www.playembedded.org/blog/category/articles/chibios-stm32/getting-started/ and example of pure command line compiling and debugging: http://wiki.chibios.org/dokuwiki/doku.php?id=chibios:community:guides:work_without_ide
 
The following users thanked this post: bd139

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 626
  • Country: us
Re: STM32 where to start?
« Reply #15 on: March 26, 2020, 05:03:11 pm »
Another thing you might like to look into, if you grok GDB, is the "black magic probe."  This is like a JTAG adapter but instead of messing with OpenOCD and all that stuff, it implements the GDB remote debugging protocol over a virtual serial port on the host PC side, and SWD JTAG on the target side.  It works quite well.  You can buy ready-made / packaged units to support the developer, or just flash the firmware (it's open source on github) onto a spare Nucleo or Discovery board and use that.
 
The following users thanked this post: bd139

Offline Karel

  • Super Contributor
  • ***
  • Posts: 1466
  • Country: 00
Re: STM32 where to start?
« Reply #16 on: March 27, 2020, 12:48:14 pm »
Yesterday I installed STM32CubeIDE. It's a mix of STM32CubeMX and System Workbench.
Actually, STM32CubeIDE copied the GNU toolchain from System Workbench  :)

So, the boilerplate I provided can be used also with that tool chain (that comes with STM32CubeIDE).

Just modify the path's to:

<your path>/stm32cubeide_1.3.0/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.7-2018-q2-update.linux64_1.0.0.201904181610/tools/bin/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf