Book/learning material: Any advice for beginners? - Page 1
Forum section: electronics / general

author: Watth
author_rank: Frequent Contributor
timestamp: February 08, 2023, 11:12:25 am
content: Hey EEV-folks,I'm looking into knowledge material for hobbyists to better understand the inner workings of STM32 µCUs. I am trained in C/C++ but nothing specifically regarding embedded programming.For example : the different elements : clocks and prescalers, timers, registers, (etc.) and how they work with each other. In other words, having a clue about what STM32MXCube does. And other aspects of µCUs.I'm looking at what ST's website offers in their e-learning section, and refer to their pletnifull different docs.I also spotted Donal Norris' book "Programming With STM32: Getting Started With the Nucleo Board and C/C++" ISBN: ‎ 978-1260031317Any opinion, advise, pointers?Thanks for reading!

author: brucehoult
author_rank: Super Contributor
timestamp: February 08, 2023, 11:30:54 am
content: Have you looked at the datasheet?

author: wek
author_rank: Frequent Contributor
timestamp: February 08, 2023, 11:37:31 am
content: > Have you looked at the datasheet?Both datasheet and reference manual. And then rest of therelated documentation.> In other words, having a clue about what STM32MXCube does.CubeMX is a clicky configurator for Cube (which is the "library"), and that in turn implements a relatively miniscule subset of what the hardware allows - the "most common cases".I don't think there is any reason to "learn Cube/CubeMX". Learn the mcu.JW

author: Watth
author_rank: Frequent Contributor
timestamp: February 08, 2023, 12:13:47 pm
content: Quote from: wek on February 08, 2023, 11:37:31 amI mean understanding what it does, as in having an idea as to what the different parameters are; without being too specific.

author: Watth
author_rank: Frequent Contributor
timestamp: February 08, 2023, 12:16:05 pm
content: Quote from: brucehoult on February 08, 2023, 11:30:54 amYup.

author: Sherlock Holmes
author_rank: Frequent Contributor
timestamp: February 08, 2023, 03:50:38 pm
content: Quote from: Watth on February 08, 2023, 11:12:25 amI too have a lot of experience with C and studied electronics, communications, radio etc etc before embarking upon a career as a programmer, but I had little recent exposure to MCUs.Here's what I did and what I recommend:1. Use Visual Studio (not Visual Studio Code) then install VisualGDB, these two together are excellent, certainly for someone just starting out.2. Install the STM Cube app too.3. Get some STM32 F4 boards like these:https://www.amazon.com/gp/product/B01I8XLEM8/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=14. Get these books (The Norris one is certainly helpful)https://www.amazon.com/gp/product/1260031314/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1https://www.amazon.com/gp/product/0997925949/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=15. Do this basic example from theVisualGDB STM32 tutorials section.VisualGDB is excellent, you can create from-scratch projects or import existing projects created by Cube.Here's atutorialspecifically forthis board.A scope and stuff can help too, these gizmos basically consume and produce signals so being able to see them is a huge help.The device's datasheets are a good reference but unhelpful to someone just starting out, you need to know what questions to ask first and have to start somewhere, that second book is more technical though and will prepare you for eventually studying the datasheets.

author: pcprogrammer
author_rank: Super Contributor
timestamp: February 08, 2023, 04:48:55 pm
content: If you really want to learn about the working of the peripherals try searching the web for information about this in general, not just the STM32 setups. Like a search for "microcontroller timer peripheral" can lead you tothis.Like others wrote, the reference manual is the place to find information about how to use them and what the register settings mean, but it does not tell much about the inner workings. For this you have to look into digital circuits.If it is to learn how to use the STM32 peripherals specific, then I suggest to get yourself some hardware like a bluepill (STM32F103) including a ST-link V2 or V3 or a clone and think up of things you like to do with it. It depends on how much money you want to throw at it and how fast you want it. You can search Aliexpress or Amazon to find yourself some interesting boards.The ST-link will allow programming and debugging, but you need some IDE for it, unless you like command line tools. It is possible to use GDB and openOCD on command line level to do all the needed tasks.I myself use an old version of Netbeans IDE on Linux, but there are many other IDE's for it.To go in deep I would say, forget about CubeMX and all other by STM32 supplied tools and their HAL. Go bare metal. It is not hard. For example see some of my workhere.Depending on what OS you are on you can pick your poison, be it Microsoft or some open source setup.When you have your setup just start programming and see if it works like you expect it to work. Having some tools to measure things can also be handy when working on peripherals. Like an oscilloscope to check if the pins are indeed making the intended PWM signal or that the SPI signals are what you expected.

author: Watth
author_rank: Frequent Contributor
timestamp: February 08, 2023, 08:22:40 pm
content: Quote from: Sherlock Holmes on February 08, 2023, 03:50:38 pmSo more info: I do have a few nucleo boards. I use STMCubeIDE with MX. I have an oscilloscope and a basic logic analyzer. So far I've tried I2C and SPI, for example.I use STM32Cube IDE for now. I'll have a look at VisualGDB.I like that Norris' book is written for non-specialist, typically people already familiar with Arduino.I do refer a lot to datasheets as much as I can, and various docs provided by ST. I sometimes refer to ST's "Community" site.As a hobbyist, I'm trying to go beyond cargo cult programming by being able to have an (albeit basic) idea of the different peripherals' roles.

