From e65b12a1b9d153991026b194341b881534a882c7 Mon Sep 17 00:00:00 2001 From: Matt Trentini Date: Mon, 24 Oct 2022 20:28:34 +1100 Subject: [PATCH] docs/library/machine: Add machine.memX to docs with brief example. --- docs/library/machine.rst | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/library/machine.rst b/docs/library/machine.rst index c3bf438961..3f5cd6f13c 100644 --- a/docs/library/machine.rst +++ b/docs/library/machine.rst @@ -19,6 +19,44 @@ This is true for both physical devices with IDs >= 0 and "virtual" devices with negative IDs like -1 (these "virtual" devices are still thin shims on top of real hardware and real hardware interrupts). See :ref:`isr_rules`. +Memory access +------------- + +The module exposes three objects used for raw memory access. + +.. data:: mem8 + + Read/write 8 bits of memory. + +.. data:: mem16 + + Read/write 16 bits of memory. + +.. data:: mem32 + + Read/write 32 bits of memory. + +Use subscript notation ``[...]`` to index these objects with the address of +interest. Note that the address is the byte address, regardless of the size of +memory being accessed. + +Example use (registers are specific to an stm32 microcontroller): + +.. code-block:: python3 + + import machine + from micropython import const + + GPIOA = const(0x48000000) + GPIO_BSRR = const(0x18) + GPIO_IDR = const(0x10) + + # set PA2 high + machine.mem32[GPIOA + GPIO_BSRR] = 1 << 2 + + # read PA3 + value = (machine.mem32[GPIOA + GPIO_IDR] >> 3) & 1 + Reset related functions -----------------------