Author Topic: Exploring ARM assembly language on STM32 with Windows desktop  (Read 3378 times)

0 Members and 1 Guest are viewing this topic.

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Exploring ARM assembly language on STM32 with Windows desktop
« on: November 29, 2022, 06:38:52 pm »
I'm looking for ways I can explore ARM assembly language with STM32 devices and using Windows desktop as my preferred workstation.

I have VisualGDB already and that's is good enough for my informal, non-professional needs but I don't think it makes it straightforward to start an assembler based project.

What other ways are there to do this?
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 3466
  • Country: us
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #1 on: November 29, 2022, 08:52:37 pm »
I was surprised to find this: https://www.amazon.com/Assembly-Language-Programming-STM32-Microcontrollers/dp/B08GFX3PTW

It's cheap, particularly on Kindle.  But, I would buy the hard copy.  There may be other resources.
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #2 on: November 29, 2022, 09:07:39 pm »
I was surprised to find this: https://www.amazon.com/Assembly-Language-Programming-STM32-Microcontrollers/dp/B08GFX3PTW

It's cheap, particularly on Kindle.  But, I would buy the hard copy.  There may be other resources.

I already have this book https://www.amazon.com/gp/product/0124080820/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1 which is a great resource and I was looking at this one too yesterday:

https://www.amazon.com/Modern-Assembly-Language-Programming-Processor-ebook/dp/B01FENFCMS/ref=sr_1_13?keywords=assembly+arm&qid=1669755973&s=books&sr=1-13

Looks like a great book, seems to be the best on Amazon, I just need to be able to start an empty project in some IDE and start coding...



“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline jpanhalt

  • Super Contributor
  • ***
  • Posts: 3466
  • Country: us
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #3 on: November 29, 2022, 11:50:36 pm »
This may help:  https://developer.arm.com/documentation/dui0473/m/assembler-document-revisions?lang=en

It seems pretty comprehensive, and you can navigate to the ARMASM assembler user guide.  As for the assembler itself, I just searched on ARMASM assembler download.  The Microsoft one is in that search.  The other ARMASM (Arm Ltd.) program is a bit expensive: https://stackoverflow.com/questions/70047209/where-can-i-download-and-configure-the-arm-macro-assembler

Presumably, with the hex code available you can use a variety of tools to program the chip.  The one and only time I have done it (edit: programmed an ARM chip), I used Flash Magic, which is a freebie download.

EDIT: Sorry, my Flash Magic was for NXP MCU's. Don't know about STM
« Last Edit: November 30, 2022, 12:05:22 am by jpanhalt »
 

Offline Sherlock HolmesTopic starter

  • Frequent Contributor
  • **
  • !
  • Posts: 570
  • Country: us
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #4 on: November 30, 2022, 12:06:43 am »
This may help:  https://developer.arm.com/documentation/dui0473/m/assembler-document-revisions?lang=en

It seems pretty comprehensive, and you can navigate to the ARMASM assembler user guide.  As for the assembler itself, I just searched on ARMASM assembler download.  The Microsoft one is in that search.  The other ARMASM (Arm Ltd.) program is a bit expensive: https://stackoverflow.com/questions/70047209/where-can-i-download-and-configure-the-arm-macro-assembler

Presumably, with the hex code available you can use a variety of tools to program the chip.  The one and only time I have done it (edit: programmed an ARM chip), I used Flash Magic, which is a freebie download.

EDIT: Sorry, my Flash Magic was for NXP MCU's. Don't know about STM

Thanks, much appreciated, I'll take a good look...
“When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.” ~ Arthur Conan Doyle, The Case-Book of Sherlock Holmes
 

Offline cfbsoftware

  • Regular Contributor
  • *
  • Posts: 115
  • Country: au
    • Astrobe: Oberon IDE for Cortex-M and FPGA Development
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #5 on: November 30, 2022, 01:28:11 am »
I've learnt all I know about STM32 assembler programming through Joseph Yiu's books. e.g.

The Definitive Guide to ARM® Cortex®-M3 and Cortex®-M4 Processors

