This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RE: PROCESSOR-SDK-AM62X: How to write mixed C and assembly PRU code

This is a continuation of the discussion at https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1442234/processor-sdk-am62x-am62x-pruss-core 

Hi Nick,

thanks. I accomplished in C language all of that. But now i am trying to write to same C code in pru inline assembly, and get syntax error constantly. I am using this guide: https://www.ti.com/lit/ug/spruij2/spruij2.pdf?ts=1736874481764&ref_url=https%253A%252F%252Fwww.google.com%252F   it looks old. It is written that it is from 2018, and i do not know if it is compatible with am62x. Is it true source for am62x ? if it is not can you give me the right sources to accomplish that task. Thanks in advance...

Best Regards

  • Hello Sevki,

    Yes, that guide will also apply to AM62x.

    Have you gone through the mixed C and assembly examples in the PRU Getting Started Labs? You can find those here:
    https://software-dl.ti.com/processor-sdk-linux/esd/AM62X/10_00_07_04/exports/docs/common/PRU-ICSS/PRU-Getting-Started-Labs_Lab2.html

    We will update those labs in the next couple months, so if you have any feedback I would love to hear it.

    If you are still running into issues, please attach the code snippet that is causing errors, as well as your build commands and the error outputs.

    Regards,

    Nick

  • Hi Nick,

    Thanks. My code is so long i am not copying everything here and waste your time. What i get in console is that:

    **** Build of configuration Debug for project Test ****

    "C:\\ti\\ccs1280\\ccs\\utils\\bin\\gmake" -k -j 20 all -O
     
    Building file: "../main.c"
    Invoking: PRU Compiler
    "C:/ti/ccs1280/ccs/tools/compiler/ti-cgt-pru_2.3.3/bin/clpru" --include_path="C:/Users/sevkierdem/workspace_v12/Test" --include_path="C:/ti/pru-software-support-package-6.4.0/include/am62x" --include_path="C:/ti/ccs1280/ccs/tools/compiler/ti-cgt-pru_2.3.3/include" --include_path="C:/ti/pru_cgt/include" --include_path="C:/ti/ccs1280/ccs/tools/compiler/ti-cgt-pru_2.3.3/include" -g --diag_warning=225 --diag_wrap=off --display_error_number --endian=little -k --preproc_with_compile --preproc_dependency="main.d_raw"  "../main.c"
     
    >> Compilation failure
    subdir_rules.mk:9: recipe for target 'main.obj' failed
    "../main.c", line 468: error #18: expected a ")"
    "../main.c", line 478: warning #12-D: parsing restarts here after previous syntax error
    1 error detected in the compilation of "../main.c".
    gmake: *** [main.obj] Error 1
    gmake: Target 'all' not remade because of errors.

    **** Build Finished ****

    and this is the inline assembly code that i have issues:

     __asm volatile(
                   "MOV     r5, %[nHostCommand]                             \n"
                   "MOV     r6, %[DATA]                                     \n"
                   "MOV     r7, %[CLK]                                      \n"
                   "MOV     r8, %[nTXData]                                  \n"
                   "MOV     r12, %[direction_out]                           \n"
                   "MOV     r13, %[direction_in]                            \n"
                   "MOV     r15, %[__R30]                                   \n"
                   "MOV     r16, %[__R31]                                   \n"

      nHostCommand and nTXData is binary like 0b0101010100101010 declared in C, they are C int variables and i want to use it in inline assembly and first assigned them to some registers, DATA and CLK is also C int variables and they equal to some  pins on board. direction_out and direction_in is also C int variables. I am using them as a parameter in C funtion named   void configure_gpio_direction(int direction) . So that was the first part of the code. In the middle there are some loops and conditional statements that i have no problem but at some point i call configure_gpio_direction function to make it writable or readable and that is the code for it:

    "MOV     r4, r12                                         \n"  // r4 argument pointer
    "BL     configure_gpio_direction                         \n"

    i could not find anything about how to call C function from inline assembly. It can be false

    Last part is where i get error:

                     :
                     : [direction_out] "r" (direction_out),
                       [direction_in]  "r" (direction_in),
                       [nHostCommand] "r" (nHostCommand),
                       [__R30]  "r" (__R30),
                       [DATA] "r" (DATA),
                       [CLK]  "r" (CLK),
                       [__R31] "r" (__R31),
                       [nTXData]  "r" (nTXData)
                     : "r4", "r5", "r6", "r7", "r8", "r12", "r13", "r15", "r16"
                 );

    error comes from first line and warning comes from last line. Thanks in advance.

    Best Regards

  • Hello,

    Hmm. I am not sure if you are allowed to put multiple pairs of quotation marks within a single __asm(); statement.

    You can definitely put multiple assembly instructions in a single __asm("assembly \n\t instructions \n\t go \n\t here \n\t"); as demonstrated in the Getting Started Labs:
    https://software-dl.ti.com/processor-sdk-linux/esd/AM62X/10_00_07_04/exports/docs/common/PRU-ICSS/PRU-Getting-Started-Labs_Lab2_mixedCandAssembly.html#write-the-inline-function-in-assembly

     https://git.ti.com/cgit/pru-software-support-package/pru-software-support-package/tree/labs/Getting_Started_Labs/c_and_inline_assembly/solution/am62x/main.c

    assembly code is just single lines of machine language. There is no such thing as a C function in assembly.

    If you have specific variables that you want to pass into your assembly code, you can do that by defining an external assembly function, and passing the variables into the function from your C code. Like this:

    https://software-dl.ti.com/processor-sdk-linux/esd/AM62X/10_00_07_04/exports/docs/common/PRU-ICSS/PRU-Getting-Started-Labs_Lab2_mixedCandAssembly.html#write-the-main-function-in-c

    https://git.ti.com/cgit/pru-software-support-package/pru-software-support-package/tree/labs/Getting_Started_Labs/c_and_assembly

    Regards,

    Nick

  • Hi Nick,

    thanks. I have another question: How can i reach the 32kB PRUSS shared memory located at 10000h from A53 core ? Thanks in advance.

    Best regards

  • Hello Sevki,

    Apologies for the delayed response here.

    The A53 core would access it using the processor-wise memory map.

    So from the Technical reference manual (TRM), Memory Map chapter, we see that the PRU memory (called ICSSM in the memory map) starts at 0x3004_0000

    As you discussed, TRM section "PRUSS Global Memory Map" puts the shared ram at an offset of 0x1_0000.

    So the A53 core would read or write to 0x305_0000 to access the SRAM.

    You can find some examples of doing that math in the "Debugging" lab of the PRU Getting Started Labs:
    https://software-dl.ti.com/processor-sdk-linux/esd/AM62X/10_01_10_04/exports/docs/common/PRU-ICSS/PRU-Getting-Started-Labs_Lab5.html

    Regards,

    Nick