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.

SK-AM64: How to load custom PRU program while booting

Part Number: SK-AM64

Hi,

I wrote my own PRU program using CCS. I load the program using CCS through the debug OR load button and everthing works fine.

Now I need to make it autmatically load the PRU code at boot.

I even wrote my own SBL.

I knew the following wouldnt work, but still gave it a shot. I copied the .out file that CCS generates after the PRU code is compiled on to a SD card. Then I made the SBL to load the .out fle form SD card into a buffer. Then initialized everthing including the PRUs and then I used the PRUICSS_writeMemory function load the buffer into IRAM of PRU. Obviously it didnt work. I debugged the PRU using load symbols and the c code dosent match the instructions that the debugger is reading. 

I assume .out is the incorrect file to load. What is the correct file format and to generate / convert to it?

Also are the any other steps to make the PRU firmware run at boot?

I am using the following functions in order:

PRUICSS_open(CONFIG_PRU_ICSS1);
PRUICSS_resetCore(gPruicssHandle, PRUICSS_PRU1);
PRUICSS_disableCore(gPruicssHandle, PRUICSS_PRU1);
PRUICSS_writeMemory(gPruicssHandle,PRUICSS_IRAM_PRU(1),0,(uint32_t *) gAppImageBuf,fileSize);
PRUICSS_enableCore(gPruicssHandle, PRUICSS_PRU1);

As there any additional steps required? Or are these enough

