STM32F103C8T6移植FreeRTOS

建议有一定STM32开发基础

1. STM32库下载

根据自己开发板型号下载地址:STM32相关内容下载地址
SDK直接下载地址:STM32直接下载地址
下载参考博客

2. FreeRTOS下载

FreeROTS下载地址 选用V9.0.0 版本

3. 创建STM32项目

个人创建目录如下,可做参考

├── CMSIS
│   ├── core_cm3.c
│   ├── core_cm3.h
│   ├── startup_stm32f10x_hd.s
│   ├── stm32f10x.h
│   ├── stm32f10x_conf.h
│   ├── stm32f10x_it.c
│   ├── stm32f10x_it.h
│   ├── system_stm32f10x.c
│   └── system_stm32f10x.h
├── FreeRTOS
│   ├── include
│   │   ├── FreeRTOS.h
│   │   ├── StackMacros.h
│   │   ├── croutine.h
│   │   ├── deprecated_definitions.h
│   │   ├── event_groups.h
│   │   ├── list.h
│   │   ├── mpu_prototypes.h
│   │   ├── mpu_wrappers.h
│   │   ├── portable.h
│   │   ├── projdefs.h
│   │   ├── queue.h
│   │   ├── semphr.h
│   │   ├── stdint.readme
│   │   ├── task.h
│   │   └── timers.h
│   ├── port
│   │   ├── MemMang
│   │   │   ├── ReadMe.url
│   │   │   ├── heap_1.c
│   │   │   ├── heap_2.c
│   │   │   ├── heap_3.c
│   │   │   ├── heap_4.c
│   │   │   └── heap_5.c
│   │   └── RVDS
│   │       ├── ARM7_LPC21xx
│   │       │   ├── port.c
│   │       │   ├── portASM.s
│   │       │   ├── portmacro.h
│   │       │   └── portmacro.inc
│   │       ├── ARM_CA9
│   │       │   ├── port.c
│   │       │   ├── portASM.s
│   │       │   ├── portmacro.h
│   │       │   └── portmacro.inc
│   │       ├── ARM_CM0
│   │       │   ├── port.c
│   │       │   └── portmacro.h
│   │       ├── ARM_CM3
│   │       │   ├── port.c
│   │       │   └── portmacro.h
│   │       ├── ARM_CM4F
│   │       │   ├── port.c
│   │       │   └── portmacro.h
│   │       ├── ARM_CM4_MPU
│   │       │   ├── port.c
│   │       │   └── portmacro.h
│   │       └── ARM_CM7
│   │           ├── ReadMe.txt
│   │           └── r0p1
│   │               ├── port.c
│   │               └── portmacro.h
│   └── src
│       ├── croutine.c
│       ├── event_groups.c
│       ├── list.c
│       ├── queue.c
│       ├── readme.txt
│       ├── tasks.c
│       └── timers.c
├── Project
│   ├── BaseRTOS.hex
│   ├── BaseRTOS.uvguix.snsop
│   ├── BaseRTOS.uvoptx
│   ├── BaseRTOS.uvprojx
│   ├── DebugConfig
│   │   ├── BaseRTOS_STM32F103C8_1.0.0.dbgconf
│   │   └── Target_1_STM32F103C8_1.0.0.dbgconf
│   ├── EventRecorderStub.scvd
│   ├── Listings
│   └── Objects
├── STM32F10x_FWLib
│   ├── inc
│   │   ├── misc.h
│   │   ├── stm32f10x_adc.h
│   │   ├── stm32f10x_bkp.h
│   │   ├── stm32f10x_can.h
│   │   ├── stm32f10x_cec.h
│   │   ├── stm32f10x_crc.h
│   │   ├── stm32f10x_dac.h
│   │   ├── stm32f10x_dbgmcu.h
│   │   ├── stm32f10x_dma.h
│   │   ├── stm32f10x_exti.h
│   │   ├── stm32f10x_flash.h
│   │   ├── stm32f10x_fsmc.h
│   │   ├── stm32f10x_gpio.h
│   │   ├── stm32f10x_i2c.h
│   │   ├── stm32f10x_iwdg.h
│   │   ├── stm32f10x_pwr.h
│   │   ├── stm32f10x_rcc.h
│   │   ├── stm32f10x_rtc.h
│   │   ├── stm32f10x_sdio.h
│   │   ├── stm32f10x_spi.h
│   │   ├── stm32f10x_tim.h
│   │   ├── stm32f10x_usart.h
│   │   └── stm32f10x_wwdg.h
│   └── src
│       ├── misc.c
│       ├── stm32f10x_adc.c
│       ├── stm32f10x_bkp.c
│       ├── stm32f10x_can.c
│       ├── stm32f10x_cec.c
│       ├── stm32f10x_crc.c
│       ├── stm32f10x_dac.c
│       ├── stm32f10x_dbgmcu.c
│       ├── stm32f10x_dma.c
│       ├── stm32f10x_exti.c
│       ├── stm32f10x_flash.c
│       ├── stm32f10x_fsmc.c
│       ├── stm32f10x_gpio.c
│       ├── stm32f10x_i2c.c
│       ├── stm32f10x_iwdg.c
│       ├── stm32f10x_pwr.c
│       ├── stm32f10x_rcc.c
│       ├── stm32f10x_rtc.c
│       ├── stm32f10x_sdio.c
│       ├── stm32f10x_spi.c
│       ├── stm32f10x_tim.c
│       ├── stm32f10x_usart.c
│       └── stm32f10x_wwdg.c
├── SYSTEM
│   ├── delay
│   │   ├── delay.c
│   │   └── delay.h
│   └── sys
│       ├── sys.c
│       └── sys.h
├── User
│   ├── FreeRTOSConfig.h
│   ├── LED.c
│   ├── LED.h
│   └── main.c
├── Userlib
│   ├── IIC.c
│   ├── IIC.h
│   ├── dac.c
│   ├── dac.h
│   ├── debug.c
│   ├── debug.h
│   ├── mygpio.c
│   ├── mygpio.h
│   ├── myiic.c
│   ├── myiic.h
│   ├── softdelay.c
│   ├── softdelay.h
│   ├── timer.c
│   └── timer.h
└── keilkilll.bat

