簡體   English   中英

RPi Pico 在 IRQ 中斷調用時凍結

[英]RPi Pico freezes on IRQ Interrupt call

我目前正在開發一個小型庫,它可以簡化 433MHz RF 模塊的使用。 我現在面臨的問題是,當我試圖在 UART0_RX 引腳 (GPIO1) 上創建 IRQ 中斷時,Pico 將調用回調 function,執行第一條指令然后凍結。

我在網上找不到任何相關信息。 這是我的代碼片段:

#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/irq.h"
#include "hardware/uart.h"

void onDataReceived()
{
    // Let the LED blink on GPIO16
    gpio_put(16, 1);

    /*
    *   Annnnnnd.... freeze, the Pico won't execute further
    *   instructions. It stays frozen until reset.
    */

    sleep_ms(500);
    gpio_put(16, 0);
    sleep_ms(500);
}

int main()
{
    // Normal initialization
    stdio_init_all();
    gpio_init(PICO_DEFAULT_LED_PIN);
    gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
    gpio_init(16);
    gpio_set_dir(16, GPIO_OUT);

    // Setup UART communication
    uart_init(uart0, 115200);
    gpio_set_function(1, GPIO_FUNC_UART);
    gpio_set_function(0, GPIO_FUNC_UART);

    // Setup IRQ handler
    irq_set_exclusive_handler(UART0_IRQ, onDataReceived);
    irq_set_enabled(UART0_IRQ, true);

    // Only call interrupt when RX data arrives
    uart_set_irq_enables(uart0, true, false);

    while (1)
    {
        // Default Pico LED blinking
        gpio_put(PICO_DEFAULT_LED_PIN, 1);
        sleep_ms(200);
        gpio_put(PICO_DEFAULT_LED_PIN, 0);
        sleep_ms(200);
    }

    return 0;
}

我已經嘗試過此代碼的不同變體、不同的參數等。我已經設置了一個 GPIO Pin IRQ,它也會凍結。

不應在中斷處理程序中使用睡眠功能

https://raspberrypi.github.io/pico-sdk-doxygen/group__sleep.html

刪除 sleep_ms(500); 從 onDataReceived()

您可以改用busy_wait_us()

如果您使用的是仿真工具,即使您讀取了整個 rx fifo,它也不會清除標志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM