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.

Compiler/MSP430F5438A: cinit routine

Part Number: MSP430F5438A

Tool/software: TI C/C++ Compiler

Hi Team,

I am trying to write custom startup routine before the main is called. Had trouble doing that as some of the stuff was not working with it.

So I went through the TI library source code and came across the cinit routine which i didnt had in my custom startup routine.

What is the cinit routine is doing exactly, why it is required? How to write the custom cinit routine without using the linker generated symbols like __TI_Handler_Table_Base and __TI_Handler_Table_Limit.

Thanks,

Ashish Mishra

  • Hi Ashish,

    Could you please let me know which IDE you are using, and also the compiler version? IAR and CCS has slight difference for this. For device, I assume you are using MSP430F5438A right?

    Also attach the most useful doc here for any compiler/startup/TI related symbols here. You may find something helpful for you at chapter 6.9 in this doc.

  • Hi Harry,

    Thanks for you reply.

    I'm using CCS 9.2 version and Compiler version is TI v18.12.3.LTS. I am using MSP430F5438A device.

  • Hi Ashish,

    Since you are using CCS, you could write your own _system_pre_init() function and have it return 0.

    And then it'll call your _system_pre_init() function and then go directly to main without any other operation.

    In your _system_pre_init you could choose not use any __TI_Handler_Table_Base or __TI_Handler_Table_Limit symbols.

    I attached an example below. You may run this for a test and should see that by using this, the variable "a" is initialized to "15" instead of the default initialization value "0". Generally in that _system_pre_init() you could write whatever you want prior to your main function and remember to make the return value "0". Also please remember the watchdog is default on so if your _system_pre_init() takes long the MSP430 may reset by watchdog timeout.

  • Hi Harry,

    Sorry for the late response. 

    if i'm not wrong, _system_pre_init() will be called by boot.c provided by the TI library? if that the case, I wanted to avoid that path if possible.

  • Hi Ashish,

    Try to put below code into an assembly code file such as "entry.asm" and add it into your project.

    		.cdecls C,LIST,"msp430f5438a.h"
    		.def Entry
    		.text
    		.retain
    		.retainrefs
    		.ref main
    
    Entry:
    		mov.w #5BF0h, SP
    
    		call #main
    		jmp $
    		nop
    
    		.global __STACK_END
    		.sect .stack
    
    		.sect ".reset"
    		.short Entry
    
    

    And make below changes for your project:

    After that, your MCU will firstly start from reset vector (0xFFFE), then go to the "Entry" to initialize your stack, and then call the "main" function. Assume you could all you want at the beginning of the main function.

    Regards,

    Harry

  • Hello Harry,

    Thanks. It works. Only thing that i was missing was, i was not making change to initialization model setting.

    Regards,

    Ashish Mishra

**Attention** This is a public forum