[CLOSED] Raspberry Pi Pico hangs after calling uart_write_blocking()

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
image
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.

file location: pico-sdk/src/common/pico_time/time.c

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.

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");

Just a guess - Can you try increasing the stack size of the task?

I increased the stack size from 256(configMINIMAL_STACK_SIZE) to 2048 but the result is still the same.

I replaced the pico and now its working.

1 Like

Thank you for taking time to report back.

2 Likes