The documentation is non-existent on how to use PRU, please help.

  • The .out file is an ELF file. This is not suitable for loading directly into PRU memory, as it contains a lot of metadata in addition to the actual instructions.

    If you want to load your PRU program from a file into a memory buffer you need to convert it into a "raw" binary.

    It seems that the hexpru utility can be used for this step, despite its name. Have a look at the example in mcu_plus_sdk_am64x_08_04_00_17\examples\pru_io\empty\firmware\am64x-evm\icssg0-pru0_fw\ti-pru-cgt.

    The .b00 file that gets generated when building this example seems to be a "plain" binary.

    You need to make sure that all your sections (in case your .out file has more than just .text) get included in your binary in the correct order, and that you load each section at the correct address.

    Regards,

    Dominic

  • What options do i need to select in the hex utitlity to make a compatible output? The default option generates a very large 420kb file while the .out file is only 27kb

  • Have a look at your outfile with dispru. The output from that utility shows you which sections you have, and at which addresses they are. If a "raw" binary is larger than the ELF file this usually means that you have sections that are further apart from each other, and that the area in between had to be padded.

    An ELF file can consist of multiple load segments that describe which parts of the binary go to which address, and these areas can be anywhere in the address space. If you want to include this is a single, flat, binary file, then you need to include a lot of padding, or make sure that all your load segments form a single consecutive area. An alternative is a file format that includes address information such as a hex file, and have a loader at runtime interpret this, so that the right data gets loaded to the right address.

    Regards,

    Dominic

  • Hi could you guide me more on how to get my binary. I tried understanding the examples and tried playing with different options, but I am getting now where. I am not very familiar with TI compilers and tools. this dispru tool give the following output:

    C:\TI\CCS1110\ccs\tools\compiler\ti-cgt-pru_2.3.3\bin>dispru ICSSG1PRU1.hex
    
    Disassembly of ICSSG1PRU1.hex:
    
    INTERNAL ERROR: dispru experienced a segmentation fault
    This is a serious problem.  Please contact Customer
    Support with this message and a copy of the input file
    and help us to continue to make the tools more robust.

  • Run dispru on the .out file.

  • Ohh LOL, my bad

    C:\TI\CCS1110\ccs\tools\compiler\ti-cgt-pru_2.3.3\bin>dispru ICSSG1PRU1.out
    
    Disassembly of ICSSG1PRU1.out:
    
    TEXT Section .text:_c_int00* (Little Endian), 0x1c bytes at 0x00000000
    0x00000000                   _c_int00_noinit_noargs:
    00000000     240000c0      LDI R0.w2, 0
    00000004     24036480      LDI R0.w0, 868
    00000008     0504e0e2      SUB R2, R0, 4
    0000000c     2eff818e      XIN 255, &R14.b0, 4
    00000010     230007c3      JAL R3.w2, main
    00000014     240001ee      LDI R14, 1
    00000018     230092c3      JAL R3.w2, abort
    
    TEXT Section .text (Little Endian), 0x23c bytes at 0x0000001c
    0x0000001c                   main:
    0000001c     2eff8190      XIN 255, &R16.b0, 4
    00000020     24036ce0      LDI R0, 876
    00000024     e1002090      SBBO &R16.b0, R0, 0, 4
    00000028     240370ef      LDI R15, 880
    0000002c     e1002f90      SBBO &R16.b0, R15, 0, 4
    00000030     240374e1      LDI R1, 884
    00000034     e1002190      SBBO &R16.b0, R1, 0, 4
    00000038     240378e1      LDI R1, 888
    0000003c     e1002190      SBBO &R16.b0, R1, 0, 4
    00000040     240004df      LDI R31.w2, 4
    00000044     2400009f      LDI R31.w0, 0
    00000048     24f000d1      LDI R17.w2, 61440
    0000004c     24000091      LDI R17.w0, 0
    0x00000050                   $C$L1:
    00000050     f100318e      LBBO &R14.b0, R17, 0, 4
    00000054     6f00eeff      QBNE $C$L1, R14, 0
    00000058     e1002090      SBBO &R16.b0, R0, 0, 4
    0000005c     e1002190      SBBO &R16.b0, R1, 0, 4
    00000060     230052c3      JAL R3.w2, _Z9ReadBank0v
    00000064     21003100      JMP $C$L8
    0x00000068                   $C$L2:
    00000068     230052c3      JAL R3.w2, _Z9ReadBank0v
    0x0000006c                   $C$L3:
    0000006c     f1002f92      LBBO &R18.b0, R15, 0, 4
    00000070     0b05f2f2      LSR R18, R18, 5
    00000074     6900f203      QBNE $C$L4, R18, 0
    00000078     f1002192      LBBO &R18.b0, R1, 0, 4
    0000007c     5700f2fb      QBEQ $C$L2, R18, 0
    0x00000080                   $C$L4:
    00000080     f1002192      LBBO &R18.b0, R1, 0, 4
    00000084     6900f213      QBNE $C$L9, R18, 0
    00000088     f1002092      LBBO &R18.b0, R0, 0, 4
    0000008c     0120f2f2      ADD R18, R18, 32
    00000090     e1002092      SBBO &R18.b0, R0, 0, 4
    00000094     21002700      JMP $C$L6
    0x00000098                   $C$L5:
    00000098     230072c3      JAL R3.w2, _Z9ReadBank1v
    0x0000009c                   $C$L6:
    0000009c     f1002f92      LBBO &R18.b0, R15, 0, 4
    000000a0     0b05f2f2      LSR R18, R18, 5
    000000a4     6901f203      QBNE $C$L7, R18, 1
    000000a8     f1002192      LBBO &R18.b0, R1, 0, 4
    000000ac     5700f2fb      QBEQ $C$L5, R18, 0
    0x000000b0                   $C$L7:
    000000b0     f1002192      LBBO &R18.b0, R1, 0, 4
    000000b4     6900f207      QBNE $C$L9, R18, 0
    000000b8     f100208e      LBBO &R14.b0, R0, 0, 4
    000000bc     0120eeee      ADD R14, R14, 32
    000000c0     e100208e      SBBO &R14.b0, R0, 0, 4
    0x000000c4                   $C$L8:
    000000c4     2405f0ee      LDI R14, 1520
    000000c8     f1002092      LBBO &R18.b0, R0, 0, 4
    000000cc     4ef2eee8      QBLT $C$L3, R14, R18
    0x000000d0                   $C$L9:
    000000d0     240004df      LDI R31.w2, 4
    000000d4     2400009f      LDI R31.w0, 0
    000000d8     f1002092      LBBO &R18.b0, R0, 0, 4
    000000dc     70f2ee18      QBGE $C$L13, R14, R18
    000000e0     240000f2      LDI R18, 0
    0x000000e4                   $C$L10:
    000000e4     f1002093      LBBO &R19.b0, R0, 0, 4
    000000e8     0b01f3f3      LSR R19, R19, 1
    000000ec     f0f31213      LBBO &R19.b0, R18, R19, 1
    000000f0     510a1307      QBEQ $C$L11, R19.b0, 10
    000000f4     f1002093      LBBO &R19.b0, R0, 0, 4
    000000f8     0102f3f3      ADD R19, R19, 2
    000000fc     e1002093      SBBO &R19.b0, R0, 0, 4
    00000100     f1002093      LBBO &R19.b0, R0, 0, 4
    00000104     4ef3eef8      QBLT $C$L10, R14, R19
    00000108     21004f00      JMP $C$L13
    0x0000010c                   $C$L11:
    0000010c     f100208e      LBBO &R14.b0, R0, 0, 4
    00000110     0b01eeee      LSR R14, R14, 1
    00000114     00f2eeee      ADD R14, R14, R18
    00000118     f1010e0e      LBBO &R14.b0, R14, 1, 1
    0000011c     510a0e05      QBEQ $C$L12, R14.b0, 10
    00000120     f100208e      LBBO &R14.b0, R0, 0, 4
    00000124     0502eeee      SUB R14, R14, 2
    00000128     e100208e      SBBO &R14.b0, R0, 0, 4
    0000012c     21004f00      JMP $C$L13
    0x00000130                   $C$L12:
    00000130     f100208e      LBBO &R14.b0, R0, 0, 4
    00000134     0501eeee      SUB R14, R14, 1
    00000138     e100208e      SBBO &R14.b0, R0, 0, 4
    0x0000013c                   $C$L13:
    0000013c     f100208e      LBBO &R14.b0, R0, 0, 4
    00000140     e100318e      SBBO &R14.b0, R17, 0, 4
    00000144     21001400      JMP $C$L1
    0x00000148                   _Z9ReadBank0v:
    00000148     2f051380      XOUT 10, &R0.b0, 40
    0000014c     2f05138a      XOUT 10, &R10.b0, 40
    00000150     2e8a0f82      XIN 20, &R2.b0, 32
    00000154     2e8a118a      XIN 20, &R10.b0, 36
    00000158     24000880      LDI R0.w0, 8
    0000015c     24f000c0      LDI R0.w2, 61440
    00000160     24036ce1      LDI R1, 876
    00000164     f1002181      LBBO &R1.b0, R1, 0, 4
    00000168     00e1e0e0      ADD R0, R0, R1
    0000016c     e300e082      SBBO &R2.b0, R0, 0, 32
    00000170     240000e0      LDI R0, 0
    00000174     0b01e1e1      LSR R1, R1, 1
    00000178     00e1e0e0      ADD R0, R0, R1
    0000017c     e100e08a      SBBO &R10.b0, R0, 0, 16
    00000180     240370e0      LDI R0, 880
    00000184     e1000012      SBBO &R18.b0, R0, 0, 1
    00000188     0b01f2f2      LSR R18, R18, 1
    0000018c     240374e0      LDI R0, 884
    00000190     e1000012      SBBO &R18.b0, R0, 0, 1
    00000194     240000e1      LDI R1, 0
    00000198     12eae1e1      OR R1, R1, R10
    0000019c     12ebe1e1      OR R1, R1, R11
    000001a0     12ece1e1      OR R1, R1, R12
    000001a4     12ede1e1      OR R1, R1, R13
    000001a8     24080880      LDI R0.w0, 2056
    000001ac     240808c0      LDI R0.w2, 2056
    000001b0     10e0e1e1      AND R1, R1, R0
    000001b4     240378e0      LDI R0, 888
    000001b8     e1002081      SBBO &R1.b0, R0, 0, 4
    000001bc     2e85138a      XIN 10, &R10.b0, 40
    000001c0     2e851380      XIN 10, &R0.b0, 40
    000001c4     20c30000      JMP R3.w2
    0x000001c8                   _Z9ReadBank1v:
    000001c8     2f051380      XOUT 10, &R0.b0, 40
    000001cc     2f05138a      XOUT 10, &R10.b0, 40
    000001d0     2e8a8f82      XIN 21, &R2.b0, 32
    000001d4     2e8a918a      XIN 21, &R10.b0, 36
    000001d8     24000880      LDI R0.w0, 8
    000001dc     24f000c0      LDI R0.w2, 61440
    000001e0     24036ce1      LDI R1, 876
    000001e4     f1002181      LBBO &R1.b0, R1, 0, 4
    000001e8     00e1e0e0      ADD R0, R0, R1
    000001ec     e300e082      SBBO &R2.b0, R0, 0, 32
    000001f0     240000e0      LDI R0, 0
    000001f4     0b01e1e1      LSR R1, R1, 1
    000001f8     00e1e0e0      ADD R0, R0, R1
    000001fc     e100e08a      SBBO &R10.b0, R0, 0, 16
    00000200     240370e0      LDI R0, 880
    00000204     e1000012      SBBO &R18.b0, R0, 0, 1
    00000208     0b01f2f2      LSR R18, R18, 1
    0000020c     240374e0      LDI R0, 884
    00000210     e1000012      SBBO &R18.b0, R0, 0, 1
    00000214     240000e1      LDI R1, 0
    00000218     12eae1e1      OR R1, R1, R10
    0000021c     12ebe1e1      OR R1, R1, R11
    00000220     12ece1e1      OR R1, R1, R12
    00000224     12ede1e1      OR R1, R1, R13
    00000228     24080880      LDI R0.w0, 2056
    0000022c     240808c0      LDI R0.w2, 2056
    00000230     10e0e1e1      AND R1, R1, R0
    00000234     240378e0      LDI R0, 888
    00000238     e1002081      SBBO &R1.b0, R0, 0, 4
    0000023c     2e85138a      XIN 10, &R10.b0, 40
    00000240     2e851380      XIN 10, &R0.b0, 40
    00000244     20c30000      JMP R3.w2
    0x00000248                   abort:
    00000248     230094c3      JAL R3.w2, C$$EXIT
    0x0000024c                   $C$L1:
    0000024c     21009300      JMP $C$L1
    0x00000250                   C$$EXIT:
    0x00000250                   loader_exit:
    00000250     10000000      AND R0.b0, R0.b0, R0.b0
    00000254     20c30000      JMP R3.w2
    
    DATA Section .data (Little Endian), 0x18 bytes at 0x00000364
    0x00000364                   R30:
    00000364      00000000              .word 0x00000000
    0x00000368                   R31:
    00000368      00000000              .word 0x00000000
    0x0000036c                   rxlength:
    0000036c      00000000              .word 0x00000000
    0x00000370                   rxl2indexdata:
    00000370      00000000              .word 0x00000000
    0x00000374                   rxl2indexstatus:
    00000374      00000000              .word 0x00000000
    0x00000378                   eof:
    00000378      00000000              .word 0x00000000

  • Hmm, there are no holes in the addresses, so that's not your problem.

    I'm not at my computer anymore. You should look at the .cmd file that's used as an argument to the hexpru call (don't remember the name). I believe this would remove your _cint_00 section though. Try adding that, too.

    You could also wait for an ti employee, maybe they have more ready-to-use advice. 

    Regards, Dominic 

  • I also tried this : https://software-dl.ti.com/processor-sdk-linux/esd/AM62X/latest/exports/docs/common/PRU-ICSS/PRU-Getting-Started-Labs_Lab3.html in which they tell me to use Array (-array) option to generate .hex although the size went down to less than 1Kb but its still not compatible. The c code and the debug view assembly instructiuons do not match. The PRU is still executing garbage.

  • Hello Aghimanyu singh,

    Please follow below steps to load binary on PRU from R5F0.

    1. Compile your PRU code and finally you will get pru_load_bin.h file.

    2. Include your pru_load_bin.f file in your R5F0 application. I copied all the buffer values ​​into the Test.h file.

    3. You can add below function in your R5F0 workspace.

    void pru_init()
    {
    int status;


    status = PRUICSS_initMemory(gPruIcss0Handle, PRUICSS_DATARAM(PRUICSS_PRUx));
    DebugP_assert(status != 0);
    status = PRUICSS_resetCore(gPruIcss0Handle, PRUICSS_PRUx);
    DebugP_assert(SystemP_SUCCESS == status);
    status = PRUICSS_disableCore(gPruIcss0Handle, PRUICSS_PRUx);
    DebugP_assert(SystemP_SUCCESS == status);


    status = PRUICSS_writeMemory(gPruIcss0Handle, PRUICSS_IRAM_PRU(PRUICSS_PRUx), 0,
    (uint32_t *) PRUFirmware, sizeof(PRUFirmware));
    DebugP_assert(status != 0);

    status = PRUICSS_resetCore(gPruIcss0Handle, PRUICSS_PRUx);
    DebugP_assert(SystemP_SUCCESS == status);

    status = PRUICSS_enableCore(gPruIcss0Handle, PRUICSS_PRUx);
    DebugP_assert(SystemP_SUCCESS == status);


    }

    4. Compile your R5F0 code.

    5. So, now R5F0 can load binaries into the PRU core for every warm reset/POR.

    Please check more details in the below example how to load PRU binaries from R5F0?

    C:\ti\mcu_plus_sdk_am64x_08_04_00_17\examples\pru_io\adc\ads85x8\am64x-evm\r5fss0-0_freertos

     

    Regards,

    S.Anil.

  • Hmm, there are no holes in the addresses, so that's not your problem.

    I may have to correct myself: that .data section could very well be "somewhere else" in your memory map. Not sure how the PRU linker and hexpru handles this. The other examples for PRU binaries I've seen didn't have a .data section. You can tell hexpru to generate a map file of what it's doing: --map=file.name. That could tell you what's going on when hexpru generated the ~420kb file.

  • Hi

    I understand your method, it looks simpler than mine. BUT you didnt tell me how to get the .h file and .f file. defualt compiler settings do not generate any such files.

    Following is the snapshot of my project tree adter compiling the project

  • I think I figured it out. I was assuming the .hex generated in the by following the this method:

    I also tried this : https://software-dl.ti.com/processor-sdk-linux/esd/AM62X/latest/exports/docs/common/PRU-ICSS/PRU-Getting-Started-Labs_Lab3.html in which they tell me to use Array (-array) option to generate .hex although the size went down to less than 1Kb but its still not compatible. The c code and the debug view assembly instructiuons do not match. The PRU is still executing garbage.

    was a binary file. I just opened it and its seems to be actually a C header file that has the instructions and data stored in C type array. I assume loading this array into PRU memory should solve my problem and make everyhting work. Ill test and conclude the results.

  • YUP it worked!!! Thanks everyone. BIG help