0
\$\begingroup\$

I have a curious question. Do I really need to learn how to use registers when I program a microcontroller?

I have been using Arduino for a long time. I quit using Arduino and starting to use STM32 because they are more cheap, faster and just better microcontroller. They do require more knowledge about C programming and what a microcontroller can do, because you can do more with STM32 than Arduino.

Anyway! I have tried to blink LED and read digital inputs e.g toggle with a STM32 by program it with registers. It's time consuming and painful. Luckily STM offer CubeMX so the user can setup a complete project with HAL-libraries without using any registers. Super easy and super fun!

This is how Atollic CubeMX looks like.

enter image description here

And now my real question, why I started this question. I have been using Atollic TrueStudio. Works fine. But today I upgraded my Atollic TrueStudio and STM have implemented CubeMX into Atollic TrueStduio. Before I have to download both Atollic TrueStudio and then CubeMX. Seperate software in other words.

But today Atollic TrueStudio and CubeMX is merged together into one software. Great! That's really good.

But...to create a project for a STM32 microcontroller, you need to create a CubeMX project. There is no "Create a blank ARM project in C" as it was before. Now is like "You want to create a STM32 project? Well, you never going to use register anymore so we choose for you! Here, have a CubeMX with HAL-libraries project! Ready to run!"

Well...that's great! But do STM assume that working with registers is not necessary when I use STM32?

I have no problem to use SMT32 with CubeMX + HAL libraries. Not at all. But I'm worried if I become "stupid" if I use CubeMX + HAL just to make it easy for be.

Should I program a STM32 with registers or should I use CubeMX + HAL libraries? Notice that this is a 32-bit microcontroller of tons of documentation and not a simple AvRTiny8.

Today I create large projects with STM32 thanks to CubeMX + HAL libraries. I could never do that without this technology.

Here is the reason why I use STM32. It's just.....better if you compare the price and what you get. enter image description here

\$\endgroup\$
  • 3
    \$\begingroup\$ Yes. You're not really doing embedded programming if you're not talking to the hardware. \$\endgroup\$ – The Photon Sep 20 '19 at 23:26
  • \$\begingroup\$ @ThePhoton Ok. So I should get started with blank C projects instead of using the "cheat" CubeMX + HAL ? \$\endgroup\$ – Daniel Mårtensson Sep 20 '19 at 23:28
  • 3
    \$\begingroup\$ CubeMX takes care of the initialization of STM32, so you don't have to. You decide what you want, outputs, inputs, timers, etc and it installs the drivers to get you started. It gets you over a rather big learning curve, so that you can concentrate on your application. \$\endgroup\$ – StainlessSteelRat Sep 20 '19 at 23:42
  • 1
    \$\begingroup\$ @Daniel, it depends if your goal is to learn embedded programming, or just to make whatever cool thing you are trying to make. If you just want to make something cool and you can do it with the register access hidden by the vendor libraries, then go ahead. \$\endgroup\$ – The Photon Sep 20 '19 at 23:42
  • \$\begingroup\$ @StainlessSteelRat Yes. I know that. That's is why I have created large projects because I just declare the GPIO's so easy. Write less code too. \$\endgroup\$ – Daniel Mårtensson Sep 20 '19 at 23:43
1
\$\begingroup\$

do STM assume that working with registers is not necessary when I use STM32?

Yes. They don't want you to bang the registers directly, because then they would have to document them properly and you would have to know about any differences between devices (including hardware bugs). By going through the Hardware Abstraction Layer you are shielded from all that and can concentrate on application code, which will then work without modification on different STM32 chips.

There may come a time when either the HAL libraries can't do what you want, don't have the performance you need, or have bugs you need to work around. Then you have a choice - learn the hardware and write your own code (preferably using the same HAL system), wait for ST to update the HAL, or go to another MCU with better support.

Today I create large projects with STM32 thanks to CubeMX + HAL libraries. I could never do that without this technology.

So you already have the answer.

In the past it was different because the HAL was poorly documented and CubeMX was full of bugs, so some of us tried to work without it - and failed. Banging the hardware is only tenable if you are a masochist with a lot of time to waste, or an expert who has already built up their own codebase.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thank you for your good answer. I do have the time to dig into data sheets for hours. But I spend that time with friends, family and Java instead. :) I have not found any bugs with latest CubeMX. Ok. Then I know that working with STM32, CubeMX is mandatory. \$\endgroup\$ – Daniel Mårtensson Sep 21 '19 at 11:13
  • \$\begingroup\$ So STM32 documents are not proper written like Atmels? \$\endgroup\$ – Daniel Mårtensson Sep 21 '19 at 11:17
  • \$\begingroup\$ @DanielMårtensson STM32 registers are documented in more detail than HAL functions. \$\endgroup\$ – followed Monica to Codidact Sep 21 '19 at 11:49
  • \$\begingroup\$ @berendi Does all microcontrollers such as AVR, PIC have HAL-libraries? \$\endgroup\$ – Daniel Mårtensson Sep 21 '19 at 11:57
  • \$\begingroup\$ Use the HAL libraries when you can; it saves work. But pick a function; (something simple like a timer, not an Ethernet controller!) and read through the HAL and driver source for it in detail. Find and understand how it translates simple requests into register bit operations. Then if you need to port from STM32 to some other arch where the HAL is missing, incomplete or buggy, you won't be stuck. Or if you need to port to ZYNQ or something where you can roll your own custom hardware, which obv won't come with a ready made HAL. \$\endgroup\$ – Brian Drummond Sep 21 '19 at 12:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.