I am using the Kinetis K65 MCU.
Here is the code (which I got from youtube) that I'm trying to run. It is an example on using event groups with a software watchdog.
I noticed printf calls works in good_task and bad_task functions, but not in the sw_watchdog function. That is the only function I can't get printf to work normally.
I also tried your suggestion: Quickstart Panel -> Quick Settings -> SDK debug console -> Semihost console , but to no avail (I also made sure the Event_Groups project was selected before trying the above approach).
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MK65F18.h"
#include "fsl_debug_console.h"
#include <FreeRTOS.h>
#include "task.h"
#include "event_groups.h"
EventGroupHandle_t task_watchdog;
const uint32_t good_task_id = (1 << 0);
const uint32_t bad_task_id = (1 << 1);
const uint32_t tasks_all_bits = (good_task_id | bad_task_id);
void good_task(void *p)
{
while(1) {
xEventGroupSetBits(task_watchdog, good_task_id);
vTaskDelay(1000);
}
}
void bad_task(void *p)
{
int x = 0;
while(1) {
++x;
if (x >= 3 && x <= 6) {
}
else {
xEventGroupSetBits(task_watchdog, bad_task_id);
}
vTaskDelay(1000);
}
}
void sw_watchdog(void *p)
{
printf("hello\n");
while(1) {
uint32_t result = xEventGroupWaitBits(task_watchdog, tasks_all_bits,
pdTRUE,
pdTRUE,
2000);
if ((result & tasks_all_bits) == tasks_all_bits) {
printf("System is healthy\n");
}
else {
if (!(result & good_task_id)) {
printf("Good task stopped responding\n");
}
if (!(result & bad_task_id)) {
printf("Bad task stopped responding\n");
}
}
}
}
int main(void) {
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
BOARD_InitDebugConsole();
printf("%u %u %u\n", good_task_id, bad_task_id, tasks_all_bits);
task_watchdog = xEventGroupCreate();
xTaskCreate(good_task, "good_task", 1024, NULL, 1, NULL);
xTaskCreate(bad_task, "bad_task", 1024, NULL, 1, NULL);
xTaskCreate(sw_watchdog,"sw_watchdog", 1024, NULL, 2, NULL);
vTaskStartScheduler();
return 0;
}