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.

MSP432P4111: msp432 Flash read and write

Part Number: MSP432P4111

Hi,

I need some support how to read and write from the main flash. I read some threads and all documents but I don't why it isn't working.

#define FLASH_ADR_CFG 0x0
uint8_t cfgData[4096];

void flash_rd(void){
    for (int i = 0; i < 10; ++i) {
        Display_printf(displayHandle, 0, 0, "cfgData sram=%u flash=%u",  cfgData[i], *(uint8_t*)(i+FLASH_ADR_CFG));
    }
}

void flash_wr(void){
    MAP_FlashCtl_A_unprotectMemory(FLASH_ADR_CFG,FLASH_ADR_CFG+10);

    if(!MAP_FlashCtl_A_programMemory(cfgData,
            (void*) FLASH_ADR_CFG, 4096))
    {
        while(1);
    }

    MAP_FlashCtl_A_protectMemory(FLASH_ADR_CFG,FLASH_ADR_CFG+10);
}


// with button 1:

            for (int i = 0; i < 10; ++i) {
                cfgData[i] = i;

            }
            flash_wr();

// with button 2:
            flash_rd();

If I read the first time before writing I get (putty):

cfgData sram=0 flash=0
cfgData sram=0 flash=0
cfgData sram=0 flash=4
cfgData sram=0 flash=32
cfgData sram=0 flash=177
cfgData sram=0 flash=1
cfgData sram=0 flash=2
cfgData sram=0 flash=0
cfgData sram=0 flash=187
cfgData sram=0 flash=193

After writing I get always:

cfgData sram=0 flash=0
cfgData sram=1 flash=0
cfgData sram=2 flash=0
cfgData sram=3 flash=0
cfgData sram=4 flash=0
cfgData sram=5 flash=1
cfgData sram=6 flash=2
cfgData sram=7 flash=0
cfgData sram=8 flash=8
cfgData sram=9 flash=1

I would expect 0...9. And if reupload the code I get an error:

CORTEX_M4_0: GEL Output: Memory Map Initialization Complete
CORTEX_M4_0: GEL Output: Halting Watchdog Timer
CORTEX_M4_0: File Loader: Failed to initialize flash programming: Target failed to read 0xE004300C
CORTEX_M4_0: GEL: File: C:\...\flash_a_program_memory_MSP_EXP432P4111_nortos_ccs\Debug\flash_a_program_memory_MSP_EXP432P4111_nortos_ccs.out: Load failed.

With the next upload I don't get an error. When I see this error message I'm asking me, if this is a problem because I'm using FreeRTOS?

