Hi,
I wonder if anyone else get the same problem as me. When running in debug, I am not able to restart the program because clicking restart will jump to hardfault (INVPC). I need to stop and restart debugging in order to restart my program and this consumes a lot of time.
I found out that this happens when I use an interrupt. When I disable the interrupt, I can restart the program during debugging as many time as I wants. This is my example code (I added a timer interrupt to Freertos blinky example):
#include "board.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#define TICKRATE_HZ 1
static void prvSetupHardware(void)
{
SystemCoreClockUpdate();
Board_Init();
Board_LED_Set(0, false);
}
static void vLEDTask1(void *pvParameters) {
bool LedState = false;
while (1) {
Board_LED_Set(0, LedState);
LedState = (bool) !LedState;
vTaskDelay(configTICK_RATE_HZ / 6);
}
}
static void vLEDTask2(void *pvParameters) {
bool LedState = false;
while (1) {
Board_LED_Set(1, LedState);
LedState = (bool) !LedState;
vTaskDelay(configTICK_RATE_HZ / 14);
}
}
static void vUARTTask(void *pvParameters) {
int tickCnt = 0;
while (1) {
DEBUGOUT("Tick: %d \r\n", tickCnt);
tickCnt++;
vTaskDelay(configTICK_RATE_HZ);
}
}
int main(void)
{
uint32_t timerFreq;
prvSetupHardware();
Chip_TIMER_Init(LPC_TIMER1);
Chip_RGU_TriggerReset(RGU_TIMER1_RST);
while (Chip_RGU_InReset(RGU_TIMER1_RST)) {}
timerFreq = Chip_Clock_GetRate(CLK_MX_TIMER1);
Chip_TIMER_Reset(LPC_TIMER1);
Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1);
Chip_TIMER_SetMatch(LPC_TIMER1, 1, (timerFreq / TICKRATE_HZ));
Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1);
Chip_TIMER_Enable(LPC_TIMER1);
NVIC_EnableIRQ(TIMER1_IRQn);
NVIC_ClearPendingIRQ(TIMER1_IRQn);
xTaskCreate(vLEDTask1, "vTaskLed1", configMINIMAL_STACK_SIZE,
NULL, (tskIDLE_PRIORITY + 1UL), (TaskHandle_t *) NULL);
xTaskCreate(vLEDTask2, "vTaskLed2", configMINIMAL_STACK_SIZE,
NULL, (tskIDLE_PRIORITY + 1UL), (TaskHandle_t *) NULL);
xTaskCreate(vUARTTask, "vTaskUart", configMINIMAL_STACK_SIZE,
NULL, (tskIDLE_PRIORITY + 1UL), (TaskHandle_t *) NULL);
vTaskStartScheduler();
return 1;
}
void TIMER1_IRQHandler(void)
{
static BaseType_t xHigherPriorityTaskWoken;
static int interruptCount = 0;
if (Chip_TIMER_MatchPending(LPC_TIMER1, 1)) {
Chip_TIMER_ClearMatch(LPC_TIMER1, 1);
interruptCount++;
}
}
I also found that the rtos will crash after running it for several hours.
Can someone enlighten how this hardfault occurs? It will not occur if the timer interrupt is not enabled.
Does anyone ever succeeded to have stable freertos build with nxp?
Thanks
UAZ