add large assembly code to a Zephyr project

Hi, I have a nRF5340 Development Kit. I want to add a large amount of assembly code from a previous Cortex M4 project (from PSoC Creator 4.2). Project has *.s files and *.h files.

How can I adapt the assembly code into the Zephyr project? Where I can find the documentation that shows me how to add assembly code to a Zephyr project?

I don't know if is important, I use Visual Code Studio for development and started from echo project (because this project is using I2S peripheral).

Thank you.

Parents
  • Hello, 

    Please note that the nRF5340 SoC has two ArmRegistered CortexRegistered-M33 processors:

    • 128/64 MHz Arm Cortex-M33 application processor with 1 MB Flash & 512 KB RAM
    • 64 MHz Arm Cortex-M33 network processor with 256 KB Flash & 64 KB RAM

    You will need to make sure that the assembly code is compliant with the M33 processors. 

    Regarding assembly in the Zephyr project, it should be fully compatible with the os. Please see Application Development in the Zephyr OS

    • main.c: A source code file. Applications typically contain source files written in C, C++, or assembly language. The Zephyr convention is to place them in a subdirectory of <app> named src.

    Kind regards,
    Øyvind

Reply
  • Hello, 

    Please note that the nRF5340 SoC has two ArmRegistered CortexRegistered-M33 processors:

    • 128/64 MHz Arm Cortex-M33 application processor with 1 MB Flash & 512 KB RAM
    • 64 MHz Arm Cortex-M33 network processor with 256 KB Flash & 64 KB RAM

    You will need to make sure that the assembly code is compliant with the M33 processors. 

    Regarding assembly in the Zephyr project, it should be fully compatible with the os. Please see Application Development in the Zephyr OS

    • main.c: A source code file. Applications typically contain source files written in C, C++, or assembly language. The Zephyr convention is to place them in a subdirectory of <app> named src.

    Kind regards,
    Øyvind

Children
  • Hello, Thank you for your answer.

    I forgot the highlight that my code has to reside on the Application processor.

    BTW: how do I know what source code is compiled for one Code and what code is compiled for the other?

    I read that sentence ... but is not clear for me how?

    I create a new *.s file and what should I write in order to define a function? 

    Do you have any link to documentation related to: how to write ASM code (not in line ... because I have a large amount of ASM code).?

    Thank you.

  • There isn't much documentation on writing assembly in our nRF Connect SDK (based on Zephyr RTOS). Most of the code is based on C and some C++. I'm not able to provide more information for assembly I'm afraid. 

    You could try reaching out to the Zephyr community on Discord.

    Kind regards,
    Øyvind

  • Perhaps look at some of the Zephyr .s files for example usage, eg reset.s although they tend to use a lot of macros which is unfortunate

    C:\ncs\v2.7.0\zephyr\arch\arm\core\header.s

    C:\ncs\v2.7.0\zephyr\arch\arm\core\cortex_m\reset.s

  • Hello,

    droidecahedron/hello_world_asm (github.com)

    Here is a bare minimum sample showing both inline and externally called asm. I don't protect my registers, sp, etc. It is just showing how to call an asm fn in an NCS C application inline and externally.

    You'll have to add the assembly files to cmakelists similar to C source files and have C-callable assembly functions.

    If it just runs on the app core, it mostly just has to play nice with the RTOS wherever and however you're calling the asm functions.

    I've not tested this kind of use case extensively, and as Øyvind mentioned you'll have to make sure your *.s assembler source code will be compliant with M33 if your intention is to use the 5340 and it was written for M4.

    There is not a lot of documentation around this, as  mentioned I referenced the Zephyr .s files to write this basic arithmetic. Depending on what the end goal of the application is, how much work has to be done, and what the asm libraries do, I would heavily consider a port to C.

    Best regards,

Related