This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

statup_TM4C123.s File give error.

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

  • Abdullah Zahid said:
    my startup_TM4C123.s file

    Hi,

    This is a little bit weird - you should specify your tools - since what is provided by TI in Tiva distribution does not have such name. A good startup file you can find out in Tiva/examples/board/your_board. What you provide may be buggy or not complete. If posting again, attach the file only.

    Abdullah Zahid said:
    GPIO_PORTF_DATA_R |=0x0E;

    If you try to toggle the pins, then this line could be improved and written as: GPIO_PORTF_DATA_R ^=0x0E;

    Use an oscilloscope to see the pins toggling. 

  • Petrei said:
    ...what is provided by TI in Tiva distribution does not have such name!

    Hi Petrei,

    Such ".s" files are provided by several other ARM MCU vendors - although IMO they differ from that our poster has presented.

    We note he "breaks" from standard code form/policy via:

    • an improper, imported start-up file
    • immediate use of DRM code - sure to complicate, delay, and (likely) frustrate development.    API code - tried/true/tested - proves immensely more efficient...

    As poster notes he's "beginner" w/TM4C - use of an "imported & modified" start-up file - written in ASM - followed by exclusive use of DRM - may not prove, "best way to proceed!"

  • I am using Keil uVision for TM4C123 device. When we create a project this file is automatically added to the project. I checked those examples in the folder you specified. the Above code which didn't worked was a part of default "*.s" file added by the compiler and it didn't worked then i opened one of the example project and copied the code for reset handler in my "*.s" file and it worked.

    and i am not toggling bits i just want to set the Pin PF1, PF2 and PF3 high all of them are attached to on board LED.
  • Sir,
    So far imported .s file is concerned, it was added by the Keil uVision compiler and then i copied a piece of code from one of the .s file in example project.
    And sorry for using using DRM code because we were taught DRM not API or SDM and it does make sense too as we are engineer so we need to know what's going on in the back end of a function. I just don't wanna use and boast, i just want to learn how things actually work. However i have tried API code in the same project and problem remains the same. So, problem is with the C code, the problem is with the piece of asm code in startup_TM4C123.s file for reset handler which was added by the compiler. And notice that too Keil Always add the startup file with asm code, and notice that too i wrote that please suggest me a source which can explain the code in this file.
  • @Abdullah,

    You are indeed correct Sir - 8-9 years past we too used Keil - then switched to paid IAR.   (indeed I now recall Keil's use of ASM - used by other ARM vendors, as well...)

    Perhaps IAR's (all "C") Start-up code will prove useful:

    // This is the code that gets called when the processor first starts execution
    // following a reset event.  Only the absolutely necessary set is performed,
    // after which the application supplied entry() routine is called.  Any fancy
    // actions (such as making decisions based on the reset cause register, and
    // resetting the bits in that register) are left solely in the hands of the
    // application.
    //
    //*****************************************************************************
    void
    ResetISR(void)
    {
        //
        // 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.
        //
        HWREG(NVIC_CPAC) = ((HWREG(NVIC_CPAC) &
                             ~(NVIC_CPAC_CP10_M | NVIC_CPAC_CP11_M)) |
                            NVIC_CPAC_CP10_FULL | NVIC_CPAC_CP11_FULL);

        //
        // Call the application's entry point.
        //
        __iar_program_start();
    }

    My small firm uses this file often - it works - my hope is this aids your effort.   (Keil specific questions should be directed there - should they not?)

    I too am an engineer - run a small tech firm now - past co-founded then took another tech firm public.   And stand by the belief that, "Coding Efficiency, Robustness and Speed" trumps the "fine detail (perhaps) gleaned - from the back end of a function."   Really - looking at multiple, 32 bit Registers, where one mis-set Register bit may wreak disaster - I'd vote (every time) for the API.   BTW - this vendor's API includes FULL Source Code (in C, of course) and that - to my mind - provides the tech essence of the back-end - yet avoids gory detail!)

    Market studies have long revealed that, "He who is early to market - w/adequate features/price/performance - commands the highest profit.   (even if - and especially if - that "early to market" resulted from the use of an API!)

    Lastly - vendor's Amit long has asked that posters refrain from DRM or ASM as either add substantial time/effort to his (great) job here.   Best of luck to you - my hope is my IAR extract yields some insight...

  • cb1_mobile said:
    Such ".s" files are provided by several other ARM MCU vendors

    Hi,

    Yes, I "smelled" that... but never used Keil with Cortex-Mx, only with the ancestor ARM7TDMI...

    Observed some unusual call to a SystemInit function prior zeroing RAM section, which is weird, so I think the poster need some knowledge of program sections and their initializations.

    Regards 

  • Hi,

    Several steps to follow until you learn more:

    a) As cb1 mentioned, start by importing a whole TI project - this way you import also all compiler settings - much easier later with your own since you can replicate all settings. Keep such project as reference.

    b) If still using your own, then remove what Keil add for you and add a startup_rmvdk.S file, prepared by TI, with all you need to initialize and use in a project. 

    c) search Google or textbooks for compiler sections in a embedded program and their initialization.

  • Hi Petrei,

    We'd hazard the guess that poster's desire to "sniff out" back-end details has intruded upon the time/effort to master the elementary IDE mechanics!

    It would seem a standard Tivaware project - w/in the Tiva\Keil directory framework - would prove a more proper method to "launch."
  • Hello Petrei,

    I think that the SystemInit function comes from the native CMSIS implementation. Though not sure what Keil would be having there in that code call.

    Regards
    Amit