关于CH32V103C8T6 跑FreeRTOS遇到的坑

1.开启中断就死机(总是进HardFault_Handler)

        RISC-V 内核进中断需要保存 caller saved(顾名思义,调用者需要保存)的寄存
器。 当不开启硬件浮点时,编译器会把 16 个寄存器在中断函数开始时存入堆栈,中断返回
前恢复,如下图 2 和图 3 所示。 我们内核支持硬件压栈,硬件保存和恢复的也正是这 16 个
寄存器。使用硬件压栈时需要使能硬件功能,即硬件压栈使能(不同芯片配置位置不同,详
见手册中断章节),同时也需要通知编译器不自动生成图 2 和图 3 中的软件出入栈的代码,
即在 MRS 声明中断函数时由__attribute__((interrupt("WCH-Interrupt-fast")))方式定义编译器
不自动添加软件出入栈代码,由__attribute__((interrupt()))方式定义编译器添加软件出入栈的
代码

        当开启硬件压栈并且编译器中声明使用硬件压栈后,中断函数汇编代码如下图 4 所示。
可见进入中断后直接执行的中断代码,形如图 2 和图 3 中的 16 个寄存器的入栈和出栈由硬
件在中断开始和结束时自动完成。 同时也可以看出整个中断函数可以减少 34 条指令。

      由此也可知道一般中断切换上下文时不开启硬件压栈的原因:开启后中断返回
时硬件会复写 16 个 caller saved 寄存器。

        当开启硬件浮点时,除了上述 16 个整形还会增加 20 个浮点寄存器,如下图 5 所示。 由
此也可以看出,硬件压栈只对整形的寄存器生效。

2.串口空闲接收中断时,偶尔会丢失第一个字节数据

        

3.在中断使用portYIELD_FROM_ISR()任务切换时,会导致获取信号量的线程挂掉;其他线程能正常运行

 

### CH32V103C8T6 Keil Project Setup and Configuration Tutorial For configuring a Keil project specifically for the CH32V103C8T6 microcontroller, several key steps must be followed to ensure proper integration of hardware-specific settings into an integrated development environment (IDE). The process involves setting up the correct compiler options, linking necessary libraries, and ensuring that all peripheral configurations are accurately defined. #### Setting Up the Hardware Profile To begin with, it is essential to define the target device within the IDE. In Keil uVision, this can be done by selecting `Project` -> `Options for Target 'Target 1'` -> `Device`, then choosing the appropriate part number from the list provided or manually entering the specific model name if not listed directly[^1]. #### Configuring Compiler Settings Compiler settings play a crucial role in generating optimized code tailored for the chosen architecture. Adjustments should include enabling support for C99 standards as well as any other language extensions required by your application logic. Additionally, optimization levels may need tweaking based on performance versus size trade-offs desired during compilation. #### Linking Necessary Libraries Since official documentation might lack detailed descriptions about available library functions, exploring existing examples becomes vital. These samples often come bundled alongside SDKs distributed by manufacturers like WeAct Studio which provides comprehensive sets covering various aspects such as GPIO control, UART communication protocols among others. Incorporating these pre-built modules allows developers to focus more on implementing core functionalities rather than reinventing basic operations repeatedly. #### Peripheral Initialization Code Generation One effective approach towards familiarizing oneself with internal peripherals lies in leveraging automatic initialization tools offered through graphical interfaces embedded inside modern IDE environments. By specifying parameters interactively via dialog boxes presented when creating new projects targeting ARM Cortex-M series MCUs including those compatible with RISC-V instruction set architectures used here; users gain insights regarding register mappings along with bit fields associated therein without delving too deeply into low-level details immediately after starting out. ```c // Example: Basic System Clock Configuration Function void SystemClock_Config(void){ // Configure system clock according to user requirements. } ``` --related questions-- 1. What resources exist online where one could find additional tutorials beyond what has been officially published? 2. Are there alternative methods besides using Keil MDK for developing applications intended for use on CH32V103 devices? 3. How does understanding assembly language benefit someone working extensively at lower abstraction layers while programming microcontrollers similar to this family? 4. Can you recommend some best practices concerning version control systems usage throughout software development lifecycle phases involving embedded firmware engineering tasks?
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值