oguzkagan
(Oğuz Kağan Yağlıoğlu)
July 12, 2022, 9:53pm
1
I’m trying to send a struct using lora module with raspberry pi pico. But after I sent the data for the first time to the lora over uart, pico hangs. I’ve connected a debugger to see what’s going on. What should I do to fix that issue?
hangs here
file location: pico-sdk/src/common/pico_time/time.c
I have currently only one task
taskHandleDataPublisher = xTaskCreateStatic(taskPublishData,
"tData_PUBLISHER",
TASK_STACK_SIZE_DATA_PUBLISHER,
nullptr,
TASK_PRIORITY_DATA_PUBLISHER,
taskStackDataPublisher,
&taskBufferDataPublisher);
I know printf is not thread safe but since I have only one task I don’t thing it should be a problem.
void taskPublishData(void *pvParameters) {
static TickType_t lastWakeTime = xTaskGetTickCount();
static Packet dataPacket;
static bool timerTriggerStatus = false;
absolute_time_t lastCallTime = get_absolute_time();
for (;;) {
timerTriggerStatus = xTaskDelayUntil(&lastWakeTime, pdMS_TO_TICKS(1000 / 5));
printf("PUBLISH_WAKE: %s\t%3lu\r\n", timerTriggerStatus ? "ON_TIME" : "LATE",
us_to_ms(absolute_time_diff_us(lastCallTime, get_absolute_time())));
lastCallTime = get_absolute_time();
//publish the data
vTaskSuspendAll();
portENTER_CRITICAL();
uart_putc(LORA_UART, LORA_TARGET_ADDRH);
uart_putc(LORA_UART, LORA_TARGET_ADDRL);
uart_putc(LORA_UART, LORA_TARGET_CHANNEL);
uart_write_blocking(LORA_UART, (uint8_t *) &dataPacket, sizeof(MainCompPacket));
portEXIT_CRITICAL();
xTaskResumeAll();
}
}
I am using SMP version of the FreeRTOS
It prints PUBLISH_WAKE: ON_TIME 199
and I receive the dataPacket but then it hangs.
oguzkagan
(Oğuz Kağan Yağlıoğlu)
July 12, 2022, 9:54pm
2
file location: pico-sdk/src/common/pico_time/time.c
aggarg
(Gaurav Aggarwal)
July 13, 2022, 5:43am
3
oguzkagan:
//publish the data
vTaskSuspendAll();
portENTER_CRITICAL();
uart_putc(LORA_UART, LORA_TARGET_ADDRH);
uart_putc(LORA_UART, LORA_TARGET_ADDRL);
uart_putc(LORA_UART, LORA_TARGET_CHANNEL);
uart_write_blocking(LORA_UART, (uint8_t *) &dataPacket, sizeof(MainCompPacket));
portEXIT_CRITICAL();
xTaskResumeAll();
Is it possible that one of these calls never returns and as a result, interrupts are never enabled?
This seems related to pico and I’d recommend to ask on their repo/forum.
oguzkagan
(Oğuz Kağan Yağlıoğlu)
July 13, 2022, 6:43am
4
Thanks for the reply. I changed the code slightly to see if the UART functions return. And it seems like returns so it should not be the problem.
changed part:
printf("before delay\r\n");
timerTriggerStatus = xTaskDelayUntil(&lastWakeTime, pdMS_TO_TICKS(1000 / 5));
printf("after delay\r\n");
printf("\tPUBLISH_WAKE: %s\t%3lu\r\n", timerTriggerStatus ? "ON_TIME" : "LATE",
us_to_ms(absolute_time_diff_us(lastCallTime, get_absolute_time())));
lastCallTime = get_absolute_time();
uart_putc(LORA_UART, LORA_TARGET_ADDRH);
uart_putc(LORA_UART, LORA_TARGET_ADDRL);
uart_putc(LORA_UART, LORA_TARGET_CHANNEL);
uart_write_blocking(LORA_UART, (uint8_t *) &dataPacket, sizeof(MainCompPacket));
printf("exit uart\r\n");
Serial output:
STARTING SCHEDULER
before delay
after delay
PUBLISH_WAKE: ON_TIME 199
exit uart
before delay
//stucks here
But if I turn the code into that it is not hangs anymore.
printf("before delay\r\n");
timerTriggerStatus = xTaskDelayUntil(&lastWakeTime, pdMS_TO_TICKS(1000 / 5));
printf("after delay\r\n");
printf("\tPUBLISH_WAKE: %s\t%3lu\r\n", timerTriggerStatus ? "ON_TIME" : "LATE",
us_to_ms(absolute_time_diff_us(lastCallTime, get_absolute_time())));
lastCallTime = get_absolute_time();
// uart_putc(LORA_UART, LORA_TARGET_ADDRH);
// uart_putc(LORA_UART, LORA_TARGET_ADDRL);
// uart_putc(LORA_UART, LORA_TARGET_CHANNEL);
// uart_write_blocking(LORA_UART, (uint8_t *) &dataPacket, sizeof(MainCompPacket));
printf("exit uart\r\n");
aggarg
(Gaurav Aggarwal)
July 13, 2022, 7:18am
5
Just a guess - Can you try increasing the stack size of the task?
oguzkagan
(Oğuz Kağan Yağlıoğlu)
July 13, 2022, 7:29am
6
I increased the stack size from 256(configMINIMAL_STACK_SIZE) to 2048 but the result is still the same.
oguzkagan
(Oğuz Kağan Yağlıoğlu)
July 13, 2022, 8:28pm
7
I replaced the pico and now its working.
1 Like
aggarg
(Gaurav Aggarwal)
July 13, 2022, 8:30pm
8
Thank you for taking time to report back.
2 Likes