Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


C++ in-file assembly

I’m trying to migrate from Keil to SW4STM32 so I don’t have to drag along a Windows box just to debug my projects in an Embedded class. I made a new C++ project configured for an STM32F446 Nucleo with no HAL and brought in an existing main.cpp from my last assignment. I didn’t worry too much about the assembly causing complaints in the IDE because it caused complaints before and worked. Now it doesn’t my __asm function is full of errors and doesn’t even seem to get sent to the assembler. I found nothing on in C++ assembly in the docs so if the syntax is slightly different or if I was just being given some slack previously I don’t know. What don’t I know?

__asm int my_sqrt(int x){
PUSH {r4, r5}// push callee stored register
MOV r2, #0// a = 0
MOV r3, #0x0000b504//b = square root of largest possible argument(
MOV r1, #-1// c = -1 (a value we won’t encounter anaturally so equality fails to start)
my_sqrt_loop
CPY r4, r1// c_old

France

Hi,

Yes the syntax is quite different between Keil and System Workbench for STM32, which uses teh GCC compiler. You should look at the GCC dodumentation to learn how to write assembly language functions in C/C++; the documentation is freely available on Internet: just Google “GCC manual”.

Another alternative would be to craete a “.s” file with your assembly code, but in all cases teh ASM syntax has to be the GNU assembler syntax, not the Keil one...

Bernard (Ac6)


It took some finagling but I got it to work. Some hints for someone who comes in later:
Your in and out registers for your algorithm should be aliases like $[[par0]] $[[return]] (those should only be one set of brackets per but the forum software is trying to make them links) which you will define and map to variables in the return and parameter constraints of the asm block.
Even if you stack and unstack your temp registers, still put them in the “clobber” so GCC doesn’t choose to try to pass your parameters in on them.
Remember the order is code-return-parameters-clobber if you mix up parameter and return GCC will happily overwrite your input with your output variable, and do it by reference because why not.
If you’re porting from an assembly subroutine for the love of God, remove your “BX lr” first. Just return in your wrapping function to make life easier.
Despite what everything I read says, you can use plain old r1, r2, r3, etc. instead of %1, %2, %3.
Ignore the LDP documentation: it’s very x86 oriented and may confuse you if you aren’t that familiar. http://www.ethernut.de/en/documents/arm-inline-asm.htmlQuestion seems much better for learning instead of quick reference.


 

Newest Forum Posts

  1. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  2. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  3. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  4. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  5. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  6. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  8. Build a project in "release" mode by tang, 2025-02-20 10:36
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35
  10. Fail to debug in Win 11 C/C++ by mortenlund, 2024-12-26 20:27

Last-Modified Blogs