Thanks for any help!

  • It looks like you are trying to write to flash address 0x0.  Please note that at this location the stack pointer and the interrupt vector table are loaded.  

    Regards,

    Chris

  • Hi Chris,

    oh that's not good, but how can I address the main flash at 0x0?

    As far as I can understand, the whole main memory is for the user and not used by the system.

    Thanks

  • Ok, the vector table is from 0x0...0x268. Are there any more addresses that are used by the system?

    Now I start from main memory bank0 0x10 000. But I read some random values:

    cfgData sram=0 flash=225
    cfgData sram=0 flash=84
    cfgData sram=0 flash=65
    cfgData sram=0 flash=63
    cfgData sram=0 flash=97
    cfgData sram=0 flash=206
    cfgData sram=0 flash=39
    cfgData sram=0 flash=63
    cfgData sram=0 flash=183
    cfgData sram=0 flash=150

    After flash writing:

    cfgData sram=0 flash=0
    cfgData sram=1 flash=0
    cfgData sram=2 flash=0
    cfgData sram=3 flash=3
    cfgData sram=4 flash=0
    cfgData sram=5 flash=4
    cfgData sram=6 flash=6
    cfgData sram=7 flash=7
    cfgData sram=8 flash=0
    cfgData sram=9 flash=0

    ... some value matches some not.

    The good thing is that this error message is gone.

    But if I restart the MCU I read out the old values:

    cfgData sram=0 flash=225

    ...

    For another test I start from main memory bank1 0x10 0000. The values after restart are:

    cfgData sram=0 flash=255
    cfgData sram=0 flash=255
    cfgData sram=0 flash=255
    cfgData sram=0 flash=255
    cfgData sram=0 flash=255
    cfgData sram=0 flash=255
    cfgData sram=0 flash=255
    cfgData sram=0 flash=255
    cfgData sram=0 flash=255
    cfgData sram=0 flash=255

    After flash writing:

    cfgData sram=0 flash=0
    cfgData sram=1 flash=1
    cfgData sram=2 flash=2
    cfgData sram=3 flash=3
    cfgData sram=4 flash=4
    cfgData sram=5 flash=5
    cfgData sram=6 flash=6
    cfgData sram=7 flash=7
    cfgData sram=8 flash=8
    cfgData sram=9 flash=9

    all values I had written I can read from flash. But again, if I restart the MCU and read out the old values are there:

    cfgData sram=0 flash=225
    cfgData sram=0 flash=255
    ...

    What's going wrong?

  • Ok, why the values after restart are gone I found: "Erase-Configuration" in "Debug-Configuration->MSP432_Settings":
    I switched from "Erase main memory only" to "Do not erase Flash memory".

    But which addresses are used by the system, e.g. vector table from 0x0...0x268?
    I think there are more than only the vector table, because I read at 0x1 0000 not a value like 255 (see reading above).

    Thanks
  • Hi,

    when I restart a debug session with ccs after I switched the "Erase-Configuration" in "Debug-Configuration->MSP432_Settings" from "Erase main memory only" to "Do not erase Flash memory" then ccs ends up in different "errors" at beginning of the code. The only way I can recover this is to switch back to "Erase main memory only". But then the programmed values are gone...

    So I'm asking me is this the right way to prevent ccs for delete the memory?

    Thanks

  • If you want to reflash the application code but leave the space that you have written to, then you can either use the 'Erase and download necessary segments only' or in the linker command file you can create a section to which the IDE does not write to.  Additionally, in CCS you can launch a target configuration and connect to the device and look at the memory content without actually downloading any code and running the debugger. 

    Regards,

    Chris

  • Hi Chris,

    thank you for your answer. 'Erase and download necessary segments only' I tried before but it also ends up in errors.

    linker command file - create a section to which the IDE does not write to:

     *  ======== MSP_EXP432P4111_FREERTOS.cmd ========
     *  Define the memory block start/length for the MSP_EXP432P4111 M4
     */
    
    --stack_size=1024
    --heap_size=0       /* minimize heap since we're using heap_4.c */
    --entry_point=resetISR
    
    MEMORY
    {
        MAIN       (RX) : origin = 0x00000000, length = 0x00200000
        INFO       (RX) : origin = 0x00200000, length = 0x00008000
        ALIAS
        {
        SRAM_CODE  (RWX): origin = 0x01000000
        SRAM_DATA  (RW) : origin = 0x20000000
        } length = 0x00040000
    }
    
    /* Section allocation in memory */
    
    SECTIONS
    {

    Can you explain how to do this in this file?

    Is there a tutorial how to do this: "launch a target configuration and connect to the device and look at the memory content without actually downloading any code and running the debugger" ?

    Thanks

  • Hi Chris,

    Ok I found the memory browser and I also found out how to connect without debugging, great!
    But how can I prevent the ccs to erase e.g. bank 1 from main memory (0x10 000...0x1F FFFF) ?
  • Hello,

      Please check out this example:

    If you look into the linker command file: http://dev.ti.com/tirex/explore/node?node=APaqSb5Gq.hTaeSQBTXwBA__kmPly-e__LATEST

    You will find the main is limited to 0xFE000, the lower 1MB of the part.  

    MEMORY
    {
        OAD_BSL    (RX) : origin = 0x00000000, length = 0x00002000
        MAIN       (RX) : origin = 0x00002000, length = 0x000FE000
        INFO       (RX) : origin = 0x00200000, length = 0x00008000
        ALIAS
        {
        SRAM_CODE  (RWX): origin = 0x01000000
        SRAM_DATA  (RW) : origin = 0x20000000
        } length = 0x00040000
    }

    Let me know if that is not clear

    Regards,

    Chris

  • Thank you Chris for answering.

    I reduced the range of the main flash to ony bank 0:

        MAIN       (RX) : origin = 0x00000000, length = 0x000FFFFF
    

    But after restart debugging, the written values beginning from 0x10 0000 are all erased (FF).

    Normally it shouldn't erase the not declared range bank1 0x10 000.... (even with the setup is "Erase main memory only").

    What's going wrong?

  • I believe that you project settings are configured to erase main memory on debug.  I would recommend changing so that it is only the necessary segments are erased.  

    Regards,
    Chris

  • Hi,

    'Erase and download necessary segments only': what is the meaning with necessary segments?

    'Erase main memory only': I thougt, that if I set the main flash with
    MAIN (RX) : origin = 0x00000000, length = 0x000FFFFF
    then bank1 will not be erased regardless of whether 'Erase main memory only' or 'Erase and download necessary segments only'.

    Thanks
  • The Flash memory can only be written as '0'. You cannot write a '1'. Therefore in order to program memory you must first erase, set all bits to '1' before you can program, set bits to '0'. A mass erase is much faster but it erases everything. You can selectively tell the IDE to only erase the sections which need to be programmed.

    The linker definition of MAIN only tells the IDE which locations to program. Which locations are to be erase can be controlled independently from the IDE. You must make sure not to 'program' the same location twice without first erasing.

    Regards,
    Chris
  • As far as I understand, the

    • 'Erase and download necessary segments only': write to all segments that are needed for code a 'FF'. But this is dependent of the code size.
    • 'Erase main memory only': writes 'FF' to the range as defined MAIN (RX) : origin = 0x00000000, length = 0x000FFFFF, but this would mean that in this case bank1 will not be erased regardless of whether 'Erase main memory only' or 'Erase and download necessary segments only'. But bank1 was deleted ...?

    That '1' can't be programmed is clear to me.

  • This statement is not correct:

    • 'Erase main memory only': writes 'FF' to the range as defined MAIN (RX) : origin = 0x00000000, length = 0x000FFFFF, but this would mean that in this case bank1 will not be erased regardless of whether 'Erase main memory only' or 'Erase and download necessary segments only'. But bank1 was deleted ...?

    Using the erase main memory will invoke the mass erase in the device and erase main memory.  Please perform a simple experiment to prove this to yourself.  

    Regards.

    Chris

**Attention** This is a public forum