asm not working with C

Post here first, or if you can't find a relevant section!
Post Reply
IanNoob
Posts: 15
Joined: Wed Oct 07, 2020 5:35 pm

asm not working with C

Post by IanNoob »

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:

Code: Select all

void loop(); {
    Serial.print something
       // asm routine commented out
    Serial.print something
}
This prints nothing – shows no sign of life:

Code: Select all

void loop(); {
    Serial.print something
      asm 
    Serial.print something
}
I have tried putting the asm as a separate function but that does exactly the same thing.

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;
   }
Can anyone see what I'm doing wrong?

Thank you
Ian

gdenton61
Posts: 1
Joined: Wed Jan 22, 2020 11:15 pm
Location: USA, Texas

Re: asm not working with C

Post by gdenton61 »

void loop();

should be:

void loop() {

IanNoob
Posts: 15
Joined: Wed Oct 07, 2020 5:35 pm

Re: asm not working with C

Post by IanNoob »

Thanks gdenton61, that's embarassing - that error is in all of the 4 code examples that I put up.
In reality, it's not in the codes that I'm actually trying as the compiler rejects that error.

Ian

Post Reply

Return to “General discussion”