Loop not getting called? [SOLVED]

I’m working on porting my FastLED library to the SparkCore platform, working on the fast pin i/o at the moment. I have a simple test program to just toggle the value of pin 13 (PA5) and it appears that my loop function isn’t ever getting called. I have an application that looks like this:

using namespace FastLED;
void setup() { FastPin<13>::setOutput(); }
void loop()  { FastPin<13>::hi(); delay(500); FastPin<13>::lo(); delay(1000); }

I’ve verified that this is compiling correctly - looking at the asm of the elf file:

08005a2c <loop>:
 8005a2c:       b538            push    {r3, r4, r5, lr}
 8005a2e:       4c07            ldr     r4, [pc, #28]   ; (8005a4c <loop+0x20>)
 8005a30:       2520            movs    r5, #32
 8005a32:       6125            str     r5, [r4, #16]
 8005a34:       f44f 70fa       mov.w   r0, #500        ; 0x1f4
 8005a38:       f000 ff30       bl      800689c <delay>
 8005a3c:       6165            str     r5, [r4, #20]
 8005a3e:       f44f 707a       mov.w   r0, #1000       ; 0x3e8
 8005a42:       e8bd 4038       ldmia.w sp!, {r3, r4, r5, lr}
 8005a46:       f000 bf29       b.w     800689c <delay>
 8005a4a:       bf00            nop
 8005a4c:       40010800        andmi   r0, r1, r0, lsl #16

Right now, FastPin::setOutput is just a call to pinMode, which looking at the disasm for setup() is getting called. And I’m flipping the bit for pin 13, 40010800 is the base address for GPIOA, the offset of #16 is BSRR and #20 is BRR, and I’m setting the 6th bit on BSRR, which should be raising the pin high, and then setting the 6th bit of BRR which should be raising the pin low. However, I’m not seeing pin13 toggling on my logic probe.

Also, if I change my loop function to call digitalWrite directly instead of my own code:

  void loop() { digitalWrite(13,1); delay(500); digitalWrite(13,0); delay(1000); }

I’m also still not seeing the toggle in the logic probe.

I’m building the firmware from the command line, and I’m definitely flashing the built .bin file and the asm dumps above come from the .elf file alongside the .bin file that gets flashed.

Are you actually testing the pin labled A3 on your Core`?

Just for testing you could also use D7 (pin number 07) and have a look at the blue LED.

1 Like

Pin A3/13 is on GPIO _P_ort A, pin 5 (that's the PA5) - so, yes, I am testing A3. The important thing is that i'm writing a 0x0020 into GPIOA->BSRR to turn the pin on and a 0x0020 into GPIOA->BRR to turn it off (and, before you ask, yes, I also tried this with writing a 0x00200000 into GPIOA->BSRR).

Sure, when I change my code to use pinMode/digitalWrite on pin7 - I'm still not seeing the pin toggle on the scope (ditto for using my fast, direct access to PA13).

So, again, it would appear that my loop function is not getting called.

The problem was I needed the following in my code:




As documented under advanced system modes. It seems that under the default, SYSTEM_MODE(AUTOMATIC), setup/loop aren’t called until the Spark Core has made a wifi connection.

1 Like