Hi all,
i try to make a SW reset on the MKW01Z in a simple application derived from the WirelessUart example with a bare metal OS.
The code that i use to reset is simply:
NVIC_SystemReset();
I try even this:
int index_timer=0;
MLMEPhySoftReset();
GPIO_DRV_WritePinOutput(kGpioXcvrReset, 0);
while(TMR_StopTimer(index_timer)!=gTmrInvalidId_c){index_timer++;};
OSA_EXT_InterruptDisable();
NVIC_SystemReset();
But in any case the result is that sometimes HardFault rises up.
Any suggestions?
Best,
Stefano
Hi Stefano Pieri,
What is going on with the issue now?
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Sorry the while cycle is:
while(1)
{
(void)OSA_EventWait(&gTaskEvent, gEventsAll, FALSE, OSA_WAIT_FOREVER ,&gTaskEventFlags);
if(gUART_RX_EVENT_c == gTaskEventFlags ){
if (toggle_led){
PrintMenu(cu8FreescaleLogo, mAppSer);
toggle_led=FALSE;
}else{
toggle_led=TRUE;
int index_timer=0;
MLMEPhySoftReset();
GPIO_DRV_WritePinOutput(kGpioXcvrReset, 0);
while(TMR_StopTimer(index_timer)!=gTmrInvalidId_c){index_timer++;};
OSA_EXT_InterruptDisable();
Boot_Cpu_SystemReset();
}
}
Hi Stefano,
Please refer to the thread below.
https://mcuoneclipse.com/2015/07/01/how-to-reset-an-arm-cortex-m-with-software/
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Ping,
In effect NVIC_SystemReset() makes the instructions:
__DSB(); /* Ensure all outstanding memory accesses included
buffered write are completed before reset */
SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB(); /* Ensure completion of memory access */
while(1) { __NOP(); }
But in some reboot the program go into the HardFault_Handler when the Application Restart.
I think that could be caused by the transciever that is not well reset or by a bad Memory management.
I use the bare metal OS and the program is very simple:
void main_task(uint32_t param)
{
static bool_t bIsInitialized = FALSE;
static bool_t bUserInteraction = FALSE;
static bool toggle_led = TRUE;
if( !bIsInitialized )
{
hardware_init();
CACHE_DISABLE
NV_Init();
gFlashConfig.CallBack = (PCALLBACK)RelocateFunction((uint32_t)__ram_for_callback , CALLBACK_SIZE , (uint32_t)callback);
MCM_BWR_PLACR_DFCC(MCM_BASE_PTR, 1);
MEM_Init();
TMR_Init();
LED_Init();
//initialize PHY
Phy_Init();
//initialize Serial Manager
SerialManager_Init();
LED_StartSerialFlash(LED1);
OSA_EventCreate(&gTaskEvent, kEventAutoClear);
Serial_InitInterface( &mAppSer, APP_SERIAL_INTERFACE_TYPE, APP_SERIAL_INTERFACE_INSTANCE);//Get handle of serial interface
Serial_SetBaudRate (mAppSer, gUARTBaudRate115200_c); //Set 115200 as default baud
Serial_SetRxCallBack(mAppSer, UartRxCallBack, NULL); //Set Receive callback for uart
InitApp();
#ifdef VERBOSE
/*Prints the Welcome screens in the terminal*/
PrintMenu(cu8FreescaleLogo, mAppSer);
Serial_Print(mAppSer,"\r\n\r\n Press switch1 button to start application\r\n\r\n",gAllowToBlock_d);
#endif
bIsInitialized = TRUE;
}
bUserInteraction = TRUE;
if(bUserInteraction)
{
while(1)
{
(void)OSA_EventWait(&gTaskEvent, gEventsAll, FALSE, OSA_WAIT_FOREVER ,&gTaskEventFlags);
if(gUART_RX_EVENT_c == gTaskEventFlags ){
if (toggle_led){
PrintMenu(cu8FreescaleLogo, mAppSer);
toggle_led=FALSE;
}else{
LED_StartSerialFlash(LED1);
toggle_led=TRUE;
// relocate vector table
SCB->VTOR = RELOCATED_VECTORS;
AppIDC = 0;
// Jump to user application
JumpToUserApplication(*((unsigned long*)RELOCATED_VECTORS), *((unsigned long*)(RELOCATED_VECTORS+4)));
int index_timer=0;
MLMEPhySoftReset();
GPIO_DRV_WritePinOutput(kGpioXcvrReset, 0);
while(TMR_StopTimer(index_timer)!=gTmrInvalidId_c){index_timer++;};
OSA_EXT_InterruptDisable();
Boot_Cpu_SystemReset();
}
}
if (gUseRtos_c == 0)
{
break;
}
}
}
}