【发布时间】:2022-05-20 06:34:59
【问题描述】:
我正在尝试让多核在我的 pico 上工作,
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"
void core1_main()
{
stdio_init_all();
while (1)
{
uint32_t t = multicore_fifo_pop_blocking();
printf("hellow world %d \n", t);
}
}
int main()
{
multicore_launch_core1(&core1_main);
uint32_t i = 0;
while (1)
{
sleep_ms(250);
multicore_fifo_push_blocking(i++);
}
}
这是我试图开始工作的一项非常基本的任务。我正在尝试更多地了解这种多核魔法。基本上我开始在 core1 上等待一些数据通过。然后我只需将其打印出来并等待下一条数据。
在核心 0 上,我每 250 毫秒将一个数字推入 FIFO 一次。
我在编译中没有收到任何错误,但运行代码不会产生任何输出。
我在这里做错了什么?有什么需要注意的吗?
我已经尝试了很多东西来获得多核,但没有用。
更新这给了我一些输出。 我添加了等待 USB 连接和初始化的时间。现在我从核心 2 收到一些消息。
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/multicore.h"
// const uint led = PICO_DEFAULT_LED_PIN;
void core1_main()
{
printf("hellow world from second core");
printf("hellow world from second core");
printf("hellow world from second core");
}
int main()
{
stdio_init_all();
while (!stdio_usb_connected())
;
while (!stdio_usb_init())
;
multicore_launch_core1(core1_main);
printf("hellow wow \n");
uint32_t i = 0;
while (1)
{
printf("hellow nice %d\n", i++);
sleep_ms(1000);
}
}
这是我得到的输出。注意来自第二个核心的消息只通过一次。我很困惑,为什么?
同时改变stdio_init_all() 的位置会破坏一些东西并且没有更多的输出。
【问题讨论】:
-
如果您删除对
multicore_fifo_pop_blocking()的调用(或在其前面放置printf()语句),您会看到任何输出吗?这将有助于区分“core1_main根本没有运行”与“core1_main正在阻塞并且 fifo 正在按预期工作”。 -
@larsks 我在帖子中添加了更多信息。谢谢
标签: c microcontroller cortex-m raspberry-pi-pico