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:
- Write CSC code which either starts the app or runs the sysctl method to execute from one of the banks (upper / lower)
- Debug this code, while erasing necessary sections of main and nonmain.
- Before the code executes, load the same CSC binary file into the memory at 0x10000
- 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.
- 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:
- 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!"
- 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.