author: Watth
author_rank: Frequent Contributor
timestamp: February 08, 2023, 08:31:06 pm
content: Quote from: pcprogrammer on February 08, 2023, 04:48:55 pmI do often refer to datasheets. My goal is far from being a specialist, and rely on ST's IDE and HAL. But I like your idea to make at least a few basic "bare metal" projects, with the tool chain you talk about.What I didnt specify: I have a few nucleo boards and I think I'll try to program a standalone STM32.

author: Sherlock Holmes
author_rank: Frequent Contributor
timestamp: February 08, 2023, 09:35:40 pm
content: Quote from: Watth on February 08, 2023, 08:22:40 pmI'd never even heard of SPI until about a year ago, so I jumped into interfacing andNRF radio deviceto a Nucleo, because the NRF relies on SPI and the STM chip on the Nucleo has several SPI units.I spent many weeks on this and made good progress, this isa small API created(fully reusable source) and a "test app" that pumped data and commands into the NRF while I watched the data flow using a logic analyzer.Other than VisualGDB and Visual Studio, those books and the internet, I really didn't need much except a lot of patience!

author: luiHS
author_rank: Frequent Contributor
timestamp: February 08, 2023, 10:32:48 pm
content: The only serious, complete and practical book on STM32, the "Mastering STM32" by Carmine Noviello. He explains absolutely everything with detail and practical examples. 910 PDF pages for $30. I wish something similar existed for the NXP i.MX RT, but unfortunately it doesn't.You can buy it online and download it instantly.https://leanpub.com/mastering-stm32-2nd

author: Smokey
author_rank: Super Contributor
timestamp: February 08, 2023, 11:53:44 pm
content: I'm going to disagree with some of the above. As an "expert" it's hard to remember how bewildering embedded is when you first encounter it. You can't really say "go learn how to configure everything at the register level! Wizards and HALs are cheating!" if they have no idea what a timer is (I mean you can, but then you are just being difficult).ST now has a pretty complete, well documented, set of tools with the STM32Cube ecosystem and nucleo boards. It's an excellent way to get some exposure using (mostly) known working examples and wizard type configuration tools. Use their tools! CubeMX, CubeIDE, etc. Pull up one of the demos and explore everything. Pull up the CubeMX configuration and go through all the windows. See what stuff does and what the options are. If you don't know what something done, look it up. Run the demo on a board and change stuff. Make the timer blink the LED faster and slower. See how the HAL functions are called. If you get ambitious, dig into the HAL functions and see how the HAL is talking to the hardware. Remember, you can almost always make things faster if you skip the HAL and go straight to the hardware but that's not always necessary so don't sweat it unless it's important.Build on a project piece by piece. Get the LED blinking. Add UART communications. Trigger some GPIO interrupts. There should be demos for all that stuff.One more thing: Use C. If your embedded system needs stuff like c++ template functions and ploymorphism and it's not a Cortex-A7 or some such mini computer, you are probably using the wrong processor platform.

author: wek
author_rank: Frequent Contributor
timestamp: February 09, 2023, 12:21:09 am
content: > You can't really say "go learn how to configure everything at the register level! Wizards and HALs are cheating!" if they have no idea what a timer is (I mean you can, but then you are just being difficult).If you don't know what a timer is, then go and learn that. Wizards and HALs won't teach you that. And then come back and configure everything at the register level.JW

author: Smokey
author_rank: Super Contributor
timestamp: February 09, 2023, 12:47:53 am
content: Quote from: wek on February 09, 2023, 12:21:09 amAnd while you are at it, get off my lawn!

author: julian1
author_rank: Frequent Contributor
timestamp: February 09, 2023, 02:01:20 am
content: I like the book Beginning STM32 Developing with FreeRTOS, libopencm3 and GCC, by Warren Gay. The author is a former linux kernel developer.If you have c/c++ experience, then have a look at the libopencm3 code on github for interfacing to peripherals. Compare it with the HAL/cube approach and decide on which you prefer.

author: pcprogrammer
author_rank: Super Contributor
timestamp: February 09, 2023, 06:07:26 am
content: The OP expressed a desire to learn about the inner workings of the peripherals in the STM32's and microcontrollers in general.Learning HAL specific for STM32 does not teach you anything about the actual inner workings, just how to make use of them on a simplified level, but simple it ain't, because you have to learn HAL, which is also wading through a lot of information. And diving into the shit pool of code that lies beneath it, is something I would not advice to a beginner. Don't know about the state of it at present, but the view times I tried to use it for something more exotic, it failed for what ever reason.You can argue that register level is much more difficult, but that depends on how you can pick up on things. Some people will never learn how to use either. And with HAL you still have to know about the settings, because you have to provide them there too. Either way it is not rocket science.To get a better understanding of the inner workings forget about software. Study hardware, because that is what it is. A timer is a piece of configurable hardware. A serial interface is a piece of configurable hardware. The registers are the interface with the software.With the nucleo boards the OP has, a lot of fun can be have with.

author: tellurium
author_rank: Frequent Contributor
timestamp: February 09, 2023, 08:50:15 pm
content: My (biased) recommendation would be myhttps://github.com/cpq/bare-metal-programming-guidewhich covers Nucleo-F429ZI and more