Hello,
I am trying to add entries to an array using inline assembly and then send the array out through the Native USB port on an Arduino Due
Currently I have a sensor connected to an Arduino Due that passes bytes of data that I am collecting.
I would like to place the bytes into the array using inline assembly code rather than using C code.
I have a working test code in C and I used the assembly dump from it to build a test version in assembly, but for some reason, it does not work.
C version:
uint32_t FIFO[512];
int cnt1 = 0;
int cnt2 = 0;
void setup() {
SerialUSB.begin(250000);
}
void loop() {
while(1)
{
FIFO[cnt1] = 1;
cnt1++;
if (cnt1 == 512)
{
cnt1 = 0;
}
FIFO[cnt1] = 2;
cnt1++;
if (cnt1 == 512)
{
cnt1 = 0;
}
SerialUSB.println(FIFO[cnt2]);
cnt2++;
if (cnt2 == 512)
{
cnt2 = 0;
}
SerialUSB.println(FIFO[cnt2]);
cnt2++;
if (cnt2 == 512)
{
cnt2 = 0;
}
}
}
Inline Assembly version:
uint32_t FIFO[512];
volatile uint32_t *addPointer = &FIFO[0];
int cnt = 0;
void setup() {
SerialUSB.begin(250000);
}
void loop() {
__asm__ volatile( "MOV R9, #0\n\t");
__asm__ volatile( "LDR R8, [%0]\n\t" ::"r"(&FIFO)); //I believe this is where the problem is
while(1)
{
__asm__ volatile( "MOV R10, #1\n\t");
__asm__ volatile( "STR.W R10, [R8, R9, LSL #2]\n\t");
__asm__ volatile( "ADD R9, #1\n\t");
__asm__ volatile( "CMP.W R9, #512\n\t");
__asm__ volatile( "ITE EQ\n\t");
__asm__ volatile( "MOVEQ R9, #0\n\t");
__asm__ volatile( "NOPNE\n\t");
__asm__ volatile( "MOV R10, #2\n\t");
__asm__ volatile( "STR.W R10, [R8, R9, LSL #2]\n\t");
__asm__ volatile( "ADD R9, #1\n\t");
__asm__ volatile( "CMP.W R9, #512\n\t");
__asm__ volatile( "ITE EQ\n\t");
__asm__ volatile( "MOVEQ R9, #0\n\t");
__asm__ volatile( "NOPNE\n\t");
SerialUSB.println(FIFO[cnt]);
cnt++;
if(cnt == 512)
{
cnt = 0;
}
SerialUSB.println(FIFO[cnt]);
cnt++;
if(cnt == 512)
{
cnt = 0;
}
}
}
I believe that the problem with the code is finding the correct memory address for the first entry spot of FIFO, but I have no idea where that memory address is or how to find it.
Thanks so much for your time
EDIT: See reply #2 for solution