Skip to content

Embedded Programming

Group assignment

Here is our group assignment link For group assignment we have done ATMega328P vs STM32 comparison. It was very useful to know what is difference betwen microcontrollers and what functions they can do. We compared different parameters from datasheets. Register size, Opeating conditions. Flash memory, SRAM, Clock speed, etc.

Based on the results of the test, it appears that the STM32 outperformed the ATMega328P in terms of frequency, with a frequency of 489 kHz compared to the Arduino frequency of 147 kHz for C++ with library and 512 kHz for Assembly. This could be due to the fact that the STM32 has a clock speed of 4-32 MHz compared to the ATMega328P’s clock speed of 0-72 MHz.

Additionally, it’s worth noting that the development workflows for the STM32 and ATMega328P differ in terms of register size, operating conditions, flash memory, and SRAM. While the STM32 has a 32-bit register size and operates at 2-3.6 V, the ATMega328P has an 8-bit register size and operates at 2.7-5.5 V. The STM32 also has more flash memory and SRAM compared to the ATMega328P.

Overall, the choice between the STM32 and ATMega328P will depend on the specific requirements of the project, including performance, power consumption, cost, and development workflow. It’s important to carefully evaluate the options and choose the microcontroller that best meets the needs of the project.

Blinking LEDs (2025)

MX configuration

For My Embedded Programming assignment I decided to make Blinking Led project, as it is “HELLO WORLD” Project for Embedded programming, but I want to do that different way.

I want to blink 3 LEDs, and to do that with different frequensies at the same time.

(Also I will do that without using any computational power :) )

I will use STM32 Nucleo board for that, espesially NUCLEO - F446RE

I started with downloading CubeIDE software from Official Website

Then in CubeIDE i started new project

I found my board

And after naming project I see this window

Firstly I go to Clock Configuration panel and check for my clocks, as you can see they are all 16 MHz

Now is the most interesting part. I am going back to “Pinout & Configuration” panel and select “Timers”

You can learn about Timer peripherals at ST official documentation page. Briefly, Timers in STM32 are hardware peripherals used to measure time, generate precise delays, and control events like PWM, input capture, and output compare.

I will attach “LED Blinking” event to them. Each LED to different Timers.

I started with configurating TIM1, for one of LEDs.

I am using Internal clock of processor for Timer Clock Source

Then in Counter Settings i am changing this two parameters - Prescaler (PSC) and Counter Period (Auto Reload Register-ARR)

For calculating right values, I am using this equation

It is better to have value of PSC bigger, si i set it’s value 15999.

I want my first LED to blink with 200ms period, so its frequensy would be 1/200ms=5 Hz.

From my equation 5 Hz = 16 MHz / (15999+1)*(ARR+1)

You can see that my ARR must be 199

I want to use “Update Interrupt” method, si in NVIC Settings I select Update interrupt enabled. (Just check couple of tutorials on youtube like this one)

After that I am configuring 2 more Timers for 2 more LEDs. one for 500ms period and one for 333ms period.

NOTE!! If you have one option only in NVIC settings, just select it))

After Configuring 3 Timers, I am defining 3 pins of processor as GPIO Output pins (to control LEDs)

After checking board pinout, i decided to use PA0, PA1, PA4 pins, so I left clicked on each of them and Selected GPIO_Output

But I want to set names for that pins, to use them in my code

I right-clicking on pins and selecting “Enter user Lable”

Then you can write any Label you want

Code

Finally I finished my project configuration, and by pushing Ctrl+S it will generate my code.

Here is two files I must work with.

One is main program file, and the other is for interrupt functions.

In interrupt function file I found functions for Timers Interrupts, where I can write Led blinking function

So in User Code section i write TogglePin command from HAL library.

HAL_GPIO_TogglePin(LEDB_GPIO_Port, LEDB_Pin);

In the main.c file, before main program begin, there are peripheral definitions, so I just add commands to start Timers.

HAL_TIM_Base_Start_IT(&htim1);

But in main cycle ( while(1) ) there is no command. Thats why this programm dont use any computational power, it just attaches LEDs to Timers))

Then I connected LEDs to my board (STM32 works with 3.3V so I absolutely can connect LEDs without resistors)

So I builded my project

Most pleasant words real men want to read

And then “Run”

Work Video

Conclusion

I learned about Timers and interrupt functions this week, I felt huge potential of using them in my projects, and demonstrated one example of project with Timers.

Files

You can find all files of this project here


Last update: May 15, 2025