Advertisement
tom_burgess

Link Register used for similar functions + ButtonedBlinky

Feb 15th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 4.00 KB | None | 0 0
  1.             TTL Blinky
  2.             AREA Myprog,CODE,READONLY
  3.             ENTRY
  4.             EXPORT __main
  5.             ;Some Notes for the STM32F401RE NUCLEO Board
  6.             ;NB Onboard LED is PA5 and User Button is PC13
  7.             ;Setup Registers as follows
  8.             ;
  9.             ;RCC_AHB1ENR Peripheral clock enable register THIS NEEDS TO BE ENABLED FIRST before changing GPIOx as below!
  10.             ;
  11.             ;GPIOA_MODER
  12.             ;GPIOA_OTYPER
  13.             ;GPIOA_SPEEDR
  14.             ;GPIOA_PUPDR
  15.             ;
  16.             ;Data Registers as follows (All 32bit Registers)
  17.             ;GPIOA_IDR  (Input)
  18.             ;GPIOA_ODR  (Output)
  19.             ;GPIOA_BSRR (Set/Reset)
  20.             ;GPIOA_LCKR (Locking)
  21.             ;GPIOA_AFRH (Alternate function Selection High 32bit Word)
  22.             ;GPIOA_AFRL (Alternate function Selection Low  32bit Word)
  23.  
  24. __main      ;Notes for the Following M.R.Simpson November 2015
  25.             ; (+ some bits by R.Merrison-Hort February 2016)
  26.             ;Your Initialization code could go here e.g. Clearing Regsiters setup IO etc.,
  27.             ;Note This is a very simple Program 'blinky'
  28.  
  29. setupIO     LDR R0,=0x40023800      ;Load Address in R0 i.e. RCC REG Base Address (offset 0x30 for GPIO Clock Enable Register (RCC_AHB1ENBR)) Page 114 RM0368
  30.             LDR R1,[R0, #0x30]      ;Load R1 with contents of Address in R0 offset by 0x30 i.e. RCC_AHB1ENR
  31.             MOV R2,#5               ;Move a 5 into R2 to enable clock for ports A and C.
  32.             ORR R1,R2               ;Set the bit as above using OR function and store in R1
  33.             STR R1,[R0, #0x30]      ;Store R1 into Address in R0 offset by 0x30 i.e. RCC REG Base Address offset 0x30 for GPIO Clock EN (AHB1)
  34.  
  35.             LDR R0,=0x40020000      ;GPIOA Base Address in R0 Page 38 RM0368
  36.            
  37.             LDR R1,[R0, #0x00]      ;MODER Offset by 0x00 Page 151 RM0368
  38.             MOV R2,#1               ;Setting GPIOA Bit 10 which is PA5 on the Nucleo Board i.e.Onboard LED
  39.             LSL R2,#10              ;  using in 'c' terms
  40.             ORR R1,R2               ;   'R1=R1|(1<<10)'
  41.             STR R1,[R0, #0x00]      ;Store R1 in Address in R0 offset by 0x00 i.e. MODER REG
  42.            
  43.             LDR R1,[R0, #0x08]      ;OSPEEDR Offset by 0x08 Page 152 RM0368
  44.             MOV R2,#00              ;Setting OSPEEDR Bits 11:10 which is PA5 on the Nucleo Board i.e.Onboard LED to 0:0 slow, 0:1 medium, 1:0 fast, 1:1 high
  45.             LSL R2,#10              ;  using in 'c' terms
  46.             ORR R1,R2               ;   'R1=R1|(1<<10)'
  47.             STR R1,[R0, #0x08]      ;Store R1 in Address in R0 offset by 0x00 i.e. MODER REG
  48.  
  49.             LDR R5,=0x40020800      ;GPIOC Base Address in R5 Page 38 RM0368
  50.             LDR R1,[R5, #0x08]      ;Set P13 as input mode (should be the case at startup anyway).
  51.             BIC R1, #0xC000000
  52.             STR R1,[R5, #0x08]
  53.            
  54.            
  55. loopy       LDR R7, [R5, #0x10]
  56.             AND R7, R7, 0x2000
  57.             CMP R7, #0
  58.             BNE loopy
  59.             ;LED ON
  60.             LDR R1,[R0, #0x14]      ;LOAD the contents of ODR offset by 0x14 into R1 referance Page 155 RM0368
  61.             MOV R2,#1               ;1 of 3 lines to do a 'R1=R1|(1<<5)'
  62.             LSL R2,#5               ;2 of 3 lines to do a 'R1=R1|(1<<5)'
  63.             ORR R1,R2               ;3 of 3 lines to do a 'R1=R1|(1<<5)'
  64.             STR R1,[R0,#0x14]       ;STORE the contents of R1 back into the ODR offset by 0x14 Page 155 RM0368
  65.            
  66.             ;DELAY Load R6 with the number of milliseconds to wait (500)
  67.             BL delayStart
  68.            
  69.             ;LED OFF
  70.             LDR R1,[R0, #0x14]      ;LOAD the contents of ODR offset by 0x14 into R1 referance Page 155 RM0368
  71.             MOV R2,#1               ;1 of 3 lines to do a 'R1=R1|1<<5' note: 1 = a bit to manipulate
  72.             LSL R2,#5               ;2 of 3 lines to do a 'R1=R1|1<<5' note: 5 = num places to move
  73.             BIC R1,R2               ;3 of 3 lines to do a 'R1=R1&~(1<<5)' note: push down the 5th (r2) bit to 0
  74.             STR R1,[R0,#0x14]       ;STORE the contents of R1 back into the ODR offset by 0x14 Page 155 RM0368
  75.  
  76.             ;DELAY Load R6 with the number of milliseconds to wait (500)
  77.             BL delayStart
  78.            
  79.             B   loopy               ;Branch to loopy (Forever...)
  80.                
  81.                                     ;This is just a Blocking Method
  82.                                     ;1,600,000 each Instruction is 84MHz=11.9ns 1600000*21(instructions 1+1+1+18(Stack))=500ms
  83.    
  84.             BX  LR          ;1+P    ;Return to address Stored in LR (Link Register)
  85.  
  86. delayStart  MOV R6,#500  ; Start of outer loop, counts down from 500
  87. delay       MOV R7,#3200 ; Start of inner loop, counts down from 3200 (takes ~1ms)
  88. delayi      SUB R7,#0x01
  89.             CMP R7,#0x00
  90.             BNE delayi 
  91.             SUB R6,#1  
  92.             CMP R6,#0  
  93.             BNE delay
  94.             BX lr
  95.  
  96.             END                     ;Inform Compiler this is end of the Coding
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement