全能小网关|CH32V208--第一篇:搭建环境,初步入手
<div class='showpostmsg'> 本帖最后由 xiaolinen 于 2024-6-5 17:27 编辑<p><span style="font-size:22px;"><strong>一:说明</strong></span></p>
<p><span style="font-size:20px;"> 关于CH32V208的测试,均为自己的使用过程,因个人水平有限,有失误的地方,敬请指导。</span></p>
<p><span style="font-size:20px;"> 本篇主要记录自己的开箱,以及环境安装好后的工具调试步骤。</span></p>
<p><strong><span style="font-size:22px;">二:烧录器部分</span></strong></p>
<p><span style="font-size:20px;"> 2.1,烧录器为WCH-LinkE,该烧录器既支持RISC-V内核的MCU烧录,又支持ARM内核的MCU烧录;</span></p>
<p><span style="font-size:20px;"> 模式更改操作如下:</span></p>
<p><span style="font-size:20px;"> 首先,打开MounRiver Studio软件->下载配置->目标模式;</span></p>
<p><span style="font-size:20px;"> 其次,点击查询->选择“WCH-LinkRV”->应用;</span></p>
<div style="text-align: center;"></div>
<p> </p>
<p><span style="font-size:20px;"> <span style="color:#e74c3c;">备注:烧录器的更多使用方式,请移步:</span><a href="https://www.wch.cn/downloads/WCH-LinkUserManual_PDF.html" target="_blank"><span style="color:#e74c3c;">https://www.wch.cn/downloads/WCH-LinkUserManual_PDF.html</span></a><span style="color:#e74c3c;">下载。</span></span></p>
<p><span style="font-size:20px;"> 2.2,两种模式的指示灯对比,如下(左图为烧录ARM内核MCU指示灯,右图为烧录RISC-V内核MCU指示灯):</span></p>
<div style="text-align: center;"></div>
<div><span style="font-size:20px;"> 2.3,接线方式:</span></div>
<div><span style="font-size:20px;"> 开发板 -> 烧录器</span>
<p><span style="font-size:20px;"> CLK -> SWCLK</span></p>
<p><span style="font-size:20px;"> DIO -> SWDIO</span></p>
<p><span style="font-size:20px;"> GND -> GND</span></p>
<p><span style="font-size:20px;"> VDD -> 3V3</span></p>
<p><span style="font-size:20px;"> TXD -> RX </span></p>
<p><span style="font-size:20px;"> RXD -> TX </span></p>
<p> </p>
<p><span style="font-size:20px;"> 接线如图所示:</span></p>
<div style="text-align: center;"></div>
<p><span style="font-size:20px;"><span style="color:#e74c3c;"> 如果已经通过PC的USB口连接了开发板, 就不要连WCHLink VCC, 如果连了WCHLink VCC, 就不要接USB口。</span></span></p>
<p><strong><span style="font-size:22px;">三:程序部分</span></strong></p>
<p><span style="font-size:20px;"> 3.1,功能说明:</span></p>
<p><span style="font-size:20px;"> 在rt-thread下,使一个LED灯连接到PA0引脚,观察引脚输出变化;并在主线程中周期打印。</span></p>
<p><span style="font-size:20px;"> 3.2,主要程序展示:</span></p>
</div>
<pre>
<code class="language-objectivec">/********************************** (C) COPYRIGHT *******************************
* File Name : main.c
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : Main program body.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "ch32v20x.h"
#include <rtthread.h>
#include <rthw.h>
#include "drivers/pin.h"
/* LED0 */
#define LED_PIN10 //PA0
/* main is just one of the threads, in addition to tshell,idle
* main is just an LED blinking, the main thread is registered in rtthread_startup,
* tshell uses the serial port to receive interrupts, and the interrupt stack and thread stack are
* used separately.Note that when entering an interrupt, the 16caller register needs to be pushed
* into the thread stack
*/
int main(void)
{
SystemCoreClockUpdate();
while(1)
{
rt_kprintf("Welcome to eeworld!\r\n");
rt_thread_mdelay(1000);
}
}
/*
* @fn pro_led_blink_thread_entry
*
* <a href="home.php?mod=space&uid=159083" target="_blank">@brief </a> run thread
*
* <a href="home.php?mod=space&uid=784970" target="_blank">@return </a>none
*/
void pro_led_blink_thread_entry(void *param)
{
rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
while(1){
rt_pin_write(LED_PIN, PIN_LOW);
rt_thread_mdelay(500);
rt_pin_write(LED_PIN, PIN_HIGH);
rt_thread_mdelay(500);
}
}
/*
* @fn pro_led_blink_func
*
* @brief create thread
*
* @returnRT_EOK/RT_ERROR
*/
int pro_led_blink_func(void)
{
int ret = RT_ERROR;
static rt_thread_t blink_thread = RT_NULL;
// 动态创建线程
blink_thread = rt_thread_create("blink_thread",pro_led_blink_thread_entry,RT_NULL,1024,8,20);
if(blink_thread != RT_NULL){
rt_thread_startup(blink_thread);
ret = RT_EOK;
}else{
rt_kprintf("create blink_thread failed!\r\n");
ret = RT_ERROR;
}
return ret;
}
INIT_APP_EXPORT(pro_led_blink_func);</code></pre>
<p><span style="font-size:20px;"> 3.3,实验现象如下:</span></p>
<p><span style="font-size:20px;"> 3.3.1,周期打印现象,如下:</span></p>
<div style="text-align: center;"></div>
<p><span style="font-size:20px;"> 3.3.2,LED灯运行现象,如下:</span></p>
<p>e7fe0501698ae20ad4a2b3cd6c44f493</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>
页:
[1]