Last active
September 19, 2019 15:25
-
-
Save sebi5361/07813d21539f5fd9250ef7cfe2815220 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2019-09-19 SK, MIT license | |
""" | |
MicroPython code. | |
Memory map access using the peek and poke functions. | |
Tested on nRF52. | |
""" | |
# Peek | |
@micropython.asm_thumb | |
def reg_read(r0): # address | |
ldr(r0, [r0, 0]) | |
def int2uint(value): | |
value = value + 0x1_0000_0000 if value < 0 else value | |
return value | |
def peek(address): | |
value = reg_read(address) | |
return int2uint(value) | |
# Poke | |
@micropython.asm_thumb | |
def reg_write(r0, r1): # address, value | |
str(r1, [r0, 0]) | |
def poke(address, value): | |
reg_write(address, value) | |
return peek(address) | |
# Tests | |
if __name__ == "__main__": | |
address = 0x1000_1000 | |
print(hex(peek(address))) | |
address = 0x20_00_44_40 + 0x10_00 + 42 | |
value = 0x_af_e5_34_8b | |
print(hex(poke(address, value))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment