2014-04-12 17:27:23 +00:00
|
|
|
# flash LED #1 using inline assembler
|
2014-04-12 23:30:32 +00:00
|
|
|
# this version is overly verbose and uses word stores
|
2014-04-12 17:27:23 +00:00
|
|
|
@micropython.asm_thumb
|
|
|
|
def flash_led(r0):
|
|
|
|
movw(r1, (stm.GPIOA + stm.GPIO_BSRRL) & 0xffff)
|
|
|
|
movt(r1, ((stm.GPIOA + stm.GPIO_BSRRL) >> 16) & 0x7fff)
|
|
|
|
movw(r2, 1 << 13)
|
|
|
|
movt(r2, 0)
|
|
|
|
movw(r3, 0)
|
|
|
|
movt(r3, 1 << 13)
|
|
|
|
|
|
|
|
b(loop_entry)
|
|
|
|
|
|
|
|
label(loop1)
|
|
|
|
|
|
|
|
# turn LED on
|
2014-04-12 23:30:32 +00:00
|
|
|
str(r2, [r1, 0])
|
2014-04-12 17:27:23 +00:00
|
|
|
|
|
|
|
# delay for a bit
|
|
|
|
movw(r4, 5599900 & 0xffff)
|
|
|
|
movt(r4, (5599900 >> 16) & 0xffff)
|
|
|
|
label(delay_on)
|
2014-04-12 23:30:32 +00:00
|
|
|
sub(r4, r4, 1)
|
2014-04-12 17:27:23 +00:00
|
|
|
cmp(r4, 0)
|
|
|
|
bgt(delay_on)
|
|
|
|
|
|
|
|
# turn LED off
|
2014-04-12 23:30:32 +00:00
|
|
|
str(r3, [r1, 0])
|
2014-04-12 17:27:23 +00:00
|
|
|
|
|
|
|
# delay for a bit
|
|
|
|
movw(r4, 5599900 & 0xffff)
|
|
|
|
movt(r4, (5599900 >> 16) & 0xffff)
|
|
|
|
label(delay_off)
|
2014-04-12 23:30:32 +00:00
|
|
|
sub(r4, r4, 1)
|
2014-04-12 17:27:23 +00:00
|
|
|
cmp(r4, 0)
|
|
|
|
bgt(delay_off)
|
|
|
|
|
|
|
|
# loop r0 times
|
2014-04-12 23:30:32 +00:00
|
|
|
sub(r0, r0, 1)
|
2014-04-12 17:27:23 +00:00
|
|
|
label(loop_entry)
|
|
|
|
cmp(r0, 0)
|
|
|
|
bgt(loop1)
|
|
|
|
|
2014-04-12 23:30:32 +00:00
|
|
|
# flash LED #2 using inline assembler
|
|
|
|
# this version uses half-word sortes, and the convenience assembler operation 'movwt'
|
2014-04-12 17:27:23 +00:00
|
|
|
@micropython.asm_thumb
|
|
|
|
def flash_led_v2(r0):
|
2014-04-12 23:30:32 +00:00
|
|
|
# get the GPIOA address in r1
|
|
|
|
movwt(r1, stm.GPIOA)
|
|
|
|
|
|
|
|
# get the bit mask for PA14 (the pin LED #2 is on)
|
|
|
|
movw(r2, 1 << 14)
|
2014-04-12 17:27:23 +00:00
|
|
|
|
|
|
|
b(loop_entry)
|
|
|
|
|
|
|
|
label(loop1)
|
|
|
|
|
|
|
|
# turn LED on
|
2014-04-12 23:30:32 +00:00
|
|
|
strh(r2, [r1, stm.GPIO_BSRRL])
|
2014-04-12 17:27:23 +00:00
|
|
|
|
|
|
|
# delay for a bit
|
|
|
|
movwt(r4, 5599900)
|
|
|
|
label(delay_on)
|
2014-04-12 23:30:32 +00:00
|
|
|
sub(r4, r4, 1)
|
2014-04-12 17:27:23 +00:00
|
|
|
cmp(r4, 0)
|
|
|
|
bgt(delay_on)
|
|
|
|
|
|
|
|
# turn LED off
|
2014-04-12 23:30:32 +00:00
|
|
|
strh(r2, [r1, stm.GPIO_BSRRH])
|
2014-04-12 17:27:23 +00:00
|
|
|
|
|
|
|
# delay for a bit
|
|
|
|
movwt(r4, 5599900)
|
|
|
|
label(delay_off)
|
2014-04-12 23:30:32 +00:00
|
|
|
sub(r4, r4, 1)
|
2014-04-12 17:27:23 +00:00
|
|
|
cmp(r4, 0)
|
|
|
|
bgt(delay_off)
|
|
|
|
|
|
|
|
# loop r0 times
|
2014-04-12 23:30:32 +00:00
|
|
|
sub(r0, r0, 1)
|
2014-04-12 17:27:23 +00:00
|
|
|
label(loop_entry)
|
|
|
|
cmp(r0, 0)
|
|
|
|
bgt(loop1)
|
|
|
|
|
2014-04-12 23:30:32 +00:00
|
|
|
flash_led(5)
|
2014-04-12 17:27:23 +00:00
|
|
|
flash_led_v2(5)
|