not logged in | [Login]

References

The stm module is very interesting ... it exposes access directly to the MCU's memory (to read and set values) and a whole heap of constants that make it trivial to peer into and influence the behaviour of the MCU's hardware peripherals directly.

directly access MCU memory

Three objects are exposed;

  • stm.mem8 - access 8 bits of memory (right aligned in a 32bit word?)
  • stm.mem16 - access 16 bits of memory (right aligned in a 32bit word?)
  • stm.mem32 - access a 32 bit word of memory

In combination with the constants described hereunder they can be used to read, and write, to the control (and monitoring) registers of the MCU's hardware peripherals, and perhaps all other areas of MCU memory(?).

Examples;

stm.mem32[stm.TIM3 + stm.TIM_CR1] 
#return the contents of Timer 3's Control Register 1 (yes Timer 3 - one of the ones that uPy won't let you access with pyb.Timer
stm.mem32[stm.TIM3 + stm.TIM_CR1] = value
#yes ... set the value of Timer 3's Control Register 1

Of course, it goes without saying - tinkering around at this level is inevitably going to crash the pyboard more than occasionally, but the likelihood of you permanently damaging it is relatively low.

constants

The stm module exposes a lot of constants ... generally of two types;

  • start of the sequence of memory addresses associated with a particular instance of a peripheral class, for example;

    • stm.TIM1 - the starting address of the block assigned to Timer 1
    • stm.GPIOA - the starting address of the block assigned to General Purpose IO peripheral A
  • offsets (from a starting address), for each class of peripherals specific settings memory areas, for example

    • stm.TIM_CR1 - Timer Control Register 1 offset (stm.TIM1 + stm.TIM_CR1 is Timer 1's Control Register 1 address, and stm.TIM2 + stm.TIM_CR1 is Timer 2's Control Register 1 address)