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.

Debug asserts on the MSP430

Other Parts Discussed in Thread: MSP430F5438A, MSP430WARE

Hello everyone, first post here!

I'm currently porting my firmware code over to the MSP430 micro (MSP430F5438A to be exact) from Atmel's XMEGA micro.  In our current code base, we use an assert() macro in our debug build to call an assembly "BREAK" instruction.  I've dug around a bit and it doesn't look like the "BREAK" instruction is supported in the MSP430...

Is there something else I can use here that will pause the debugger if the assert == false?  What do others here use?  I'd prefer to use an assembly instruction or some sort of keyword to automatically pause the debugger and NOT have to use a breakpoint for this.

  • You can use something like this (defined in a header file). (Note I took this from DriverLib for F5xx-6xx)

    //*****************************************************************************
    //
    //Prototype for the function that is called when an invalid argument is passed
    //to an API. This is only used when doing a DEBUG build.
    //
    //*****************************************************************************

    extern void __error__ (char *pcFilename, unsigned long ulLine);

    //*****************************************************************************
    //
    //The ASSERT macro, which does the actual assertion checking. Typically, this
    //will be for procedure arguments.
    //
    //*****************************************************************************
    #ifdef DEBUG
    #define ASSERT(expr) { \
            if (!(expr)) \
            { \
                __error__(__FILE__, __LINE__); \
            } \
    }
    #else
    #define ASSERT(expr)
    #endif

  • Hi Corey,

    I've just been looking into this myself. I found that the CCS debugger uses the opcode 0x4343 to place software breakpoints, and configures an EEM trigger to halt the cpu and clocks when that opcode is fetched.

    If you put an _op_code(0x4343) in your program and run it with the debugger attached and software breakpoints enabled it should cause the program to pause on the following line. Otherwise the opcode represents a NOP, so it won't do anything unpleasant (other than using up two bytes and wasting a cycle).

    This works on the MSP430 G-series, but I think it should work on the other families as long as they have an EEM.

    Rob

  • Robert,

    That's also good information to have. I wonder if it works in IAR debugger as well....

    Seems like the two "answers" could be combined into an ASSERT macro for CCS. The code I posted is from the DriverLib_5xx-6xx in MSP430Ware, which compiles under both CCS and IAR.

    ~Brian

  • Great information guys!  I'm currently working under IAR Workbench since we are still undecided about using the MSP430.  I'll try out the options provided below on IAR Workbench (and possibly the 30 day trial of CCS) and let you know what I figure out.

**Attention** This is a public forum