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.

  • Resolved

AM3358: PRU Assembler issue

Prodigy 150 points

Replies: 3

Views: 575

Part Number: AM3358

Greetings,

I appreciate the help you provide for this question in advance. I have been stuggling in PRU programming on Beaglebone black Rev C (I'm a newbie in Assembly programming) for polling one of the ports for input in determining the frequency of the incoming digital signal. Its unclear for me because for some reason I can't generate .bin file generated  "pasm -b filename.p"(I use this command for generating .bin file) 

- It does generate .bin file for other assembler program which I tried.

- There is no error in program as it shows 0 Errors after i run pasm -b command

I'm getting following output-

 

Pass 2 : 0 Error(s), 0 Warning(s)

Writing Code Image of 27 word(s)

Error: Unable to open output file: SIGNAL.bin

//SIGNAL.p is my assember program file

I have written following program -

.origin 0 // start of program in PRU memory
.entrypoint START // program entry point (for a debugger)

#define DELAY 49994
#define INIT 0 // choose the delay value to suit the frequency required
// 1 gives a 20MHz clock signal, increase from there
START:
MOV r0,INIT
MOV r1,DELAY
MOV r2,INIT
MOV r3,INIT
MOV r4,INIT
MOV r5,INIT
MOV r6,INIT // load the DELAY value into r1

MAINLOOP:
MOV r6,r30
MOV r0,r1 //r6 is assigned with the input at the r30 or P9_27
QBNE COUNTER1,r6,0 // compares the r6 value to 0 and if proven wrong then jumpes to COUNTER1
QBNE COUNTER0,r6,1 // compares the r6 value to 1 and if the proven wrong then jumps to COUNTER0

COUNTER1:
SUB r0, r0, 1 // decrement the counter by 1 and loop (next line)
QBNE COUNTER1, r0, 0 // loop until the delay has expired (equals 0)
MOV r2,0 //r2 is the counter of 0 time period is set 0
ADD r3,r3,r4 //r4 is the local counter of 0 time counter loop
ADD r5,r5,1 //r5 is the local counter of 1 time counter loop
MOV r4,0 //ONE extra command is added inorder to balance the execution period
MOV r4,0 //r4 is set 0 after transfering the data to main conter variable r3
QBA MAINLOOP

COUNTER0:
SUB r0, r0, 1 // decrement the counter by 1 and loop (next line)
QBNE COUNTER0, r0, 0 // loop until the delay has expired (equals 0)
MOV r3,0 //r3 is the counter of 1 and set as 0
ADD r2,r2,r5 //the final value of the local counter of 1 is trasfered to gloval counter of 1
ADD r4,r4,1
MOV r5,0
QBA MAINLOOP //This is used to send the pointer back to MAINLOOP this makes the program to be infinite

END:
HALT // end the pru program this isnt realised

Thanks for the help

  • Hello Hithesh,

    TI no longer supports PASM.

    • If you'd like PASM support, please check the Beaglebone forums.
    • If you want to switch your code to the TI-supported compiler CLPRU, the PRU Assembly Instructions wiki has a good overview of the differences between PASM and CLPRU.
    • We have a sample CLPRU project built for TIDA-01555 PRU_ADS8688_Interface

    The simplest skeleton for a CLPRU project is

    ; Resource table needed for remoteproc Linux driver
    	.global	||pru_remoteproc_ResourceTable||
    	.sect	".resource_table:retain", RW
    	.retain
    	.align	1
    	.elfsym	||pru_remoteproc_ResourceTable||,SYM_SIZE(20)
    	
    ||pru_remoteproc_ResourceTable||:
    	.bits	1,32			; pru_remoteproc_ResourceTable.base.ver @ 0
    	.bits	0,32			; pru_remoteproc_ResourceTable.base.num @ 32
    	.bits	0,32			; pru_remoteproc_ResourceTable.base.reserved[0] @ 64
    	.bits	0,32			; pru_remoteproc_ResourceTable.base.reserved[1] @ 96
    	.bits	0,32			; pru_remoteproc_ResourceTable.offset[0] @ 128
    
    	.sect	".text:main"
    	.clink
    	.global	||main||
    	
    ||main||:
    
    	; code goes here
    	
    	HALT

    Regards, 

    Nick

  • In reply to Nick Saulnier:

    Thanks for the response. I did figure it out using TI assember code by modifying many bugs in the code and it works fine now.
  • In reply to Hithesh Karanth:

    Those who are in search for building same functionality. I have modified the follwing code to measure the frequency of discrete input by method of repeated polling of input. As mentioned above TI doesnt support the follwing code assosiated with kernel 3.8 and PASM. However if you wish to proceed use the follwing code to generate the output file(binaries) follwed on by loading PRU with loading program(basically pushes the PRU assembler generated binaries to PRU). The code goes like this:

    .origin 0
    
    #define PRU0_ARM_INTERRUPT 19
    
    #define CONST_PRUCFG C4
    #define CONST_PRUSHAREDRAM C28
    
    #define PRU0_CTRL 0x22000
    #define PRU1_CTRL 0x24000
    
    #define CTPPR0 0x28
    
    #define OWN_RAM 0x000
    #define OTHER_RAM 0x020
    #define SHARED_RAM 0x100
    
    #define SECOND 200000000 // 2e8 5ns cycles
    #define DELAY 200 // 0.01 s
    
    START:
    lbco r0, CONST_PRUCFG, 4, 4 // Enable OCP master port
    clr r0, r0, 4
    sbco r0, CONST_PRUCFG, 4, 4
    
    mov r0, SHARED_RAM // Set C28 to point to shared RAM
    mov r1, PRU0_CTRL + CTPPR0
    sbbo r0, r1, 0, 4
    
    mov r2.w0, DELAY & 0xFFFF
    mov r2.w2, DELAY >> 16 
    
    WAITLO:
    qbbc WAITLO, r31.t15
    
    IGNORE: // Wait for 50 consecutive readings of 1
    add r0, r0, 2 // 3 cycles per loop
    qbgt IGNORE, r0, r2
    
    WAIT1: // Continue counting while input is still 1
    add r0, r0, 2
    qbbs WAIT1, r31.t15
    
    WAIT2: // Continue counting while input is 0
    add r0, r0, 2
    qbbc WAIT2, r31.t15 // End count when input goes to 1
    
    sbco r0, CONST_PRUSHAREDRAM, 0, 4 // Write count to RAM
    MOV R31.b0, PRU0_ARM_INTERRUPT+16 // Send notification to Host for program completion
    mov r0,0
    jmp IGNORE


    NOTE: the follwing code works only when P8_15 is set as "pruin" and this code shares the data via shared-ram which should be fetch by loader program inorder to display it on ARM end or OS end. If any of you require help in completing loader file do continue this discussion. Peace

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.