本帖最后由 xiaolinen 于 2024-6-5 17:27 编辑
一:说明
关于CH32V208的测试,均为自己的使用过程,因个人水平有限,有失误的地方,敬请指导。
本篇主要记录自己的开箱,以及环境安装好后的工具调试步骤。
二:烧录器部分
2.1,烧录器为WCH-LinkE,该烧录器既支持RISC-V内核的MCU烧录,又支持ARM内核的MCU烧录;
模式更改操作如下:
首先,打开MounRiver Studio软件->下载配置->目标模式;
其次,点击查询->选择“WCH-LinkRV”->应用;
备注:烧录器的更多使用方式,请移步:https://www.wch.cn/downloads/WCH-LinkUserManual_PDF.html下载。
2.2,两种模式的指示灯对比,如下(左图为烧录ARM内核MCU指示灯,右图为烧录RISC-V内核MCU指示灯):
2.3,接线方式:
开发板 -> 烧录器
CLK -> SWCLK
DIO -> SWDIO
GND -> GND
VDD -> 3V3
TXD -> RX
RXD -> TX
接线如图所示:
如果已经通过PC的USB口连接了开发板, 就不要连WCHLink VCC, 如果连了WCHLink VCC, 就不要接USB口。
三:程序部分
3.1,功能说明:
在rt-thread下,使一个LED灯连接到PA0引脚,观察引脚输出变化;并在主线程中周期打印。
3.2,主要程序展示:
/********************************** (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_PIN 10 //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
*
* @brief run thread
*
* @return 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
*
* @return RT_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);
3.3,实验现象如下:
3.3.1,周期打印现象,如下:
3.3.2,LED灯运行现象,如下:
39a036c785e35dd890d71e798237f1e4_raw