Hello everyone, i am quite a beginner with tm4c123 device. i wrote a simple code use my pin 1,2,3 of PORTF as output. Apparently the code is correct, i build the target with no errors or warning and then I downloaded it to my device but the code didn't work. I tried to debug and i got Hard Fault error. Then i opened my startup_TM4C123.s file and copied some code other startup file from example project and it worked. My C code is
#include "tm4c123gh6pm.h"
void PORTF_Init(void)
{
SYSCTL_RCGCGPIO_R |=0x20;
GPIO_PORTF_LOCK_R = 0x4C4F434B;
GPIO_PORTF_CR_R = 0x1F;
GPIO_PORTF_AMSEL_R = 0x00;
GPIO_PORTF_PCTL_R = 0x00000000;
GPIO_PORTF_DIR_R = 0x0E;
GPIO_PORTF_AFSEL_R = 0x00;
GPIO_PORTF_PUR_R = 0x11;
GPIO_PORTF_DEN_R = 0x1F;
}
int main(void)
{
PORTF_Init();
GPIO_PORTF_DATA_R &=0x00;
while(1)
{
GPIO_PORTF_DATA_R |=0x0E;
}
}
Previously, my startup_TM4C123.s has RESET_HANDLER has the following code.
; Reset Handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
;IMPORT SystemInit
IMPORT __main
;LDR R0, =SystemInit
;BLX R0
LDR R0, =__main
BX R0
ENDP
then i changed it to
Reset_Handler
; Floating Point Unit.
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
then it worked. I could not figure out the problem additionally if someone could share any source where i could learn the details about the code in startup_TM4C123.s