Skip to content

4. Embedded Programming

Group assignment: compare the performance and development workflows for other architectures

ATMega328P vs STM32 comparison

In order to compare these two microcontrollers, we refered to their datasheets: ATMega328P and STM32 F303 xB or xC

Feature STM32 ATMega328P
Register size 32-bits 8-bits
Operating conditions 2 - 3.6 V 2.7 - 5.5 V
Flash memory 128 - 256 kB 32 kB
SRAM up to 40 kB 2 kB
Clock speed 4 - 32 MHz 0 - 72 MHz at 4.5 - 5.5 V

We noticed that the STM32 is significantly more powerful than the ATMega328P. We then compared their pins configurations:

For the ATMega328P:

And for the STM32:

Performance test based on different workflows

overview In order to compare and better understand the performance and development workflows we conducted a simple test where we tell the microcontroller to define a digital output and change it’s state to High and low without any delay function. This should make a puls train generated on the defined pin with a maximum possible frequency for that specific scenario.Here are the scenarios we tested:

Arduino with C++ code and library
Arduino with C code without library
Arduino with Assembly code
STM32 with C code
STM32 with Assembly code

And here are the results of the tests:

Arduino frequency for C++ with library: 147 kHz. 147 CODE:
void setup() {
pinMode (13, OUTPUT);
} void loop() {
digitalWrite(13, HIGH);
digitalWrite(13, LOW);
}

Arduino frequency for Assembly: 512kHz 512 There are 2 files: 1 .ino written in C and 1 .S file written in Assembly C CODE:
extern “C”
{
void start();
void led(byte);
}
void setup() {
start();
} void loop() {
led(1);
led(0);
}
Assembly CODE:
define __SFR_OFFSET 0x00
include “avr/io.h”

.global start
.global led

start:
SBI DDRB,5 ;set bit in the 5th DDR register of port B to 1 (output)
RET
led:
CPI R24, 0x00 ;compare the value in register 24 passed as parameter to the function to 0x00
BREQ ledOFF
SBI PORTB,5 ;set bit in the 5th PORT B register to 1 (HIGH)
RET
ledOFF:
CBI PORTB, 5 ;set bit in the 5th PORT B register to 0 (LOW)
RET

STM32 frequency: 489 kHz 489 Modification in the C code:
while (1)
{
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_13);
}


Last update: February 22, 2023