CANopen Bootloader Documentation
Version 4.10.00
Loading...
Searching...
No Matches
Flash Programming

Access to the Flash memory is done via three callback functions. They are called when data is written to the CANopen objects 1F50h and 1F51h by a CANopen Program Download Tool.

CblMgrBufferStore()

Store program / data in flash memory, callback function in cbl_user.c

CblMgrFlashDelete()

Delete program / data in flash memory, callback function in cbl_user.c

CblMgrFlashFinalize()

Finalize program / data in flash memory, callback function in cbl_user.c

The next figure gives an overview of the involved CANopen objects during program download.

The following global variables are used inside the callback functions.

Variable Access

Description

aulIdx1F56_SoftIdentG[] write

CRC value of program, CANopen access via 1F56h

aulIdx1F57_FlashStatusG[] write

Flash status, CANopen access via 1F57h

ubCblMgrBufferStoreG[] read/write Write value 0 to mark the end of a flash operation

Erase Flash Memory

The function CblMgrFlashDelete() is called by the CANopen Bootloader upon reception of a program erase command in object 1F51h. The following code has to be adopted to the target system.

void CblMgrFlashDelete(uint8_t ubProgNumV)
{
//---------------------------------------------------------------------------------------------------
// Unlock flash memory
//
//---------------------------------------------------------------------------------------------------
// Set status in object 1F57h: flash operation in progress
//
//---------------------------------------------------------------------------------------------------
// Erase flash and set status in object 1F57h
//
{
}
else
{
}
//---------------------------------------------------------------------------------------------------
// lock flash
//
//---------------------------------------------------------------------------------------------------
// clear software identification
//
aulIdx1F56_SoftIdentG[ubProgNumV] = 0x00000000;
}
#define CBL_APP_START_ADDR
Definition cbl_conf.h:291
@ eCBL_FLASH_FAIL_NO_PROGRAM
Definition cbl_mgr.h:94
@ eCBL_FLASH_FAIL_WRITE_ERROR
Definition cbl_mgr.h:106
void CblMgrFlashDelete(uint8_t ubProgNumV)
@ eCBL_FLASH_STATUS_PROGRESS
Definition cbl_mgr.h:78
uint32_t aulIdx1F57_FlashStatusG[]
Flash status identification - index 1F57:0xh
uint32_t aulIdx1F56_SoftIdentG[]
Program software identification - index 1F56:0xh
Status_tv McFlashLock(void)
Lock the Flash memory controller.
@ eFLASH_ERR_OK
Definition mc_flash.h:77
Status_tv McFlashUnlock(void)
Unlock the Flash memory controller.
Status_tv McFlashErase(uint32_t ulFlashAddrV, uint32_t ulSizeV)
Erase page of selected address.
uint32_t McIapAppSizeLimit(void)

The following flowchart shows the interaction upon writing the Erase command or a Manufacturer-specific command to index 1F51h inside the object dictionary.

Store Data to Flash Memory

The function CblMgrBufferStore() is called by the CANopen Bootloader after a certain amount of data has been copied to the internal RAM of the target system by the CANopen Download Tool. The following code has to be adopted to the target system.

void CblMgrBufferStore(uint8_t ubProgNumV, uint8_t * pubBufferV, uint16_t uwSizeV)
{
static uint32_t ulAddrStartS = (CBL_APP_START_ADDR);
static uint32_t ulBlockNumS = 0;
//---------------------------------------------------------------------------------------------------
// This function is called by the CANopen bootloader when new data shall be stored inside the Flash
// memory. The global variable 'ubCblMgrBufferStoreG' is > 0 when data needs to be stored. This
// function has to set the value back to 0 when data store is done.
//
if (ubCblMgrBufferStoreG > 0)
{
//-------------------------------------------------------------------------------------------
// Test if flash is empty: we initialize the start address then and set the block counter
// to 0.
//
{
ulAddrStartS = (CBL_APP_START_ADDR);
ulBlockNumS = 0;
}
//-------------------------------------------------------------------------------------------
// At this point the flash status shall be eCBL_FLASH_STATUS_PROGRESS, otherwise something
// went really wrong.
//
{
//-----------------------------------------------------------------------------------
// unlock flash
//
ulBlockNumS++;
//-----------------------------------------------------------------------------------
// Write data from SRAM buffer to flash, the size must be an even value
//
if (uwSizeV % 2)
{
uwSizeV++;
}
if (McFlashWrite(ulAddrStartS, pubBufferV, uwSizeV) != eFLASH_ERR_OK)
{
}
//-----------------------------------------------------------------------------------
// Increase the start address for the next call of this function
//
ulAddrStartS = ulAddrStartS + uwSizeV;
//-----------------------------------------------------------------------------------
// lock flash
//
}
//-------------------------------------------------------------------------------------------
// store operation finished
//
ubCblMgrBufferStoreG = 0;
}
}
void CblMgrBufferStore(uint8_t ubProgNumV, uint8_t *pubBufferV, uint16_t uwSizeV)
Status_tv McFlashWrite(uint32_t ulAddressV, void *pvdDataV, uint32_t ulSizeV)
Write data.

Finalize Flash Programming

The function CblMgrFlashFinalize() is called by the CANopen Bootloader after all data has written to the target system. The following pseudo code has to be adopted to the target system.

void CblMgrFlashFinalize(uint8_t ubProgNumV, uint32_t ulSizeV)
{
uint8_t * pubMemStartT; // memory start address
//---------------------------------------------------------------------------------------------------
// The function is called after the download is completed. We store the infomration about the
// program size and the program CRC inside the IAP block.
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
// If the flash status is not equal to eCBL_FLASH_STATUS_PROGRESS something went wrong
//
{
aulIdx1F56_SoftIdentG[ubProgNumV] = 0;
}
else
{
//-------------------------------------------------------------------------------------------
// build checksum over stored data
//
pubMemStartT = (uint8_t *)(CBL_APP_START_ADDR);
aulIdx1F56_SoftIdentG[ubProgNumV] = CblMgrBufferCrc(pubMemStartT, ulSizeV);
}
}
uint32_t CblMgrBufferCrc(uint8_t *pubMemStartV, uint32_t ulSizeV)
void CblMgrFlashFinalize(uint8_t ubProgNumV, uint32_t ulSizeV)
@ eCBL_FLASH_STATUS_OK
Definition cbl_mgr.h:75