Date:2016.06.01
步驟
- 新建一個(gè)MDK5工程
- stm32f10x相關(guān)文件導(dǎo)入
- 工程設(shè)置
- 裸奔點(diǎn)燈
- freeRTOS系統(tǒng)文件導(dǎo)入
- 點(diǎn)個(gè)高級(jí)燈再試試
新建一個(gè)MDK5工程
-
新建工程目錄和文件目錄
stm32f10x相關(guān)文件導(dǎo)入
庫(kù)文件導(dǎo)入
將..\STM32F10x_StdPeriph_Lib_V3.5.\Libraries\STM32F10x_StdPeriph_Driver
整個(gè)文件夾復(fù)制到\lib下內(nèi)核和啟動(dòng)代碼導(dǎo)入
2.0 將以下所有文件復(fù)制到\core
2.1 core_cm3.c和core_cm3.h位于:
..\STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\CoreSupport
2.2 startup_stm32f10x_hd.s位于:
..\STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm
2.3 stm32f10x.h墙贱,system_stm32f10x.c捐顷,system_stm32f10x.h位于:
..\STM32F10x_StdPeriph_Lib_V3.5.0\Libraries\CMSIS\CM3 \DeviceSupport\ST\STM32F10x
2.4 stm32f10x_conf.h猖败,stm32f10x_it.c立轧,stm32f10x_it.h位于:
..\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template
工程設(shè)置
-
將文件導(dǎo)入工程
-
Obj路徑設(shè)置并勾選生成hex文件
-
頭文件路徑設(shè)置
-
全局宏定義變量設(shè)置
-
JLink設(shè)置
裸奔點(diǎn)燈
- 在\init下添加一個(gè)main.c
#include "stm32f10x.h"
#include "stm32f10x_it.h"
void Delay(u32 count) {
u32 i=0;
for(;i<count;i++);
}
void LED_config() {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA
| RCC_APB2Periph_GPIOD,
ENABLE
);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOA, &GPIO_InitStructure );
GPIO_SetBits( GPIOA, GPIO_Pin_8 );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init( GPIOD, &GPIO_InitStructure);
GPIO_SetBits( GPIOD, GPIO_Pin_2 );
}
int main(void) {
LED_config();
while(1) {
GPIO_ResetBits(GPIOA,GPIO_Pin_8);
GPIO_SetBits(GPIOD,GPIO_Pin_2);
Delay(3000000);
GPIO_SetBits(GPIOA,GPIO_Pin_8);
GPIO_ResetBits(GPIOD,GPIO_Pin_2);
Delay(3000000);
}
}
freeRTOS系統(tǒng)文件導(dǎo)入
與FreeRTOS內(nèi)核有關(guān)的文件:list.c, queue.c, tasks.c
位于..\FreeRTOSv9.0.0\FreeRTOS\Source
復(fù)制到lib\freeRTOS\src與內(nèi)存分配有關(guān)的文件: heap_1.c,heap_2.c,heap_3.c玷氏,heap_4.c,heap_5.c腋舌。五選一盏触,STM32選擇heap_2.c
位于..\FreeRTOSv9.0.0\FreeRTOS\Source\portable\MemMang
復(fù)制到lib\freeRTOS\src移植平臺(tái)相關(guān)文件port.c
位于..\FreeRTOSv9.0.0\FreeRTOS\Source\portable\RVDS\ARM_CM3
復(fù)制到lib\freeRTOS\src配置文件portmacro.h,F(xiàn)reeRTOSConfig.h
分別位于
..\FreeRTOSv9.0.0\FreeRTOS\Source\portable\RVDS\ARM_CM3
..\FreeRTOSv9.0.0\FreeRTOS\Demo\CORTEX_STM32F103_Keil
復(fù)制到lib\freeRTOS\inc通用代碼文件
將..\FreeRTOSv9.0.0\FreeRTOS\Source\include下的所有文件
復(fù)制到lib\freeRTOS\inc-
將freeRTOS系統(tǒng)文件導(dǎo)入工程結(jié)構(gòu)
-
更改啟動(dòng)文件startup_stm32f10x_hd.s
. 更改1
具體代碼:
__heap_limit
PRESERVE8
THUMB
IMPORT xPortPendSVHandler ; insert for freeRTOS
IMPORT xPortSysTickHandler ; insert for freeRTOS
IMPORT vPortSVCHandler ; insert for freeRTOS
. 更改2
具體代碼:
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
; DCD SVC_Handler ; SVCall Handler
DCD vPortSVCHandler ; change for freeRTOS
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
; DCD PendSV_Handler ; PendSV Handler
; DCD SysTick_Handler ; SysTick Handler
DCD xPortPendSVHandler ; change for freeRTOS
DCD xPortSysTickHandler ; change for freeRTOS
點(diǎn)個(gè)高級(jí)燈再試試
. 更改main.c中的內(nèi)容為:
#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "list.h"
#include "portable.h"
#include "FreeRTOSConfig.h"
void LED_config() {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA
| RCC_APB2Periph_GPIOD,
ENABLE
);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOA, &GPIO_InitStructure );
GPIO_SetBits( GPIOA, GPIO_Pin_8 );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init( GPIOD, &GPIO_InitStructure);
GPIO_SetBits( GPIOD, GPIO_Pin_2 );
}
void vLED_1_Task( void *pvParameters ) {
while( 1 ) {
GPIO_ResetBits( GPIOA, GPIO_Pin_8 );
vTaskDelay( 1000 / portTICK_RATE_MS );
GPIO_SetBits( GPIOA, GPIO_Pin_8);
vTaskDelay( 2000 / portTICK_RATE_MS );
}
}
void vLED_2_Task( void *pvParameters ) {
while( 1 ) {
GPIO_SetBits( GPIOD, GPIO_Pin_2);
vTaskDelay( 1000 / portTICK_RATE_MS );
GPIO_ResetBits( GPIOD, GPIO_Pin_2);
vTaskDelay( 1000 / portTICK_RATE_MS );
}
}
int main(void) {
LED_config();
xTaskCreate( vLED_1_Task, "LED1",configMINIMAL_STACK_SIZE,NULL,tskIDLE_PRIORITY+1 ,NULL);
xTaskCreate( vLED_2_Task, "LED2",configMINIMAL_STACK_SIZE,NULL,tskIDLE_PRIORITY+2 ,NULL);
vTaskStartScheduler();
return 0;
}
. 注意freeRTOSConfig.h中的配置
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 72000000 )
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 17 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1