Architecture difference between Cortex-M microcontrollers - Page 1
Forum section: electronics / projects

author: MildInductor
author_rank: Regular Contributor
timestamp: September 17, 2024, 09:57:58 pm
content: Hello, I am comparing the STM32 (found in the STM32F411 "BlackPill") to the ATSAMD21G18 Cortex-M0+ (found in the Adafruit ItsyBitsy M0 Express). From what I can find, the STM32 seems to be based on the Cortex-M4. Because both of these boards run on the Cortex-M series architectures, does that mean the programming will be similar? I am moving away from the AVR series to something with more grunt and am trying to wrap my head around the Cortex-M series.

author: ataradov
author_rank: Super Contributor
timestamp: September 17, 2024, 11:58:08 pm
content: Architecture only defines the core behavior. All the peripherals are different between those devices. Even the difference between CM4 and CM0+ is significant.But if you are moving from AVR, even SAM D21 with CM0+ will be way more performant.It is not really a 100% comparison, but you can think of it this way. Both Attiny10 and Atmega128 use AVR core, does it mean that programming them would be similar? Again, not a perfect analogy, since both devices are from the same vendor, so somewhat similar, yet they have significant differences and limitations.

author: moffy
author_rank: Super Contributor
timestamp: September 18, 2024, 12:03:41 am
content: Presumably you will be programming in C/C++ so the architecture will be somewhat abstracted. The M0 have a lower clock frequency than the M4, I think the M4 has a deeper instruction pipeline for the higher frequency. Mostly you will be concerned with peripherals, highest throughput and onboard RAM and FLASH, you tend to treat each device as unique mainly because of the peripherals and the application framework for each device though there is a lot of commonality. I tried the STM32 processors for quite a while but gave up because of the buggy examples code and moved across to NXP, which while not perfect I found more reliable.P.S. The programming framework will help by providing basic code for the peripherals if selected and initialising clocks and pins and even such things as USB.

author: ArdWar
author_rank: Frequent Contributor
timestamp: September 18, 2024, 12:43:15 am
content: You likely will get more problem adjusting with the difference in peripheral setup than the difference in core architecture.

author: pcprogrammer
author_rank: Super Contributor
timestamp: September 18, 2024, 06:38:05 am
content: To know about the differences between the two MCU's it is best to read the datasheets. The same applies to the differences between the two cores.When one plans to use assembler there are differences between the two. Seehttps://developer.arm.com/documentation/dui0662/b/The-Cortex-M0--Instruction-Set/Instruction-set-summary?lang=enandhttps://developer.arm.com/documentation/ddi0439/b/CHDDIGACfor more information on this.When using C/C++ one has to tell the compiler which core is being targeted. For instance for the gcc compiler and the Cortex-M4:Code:-mcpu=cortex-m4 -mthumbThe choice between the two depends also on what one wants to do. What kind of interfaces are needed and how many, like SPI, UART, CAN, ADC, DAC, etc. Also how fast does it need to be. The STM32F411 can clock up to 100MHz, where the ATSAMD21G18 can only go up to 48MHz. This also has a bearing on the max speed of the peripherals.Both I assume have enough support in the Arduino environment, but for me to unleash the real potential of either would mean bare metal programming. That also makes moving to another manufacturer, like moffy did, unnecessary. This would only be needed when there is a hardware bug in the MCU that causes run time problems.In the beginning bare metal programming won't allow fast development of projects, like with Arduino, but in the end, at least for me, it is way more satisfying and on my good days just as fast as developing with the use of SDK's or the Arduino environment.So like others wrote it is not a simple one on one comparison that can be done.

author: MildInductor
author_rank: Regular Contributor
timestamp: September 19, 2024, 02:13:41 pm
content: Thank you everyone. That clears things up