Exploring ARM assembly language on STM32 with Windows desktop - Page 1
Forum section: electronics / general

author: Sherlock Holmes
author_rank: Frequent Contributor
timestamp: November 29, 2022, 06:38:52 pm
content: 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?

author: jpanhalt
author_rank: Super Contributor
timestamp: November 29, 2022, 08:52:37 pm
content: I was surprised to find this:https://www.amazon.com/Assembly-Language-Programming-STM32-Microcontrollers/dp/B08GFX3PTWIt's cheap, particularly on Kindle. But, I would buy the hard copy. There may be other resources.

author: Sherlock Holmes
author_rank: Frequent Contributor
timestamp: November 29, 2022, 09:07:39 pm
content: Quote from: jpanhalt on November 29, 2022, 08:52:37 pmI already have this bookhttps://www.amazon.com/gp/product/0124080820/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1which 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-13Looks 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...

author: jpanhalt
author_rank: Super Contributor
timestamp: November 29, 2022, 11:50:36 pm
content: This may help:https://developer.arm.com/documentation/dui0473/m/assembler-document-revisions?lang=enIt 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-assemblerPresumably, 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

author: Sherlock Holmes
author_rank: Frequent Contributor
timestamp: November 30, 2022, 12:06:43 am
content: Quote from: jpanhalt on November 29, 2022, 11:50:36 pmThanks, much appreciated, I'll take a good look...

author: cfbsoftware
author_rank: Regular Contributor
timestamp: November 30, 2022, 01:28:11 am
content: 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 ProcessorsThe Definitive Guide to the ARM® Cortex®-M0I also find it informative to inspect the disassembled code produced by a compiler.

author: cfbsoftware
author_rank: Regular Contributor
timestamp: November 30, 2022, 01:30:52 am
content: Quote from: jpanhalt on November 29, 2022, 11:50:36 pmYou can use STM32 ST-Link to program STM32 devices:https://www.st.com/en/development-tools/stsw-link004.html

author: westfw
author_rank: Super Contributor
timestamp: November 30, 2022, 11:44:22 am
content: 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.

author: AVI-crak
author_rank: Regular Contributor
timestamp: November 30, 2022, 01:38:47 pm
content: 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 examplehttps://godbolt.org/z/Wf6sEfE4bExciting task: to write code in C or another language (47 positions) so that the result in assembler is as compact as possible, and fast.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 30, 2022, 02:11:10 pm
content: 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.

author: Siwastaja
author_rank: Super Contributor
timestamp: November 30, 2022, 02:22:40 pm
content: 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.

author: cfbsoftware
author_rank: Regular Contributor
timestamp: December 01, 2022, 12:20:26 am
content: Quote from: westfw on November 30, 2022, 11:44:22 amJust 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.

author: cfbsoftware
author_rank: Regular Contributor
timestamp: December 01, 2022, 12:25:13 am
content: Quote from: AVI-crak on November 30, 2022, 01:38:47 pm... unless, like me, you happen to be writing the code generator for a compiler

author: brucehoult
author_rank: Super Contributor
timestamp: December 01, 2022, 12:46:51 am
content: Quote from: cfbsoftware on December 01, 2022, 12:20:26 amNot 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 ThumbMSR, MRS: move to/from status registersDMB, DSB, ISB: fence/barrier instructionsThat's all! Nothing a C compiler cares about.

author: westfw
author_rank: Super Contributor
timestamp: December 01, 2022, 01:33:44 am
content: QuoteYeah, 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.QuoteIME, not at all "vis versa." Very common m3 (v7m) code patterns don't exist for m0 (v6m.)

author: brucehoult
author_rank: Super Contributor
timestamp: December 01, 2022, 01:38:02 am
content: Quote from: westfw on December 01, 2022, 01:33:44 amNo 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!

author: harerod
author_rank: Frequent Contributor
timestamp: December 01, 2022, 11:43:27 am
content: Quote from: Sherlock Holmes on November 29, 2022, 06:38:52 pmI 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.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 01, 2022, 06:44:40 pm
content: 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-downloadsYou 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/STM32CubeF4All the base include files are in there :https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Drivers/CMSISIt'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-svdA 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".