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.

CCS, assembler project, PC is incorrect

Other Parts Discussed in Thread: MSP-TS430RGC64C, MSP430F5256

Hi all.

I have:

1. msp-ts430rgc64c.

2. msp430f5256.

3. licensed CCS v. 5.5.0.00077

4. MSP-FET430UIF

For MSP-TS430RGC64C I did:

  1. insert msp430f5256
  2. close JP3 to “int” state
  3. close JP4, i.e. DVCC = DVIO
  4. other jumpers setup by default

Сreate a assemble-only project for msp430f5256. In attached .doc file is described how I did this.0118.msp430f5256.doc

When I try to debug, programm count ( PC ) is incorrect, i.e. it is 0x000004 instead of 0x010004.

How to fix it? And why PC is incorrect?

  • Anyone can help me?

    Why PC ( programm counter ) is assigned to zero address instead a start address of flash ?
    MCU is msp430f5256

  • Sorry if I don’t open a DOC file from a public forum.
    However, one thing that comes in mind is that the interrupt vectors, including the reset vector, are 16 bit only. So you can’t put a start address of 0x10004 into it. All ISRs, including the program start, need to be in lower 64k.
    However, you should get some kind of warning.

    Or you have problems with your stack (stack overflow, uninitialized stack, stack corruption, unblananced push/pop)

  • Thanks for your answer.

    But problem in the CCS.

    Please, try create default assembler only project for msp430f5256 and compile simple program.

    In this case, after programming MCU it run fail! CPU has incorrect PC.

    How to fix this problem in CCS? 

  • The reset vector (address 0xFFFE) which holds the address where to start the user program (which isn’t necessarily the start of flash) holds a 16 bit value. After executing the boot code (internal), this value is move to PC. Since it is a 16 bit value, the program entry point needs to be in the range 0x00000 to 0x0FFF8. You simply can’t directly start your code at 0x10004.

    BTW: start of flash on the 5256 is 0x0A400 :)

  • Thanks for you answer, but it is theory.

    In practice will be following:

    simple code 

    [code]

    ;-------------------------------------------------------------------------------
    ; MSP430 Assembler Code Template for use with TI Code Composer Studio
    ;
    ;
    ;-------------------------------------------------------------------------------
    .cdecls C,LIST,"msp430.h" ; Include device header file

    .text
    .global RESET
    ;-------------------------------------------------------------------------------
    RESET nop
    mov.w #__STACK_END,SP
    mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
    mov.b #00000000b, &P1SEL
    mov.b #00000001b, &P1DIR
    loop mov.b #00000001b, &P1OUT

    jmp loop
    ;-------------------------------------------------------------------------------
    ; Main loop here
    ;-------------------------------------------------------------------------------


    ;-------------------------------------------------------------------------------
    ; Stack Pointer definition
    ;-------------------------------------------------------------------------------
    .global __STACK_END
    .sect .stack

    ;-------------------------------------------------------------------------------
    ; Interrupt Vectors
    ;-------------------------------------------------------------------------------
    .sect ".reset" ; MSP430 RESET Vector
     .short RESET

    [/code]

    It is does not work and PC is set incorrect value. Please see my first post here.

    but second example code 

    [code]

    ;-------------------------------------------------------------------------------
    ; MSP430 Assembler Code Template for use with TI Code Composer Studio
    ;
    ;
    ;-------------------------------------------------------------------------------
    .cdecls C,LIST,"msp430.h" ; Include device header file

    .text
    .global RESET
    ;-------------------------------------------------------------------------------
    RESET nop
    mov.w #__STACK_END,SP
    mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
    mov.b #00000000b, &P1SEL
    mov.b #00000001b, &P1DIR
    loop mov.b #00000001b, &P1OUT

    jmp loop
    ;-------------------------------------------------------------------------------
    ; Main loop here
    ;-------------------------------------------------------------------------------


    ;-------------------------------------------------------------------------------
    ; Stack Pointer definition
    ;-------------------------------------------------------------------------------
    .global __STACK_END
    .sect .stack

    ;-------------------------------------------------------------------------------
    ; Interrupt Vectors
    ;-------------------------------------------------------------------------------
    ;.sect ".reset" ; MSP430 RESET Vector
    ; .short RESET

    [/code]

    It works correctly!

    code 1 and code 2 diff only that:

    [code]

    .sect ".reset" ; MSP430 RESET Vector
     .short RESET

    [/code]

    In fisrt example this section is comment, but first example it is uncomment.

    Why first example does not work?

    Why TI dont ask about it anythere?

  • If disable runtime support library in CCS and  the code( example 1 ) does not work fine.

    How Ican in CCS 6 designed only assembler project without internal bugs of CCS and commenting ISRs?

  • It’s obvious. In your first code, you (correctly) have a short value on the reset vector. Which is the lower 16 bit of the address of RESET. This is fine as long as RESET is in lower 64k, but bad, if RESET is above 64k. Don’t you get a truncation warning?
    In the second code, you do not put anything into the reset vector. So it holds 0xFFFF. As a result, the CPU tries to start at 0xFFFF (actually 0xFFFE, as the LSB is ignored for PC), executes the instruction 0xFFFF (AND.B @R15+, x(R15)) where x is the word value at 0x10000, then proceeds with the instruction at 0x10002 and so on. Where it coincidentally stumbles over your RESET function. So the second code is only coincidentally working. And the first one is correctly failing.

    The solution is that RESET should not be put into normal text segment (which the linker puts into memory above 64k by default, to keep the space below 64k clean for constants and ISRs). It should be handled like any other interrupt function and forced into lower 64k.

    I’m pretty sure, the code template was written for an older MSP processor with standard core (16bit/64k address range) while you are using it on an MSP with extended core (20bit/1M address range). Or it was written for an older IDE verison where the memory usage defaulted to 64k use only, even on extended CPUs.
    Using the wrong example leads to the wrong result. This is not an ‘internal CCS bug’.
    If you carefully read the users guide chapter about the CPUX core, this all becomes obvious. Without reading this chapter, you shouldn’t try to program an MSP (or any CPU) in assembly language.

**Attention** This is a public forum