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.

Accessing Invalid Memory

Elsewhere in the forum there are threads which say that accessing an invalid area of memory causes an error.  I would like this to be the case, but find code executes fine.  e.g.

        void main(void)
        {
            int *p = (int*)0x2000;
            int a;

            *p = 13;    // Write to invalid memory
            a = *p;     // read from invalid memory

            for(;;);
        }

This runs through to the for(;;) with no problems.

Is it possible to trap either of the above?

  • Giles,

    You don't say what device you are using nor cite which threads are saying that accessing an invalid memory area causes an error, but in general on C2000 devices just "Accessing" an invalid (e.g., reserved) memory location will not cause an error.  It will just read garbage or write to nothing.  What will typically cause an error is attempting to fetch an instruction from invalid memory.  When the instruction is executed, it will probably be an invalid opcode, and will trigger an ILLEGAL interrupt.  Erased flash contains the value 0xFFFF, which is an invalid opcode.  So, attempting to execute from any unused (unprogrammed) flash will trigger the ILLEGAL interrupt too.

    Regards,

    David

  • David,

    The particular device is TMS320F2833F.

    I forget which threads, but it was something about getting Data Access Error when reading from a buffer where the pointer was pointing a location where there was no memory present.

    Executing from such memory, as you say, triggers an error, but the above led me to expect read and/or write would too, and that I was omitting to setup something.  However, from what you say, I am getting the expected behaviour.

    Regards,

    Giles

  • Giles,

    If this is just a debug issue where you are trying to track down an out of control pointer, there are facilities in the C28x that will allow you to monitor a specific region of memory for data access.  This capability is part of the emulation analysis block.  You can access it in CCSv5 through the View->Breakpoints window.

    In the breakpoint window, right-click and choose Breakpoint->Hardware_Watchpoint.  Type in the base address (if a range, use the lowest address in the range), and then choose either write or read (if you want to monitor both writes and reads, you will need to setup two different watchpoints).  Then click OK.  This will setup a basic watchpoint for the specific address you specified.  If you want to monitor a range of addresses, now right-click on the watchpoint you just setup in the breakpoint window, and choose Breakpoint_Properties.  You can now modify the "Location Mask" property.  You specify the address bits that you want to be "Don't Cares".  Note that this does place limitations on what you can monitor.  For example, if you wanted to monitor addresses 0x2000 to 0x3000, no problem.  You would specify 0x2000 as the location, and 0x0FFF as the location mask.  But if you wanted to monitor, say, 0x2004 to 0x2100, you wouldn't be able to do it.  If you are monitoring a buffer pointer for overrun, sometimes you can adjust the link address of the buffer so you can better monitor the addresses after the buffer.  Or, sometimes it is sufficient to just monitor the very first address after the end of the buffer (e.g., don't use the location mask).

    Note that there are only two analysis units on the C28x.  You can use these for hardware breakpoints or watchpoints as you wish.  But CCS has a habit of grabbing the analysis units for its own purposes.  To stop CCS from doing that, go to your project properties and uncheck the "Halt at program termination" and also the "Enable CIO function use" boxes.  Each of these will eat up one analysis unit.  The first sets a breakpoint upon exit from main(), which we don't really care about since we should never get there anyway (except in a SYS/BIOS program, where it sets the breakpoint elsewhere).  The second (CIO) breakpoint allows things like printf() to work.  You just need to do without CIO when debugging your pointer overrun.

    Hope this helps.

    - David