Last active
December 25, 2016 07:41
-
-
Save idt12312/f4b39a46f8b5350e6fb31e6f066cb768 to your computer and use it in GitHub Desktop.
アセンブリでSystickを使ってLチカをする : Nucleo STM32F103
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text | |
.global _start | |
.code 16 | |
.syntax unified | |
.equ STACK_TOP, 0x20005000 | |
.equ SCB_VTOR, 0xE000ED08 | |
.equ RCC_APB2ENR, 0x40021018 | |
.equ GPIOA_CRL, 0x40010800 | |
.equ GPIOA_ODR, 0x4001080C | |
.equ SYSTICK_CTRL, 0xE000E010 | |
.equ SYSTICK_LOAD, 0xE000E014 | |
_start: | |
.org 0x00000000 | |
.word STACK_TOP | |
.word init | |
.type init, function | |
.org 0x0000003C | |
.word systick_handler | |
.type systick_handler, function | |
init: | |
// 割り込みベクタの先頭アドレスを設定 | |
LDR r0, =SCB_VTOR | |
LDR r1, =0x08000000 | |
str r1, [r0] | |
// GPIOAのクロックを有効にする | |
LDR r0, =RCC_APB2ENR | |
mov r1, #0x0004 | |
str r1, [r0] | |
// PA5を出力に設定 | |
LDR r0, =(GPIOA_CRL+2) | |
mov r1, #0x0020 | |
str r1, [r0] | |
// systickのロードレジスタを設定(1sでタイムアウト) | |
LDR r0, =SYSTICK_LOAD | |
LDR r1, =8000000 | |
str r1, [r0] | |
// systickを動作開始 | |
LDR r0, =SYSTICK_CTRL | |
mov r1, #0x0007 | |
str r1, [r0] | |
// systickの割り込みが発生するまで待機 | |
loop: | |
b loop | |
systick_handler: | |
// GPIOAの出力状態を読み出し、 | |
// PA5に当たるビットをXORで反転する | |
LDR r0, =GPIOA_ODR | |
ldr r1, [r0] | |
eor r1, #0x0020 | |
str r1, [r0] | |
// return | |
bx lr | |
.end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment