Fastest IO toggle

Posted on
Page
of 2
Prev
/ 2
  • I guess I only tested the "on" and not the "off". Your description is not making sense to my old brain. Any chance for a snippet code to turn off B4?

  • Does this mean that time-keeping will be off by ~10%?

    Sadly yes, at the moment (on the Pico). The original Espruino board is much more accurate for some reason, and the rev 1v4 has a crystal on board anyway.

    It's something that's been on my list to change, because if done right a firmware update should basically fix it.

  • Ahh - just read the assembler page again, and the problem is that the STM32F1 in the original Espruino (what the Assembler page describes) and the STM32F4 in the Pico are different.

    On the F1, the bit set and bit reset registers are 4 bytes apart, which is great because you can use the str data,[reg, #4] command. On the F4 they're 2 bytes apart, which means you have to shift the value left by 16 bits in the same register (since str has to be aligned to the nearest 4 bytes).

    Try:

    var on = E.asm("void()",
                     "ldr  r2,gpiob_addr",
                     "movw  r3,#4",
                     "str  r3,[r2]",
                     "bx  lr",
                     "nop",
                     "gpiob_addr:",
                     ".word  0x40020418"
                     );
    var off = E.asm("void()",
                     "ldr  r2,gpiob_addr",
                     "movw  r3,#4",
                     "lsl r3,r3,#16", // shift it left by 16
                     "str  r3,[r2]",
                     "bx  lr",
                     "gpiob_addr:",
                     ".word  0x40020418"
                     );
    
    
    var test = E.asm("void()",
                     "ldr  r2,gpiob_addr",
                     "movw  r0,#4",
                     "lsl r1,r0,#16", // shift r0 left by 16, put in r1
                     "loopStart:",
                     "str  r0,[r2]", // on
                     "str  r1,[r2]", // off
                     "b  loopStart",
                     "bx  lr",
                     "gpiob_addr:",
                     ".word  0x40020418"
                     );
    LED1.set();
    

    I'll update the docs.

  • Thank you for the quick and informative reply. I had tried everything I could think of last night and was never successful and now I know why. ;-)

  • 14 Mhz using assembly


    1 Attachment

    • espruino-assembly.png
  • Nice! But no way to break out of it? ;)

  • I just need to put a for loop into it.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Fastest IO toggle

Posted by Avatar for cwilt @cwilt

Actions