How do I get the reset reason after the DA14580 resets, loads the otp to SysRam and starts to run? I have the application flags set and otp code is loaded and executed immediately. I want to know if it is a hard reset or soft reset and if possible, I'd like to pass a custom value for the reason for the reset.
Device:
Hi NScherdin,
There is no standard way to do this or a dedicated mechanism to apply, what you can try is to apply a scheme where you keep a variable in the retention memory area (depends if the sysram shuts down when sleeping or not), initialize it in a HW_reset code and change the status according to the reset that you have by changing the status code in the variable from the handler that your code passes. Hardfault, platform_reset, NMI_Handler etc. In case you use the retention memory area you should have in mind that it is set to zero every time you restart the system via the SystemInit() function, you will have to tweak that function in order not re-initialize the reset reason that you have store previously when the reset occured.
Thanks MT_dialog
Can you explain how the platform_reset argument is used then? It appears to be used by the ROM after the reset to determine how to load the user program.
After some digging it appears the error value sent to platform reset is provided in system.init(). It is used by rwip_init(error). This would indicate there is already a mechanism that is passing this error state from the previous running instance to the new instance. What I need to know is can I send my own value instead of one of the predefined ones:
/// Possible errors detected by FW
#define RESET_NO_ERROR 0x00000000
#define RESET_MEM_ALLOC_FAIL 0xF2F2F2F2
/// Reset platform and stay in ROM
#define RESET_TO_ROM 0xA5A5A5A5
/// Reset platform and reload FW
#define RESET_AND_LOAD_FW 0xC3C3C3C3
#define RESET_AFTER_SPOTA_UPDATE 0x11111111
I can modify the system_init to check the error value and if it is my value set the error code back to RESET_NO_ERROR and then set my own variable to tell my main program how to procede.
The reason I am doing this is to save on code space. Currently I have a ota bootloader that works very well but I keep a trimmed down version in OTP that is loaded if the flash firmware is corrupt(instead of keeping two different copies of firmware in the flash both of which could technically get corrupted). It works well but it requires I keep a copy of the ota code in the main user program which wastes 4 to 5k of code space. If I can instead simply reset and pass a error that tells my otp bootloader to run the ota bootloader included in OTP memory then I can completely remove that block of code from my flash user program and just use a platform_reset with my custom error value.
If that is not possible, yes I will use a memory flag but it seems this is already inherent to your current system and I want to save every byte of code space I can.
Hi NScherdin,
In the SDK with the BLE_HOST_PRESENT defined, the rwip_init() is implemented in the ROM code, the platform_reset_func() (which is invoked from the platform_reset() ) is a function that is implemented by the ROM code as well but it doesn't checks any values in order to do predefined operations. It doens't store the previous reset reason to any specific variable or have any implementation from where to load the user code, it justs sets to 1 the SW_RESET bit in the SYS_CTRL_REG and restarts with the booting procedure.
Thanks MT_dialog
Can you then explain the value of error when rwip_init is called in system_init? It seems rwip_init requires error to be either RESET_NO_ERROR or not. If it is always RESET_NO_ERROR then the following code in rwip_init makes no sense. If the error value can be other than RESET_NO_ERROR what are the possibilities and where is the value coming from that it is being set to.:
如果(错误! = RESET_NO_ERROR)
{
#if (BLE_EMB_PRESENT && HCIC_ITF)
rwble_send_message(error);
# elif (BLE_HOST_PRESENT && GTL_ITF)
rwble_hl_send_message(error);
#endif // BLE_EMB_PRESENT
}
Hi NScherdin,
The rwip_init() function in the system_init() function isn't the one that is actually called when the system starts, the #define above the functions implementation is allways 1, and the rwip_init() that is called is from the ROM code and not the one implemented in the SDK. Nevertheless the functions are quite similar and the rwble_hl_send_message(error) that is called in the #elif you mention is just an empty function in the ROM code. I suppose that the implementation is a riviera_waves leftover for debugging or testing purposes, there is no implemented mechanism for the functionallity you want, and as i allready mentioned the platform_reset_func doesn't store or checks any variables it justs resets the device.
Thanks MT_dialog
Ok. That explains that.
One last related questions. How do I find out the reason for a reset/crash? I see a couple people mention RESET_MEM_ALLOC_FAIL as the reason for their reset. I have a potential memory allocation failure causing a reset and I want to confirm that is the case.
Hi NScherdin,
The ROM code traces this kind of allocation failure and forces a platform reset with a RESET_MEM_ALLOC_FAIL as a parameter, if there is a reset in your custom code then running out of ram is the cause of it.
Thanks MT_dialog