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.

How to access PC register of MSP430F5438A from C

Hi,

I need to download the intel hex file from my bootloader into the CPU in order to update the firmware.

The intel hex file is generated by compiler. I am currently using IAR, and the version is listed below:

- IAR C/C++ Compiler for MSP430 5.10.6 (5.10.6.50180)

- IAR Assembler for MSP430 5.10.4 (5.10.4.50168)

The format of the intel hex has been set to intel-extended.

However, after downloading, i am not able to start the system with the new firmware.

I found that  there is a start segment address record (:040000030000633264) before the end-of-file record (:00000001FF) in the intel hex file.

The start segment address record is used to specify the start address for Intel processors, namely, what values should be loaded into CS and IP registers.

So, for MSP430, I think the start segment address record should set the program counter (PC). But, I didn't find a way to modify the value of PC register.

 

So, here are my questions:

(1) Is my understanding for start segment address record correct?

(2) How do I change the value of PC register?

 

Thanks

 

Liu

  • At power up, or after a Reset, MSP430 hardware copies the content of Flash memory at 0xFFFE & 0xFFFF to the PC. After that, if there is no interrupt, PC automatically changes according to the instruction the CPU is executing. If there is an interrupt, PC changes to the contents of the Interrupt Vector.

    The c compiler and linker should know all these, otherwise it will not work.

  • I'm not sure about the start segment address record, perhaps have a look in the disassembly or map file to see what is at that address.  If it doesn't look good you could always force your main function to be placed at a specific location.  One thing to consider: if you have global/static variables they won't be initialised if you jump straight to "main" - you might be better doing a reset at the end of the bootloader sequence in order to run the initialisation section(s) and then jump/branch to main.

    To change the PC you can use an inline assembler statement e.g. something like asm("    MOV.W    #xxxx, PC").  If you need to move to an address >64k then you need a MOVA.W.

     

    Chris.

  • milanqingren said:
    However, after downloading, i am not able to start the system with the new firmware.


    There is no dedicated start address for your firmware in teh hex file. The MSP has a dedicated reset vector which is located at 0xfffe. Whatever address is written at 0xfffe will be jumped to when the MSP is started.

    Inside the hex file, the reset vector area (as well as all otehr interrupt vectors, the so-called vector table) is just a normal FLAHS area that is programmed.

    It is up to your assembly code to fill this address with your start address. If you use a C compiler for the MSP, it will automatically take care of it.

    Compared to the PC, your firmare is not a loaded program, but rather the BIOS chip - which too has the reset vector at 0xfffffffe (mapped to 0xffffe)

    milanqingren said:
    (1) Is my understanding for start segment address record correct?


    This is only for systems where soem bios is already running, so after loading the data, the 'bios' knows where to jump to after loading.
    Which isn't the case for the MSP. At startup, the MSP loads the PC with the value stored at 0xfffe. And whatever code is found at this address will be executed. It has to set the stack pointer, init gloabl variables etc.

    milanqingren said:
    (2) How do I change the value of PC register?

    Either by writing the start value into memory location 0xfffe (initial value) or by writign something into processor register R0 (=PC). See the orthogonal structure of the MSP core. The PC can be used as any other register in all assembly instructions.

**Attention** This is a public forum