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.
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.
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.
你能解释一下吗?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.:
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.
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.
嗨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
你能解释一下如何platform_reset参数is used then? It appears to be used by the ROM after the reset to determine how to load the user program.
在一些挖掘之后,它看起来会在system.init()中提供发送到平台重置的错误值。它由rwip_init(错误)使用。这将指示已经存在从前一个运行实例到新实例的错误状态。我需要知道的是我可以发送自己的价值而不是其中一个预定义的值:
/// Possible errors detected by FW
#define RESET_NO_ERROR 0x00000000
#define RESET_MEM_ALLOC_FAIL 0xF2F2F2F2
///重置平台并留在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.
嗨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
你能解释一下吗?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.:
if(错误!= 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
}
嗨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
好的。这解释了这一点。
最后一个相关的问题。如何找到重置/崩溃的原因?我看到几个人提到reset_mem_alloc_fail作为重置的原因。我有一个潜在的内存分配失败,导致重置,我想确认就是这种情况。
嗨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