asm not working with C
Posted: Fri Oct 30, 2020 3:37 pm
Hello again.
I’ve been trying to move forward with trying to measure the time interval between 2 pulses.
Having got the asm working (the one labelled “asm1” on:
viewtopic.php?f=7&t=704&start=21
I am now trying to integrate this into C code but whatever I try, the asm stops any C code from running.
For example, this prints as expected:
This prints nothing – shows no sign of life:
I have tried putting the asm as a separate function but that does exactly the same thing.
Can anyone see what I'm doing wrong?
Thank you
Ian
I’ve been trying to move forward with trying to measure the time interval between 2 pulses.
Having got the asm working (the one labelled “asm1” on:
viewtopic.php?f=7&t=704&start=21
I am now trying to integrate this into C code but whatever I try, the asm stops any C code from running.
For example, this prints as expected:
Code: Select all
void loop(); {
Serial.print something
// asm routine commented out
Serial.print something
}
Code: Select all
void loop(); {
Serial.print something
asm
Serial.print something
}
Code: Select all
uint32_t t0,t1;
void setup() {
pinMode(PB4,OUTPUT);
pinMode(PB3,INPUT);
Serial.begin(250000);
}
void loop();
t0 = micros();
Serial.println(t0);
FastReadAsm();
t1 = micros();
Serial.println(t1);
Serial.println();
} // end loop
void FastReadAsm() {
asm (
" ldr.w r0, = #0x40010C08 \n" // GPIOB_IDR (0x40010C00 + 0x08)) Input Data Register
" ldr r2, = #0x40010C10 \n" // GPIOB_BSRR (0x40010C00 + 0x10))Bit Set Reset Register
" ldr r3, = #0x10 \n" // Bit 4 = 0b0001 0000
" ldr r4, = #0x100000 \n" // Bit 4 = 0b0001 0000 but shifted 16bits higher into
// Bit 4 = 0b0001 0000 upper (reset) register. See BSRR p173.
"again: \n"
" ldr r1, [r0] \n" // Load contents of IDR to r1
" ands r1, r1, #0x08 \n" // AND with Set flags against Bit 3 = 0b0000 1000
" beq again \n" // Branch if equal to zero (ie, no pulse there)
" str r3, [r2] \n" // Set port high
" str r4, [r2] \n" // Set port low
); // end Asm
return;
}
Thank you
Ian