about wdog WDOG_EWM_IRQHandler: crash in freertos with s32k144

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

about wdog WDOG_EWM_IRQHandler: crash in freertos with s32k144

Jump to solution
1,368 Views
alice_thanks
Contributor III

hello,

do you have example with wdog feature in freertos, 

i can run wdog under Bare metal 

but it will crash/hold on run with freertos, could you help to check it.

alice_thanks_0-1685690774188.png

 

0 Kudos
1 Solution
1,307 Views
alice_thanks
Contributor III

Hello @danielmartynek 

now it work with two task and printf , but when i can create the third task, all task will hold on.

can you help check it.

View solution in original post

Tags (1)
0 Kudos
5 Replies
1,361 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hello Alice,

As far as I can see from the source code you posted, you did not enable the WDOG.

This is a DefaultISR() which can be caused by any interrupt whose ISR is not implemented in the code, probably a fault exception.

Please add this handler:

void HardFault_Hander(void){
  while(1){}
}

And find the fault instruction as explained here:

https://community.nxp.com/t5/S32K-Knowledge-Base/Fault-handling-on-S32K14x/ta-p/1114447

 

Regards,

Daniel

0 Kudos
1,340 Views
alice_thanks
Contributor III

Hello @danielmartynek 

i add the example code, i find the is the when open printf in task, it will cause this issue.

but i didn't see the issue in printf function, attached is the project, can you help to check it, thank you!

 

alice_thanks_0-1685951469108.png

/*
 * rtos.c
 *
 *  Created on: Jun 2, 2023
 *      Author: fshi
 */
/*
 * rtos_process.c
 *
 *  Created on: Jun 2, 2023
 *      Author: fshi
 */
 
/* Kernel includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
 
/* SDK includes. */
#include "interrupt_manager.h"
#include "clock_manager.h"
#include "clockMan1.h"
#include "pin_mux.h"
#include "console.h"
#include "falut_debug.h"
#include <string.h>
#include <stdio.h>
 
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
 
#include "lpi2c1.h"
#include "dmaController1.h"
#if CPU_INIT_CONFIG
  #include "Init_Config.h"
#endif
/* Priorities at which the tasks are created. */
#define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
#define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
 
/* The rate at which data is sent to the queue, specified in milliseconds, and
converted to ticks using the portTICK_PERIOD_MS constant. */
#define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_PERIOD_MS )
 
/* The LED will remain on until the button has not been pushed for a full
5000ms. */
#define mainBUTTON_LED_TIMER_PERIOD_MS ( 5000UL / portTICK_PERIOD_MS )
 
/* The number of items the queue can hold.  This is 1 as the receive task
will remove items as they are added, meaning the send task should always find
the queue empty. */
#define mainQUEUE_LENGTH ( 1 )
 
/* The LED toggle by the queue receive task (blue). */
#define mainTASK_CONTROLLED_LED ( 1UL << 0UL )
 
/* The LED turned on by the button interrupt, and turned off by the LED timer
(green). */
#define mainTIMER_CONTROLLED_LED ( 1UL << 1UL )
 
/* The vector used by the GPIO port C.  Button SW7 is configured to generate
an interrupt on this port. */
#define mainGPIO_C_VECTOR ( 61 )
 
/* A block time of zero simply means "don't block". */
#define mainDONT_BLOCK ( 0UL )
/* Definition of the data transfer size */
#define TRANSFER_SIZE (3u)
/*-----------------------------------------------------------*/
 
/*
 * Setup the NVIC, LED outputs, and button inputs.
 */
static void prvSetupHardware( void );
 
/*
 * The tasks as described in the comments at the top of this file.
 */
static void prvQueueReceiveTask( void *pvParameters );
static void prvQueueSendTask( void *pvParameters );
 
/*
 * The LED timer callback function.  This does nothing but switch off the
 * LED defined by the mainTIMER_CONTROLLED_LED constant.
 */
