2024-08-16 11:33 AM
I have made the STM32 BootLoader OTA on a STM32WB35CE several months ago and now I'm facing with a problem to expand it. The initial OTA bootloader and an user App work well for me, but I want to merge the OTA bootloader with some more stuff and changing size of it to bigger than before. So it growed and the start addr of user App now is 0x800D000 (instead of 0x8007000), but it doesnt work. I have new constant address for magic number on 0x800D140 (instead of 0x8007140) on the user App ld file. On the OTA bootloader I modified the start vector:
#define CFG_APP_START_SECTOR_INDEX (13) on the app_config.h file, and even I defined it on general preprocessor macros in the properties of project. I'm searching a lot to fix my problem, the problem is after connecting to OTA bootloader and after sending the user App, the user app dosn't start and it will return to Bootloader OTA and again advertises there. Could you please give me some tips about what I'm missing for this changing start Addr of user App? So in a brief, I just want to change the start Addr of user App from 0x8007000 to a new Addr like 0x800D000. On the hex file of user App which is made by STMCUBE-IDE I can see the magic number Addr and its value are on supposed sections, and everything seems prepared, but doesn't work.
I don't know that I need to fix the OTA BootLoader or the user App to fix the issue, because both have been changed.
I found the user App seems is still writen on previous Addr (from 0x8007000) which is wrong and should be write at Addr 0x800D000. But what should I do to fix it properly.
Thank you in advance
2024-08-16 03:18 PM
On the Bootloader OTA, in otas_app.c, I added an offset for the new start Addr to patch it and fixed it temporary:
void OTAS_STM_Notification( OTA_STM_Notification_t *p_notification )
{
....
....
case OTAS_STM_APPLICATION_UPLOAD:
....
OTAS_APP_Context.base_address += (CFG_APP_START_SECTOR_INDEX -7) * 0x1000; // I added this line
}
So the base Addr to write user App on the flash shifted for 0x6000 and the problem fixed.
But I know this is not a true way to fix it since that value should be configured somewhere else or even worse, this value comes from user App and Bootloader just use it and should not modify it.
I think this value comes from a BLE notify of user App. I use p2p_server_App_OTA and also I tried HRS_App_OTA of ST but I couldnt find the BLE notify value about it.
The value of base_address trace is in following scripts of BootLoader OTA:
static SVCCTL_EvtAckStatus_t OTAS_Event_Handler(void *Event)
{
...
OTA_STM_Notification_t notification;
notification.ChardId = OTAS_STM_BASE_ADDR_ID;
notification.pPayload = (uint8_t*)&attribute_modified->Attr_Data[0];
notification.ValueLength = attribute_modified->Attr_Data_Length;
OTAS_STM_Notification( ¬ification );
}
void OTAS_STM_Notification( OTA_STM_Notification_t *p_notification )
{
....
case OTAS_STM_APPLICATION_UPLOAD:
OTAS_APP_Context.file_type = Fw_App;
OTAS_APP_Context.base_address = FLASH_BASE;
((uint8_t*)&OTAS_APP_Context.base_address)[0] = (((uint8_t*)((OTA_STM_Base_Addr_Event_Format_t*)(p_notification->pPayload))->Base_Addr))[2];
((uint8_t*)&OTAS_APP_Context.base_address)[1] = (((uint8_t*)((OTA_STM_Base_Addr_Event_Format_t*)(p_notification->pPayload))->Base_Addr))[1];
((uint8_t*)&OTAS_APP_Context.base_address)[2] = (((uint8_t*)((OTA_STM_Base_Addr_Event_Format_t*)(p_notification->pPayload))->Base_Addr))[0];
OTAS_APP_Context.write_value_index = 0;
OTAS_APP_Context.base_address += (CFG_APP_START_SECTOR_INDEX -7) * 0x1000; // I added this line as patch the issue temporary
break;
....
}
So how can I fix it in a true way. Which part of user App or OTA-BootLoader should be modify for the change of start Addr of user App.
Thank you