I’m trying to get some C code to do some frequency measurements on the PRU GPIOs, and then to write the results to the PRU shared RAM so it can be retrieved and acted upon by the linux loader C code.
So the PRU C code executes, and I have some values ready to store. My initial method of attack to achieve this was to write some inline assembly to store the results to the shared memory. But I’m having trouble with this - the clpru compiler will not permit me to use the MOV command inline (is this just me or is it a thing?).
void shm_test()
{
asm volatile
(
" MOV r3, 0x00002222 \n" // r3 will store the freq
" MOV r0, 0x00000008 \n" // going to write the result to this address
" SBBO r3, r0, 0, 4 \n" // store the count at this address
);
}
The above will not compile (MOV and SBBO seem to be forbidden by the compiler).
When I’ve been looking for examples of using C code on the PRU the methods used to write to the shared memory seem rather complex (and many use inline assembly that is pretty opaque to me) - e.g Fabien Le Mentec’s pruss_c example from his pru_sdk repo: http://www.embeddedrelated.com/showarticle/603.php
Can someone point me to a decent example of getting C on the PRU to write to shared RAM (e.g. 0x00010000).
Cheers,
Jon Ross
That is one of those little things you need to be careful when writing code for the clpru: that code will work fine for pasm, but clpru will complain (I am talking about the assembly, no idea about inline or C, I’ve only worked with assembly in the PRU). Basically two things:
- you need to “dereference origin registers” (I have no better way to say this, just use &): SBBO &r3, r0, 0, 4;
- you need to explicitly use LDI instead of MOV when working with immediate values. In your case, LDI32: e.g., LDI32 r3, 0x00002222
You can try this and see if it helps.
Cheers!
Worked perfectly! Thankyou so much. No idea why clpru is pickier than pasm, but at least that problem is solved.
And I’d still be curious if anyone has any simple methods of using C to write to the pru data ram rather than assemby code.
Cheers,
JR
Worked perfectly! Thankyou so much. No idea why clpru is pickier than pasm, but at least that problem is solved.And I’d still be curious if anyone has any simple methods of using C to write to the pru data ram rather than assemby code.
Cheers,
JR
All the examples I’ve seen, which I may have only seen the same post as you( can’t remember been doing lots of reading the last few days) I’ve only ever seen use of inline assembly. There is also an open sourced C compiler somewhere, but no idea if it’s been updated in the last year+ or so. Since TI released theirs. There should be documentation for the TI PRU C compiler somewhere though. I have not looked yet.
According to texane though, the compiler comes with CCS, and is self contained in it’s own directory. Meaning it can be used standalone. The point here being, I would assume the documentation is in that directory as well.
Doing a quick google search, I found this project: https://github.com/BeaglePilot/PRUSS-C/, and looking through one C file it seems to be all C. However, I did not check to see, if the file in question was actually just some C abstraction layer for inline assembly or some compiled library that was initially written in assembly . . .
Keywords I used where “TI PRU C compiler” in google. turned up many results, and many seemingly decent prospects. Anyway, I’m off doing something different otherwise I’d look deeper into it. Good luck !