qinyunti 发表于 2022-12-3 15:48

【微雪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 >&nbsp;</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 >&nbsp;</p>

<p >cd pico-setup/</p>

<p >./pico_setup.sh</p>

<p >&nbsp;</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 >&nbsp;</p>

<p >输入密码自动安装相关工具</p>

<p >&nbsp;</p>

<p >相关环境安装在当前目录下pico</p>

<p >&nbsp;</p>

<p >lhj@lhj:~/pico-setup$ ls pico</p>

<p >pico-examples &nbsp;pico-extras &nbsp;pico-playground &nbsp;pico-sdk</p>

<p >其中</p>

<p >pico-examples是例程</p>

<p >pico-sdk是sdk包</p>

<p >&nbsp;</p>

<p >sdk如果有子仓库没有同步可以</p>

<p >cd pico-sdk</p>

<p >git submodule update --init</p>

<p >&nbsp;</p>

<h1 ><b>编译example</b></h1>

<p >&nbsp;</p>

<p >cd pico-examples/build</p>

<p >export PICO_SDK_PATH=&quot;/home/lhj/pico-setup/pico/pico-sdk&quot; &amp;&amp; cmake ..</p>

<p >make hello_usb</p>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p >编译的程序位于hello_world/usb/下</p>

<p >lhj@lhj:~/pico-setup/pico/pico-examples/build$ ls hello_world/usb/</p>

<p >CMakeFiles &nbsp;cmake_install.cmake &nbsp;hello_usb.dis &nbsp;hello_usb.elf.map &nbsp;hello_usb.uf2</p>

<p >Makefile &nbsp;&nbsp;&nbsp;hello_usb.bin &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hello_usb.elf &nbsp;hello_usb.hex</p>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p >将hello_usb.uf2复制到windows下</p>

<p >cp hello_world/usb/hello_usb.uf2 /mnt/d</p>

<p >下载到开发板即可</p>

<p >接上USB线,可以看到串口打印信息如下</p>

<p >&nbsp;</p>

<p > &nbsp;</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 >&nbsp;</p>

<p >vscode打开\RP2040-LCD-1.28\c文件夹</p>

<p >在wsl中打开该文件夹</p>

<p >新建终端</p>

<p >cd build</p>

<p >export PICO_SDK_PATH=&quot;/home/lhj/pico-setup/pico/pico-sdk&quot; &amp;&amp; cmake ..</p>

<p >make</p>

<p >生成的程序位于当前目录下main.uf2</p>

<p >将其复制到windows下,下载到开发板</p>

<p > &nbsp;</p>

<p >&nbsp;</p>

<p > &nbsp;</p>

<h1 ><b>创建工程</b></h1>

<p >参考https://github.com/raspberrypi/pico-sdk</p>

<p >&nbsp;</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 >&nbsp;</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 >&nbsp;</p>

<p >project(my_project)</p>

<p >&nbsp;</p>

<p ># initialize the Raspberry Pi Pico SDK</p>

<p >pico_sdk_init()</p>

<p >&nbsp;</p>

<p ># rest of your project</p>
</div>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p >添加源码</p>

<p >hello_usb.c</p>

<div class="parsedown-markdown">
<p>#include &lt;stdio.h&gt;</p>

<p >#include &quot;pico/stdlib.h&quot;</p>

<p >&nbsp;</p>

<p >int main() {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;stdio_init_all();</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;while (true) {</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Hello, world!\n&quot;);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep_ms(1000);</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;}</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;return 0;</p>

<p >}</p>
</div>

<p >&nbsp;</p>

<p >添加如下内容到CMakeLists.txt</p>

<div class="parsedown-markdown">
<p>if (TARGET tinyusb_device)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;add_executable(hello_usb</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hello_usb.c</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;# pull in common dependencies</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;target_link_libraries(hello_usb pico_stdlib)</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;# enable usb output, disable uart output</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;pico_enable_stdio_usb(hello_usb 1)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;pico_enable_stdio_uart(hello_usb 0)</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;# create map/bin/hex/uf2 file etc.</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;pico_add_extra_outputs(hello_usb)</p>

<p >&nbsp;</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;# add url via pico_set_program_url</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;# example_auto_set_url(hello_usb)</p>

<p >elseif(PICO_ON_DEVICE)</p>

<p >&nbsp;&nbsp;&nbsp;&nbsp;message(WARNING &quot;not building hello_usb because TinyUSB submodule is not initialized in the SDK&quot;)</p>

<p >endif()</p>
</div>

<p >&nbsp;</p>

<p >&nbsp;</p>

<p >编译</p>

<p >mkdir build</p>

<p >cd build</p>

<p >export PICO_SDK_PATH=&quot;/home/lhj/pico-setup/pico/pico-sdk&quot; &amp;&amp; cmake ..</p>

<p >make</p>

<p >&nbsp;</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 >&nbsp;</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>

秦天qintian0303 发表于 2022-12-4 08:11

<p>有时间得体验一下</p>
页: [1]
查看完整版本: 【微雪RP2040双核开发板】WSL+Ubuntu C开发环境体验