STM32、FreeRTOS—— SVC 和 PendSV

I went through the xTaskStartSechudler() function, which ends up triggering the SVC instruction.
and i came to know that it used in only in this function.
If i am not wrong , is SVC used to launch the first Task ?
So, in my understanding SVC is used only one time, and subsequent task switching in and out is carried out in the PendSV handler. am i right ?
Why can cant we use pendsv itself instead of SVC ?

Yes you are correct, unless you are using the version that supports the
MPU the SVC instruction is only used once.

Old versions don’t use the SVC, and instead use the PendSV,
and there was a really good reason for changing that I can’t recall the exact details of but it was something to do with having to add extra code into the PendSV instruction so it knew whether it had to save a context or not, and also loosing a bit of stack space.
If you use SVC to start the first task then the SVC

### STM32 FreeRTOS 的移植过程 #### 1. 准备工作 在开始移植之前,需要准备以下资源: - 下载并安装 STM32CubeMX 工具用于初始化项目配置[^1]。 - 获取 FreeRTOS 源码包。可以从官方网站下载最新版本的 FreeRTOS 源码[^2]。 #### 2. 创建基础工程 使用 STM32CubeMX 配置硬件外设时钟树,并生成初始代码框架。确保启用 `SysTick` 定时器作为时间基准。 #### 3. 添加 FreeRTOS 文件 将 FreeRTOS 源文件集成到项目中: - 将 FreeRTOS 核心文件夹中的所有 `.c` 文件复制到项目的源目录下。这些文件通常位于 `\FreeRTOS\Source` 中[^2]。 - 复制特定于 Cortex-M4/M7 架构的端口层实现文件至指定路径。例如,在 ARM CM4F 平台下需拷贝 `port.c` `portmacro.h` 到目标位置[^3]。 #### 4. 修改中断服务程序 针对 RTOS 运行环境调整默认 ISRs (Interrupt Service Routines),具体如下所示: ```c // SVC_Handler, PendSV_Handler 及 SysTick_Handler 是 FreeRTOS 正常运行所必需的关键函数 void SVC_Handler(void) { // 实现系统调用处理逻辑 } void PendSV_Handler(void) { // 提供上下文切换支持 } void SysTick_Handler(void) { // 更新滴答计数器 } ``` 以上三个 ISR 应按照官方文档指导完成定义与重写操作。 #### 5. 初始化调度器 最后一步是在主循环启动前调用 `vTaskStartScheduler()` 来激活任务管理功能: ```c int main(void){ HAL_Init(); SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); ... /* Create tasks here */ vTaskStartScheduler(); while(1); } ``` 通过上述步骤即可成功把 FreeRTOS 移植到基于 STM32 微控制器的应用场景当中去[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值