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.

MSPM0G5187: MSPM0G5187 Bank Swapping Issues

Part Number: MSPM0G5187
Other Parts Discussed in Thread: SYSCONFIG

Hello, I am looking for help with implementing the simplest possible bank swap on a custom circuit board which posesses an MSPm0G5187 as the MCU. 

I have read through the bank swap documentaiton I could find ("MSPM0 Live Firmware Update (LFU) Bootloader Implementation" and "Live Firmware Update via Flash Bank Swap") along with a whole lot of posts on this forum and SDK examples. 

My understanding of what i need to do is as follows:

  1. Write CSC code which either starts the app or runs the sysctl method to execute from one of the banks (upper / lower)
  2. Debug this code, while erasing necessary sections of main and nonmain.
  3. Before the code executes, load the same CSC binary file into the memory at 0x10000
  4. Before the code executes, load my firmware binaries into 0x400 and 0x10400 (my csc code is small, and I believe I have set up the linking files correctly for this.
  5. Resume my MCU debug process, I should enter the lower bank. On power restart, I should optionally enter the upper bank (mine is mapped to a button press which I have on PA14 - it is pulled up externally and when pressed goes to GND)

The CSC code I have written is this:

#define BANK1_APP_START 0x00010400   // Bank1 base (0x10000) + CSC_SIZE (0x400)
#define APP_START        0x00000400
#include "ti_msp_dl_config.h"

static void start_app(uint32_t *vector_table);

int main(void){
    SYSCFG_DL_init();

    if (DL_SYSCTL_isINITDONEIssued()){
        start_app((uint32_t *)APP_START);
    }else{
        volatile bool buttonPressed = DL_GPIO_readPins(FW_SEL_PORT, FW_SEL_button1_PIN);
        if(!buttonPressed){
            DL_SYSCTL_executeFromUpperFlashBank();
        }else{
            DL_SYSCTL_executeFromLowerFlashBank();
        }
        delay_cycles(1600);
        DL_SYSCTL_issueINITDONE();
    }
    while (1) { }
}

static void start_app(uint32_t *vector_table){
    __asm volatile(
        "LDR R3,[%[vectab],#0x0] \n"
        "MOV SP, R3 \n" ::[vectab] "r"(vector_table));
    SCB->VTOR = (uint32_t) vector_table;
    ((void (*)(void))(*(vector_table + 1)))();
}

and it uses the following linker:

--define=_CSC_SIZE_=(1024)

MEMORY
{
    FLASH_CSC   (RX) : origin = 0x00000000, length = _CSC_SIZE_
    FLASH_APP   (RX) : origin = _CSC_SIZE_, length = (0x00010000 - _CSC_SIZE_)
    SRAM_BANK0  (RWX): origin = 0x20200000, length = 0x00008000
    BCR_CONFIG  (R)  : origin = 0x41C00000, length = 0x00000100
    BSL_CONFIG  (R)  : origin = 0x41C00100, length = 0x00000080
}

SECTIONS
{
    .intvecs : > 0x00000000
    .text    : palign(8) {} > FLASH_CSC
    .const   : palign(8) {} > FLASH_CSC
    .cinit   : palign(8) {} > FLASH_CSC
    .pinit   : palign(8) {} > FLASH_CSC
    .rodata  : palign(8) {} > FLASH_CSC
    .vtable  : > SRAM_BANK0
    .data    : > SRAM_BANK0
    .bss     : > SRAM_BANK0
    .stack   : > SRAM_BANK0 (HIGH)

    .BCRConfig : {} > BCR_CONFIG
    .BSLConfig : {} > BSL_CONFIG
}

My Firwmare code is simplified to the following:

int main(void){
    SYSCFG_DL_init();

    LCD_init();
    LCD_setCursor(1, 1);
    LCD_writeString("FW-Ver 2");

    while (1) {
    }
}

Where the displayed text (FW-Ver X) changes from 1 -> 2 depending on which firmware file is executed.

The linker file for this one is:

MEMORY
{
    FLASH_APP  (RX)  : origin = 0x00000400, length = (0x00010000 - 0x00000400)
    SRAM_BANK0 (RWX) : origin = 0x20200000, length = 0x00008000
}

SECTIONS
{
    .intvecs : > 0x00000400
    .text    : palign(8) {} > FLASH_APP
    .const   : palign(8) {} > FLASH_APP
    .cinit   : palign(8) {} > FLASH_APP
    .pinit   : palign(8) {} > FLASH_APP
    .rodata  : palign(8) {} > FLASH_APP
    .vtable  : > SRAM_BANK0
    .data    : > SRAM_BANK0
    .bss     : > SRAM_BANK0
    .stack   : > SRAM_BANK0 (HIGH)
}

(Apologies for all of the code, I feel it is important in this instance)

NOW - ISSUES

The issues I seem to be having are as follows:

  1. When my CSC linker file includes the lines for BCR and BSL config, loading my CSC binary into 0x10000 fails with the error: "File Loader: Memory write failed: Flash Programmer: Invalid sector erase address!"
  2. When I remove these, it loads into the memory correctly, but I get no firmware swap (I have never seen firmware 2 load despite many different attempts)

I have tried using the SDK's example but since I am not on a launchpad the LED section makes no sense, so I modify it to display on my screen and seem to still get no bank swapping.

I have tried implementing the memory addresses from the SDK's examples but again, no bank swapping. 

I always factory reset (manual) before flashing the CSC. 

The CSC sysconfig has the checkboxes selected to enable CSC policy and Bank Swap Policy and I always flash with nonmain and main necessary sectors only.

I feel as though I have been trying so many different things over the past few days of debugging that I have somewhat lost track of all the things I have tried and the specific errors which each of them produce, so I am wondering if there is anything that jumps out as immediately wrong in my code, understanding, or process. 

My goal is simply to program my hardware so that if the button is held on powerup, it boots into firmware 2, otherwise it boots into firmware 1 (Or even just running firmware 1 until I press the button on boot and then continually running firmware 2)

The closest attempt I have gotten involves the following files, and after flashing the CSC and placing my binary file at 0x400, it correctly executes. I am consistently unable to swap out the firmware on boot however. 

  • When my CSC linker file includes the lines for BCR and BSL config, loading my CSC binary into 0x10000 fails with the error: "File Loader: Memory write failed: Flash Programmer: Invalid sector erase address!"

     

    Nonmain need to erase first then program.

    Enable nonmain erase in CCS:

    CCS Project properties - Debug - Category=MSPM0 Flash Settings - Erase main and nonmain necessary sectors only

     

    Nonmain operation has risk, when nonmain is empty, this MSPM0/M33 will be locked permanently.

    Recommend to setup a standalone CCS project that only program nonmain. Program this project once is enough during your dev phase.

    Unless run Factory reset script, the nonmain region will retain during default project programming (Erase main memory only).

     

    For detailed nonmain operation guide, please refer to document:

    MSPM0 NONMAIN FLASH Operation Guide

    https://www.ti.com/lit/pdf/slaaeo4

    When I remove these, it loads into the memory correctly, but I get no firmware swap (I have never seen firmware 2 load despite many different attempts)

    Because you didn't enable dual bank and CSC in nonmain.

    Enable them based on your requirement.

    And here, I highly recommend you double check the software flow based on this dual bank demo:

    8284.G3519_Bank_Swap_Demo_V3.0_PDF.zip

    Mark: I didn't check your code yet, better to run the above demo first.

  • I am not sure how I didn't mention this, but nonmain erase is setup for my CSC code. I have also tried Just having a blank program for nonmain to be configured by.

    I DID also enable dual bank and CSC in nonmain...

    I will have a look at the demo thankyou

  • I am not sure how I didn't mention this, but nonmain erase is setup for my CSC code. I have also tried Just having a blank program for nonmain to be configured by.

    Please take a screenshot to me, I can double check it with you.

    I DID also enable dual bank and CSC in nonmain...

    Try to connect to debugger, monitor the nonmain region raw data, to confirm the config is programmed.