import machine
import utime
# === address from datasheet RP2040 ===
RESETS_BASE = 0x4000C000
RESETS_RESET = RESETS_BASE + 0x0
RESETS_DONE = RESETS_BASE + 0x8
IO_BANK0_BASE = 0x40014000
SIO_BASE = 0xD0000000
GPIO0_CTRL = IO_BANK0_BASE + 0x004 # Control register of GPIO 0
GPIO_FUNC_SIO = 5 # SIO – GPIO řízeno CPU
# === activation of IO_BANK0 a SIO peripheries ===
mask = (1 << 5) | (1 << 1) # bit 5=IO_BANK0, bit 1=SIO
machine.mem32[RESETS_RESET] &= ~mask
while (machine.mem32[RESETS_DONE] & mask) != mask:
pass
# === function of the pin ===
machine.mem32[GPIO0_CTRL] = GPIO_FUNC_SIO
# === pin serves as an output ===
SIO_GPIO_OE = SIO_BASE + 0x024
machine.mem32[SIO_GPIO_OE] |= (1 << 0)
# === LED control ===
SIO_GPIO_OUT = SIO_BASE + 0x010
# LED ON
machine.mem32[SIO_GPIO_OUT] |= (1 << 0)
# LED OFF
machine.mem32[SIO_GPIO_OUT] &= ~(1 << 0)