【微雪RP2040双核开发板】WSL+Ubuntu C开发环境体验
<div class='showpostmsg'><h1><b>准备</b></h1><p >基于以下环境</p>
<p >Ubuntu 20.04.4 LTS</p>
<p >WSL2</p>
<p >VSCODE</p>
<p >上述环境的安装网上搜索即可,不再赘述。</p>
<p > </p>
<h1 ><b>安装C/C++编译环境</b></h1>
<p >下载脚本</p>
<p >git clone <a href="https://github.com/raspberrypi/pico-setup.git"><u>https://github.com/raspberrypi/pico-setup.git</u></a></p>
<p > </p>
<p >cd pico-setup/</p>
<p >./pico_setup.sh</p>
<p > </p>
<p >如下提示</p>
<p >lhj@lhj:~/pico-setup$ ./pico_setup.sh</p>
<p >Not running on a Raspberry Pi. Use at your own risk!</p>
<p >Installing Dependencies</p>
<p > password for lhj:</p>
<p > </p>
<p >输入密码自动安装相关工具</p>
<p > </p>
<p >相关环境安装在当前目录下pico</p>
<p > </p>
<p >lhj@lhj:~/pico-setup$ ls pico</p>
<p >pico-examples pico-extras pico-playground pico-sdk</p>
<p >其中</p>
<p >pico-examples是例程</p>
<p >pico-sdk是sdk包</p>
<p > </p>
<p >sdk如果有子仓库没有同步可以</p>
<p >cd pico-sdk</p>
<p >git submodule update --init</p>
<p > </p>
<h1 ><b>编译example</b></h1>
<p > </p>
<p >cd pico-examples/build</p>
<p >export PICO_SDK_PATH="/home/lhj/pico-setup/pico/pico-sdk" && cmake ..</p>
<p >make hello_usb</p>
<p > </p>
<p > </p>
<p >编译的程序位于hello_world/usb/下</p>
<p >lhj@lhj:~/pico-setup/pico/pico-examples/build$ ls hello_world/usb/</p>
<p >CMakeFiles cmake_install.cmake hello_usb.dis hello_usb.elf.map hello_usb.uf2</p>
<p >Makefile hello_usb.bin hello_usb.elf hello_usb.hex</p>
<p > </p>
<p > </p>
<p >将hello_usb.uf2复制到windows下</p>
<p >cp hello_world/usb/hello_usb.uf2 /mnt/d</p>
<p >下载到开发板即可</p>
<p >接上USB线,可以看到串口打印信息如下</p>
<p > </p>
<p > </p>
<h1 ><b>编译Demo</b></h1>
<p >下载示例程序</p>
<p ><a href="https://www.waveshare.net/w/upload/9/9d/RP2040-LCD-1.28.zip"><u>https://www.waveshare.net/w/upload/9/9d/RP2040-LCD-1.28.zip</u></a></p>
<p > </p>
<p >vscode打开\RP2040-LCD-1.28\c文件夹</p>
<p >在wsl中打开该文件夹</p>
<p >新建终端</p>
<p >cd build</p>
<p >export PICO_SDK_PATH="/home/lhj/pico-setup/pico/pico-sdk" && cmake ..</p>
<p >make</p>
<p >生成的程序位于当前目录下main.uf2</p>
<p >将其复制到windows下,下载到开发板</p>
<p > </p>
<p > </p>
<p > </p>
<h1 ><b>创建工程</b></h1>
<p >参考https://github.com/raspberrypi/pico-sdk</p>
<p > </p>
<p >在指定工作目录创建工程目录</p>
<p >mkdir test</p>
<p >cd teset</p>
<p >复制pico_sdk_import.cmake到工程目录</p>
<p >cp /home/lhj/pico-setup/pico/pico-sdk/external/pico_sdk_import.cmake .</p>
<p >设置环境变量PICO_SDK_PATH为SDK路径/home/lhj/pico-setup/pico/pico-sdk/,也可以在编译时在export指定或者-DPICO_SDK_PATH=指定。</p>
<p >新建文件CMakeLists.txt内容如下</p>
<div class="parsedown-markdown">
<p>cmake_minimum_required(VERSION 3.13)</p>
<p > </p>
<p ># initialize the SDK based on PICO_SDK_PATH</p>
<p ># note: this must happen before project()</p>
<p >include(pico_sdk_import.cmake)</p>
<p > </p>
<p >project(my_project)</p>
<p > </p>
<p ># initialize the Raspberry Pi Pico SDK</p>
<p >pico_sdk_init()</p>
<p > </p>
<p ># rest of your project</p>
</div>
<p > </p>
<p > </p>
<p >添加源码</p>
<p >hello_usb.c</p>
<div class="parsedown-markdown">
<p>#include <stdio.h></p>
<p >#include "pico/stdlib.h"</p>
<p > </p>
<p >int main() {</p>
<p > stdio_init_all();</p>
<p > while (true) {</p>
<p > printf("Hello, world!\n");</p>
<p > sleep_ms(1000);</p>
<p > }</p>
<p > return 0;</p>
<p >}</p>
</div>
<p > </p>
<p >添加如下内容到CMakeLists.txt</p>
<div class="parsedown-markdown">
<p>if (TARGET tinyusb_device)</p>
<p > add_executable(hello_usb</p>
<p > hello_usb.c</p>
<p > )</p>
<p > </p>
<p > # pull in common dependencies</p>
<p > target_link_libraries(hello_usb pico_stdlib)</p>
<p > </p>
<p > # enable usb output, disable uart output</p>
<p > pico_enable_stdio_usb(hello_usb 1)</p>
<p > pico_enable_stdio_uart(hello_usb 0)</p>
<p > </p>
<p > # create map/bin/hex/uf2 file etc.</p>
<p > pico_add_extra_outputs(hello_usb)</p>
<p > </p>
<p > # add url via pico_set_program_url</p>
<p > # example_auto_set_url(hello_usb)</p>
<p >elseif(PICO_ON_DEVICE)</p>
<p > message(WARNING "not building hello_usb because TinyUSB submodule is not initialized in the SDK")</p>
<p >endif()</p>
</div>
<p > </p>
<p > </p>
<p >编译</p>
<p >mkdir build</p>
<p >cd build</p>
<p >export PICO_SDK_PATH="/home/lhj/pico-setup/pico/pico-sdk" && cmake ..</p>
<p >make</p>
<p > </p>
<p >生成的程序位于当前路径下</p>
<p >hello_usb.uf2</p>
<p >下载到开发板即可</p>
<h1 ><b>总结</b></h1>
<p >开发环境推荐使用WSL+Ubuntu,避免了安装虚拟机的繁琐,也避免了纯Windows下安装开发环境的麻烦。WSL的Ubuntu就相当于Windows下的一个应用程序,下载脚本一键就可以安装开发环境,而其他操作都是熟悉的在windows下。</p>
<h1 ><b>参考</b></h1>
<p ><a href="https://pico.org.cn/"><u>https://pico.org.cn/</u></a></p>
<p ><a href="https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf"><u>https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf</u></a></p>
<p ><a href="https://www.waveshare.net/w/upload/5/5f/Pico_c_sdk.pdf"><u>https://www.waveshare.net/w/upload/5/5f/Pico_c_sdk.pdf</u></a></p>
<p ><a href="https://github.com/raspberrypi/pico-examples/"><u>https://github.com/raspberrypi/pico-examples/</u></a></p>
<p >https://github.com/raspberrypi/pico-sdk</p>
<p > </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>有时间得体验一下</p>
页:
[1]