This is a weird one.
QueueHandle_t rxq;
typedef struct msg {
uint8_t buf[64];
uint8_t len;
} msg_t;
static void tud_main(__unused void *ctx)
{
#if (configNUMBER_OF_CORES > 1)
vTaskCoreAffinitySet(NULL, (1 << 1));
#endif
tud_init(0);
stdio_init_all();
while (1) {
msg_t msg;
tud_task();
if (xQueueReceive(rxq, &msg, pdMS_TO_TICKS(1)) == pdPASS) {
tud_cdc_n_write(1, msg.buf, msg.len);
tud_cdc_n_write_flush(1);
}
};
}
static void foo_main(__unused void *ctx)
{
int c = 0;
while (1) {
char buf[64];
msg_t msg;
snprintf(buf, sizeof(buf), "foo. c is %d\n", c++);
printf("this is printf - %s", buf);
memset(&msg, 0, sizeof(msg));
msg.len = strlen(buf);
memcpy(msg.buf, buf, msg.len);
xQueueSendToBack(rxq, &msg, pdMS_TO_TICKS(1));
vTaskDelay(pdMS_TO_TICKS(1000));
};
}
void main(void)
{
TaskHandle_t foo_task, tud_task;
rxq = xQueueCreate(16, sizeof(msg_t));
xTaskCreate(foo_main, "foo", 8 * configMINIMAL_STACK_SIZE, NULL, DEFAULT_TASK_PRIORITY, &foo_task);
xTaskCreate(tud_main, "tusb_device", 8 * configMINIMAL_STACK_SIZE, NULL, DEFAULT_TASK_PRIORITY + 1, &tud_task);
vTaskStartScheduler();
while (1) ;
}
tinyusb is set up to be device-only and present two CDC interfaces. The first one is the usual stdio related stuff, and the second one just prints out the messages received over the queue.
If I do not set the core affinity of tud_task it works as expected. However if I do set it, or set it and then set it back to the default (no affinity) then usb still works great, I still see the messages on the second CDC interface, but none of the printf() messages come out. I'm certain that FreeRTOS is working since if it wasn't, or if tud_task was hanging or otherwise misbehaving then I would not have either CDC interface (and the queue system wouldn't be working either.
I've played with configRUN_MULTIPLE_PRIORITIES without any change, and if I set configTASK_DEFAULT_CORE_AFFINITY so both tasks run on the same core, printf/stdio is still broken. In my actual codebase I have a few more tasks and they are all running fine, as are the FreeRTOS timers and so on... it feels like the stdio system or maybe something deeper in tinyusb is making an assumption about the system that it shouldn't be.
This is a weird one.
tinyusb is set up to be device-only and present two CDC interfaces. The first one is the usual stdio related stuff, and the second one just prints out the messages received over the queue.
If I do not set the core affinity of
tud_taskit works as expected. However if I do set it, or set it and then set it back to the default (no affinity) then usb still works great, I still see the messages on the second CDC interface, but none of the printf() messages come out. I'm certain that FreeRTOS is working since if it wasn't, or iftud_taskwas hanging or otherwise misbehaving then I would not have either CDC interface (and the queue system wouldn't be working either.I've played with
configRUN_MULTIPLE_PRIORITIESwithout any change, and if I setconfigTASK_DEFAULT_CORE_AFFINITYso both tasks run on the same core, printf/stdio is still broken. In my actual codebase I have a few more tasks and they are all running fine, as are the FreeRTOS timers and so on... it feels like the stdio system or maybe something deeper in tinyusb is making an assumption about the system that it shouldn't be.