Graeme Winter

µPython registers

GPIO registers

Decided to start looking at some higher power stuff in µPython which is not available through the standard APIs -> have to start register hacking instead. The datasheet is superb and explains everything needed.

Day 0: switch on and off GPIO output by poking registers, not cheating by using the machine.Pin interface.

Code:

from machine import mem32
import time

# set up GPIO25 (the LED) by hand and switch it on and off by
# poking values into registers - see datasheet 2.19.6.1

led = 25

# have to set the pin to SIO mode in the control register
mem32[0x40014000 | 0xCC] = 0x5

# pad drive mode - 12mA
mem32[0x4001C000 | 0x68] = 0x3 << 4

# enable output
mem32[0xD0000000 | 0x20] = 0x1 << led


def on():
    # set the right bit as on
    mem32[0xD0000000 | 0x14] = 0x1 << led


def off():
    # set the right bit as clear
    mem32[0xD0000000 | 0x18] = 0x1 << led


for j in range(10):
    on()
    time.sleep(1)
    off()
    time.sleep(1)

would have been fun to not use time.sleep() instead finding another way to poke the machine into sleeping for a while.

Hardware Interpolator

That is a really low level thing which I don’t actually understand right now, but can play with it by changing the hello_interp C program to bit bang registers to drive the interps. Turns out it was really simple viz:

from machine import mem32

# initialise lane 0 on interp
mem32[0xD0000000 | 0xAC] = 0x1F << 10

# set up 9 x table example
mem32[0xD0000000 | 0x80] = 0
mem32[0xD0000000 | 0x88] = 9

for j in range(10):
    print(mem32[0xD0000000 | 0x94])

Yes, this prints 9x table as expected.

Previous Next