-
-
Save whaleygeek/2ff467983b79c322b3d7a1764938d9d9 to your computer and use it in GitHub Desktop.
NRF51 registers described here: https://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf
micro:bit pin mappings here: https://tech.microbit.org/hardware/edgeconnector/
Use the "MCU" column in the table to work out which bit numbers in which port registers are actually mapped to which features (as the numbers on the big picture are not the actual chip identifies that you w
ill find in the NRF5x data sheet.
@carlosperate has some nice MicroPython examples here: https://gist.github.com/microbit-carlos?direction=asc&sort=created
The MicroPython thumb assembly instructions are documented here: https://docs.micropython.org/en/latest/reference/asm_thumb2_index.html
The simulator at python.microbit.org won't run the assembly instructions, but it does flash and run fine on the micro:bit even though there are lots of red marks over it all!
MakeCode shims mentioned here, that can call assembly language code from javascript code: https://forum.makecode.com/t/using-assembler-routines-in-both-js-and-c/2155
MakeCode extensions here (neopixel is a good example as it has assembly code in it as well): https://makecode.com/extensions
.asm files can't be added at present: microsoft/pxt-microbit#4426
The red underlining in the python.microbit.org editor for the asm lines can be removed with this fix:
42 in ASCII is a '*', this prints ABC then *BC, the assembly program has stored a 42 in the first memory location of the buffer data. id(b) is the bytearray address, the third longword32 of that memory holds the address of the actual buffer data.
# pyright: reportGeneralTypeIssues=false, reportUndefinedVariable=false
from machine import mem8, mem32
@micropython.asm_thumb
def ultimate_answer(r0):
mov(r1,42)
strb(r1,[r0,0])
b = bytearray(b'ABC')
print("before", b)
ITEMS_ADDR = mem32[id(b)+(4*3)]
ultimate_answer(ITEMS_ADDR)
print("after", b)
Make sure you use the ARM compiler and the -mthumb flag, to get the correct instruction set that the micro:bit uses.
If you choose 'output/compile to binary' it will also give you the bytes you could store into RAM and then jump to, to execute the code.