Quest for peek and poke ...
Posted: 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;Conclusion: no it doesn't.
I've tested that ldr [register, offset] is functionally identical to [register+offset, 0];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);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;
Or better yet;
Hard Fault's are par-for-the-course when playing with assembler ... I'm just not expecting to see them in this.
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
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
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
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***
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***