Quest for peek and poke ...

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
PinkInk
Posts: 61
Joined: Tue Mar 11, 2014 3:42 pm

Quest for peek and poke ...

Post by PinkInk » Mon Jul 14, 2014 3:09 pm

I'm trying to implement PWM with the help of in-line assembler, on this quest I've kind of decided that it's sanest to minimise the assembler to basic peek and poke and "do the logic"/heavy lifting in uPy.

However I'm running into hard-faults, which I *think* I've substantiated shouldn't be occurring. Would anyone with more assembler know-how care to comment on whether what I'm seeing is (a) expected and I'm failing to grasp something fundamental, or (b) what I think it is i.e. a bug worth reporting?

I've tested that passing a value into an assembler function doesn't mangle it;

Code: Select all

@micropython.asm_thumb
def test(r0):
  nop()
>>> test(stm.GPIOA)
-1073610752
>>> stm.GPIOA
-1073610752

@micropython.asm_thumb
def test():
  movwt(r0, stm.GPIOA)
>>> test()
-1073610752
Conclusion: no it doesn't.

I've tested that ldr [register, offset] is functionally identical to [register+offset, 0];

Code: Select all

@micropython.asm_thumb
def test():
  movwt(r0, stm.GPIOA)
  ldr(r0, [r0, stm.GPIO_MODER])
>>> test()
-694157312

@micropython.asm_thumb
def test():
  movwt(r0, stm.GPIOA)
  add(r0, stm.GPIO_MODER)
  ldr(r0, [r0, 0])
>>> test()
-694157312
Conclusion: yes it is

Because we don't have add(reg,reg) in assembler, and because values like stm.GPIOA and stm.GPIO_MODER don't intersect, I've tested (above) ldr[register, offset] == ldr[register+offset, 0] and also == ldr[register|offset, 0] (hereunder);

Code: Select all

@micropython.asm_thumb
def test():
  movwt(r0, stm.GPIOA)
  movwt(r1, stm.GPIO_MODER)
  orr(r0, r1)
  ldr(r0, [r0, 0])
>>> test()
-694157312
Conclusion: all good so far

So, onto what I was trying to do in the first place, which doesn't work, and I'm assuming is a bug;

Code: Select all

@micropython.asm_thumb
def peek(r0):
  ldr(r0, [r0, stm.GPIO_MODER])
>>> peek(stm.GPIOA)
***Hard Fault***
Or better yet;

Code: Select all

@micropython.asm_thumb
def peek(r0, r1):
  orr(r0, r1)
  ldr(r0, [r0, 0])
>>> peek(stm.GPIOA, stm.GPIO_MODER)
***Hard Fault***
Hard Fault's are par-for-the-course when playing with assembler ... I'm just not expecting to see them in this.

Post Reply