static void prvButtonLEDTimerCallback( TimerHandle_t xTimer );
 
 
 
/*-----------------------------------------------------------*/
 
/* The queue used by both tasks. */
static QueueHandle_t xQueue = NULL;
 
/* The LED software timer.  This uses prvButtonLEDTimerCallback() as its callback
function. */
static TimerHandle_t xButtonLEDTimer = NULL;
 
/*-----------------------------------------------------------*/
 
void rtos_start( void )
{
/* Configure the NVIC, LED outputs and button inputs. */
prvSetupHardware();
 
/* Create the queue. */
xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );
 
if( xQueue != NULL )
{
/* Start the two tasks as described in the comments at the top of this
file. */
 
xTaskCreate( prvQueueReceiveTask, "RX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );
xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );
 
/* Start the tasks and timer running. */
vTaskStartScheduler();
}
 
/* If all is well, the scheduler will now be running, and the following line
will never be reached.  If the following line does execute, then there was
insufficient FreeRTOS heap memory available for the idle and/or timer tasks
to be created.  See the memory management section on the FreeRTOS web site
for more details. */
for( ;; );
}
/*-----------------------------------------------------------*/
extern void reset_wdt (void);
 
static void prvQueueSendTask( void *pvParameters )
{
TickType_t xNextWakeTime;
const unsigned long ulValueToSend = 100UL;
    uint32_t i = 0;
/* Casting pvParameters to void because it is unused */
(void)pvParameters;
 
/* Initialise xNextWakeTime - this only needs to be done once. */
xNextWakeTime = xTaskGetTickCount();
 
for( ;; )
{
/* Place this task in the blocked state until it is time to run again.
The block time is specified in ticks, the constant used converts ticks
to ms.  While in the Blocked state this task will not consume any CPU
time. */
//as8579_data_process();
 
        //vTaskDelay(pdMS_TO_TICKS(10));
/* Send to the queue - causing the queue receive task to unblock and
toggle an LED.  0 is used as the block time so the sending operation
will not block - it shouldn't need to block as the queue should always
be empty at this point in the code. */
xQueueSend( xQueue, &ulValueToSend, mainDONT_BLOCK );
printf("prvQueueReceiveTask=%d\n",i);
       // vTaskDelay(pdMS_TO_TICKS(10));
        vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );
}
}
/*-----------------------------------------------------------*/
 
static void prvQueueReceiveTask( void *pvParameters )
{
unsigned long ulReceivedValue;
 
/* Casting pvParameters to void because it is unused */
(void)pvParameters;
    int i = 0;
for( ;; )
{
/* Wait until something arrives in the queue - this task will block
indefinitely provided INCLUDE_vTaskSuspend is set to 1 in
FreeRTOSConfig.h. */
xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );
i++;
printf("prvQueueReceiveTask=%d\n",i);
//vTaskDelay(pdMS_TO_TICKS(10));
 
}
}
/*-----------------------------------------------------------*/
 
static void prvSetupHardware( void )
{
/* Allocate memory for the LPI2C driver state structure */
    lpi2c_master_state_t lpi2c1MasterState;
 
    /* Declaration of the LPI2C transfer buffer */
    uint8_t buffer[TRANSFER_SIZE];
 
    /* Variable used for the loop that initializes the data buffer */
    uint16_t i;
/* Initialize and configure clocks
     *  - Configure system clocks and dividers
     *  - Configure LPI2C clock gating
     *  -   see clock manager component for details
     */
    CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
                   g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
    CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
 
    /* Initialize pins
     *  - Configure LPI2C pins
     *  -   See PinSettings component for more info
     */
    PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
 
    /* Initialize LPI2C Master configuration
     *  - Slave address 0x01
     *  - Fast operating mode, 400 KHz SCL frequency
     *  -   See LPI2C components for configuration details
     */
    LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
    LPI2C_DRV_MasterInit(INST_LPI2C1, &lpi2c1_MasterConfig0, &lpi2c1MasterState);
enable_fault_handlers();        // If not set, all fault are handled by HardFault_Handler
set_fault_handlers_priority();  // priority: MemManage (1), BusFault (1), UsageFault(1)
}
/*-----------------------------------------------------------*/
 
