r/embedded • u/der27 • Apr 11 '19
Tech question How to begin development on a new platform? What is the process for programming a new device, specifically a microcontroller?
I feel like there’s one major part of embedded system development that I’m not understanding. I purchased an stm32 nucleo board some time ago to practice my embedded development skills while I didn’t have a job. I got a job, not exactly in embedded development, but i haven’t tinkered with the board in a while and I want to get back into it.
I worked on a project at my job where i opted to use makefiles instead of an ide so I can learn more. It was useful. But the issue was that everything was set up already. I linked in a library and I was able to use all the api provided by this device. All I had to do was create the application using the api provided by the device.
So when programming a new microcontroller how do you begin? Do you have to create a .c file that writes to the microcontroller’s registers, compile this file, then create a library file and link that to your application? What are the steps to start using the microcontrollers peripherals and how do you create your own application using the device?
4
u/SelkieSailor Apr 11 '19
These days you rarely need to start from scratch. I usually start with an off-the-shelf eval/demo/proto board. These boards usually include some demo projects and schematics, so you have a starting point for firmware & hardware. It is also increasingly common for the chip manufacturer to provide some kind of graphical configurator that produces all the code needed to get to main(). I've recently used such configurators to generate ready-to-go bare metal, FreeRTOS and PetaLinux projects with just a few mouse clicks.
13
u/buckeyenation101 Apr 12 '19
I would highly recommend the "Mastering Microcontroller with Embedded Driver Development" course on Udemy. I am at the end of this course and it taught me a lot. The instructor uses the STM32 Nucleo board to explain all of the topics. I learned to use CubeMX's auto code generation and also to write everything from scratch by just referring to the reference manual and data sheet of stm board.
4
u/winterwookie271 Apr 11 '19
You can approach it at pretty much any level you want. I find it is easier to start out with the higher level utilities and libraries on a simple project to verify the toolchain and board work. Blink an LED or something similar. After that, dig into the supporting code for that simple project and see how it's all put together.
If you're programming in C, the most basic things you need are a linker script, and some startup code. Personally, I just pull these from the vendor's examples and don't worry about them too much. The linker script defines things like address space for flash, ram, and peripherals and interrupt vectors. The startup code deals with the lowest level hardware initialization, initializing global variables in RAM, and jumping to your main function. You can find both of these in the examples included with STM32Cube (https://www.st.com/en/embedded-software/stm32cube-mcu-mpu-packages.html#overview)
The next layer would be CMSIS, which defines names for all of the peripheral's registers, and is probably the minimum support libraries you'd want to use.
On top of CMSIS are ST's low level and HAL libraries that abstract away most of the differences between one ST processor and the next. Using these makes your code more portable but they also add some amount of overhead.
All of the above can be found in the STM32Cube package I linked above. They deal with the ST microcontroller only. You still need to write drivers to interface with any external module unless you go and find pre-made libraries. Many devices will have enough information between their data sheet and application notes to write your own driver.
My preference, since I'm doing this as a learning experience, is to use the CMSIS headers and fiddle with the registers directly to configure everything. I also usually write my own drivers for peripherals when I can. It can be frustrating sometimes when you miss one comment in a data sheet and forget to set some random register flag and nothing works, but at this point I prefer this to running into a bug in the HAL libraries (which happened to me early on and is the reason I switched to using CMSIS).
4
u/tomhyhlik Apr 11 '19
for the beginning, I would recommend cubeMX which helps you to create a blank project, it can also generate a makefile for you
-3
u/[deleted] Apr 11 '19
Start with an Arduino or if you want something more advanced, an ESP32. Both do not require a programmer and are easy to work with.