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.
Part Number: MSP432P401R
Hello everybody!
I would like to achieve a field firmware update for my device. Currently I am testing with a msp432p401r launchpad and CCS version: 9.0.1.00004.
My plan is to store the new firmware (led blinking program) in the flash, and after I press a button (P1.1), I invoke the BSL.
The BSL checks a fixed variable in the flash, if it matches the required value, it replaces the current program (led is off) to the blinking program
and than performs a reset.
How can I write to the BSL code? Do I have to change my cmd file for this task?
I think I invoke the BSL correctly, but I don't know how to do the replacing.
Any help is appreciated.
My code so far:
#include <msp.h> #include "flashmailbox.h" #include "driverlib.h" #include "msp432p401r.h" #include <string.h> #define FIRMWARE_READY_PARAM_ADDRESS 0x0003E000 #define BSL_PARAM 0xFC48FFFF // I2C slave address = 0x48, Interface selection = Auto #define LED_BLINK_SOFTWARE_MEMORY_ADDRESS_START 0x0003F000 #define LED_BLINK_SOFTWARE_ARRAY 512 unsigned char led_blink_software_array[LED_BLINK_SOFTWARE_ARRAY] = { 0x00, 0x00, 0x01, 0x20, 0xD1, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0xE5, 0x01, 0x00, 0x00, 0x15, 0x49, 0x08, 0x68, 0x40, 0xF4, 0x70, 0x00, 0x08, 0x60, 0x14, 0x49, 0x4F, 0xF4, 0xB5, 0x40, 0x08, 0x80, 0x13, 0x49, 0x80, 0x20, 0x08, 0x60, 0x12, 0x49, 0x46, 0xF6, 0x5A, 0x10, 0x08, 0x60, 0x11, 0x49, 0x4F, 0xF4, 0x80, 0x30, 0x08, 0x60, 0x10, 0x48, 0x10, 0x49, 0x00, 0x68, 0x20, 0xF0, 0x07, 0x10, 0x40, 0xF0, 0x03, 0x00, 0x08, 0x60, 0x0A, 0x49, 0x00, 0x20, 0x08, 0x60, 0x0C, 0x48, 0x0B, 0x49, 0x00, 0x68, 0x20, 0xF0, 0x30, 0x00, 0x08, 0x60, 0x0A, 0x48, 0x09, 0x49, 0x00, 0x68, 0x20, 0xF0, 0x30, 0x00, 0x08, 0x60, 0x70, 0x47, 0x88, 0xED, 0x00, 0xE0, 0x0C, 0x48, 0x00, 0x40, 0x14, 0x30, 0x04, 0xE0, 0x00, 0x04, 0x01, 0x40, 0x04, 0x04, 0x01, 0x40, 0x08, 0x04, 0x01, 0x40, 0x10, 0x10, 0x01, 0x40, 0x14, 0x10, 0x01, 0x40, 0xAD, 0xF1, 0x08, 0x0D, 0x0C, 0x49, 0x4F, 0xF4, 0xB5, 0x40, 0x08, 0x80, 0x0B, 0x49, 0x08, 0x78, 0x40, 0xF0, 0x01, 0x00, 0x08, 0x70, 0x0A, 0x49, 0x08, 0x78, 0x80, 0xF0, 0x01, 0x00, 0x08, 0x70, 0x08, 0x48, 0x00, 0x90, 0x00, 0x98, 0x00, 0x28, 0xF5, 0xD0, 0x00, 0x98, 0x40, 0x1E, 0x00, 0x90, 0x00, 0x98, 0x00, 0x28, 0xF9, 0xD1, 0xEE, 0xE7, 0x0C, 0x48, 0x00, 0x40, 0x04, 0x4C, 0x00, 0x40, 0x02, 0x4C, 0x00, 0x40, 0xA0, 0x86, 0x01, 0x00, 0x08, 0x48, 0x80, 0xF3, 0x08, 0x88, 0x08, 0x49, 0x08, 0x68, 0x40, 0xF4, 0x70, 0x00, 0x08, 0x60, 0x00, 0xBF, 0x00, 0xBF, 0x00, 0xF0, 0x10, 0xF8, 0x00, 0x20, 0xFF, 0xF7, 0xCD, 0xFF, 0x01, 0x20, 0x00, 0xF0, 0x0C, 0xF8, 0x00, 0x00, 0x01, 0x20, 0x88, 0xED, 0x00, 0xE0, 0x08, 0xB5, 0xFF, 0xF7, 0x87, 0xFF, 0xFF, 0xF7, 0xE5, 0xBF, 0x08, 0xBD, 0x01, 0x20, 0x70, 0x47, 0x00, 0xBF, 0xFE, 0xE7, 0xFE, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //variable detect if we interrupt occurs volatile bool jumpToBsl = false; unsigned char* firmware_ready; int main(){ // Stop watchdog MAP_WDT_A_holdTimer(); // LEDINIT MAP_GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0); P1OUT &= ~BIT0; // Set MCLK to 48MHz MAP_PCM_setCoreVoltageLevel(PCM_VCORE1); FlashCtl_setWaitState(FLASH_BANK0, 1); FlashCtl_setWaitState(FLASH_BANK1, 1); MAP_CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48); unsigned char tmp; firmware_ready=&tmp; *firmware_ready=0; //FLash write MAP_FlashCtl_unprotectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR30); if(!MAP_FlashCtl_eraseSector(FIRMWARE_READY_PARAM_ADDRESS)) while(1); if(!MAP_FlashCtl_programMemory(firmware_ready,(void*) FIRMWARE_READY_PARAM_ADDRESS, 1)) while(1); MAP_FlashCtl_protectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR30); // Flash write MAP_FlashCtl_unprotectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR31); if(!MAP_FlashCtl_eraseSector(LED_BLINK_SOFTWARE_MEMORY_ADDRESS_START)) while(1); if(!MAP_FlashCtl_programMemory(led_blink_software_array,(void*) LED_BLINK_SOFTWARE_MEMORY_ADDRESS_START, LED_BLINK_SOFTWARE_ARRAY)) while(1); MAP_FlashCtl_protectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR31); // Configure P1.1 as an input and enabling the interrupt MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1); MAP_GPIO_interruptEdgeSelect(GPIO_PORT_P1, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1); MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1); MAP_Interrupt_enableInterrupt(INT_PORT1); MAP_Interrupt_enableMaster(); unsigned long i; while(1) { for(i=2000000; i>0; i--);// delay cycles if (jumpToBsl) { //FLash write MAP_FlashCtl_unprotectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR30); if(!MAP_FlashCtl_eraseSector(FIRMWARE_READY_PARAM_ADDRESS)) while(1); if(!MAP_FlashCtl_programMemory(firmware_ready,(void*) FIRMWARE_READY_PARAM_ADDRESS, 1)) while(1); MAP_FlashCtl_protectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR30); // Flash write MAP_FlashCtl_unprotectSector(FLASH_MAIN_MEMORY_SPACE_BANK1,FLASH_SECTOR31); jumpToBsl = false; MAP_Interrupt_disableMaster(); // Setup interrupt priorities into 0x00 before entering bootloader for (i=0; i < 240; i++) NVIC->IP[i] = 0; NVIC->ICER[0] = 0xFFFF;// must be cleared before invoking BSL NVIC->ICPR[0] = 0xFFFF; NVIC->ICER[1] = 0xFFFF; NVIC->ICPR[1] = 0xFFFF; // Call the BSL with given BSL parameters BSL_INVOKE((uint32_t)BSL_PARAM); //#define BSL_INVOKE(x) ((void (*)())BSL_ENTRY_FUNCTION)((uint32_t) x) /*!< Invoke the BSL with parameters */ from msp432p401r.h } } } void PORT1_IRQHandler(void) { uint32_t status; status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1); MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status); if(status & GPIO_PIN1) { jumpToBsl = true; *firmware_ready=true; } }
Bálint
**Attention** This is a public forum