The Definitive Guide to the ARM® Cortex®-M0

I also find it informative to inspect the disassembled code produced by a compiler.
Chris Burrows
CFB Software
https://www.astrobe.com
 

Offline cfbsoftware

  • Regular Contributor
  • *
  • Posts: 115
  • Country: au
    • Astrobe: Oberon IDE for Cortex-M and FPGA Development
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #6 on: November 30, 2022, 01:30:52 am »
EDIT: Sorry, my Flash Magic was for NXP MCU's. Don't know about STM
You can use STM32 ST-Link to program STM32 devices:

https://www.st.com/en/development-tools/stsw-link004.html
Chris Burrows
CFB Software
https://www.astrobe.com
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #7 on: November 30, 2022, 11:44:22 am »
Iirc, the ARM ide (Keil) now has a free-for-non-commercial use license.
That should include the standard ARM assembler (not the slightly different gcc assembler), as well as a simulator.


Beware that cortex m0 and cortex m3 are more different than you might think.

 

Offline AVI-crak

  • Regular Contributor
  • *
  • Posts: 125
  • Country: ru
    • Rtos
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #8 on: November 30, 2022, 01:38:47 pm »
No need to learn assembler, it's a waste of time. For real tasks, a minimum amount of knowledge is required, at the level of the basics and rules of machine language. Everything you want to write is already written by someone else, you just need to find it.
However, there are free services for watching machine code, for example https://godbolt.org/z/Wf6sEfE4b

Exciting task: to write code in C or another language (47 positions) so that the result in assembler is as compact as possible, and fast.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3342
  • Country: nl
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #9 on: November 30, 2022, 02:11:10 pm »
There is plenty of books, reference manuals and other documentation. I'd say there is so much it's easy to get lost.

Apart from books, there is also GCC.
GCC is pretty much the standard for all ARM processors, and it does not compile directly to binaries, but outputs assembly, which is assembled in the next (automated) step.

GCC has options for preserving these intermediate steps, and it can even write listings to disk in which  each line of C (C++) code is followed by the assembly that is generated from that line of code.

This is a great feature for a lot of things. You can use it to find GCC bugs, learn about GCC's internals (such as what different optimization settings do) and of course also for learning assembly.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8168
  • Country: fi
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #10 on: November 30, 2022, 02:22:40 pm »
VisualGDB is probably fine (I personally use gdb in text mode, even that is fine). Asm development tooling is no rocket science. There is no benefits to complicated "professional" solutions, because professional projects rarely use asm beyond a few lines of inline asm. In some specific case it might be a 100-LoC module.

Processor documentation itself is of course of utmost importance.
 

Offline cfbsoftware

  • Regular Contributor
  • *
  • Posts: 115
  • Country: au
    • Astrobe: Oberon IDE for Cortex-M and FPGA Development
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #11 on: December 01, 2022, 12:20:26 am »
Beware that cortex m0 and cortex m3 are more different than you might think.
Just to clarify, it is the instruction sets that the processors support that are different. Cortex-M3 supports both 16-bit Thumb and (16/32-bit) Thumb-2 instructions, Cortex-M0 supports Thumb (and a few Thumb-2) instructions. i.e. assembler code written for the Cortex-M0 will generally run on a Cortex-M3 processor but not necessarily vice-versa.
Chris Burrows
CFB Software
https://www.astrobe.com
 

Offline cfbsoftware

  • Regular Contributor
  • *
  • Posts: 115
  • Country: au
    • Astrobe: Oberon IDE for Cortex-M and FPGA Development
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #12 on: December 01, 2022, 12:25:13 am »
No need to learn assembler, it's a waste of time. For real tasks, a minimum amount of knowledge is required, at the level of the basics and rules of machine language.
... unless, like me, you happen to be writing the code generator for a compiler ;)
Chris Burrows
CFB Software
https://www.astrobe.com
 
The following users thanked this post: boz

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4028
  • Country: nz
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #13 on: December 01, 2022, 12:46:51 am »
Cortex-M0 supports Thumb (and a few Thumb-2) instructions.