void vApplicationMallocFailedHook( void )
{
/* Called if a call to pvPortMalloc() fails because there is insufficient
free memory available in the FreeRTOS heap.  pvPortMalloc() is called
internally by FreeRTOS API functions that create tasks, queues, software
timers, and semaphores.  The size of the FreeRTOS heap is set by the
configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
taskDISABLE_INTERRUPTS();
for( ;; );
}
/*-----------------------------------------------------------*/
 
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;
 
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
function is called if a stack overflow is detected. */
taskDISABLE_INTERRUPTS();
for( ;; );
}
/*-----------------------------------------------------------*/
 
void vApplicationIdleHook( void )
{
    volatile size_t xFreeHeapSpace;
 
/* This function is called on each cycle of the idle task.  In this case it
does nothing useful, other than report the amount of FreeRTOS heap that
remains unallocated. */
xFreeHeapSpace = xPortGetFreeHeapSize();
 
if( xFreeHeapSpace > 100 )
{
/* By now, the kernel has allocated everything it is going to, so
if there is a lot of heap remaining unallocated then
the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be
reduced accordingly. */
}
 
}
/*-----------------------------------------------------------*/
 
/* The Blinky build configuration does not include run time stats gathering,
however, the Full and Blinky build configurations share a FreeRTOSConfig.h
file.  Therefore, dummy run time stats functions need to be defined to keep the
linker happy. */
void vMainConfigureTimerForRunTimeStats( void ) {}
unsigned long ulMainGetRunTimeCounterValue( void ) { return 0UL; }
 
/* A tick hook is used by the "Full" build configuration.  The Full and blinky
build configurations share a FreeRTOSConfig.h header file, so this simple build
configuration also has to define a tick hook - even though it does not actually
use it for anything. */
void vApplicationTickHook( void ) {}
 
/*-----------------------------------------------------------*/
 
#include "console.h"
#include "lpuart1.h"
#include <stdio.h>
#include <string.h>
 
 
int_t __read_console(__file_handle handle, uchar_t * buffer, size_t * count)
{
  uint32_t bytesRemain;
bool MsgDone=false;
uchar_t new_lin[]={"\n"};
int i=0;
while (MsgDone==false)
{
    LPUART_DRV_ReceiveData(INST_LPUART1, &buffer[i], 1);
    while(LPUART_DRV_GetReceiveStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
    LPUART_DRV_SendData(INST_LPUART1, &buffer[i], 1);
    while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
    if(buffer[i++] == '\r')
{
   buffer[i-1]='\n';
   MsgDone = true;
}
  }
  LPUART_DRV_SendData(INST_LPUART1, new_lin, 1);
while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
buffer[i]=0;
*count = (size_t)i;
return 0;
}
 
 
int_t __write_console(__file_handle handle, uchar_t * buffer, size_t * count)
{
  uint32_t bytesRemain;
  size_t bytes=*count;
  uchar_t ret_car[]={"\r"};
  LPUART_DRV_SendData(INST_LPUART1, buffer, bytes);
  while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
  LPUART_DRV_SendData(INST_LPUART1, ret_car, 1);
  while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
  return 0;
}
 
 
int_t __close_console(__file_handle handle)
{
  return 0;
}
 

 

0 Kudos
1,308 Views
alice_thanks
Contributor III

Hello @danielmartynek 

now it work with two task and printf , but when i can create the third task, all task will hold on.

can you help check it.

Tags (1)
0 Kudos
1,300 Views
alice_thanks
Contributor III

i resolved it, thanks

794 Views
JayCao
Contributor III

Hello, I am in the same case with this. Could you help to share the source which solved this problem?

0 Kudos