rk
— RV1106 MCUs的特有函数¶
这个模块提供了RV1106处理器特有的功能,包括直接访问寄存器。
内存访问¶
The module exposes three objects used for raw memory access.
- rk.mem8¶
Read/write 8 bits of memory.
- rk.mem16¶
Read/write 16 bits of memory.
- rk.mem32¶
Read/write 32 bits of memory.
Use subscript notation [...]
to index these objects with the address of
interest.
These memory objects can be used in combination with the peripheral register constants to read and write registers of the MCU hardware peripherals, as well as all other areas of address space.
Peripheral register constants¶
The module defines constants for registers which are generated from CMSIS header files, and the constants available depend on the microcontroller series that is being compiled for. Examples of some constants include:
- rk.GPIOA¶
Base address of the GPIOA peripheral.
- rk.GPIOB¶
Base address of the GPIOB peripheral.
- rk.GPIO_BSRR¶
Offset of the GPIO bit set/reset register.
- rk.GPIO_IDR¶
Offset of the GPIO input data register.
- rk.GPIO_ODR¶
Offset of the GPIO output data register.
Constants that are named after a peripheral, like GPIOA
, are the absolute
address of that peripheral. Constants that have a prefix which is the name of a
peripheral, like GPIO_BSRR
, are relative offsets of the register. Accessing
peripheral registers requires adding the absolute base address of the peripheral
and the relative register offset. For example GPIOA + GPIO_BSRR
is the
full, absolute address of the GPIOA->BSRR
register.
Example use:
# set PA2 high
stm.mem32[stm.GPIOA + stm.GPIO_BSRR] = 1 << 2
# read PA3
value = (stm.mem32[stm.GPIOA + stm.GPIO_IDR] >> 3) & 1