Other Parts Discussed in Thread: SW-TM4C,
Hello, I'm having trouble with something I'm writing in my TM4C123GX Launch Pad. I'm inexperienced with microcontrollers so I'm playing around with it using assembly. My problem is, I tried writing a program with a startup file provided in one of the TivaWare examples (startup_rvmdk.S), and it works fine except for that the variable I initialized (PM5_MASK) is blank. I tried asking this question somewhere else and was told it was the bootloader. Having little experience with microcontrollers, I'm very lost to where to even begin to figure out why my variable is 0 in RAM let alone understand how to use a bootloader. When I debug with the simulator and look at the value that should contain the value of the variable, it's always 0 unless I set it myself. What is the cause of this problem and how can I fix it? Here is my code below. I'm usaing Keil uVision. Thank you in advance!
main.s
;Include constants I define to main INCLUDE my_Constants.s ;Include variables I define to main IMPORT PB5_MASK AREA |.text|, CODE, READONLY THUMB EXPORT __main ENTRY ;This subroutine initializes GPIO GPIO_Init PROC ... ;write "high" to data register for port F pin 1 to turn on red LED. GPIODATA LDR r0, =AHB_PORTB LDR r1,[r0,#GPIODATAPB5] LDR r2, =PB5_MASK ;get RAM address of PB5 mask (pointer) LDR r3,[r2] ;get the value of PB5 mask ORR r3, r3, #0xF0 STR r3,[r2] ORR r1, r1, r3 ;Set PB5 to 'high' STR r1,[r0,#GPIODATAPB5] ;LDR r1,[r0,#GPIODATAPB5] ... BX LR ENDP ;This subroutine initialies SysTick SysTick_Init PROC ... ENDP __main ;call GPIO_Init subroutine and return BL GPIO_Init ;call SysTick_Init subroutine and return BL SysTick_Init stop B stop ;While(1) END
my_Constants.s
AREA My_Constants, CODE, READONLY THUMB ;defining addresses here for practice ;general base addresses SYS_CONTROL EQU 0x400FE000 ... ;offsets GPIOHBCTL EQU 0x06C ... END
startup_rvmdk.s
;includes constants I define to startup file INCLUDE my_Constants.s ;Include variables I define to startup file IMPORT PB5_MASK AREA STACK, NOINIT, READWRITE, ALIGN=3 StackMem SPACE Stack __initial_sp ;****************************************************************************** ; ; Allocate space for the heap. ; ;****************************************************************************** AREA HEAP, NOINIT, READWRITE, ALIGN=3 __heap_base HeapMem SPACE Heap __heap_limit ;****************************************************************************** ; ; Indicate that the code in this file preserves 8-byte alignment of the stack. ; ;****************************************************************************** PRESERVE8 ;****************************************************************************** ; ; Place code into the reset code section. ; ;****************************************************************************** AREA RESET, CODE, READONLY THUMB ;****************************************************************************** ; ; The vector table. ; ;****************************************************************************** EXPORT __Vectors __Vectors DCD StackMem + Stack ; Top of Stack DCD Reset_Handler ; Reset Handler DCD NmiSR ; NMI Handler DCD FaultISR ; Hard Fault Handler ... ; Reserved DCD IntDefaultHandler ; The PendSV handler DCD SysTick_Handler ; The SysTick handler ... ;****************************************************************************** ; ; This is the code that gets called when the processor first starts execution ; following a reset event. ; ;****************************************************************************** EXPORT Reset_Handler Reset_Handler ; ; Enable the floating-point unit. This must be done here to handle the ; case where main() uses floating-point and the function prologue saves ; floating-point registers (which will fault if floating-point is not ; enabled). Any configuration of the floating-point unit using ; DriverLib APIs must be done here prior to the floating-point unit ; being enabled. ; ; Note that this does not use DriverLib since it might not be included ; in this project. ; MOVW R0, #0xED88 MOVT R0, #0xE000 LDR R1, [R0] ORR R1, #0x00F00000 STR R1, [R0] ; ; Call the C library enty point that handles startup. This will copy ; the .data section initializers from flash to SRAM and zero fill the ; .bss section. ; IMPORT __main B __main ... ;I added the SysTick_Handler here. This toggle GPIODATA so the LED blinks SysTick_Handler PROC EXPORT SysTick_Handler ;write "high" to data register for port F pin 1 to turn on red LED. GPIODATA LDR r0, =AHB_PORTB LDR r1, =PB5_MASK ;Get RAM address of PB5 mask value LDR r2,[r1] ;Grab value of PB5 mask EOR r2, r2, #0xF0 ;Toggle mas to toggle PB5 STR r2,[r1] ;Store the toggled mask to properly toggle next time STR r2,[r0,#GPIODATAPB5] ;LDR r2,[r0,#GPIODATAPB5] ;return to __main BX LR ENDP ... END