Not a lot. And only because Thumb was not designed to be the only ISA on a machine and previously you could always switch to ARM mode to do system stuff.

BL ... an actual 32 bit instruction on M0, but two 16 bit instructions in Thumb

MSR, MRS: move to/from status registers

DMB, DSB, ISB: fence/barrier instructions

That's all! Nothing a C compiler cares about.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #14 on: December 01, 2022, 01:33:44 am »
Quote
Cortex-M3 supports both 16-bit Thumb and (16/32-bit) Thumb-2 instructions, Cortex-M0 supports Thumb (and a few Thumb-2) instructions
Yeah, but what surprises you is that a bunch of things like "immediate mode" and "range of arguments" end up pushing you from the 16bit encoding to 32bit encodings (which don't exist on M0.)  So you get "mov r1, 0x80" but not "mov r1, 0x8000", and you have "and (registers)" but not "and (immediate.)"  Grr.

Quote
i.e. assembler code written for the Cortex-M0 will generally run on a Cortex-M3 processor but not necessarily vice-versa.
IME, not at all "vis versa."  Very common m3 (v7m) code patterns don't exist for m0 (v6m.)
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4028
  • Country: nz
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #15 on: December 01, 2022, 01:38:02 am »
Quote
Cortex-M3 supports both 16-bit Thumb and (16/32-bit) Thumb-2 instructions, Cortex-M0 supports Thumb (and a few Thumb-2) instructions
Yeah, but what surprises you is that a bunch of things like "immediate mode" and "range of arguments" end up pushing you from the 16bit encoding to 32bit encodings (which don't exist on M0.)  So you get "mov r1, 0x80" but not "mov r1, 0x8000", and you have "and (registers)" but not "and (immediate.)"  Grr.

No surprise to those of us used to programming (and writing compilers for) ARM7TDMI and the like :-)

It's quite an exercise to memorise all 19 instruction formats for Thumb1 and their limitations!
 

Offline harerod

  • Frequent Contributor
  • **
  • Posts: 449
  • Country: de
  • ee - digital & analog
    • My services:
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #16 on: December 01, 2022, 11:43:27 am »
I'm looking for ways I can explore ARM assembly language with STM32 devices and using Windows desktop as my preferred workstation.

I have VisualGDB already and that's is good enough for my informal, non-professional needs but I don't think it makes it straightforward to start an assembler based project.

What other ways are there to do this?


I understood your initial question as: "Which toolchains are available that support assembly?"

In that case - why not CubeIDE with the GCC toolchain?
If it is about exploring the functionality of assembly, it may even be helpful to let your assembly function be called by C.
I have rare applications/excuses for writing ASM on ARM. However, there are some functions that I prefer doing in ASM.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14445
  • Country: fr
Re: Exploring ARM assembly language on STM32 with Windows desktop
« Reply #17 on: December 01, 2022, 06:44:40 pm »
Not sure what exactly the OP is after? You don't need anything else than what you'd use for developing with C on those MCUs. An assembler is part of any compiler distribution I know of. GCC would be the most common for ARM MCUs and strictly speaking, all you'd need is binutils, but it's always part of a GCC distribution. The rest is just your favorite programming text editor/IDE.

ARM distributes their "official" binaries for the toolchain : https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads

You don't need to download the full Cube crap from ST. You can use your own dev tools along with the above ARM toolchain, and then use the ref manuals for register description/etc.
You can browse ST's github repos for the libraries and take what you need if anything, for instance for the F4 series : https://github.com/STMicroelectronics/STM32CubeF4
All the base include files are in there : https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Drivers/CMSIS
It's only C definitions though, I'm not quite sure where you can find assembly definitions for the registers, for instance. Can probably be found somewhere. You can otherwise generate them yourself from the SVD files.

This is a very useful repo : https://github.com/posborne/cmsis-svd
A crapton of MCUs in there with their respective SVD file, and tools in Python for parsing SVD and generating various file formats from it. Recommended for anyone doing bare metal dev and especially if using prog languages that are "exotic".
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf