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.

AM335x PRU and C/C++ compiler memory access

Hi,

I'm trying to start using BeagleBone Black AM335x PRU units with the latest SDK released by TI. I need to pass array of 64 bytes from ARM to PRUSS so I want to write array of 64 bytes to PRU Data Mem0 or to Shared RAM. What is the right way to access Data RAM or Shared RAM of PRUs while using TI PRU C compiler?

Thanks.

  • Hi,

    I will ask the PRU experts to comment.
  • According to the documentation it's possible to use #pragma LOCATION directive to define the offset of the array in Data RAM of PRU. But I don't know how to create and access the array in Shared RAM.
  • Zukimo,

    If you are running Linux on the ARM core, the TI supported method of passing data between the ARM and PRUs is RPMsg. Here's a quick start guide for RPMsg that is based on the latest version of the Linux Processor SDK v2.0.1.7: http://processors.wiki.ti.com/index.php/RPMsg_Quick_Start_Guide. The shared buffers in RPMsg are located in DDR.

    If you would like to use PRU C code to place data in the PRU shared memory (and then implement your own method to get to that shared memory from the ARM core) then you can use pragma directives like you suggested. You will need to create a new section in your linker (.cmd) file and then use the DATA_SECTION pragma to place code there.

    Place this in the SECTIONS portion of your linker (.cmd) file under the other sections that look similar. Make sure there is a MEMORY at the top of the file that matches with PRU_SHAREDMEM:

    .shared_sect_name     > PRU_SHAREDMEM, PAGE 1

    Now place this pragma in your C code above the array you are trying to put in shared memory, notice that the section name matches the section in the linker file above:

    #pragma DATA_SECTION(array_name, ".shared_sect_name")

    #pragma RETAIN(array_name)

    volatile far uint32_t array_name[100];

    The DATA_SECTION pragma takes a variable name as the first argument and the section name as the section argument. The RETAIN pragma stops the PRU C compiler from optimizing the code and completely removing your array (which would happen if the compiler saw that you only read from the array and never wrote to it). The 'far' keyword is used so that the compiler will use the correct addressing offset method since the shared memory offset does not fit into a 16 bit offset.

    Jason Reeder

  • Thanks for the reply, Jason. And one more question. Will PRU C compile allocate variables in the new section sequentially starting from the beginning of the section?

  • Zukimo,

    The linker will be responsible for where everything gets placed. I think that it will most likely be the case that the variables will be allocated sequentially from the beginning but I don't think that this is absolutely guaranteed.

    You can check the placement of each section and variable in the '.map' file that the linker generates when you pass it the -m flag. See section 2.3.1 in the PRU Optimizing C/C++ Complier User's Guide (www.ti.com/.../spruhv7a.pdf).

    Jason Reeder