keil目录在这里插入图片描述链接头文件
在这里插入图片描述

4. 主程序代码

#include <stdio.h>

#include "delay.h"
#include "softdelay.h"
#include "LED.h"

#include "FreeRTOSConfig.h"
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

static int num  = 0;

void bsp_init(void)
{
    int loop = 0;
    
    delay_init();
        
    LED_Init();
    
    for(;loop * 5 < 1000; loop++)
    {
        LED_Show_Num(8888);
    }
}

static TaskHandle_t LED_Task_Handle = NULL;/* LED handel */
static void vLCD_Task(void* param)
{
    while(1)
    {
        LED_Show_Num(num);
        vTaskDelay(1);
    }
}

static TaskHandle_t Num_Task_Handle = NULL;/* Num handel */
static void vNum_Task(void* param)
{
    while(1)
    {
        vTaskDelay(1000);
        num++;
        if(num >= 9999) num = 0;
    }
}

int main()
{
    bsp_init();
    
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
    
    taskENTER_CRITICAL();          
    
    /* Start the tasks defined within this file/specific to this demo. */
    xTaskCreate(     (TaskFunction_t )vNum_Task,     /*task function*/
                                (const char*    )"Check", /*task name*/
                                (uint16_t       )128, /*configMINIMAL_STACK_SIZE stack size*/
                                (void*          )NULL,   /*task function param*/
                                (UBaseType_t    )1,  /*task priority*/
                                (TaskHandle_t*    )&LED_Task_Handle);/*task ptr*/
                                
    xTaskCreate(     (TaskFunction_t )vLCD_Task, 
                                (const char*    )"LCD",         
                                (uint16_t       )128,     
                                (void*          )NULL, 
                                (UBaseType_t    )2,                 
                                (TaskHandle_t*    )&Num_Task_Handle);
    
    taskEXIT_CRITICAL();
                          
    /* Start the scheduler. */
    vTaskStartScheduler();
                              
    return 0;
}

5. 相关配置[重点重点重点]

• 修改堆栈大小
在这里插入图片描述
• 修改中断函数名
去掉stm32f10x_it.c终端函数
在这里插入图片描述增加FreeRTOS中断
在这里插入图片描述

特别解释
FreeRTOS的5种内存管理方法

文件优点缺点
heap_1.c分配简单,时间确定只分配、不回收
heap_2.c动态分配、最佳匹配碎片、时间不定
heap_3.c调用标准库函数速度慢、时间不定
heap_4.c相邻空闲内存可合并可解决碎片问题、时间不定
heap_5.c在heap_4基础上支持分隔的内存块可解决碎片问题、时间不定

感谢:https://blog.csdn.net/thisway_diy/article/details/121420297

  • 8
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值