第一讲、移植准备
交流群:1092151263
1.1 threadx源码包
- 1、github:https://github.com/azure-rtos/threadx/releases/tag/v6.1.8_rel
- 2、百度网盘:【预留位】
1.2 资料包
- 1、官网:https://rtos.com/solutions/threadx/real-time-operating-system/
- 2、API&User Guide:https://rtos.com/solutions/threadx/api/
第二件、基础空模板搭建
2.1 开启cubemx
2.1.1 芯片选择
STM32F4707VE
2.1.2 RCC
外部高速晶振:Crystal/Ceramic Resonator
2.1.3 SYS
- 1、调试:SW模式
- 2、时基:改为定时器1。(threadx需要用systick作为时基,否则会产生冲突)
2.1.4 串口:USART1
- 1、模式:全双工,Asynchronous
- 2、其余参数:默认即可,波特率是115200
- 3、开启中断:中断优先级设置为6。因为用freertos,习惯了设置成6,没什么特别意思。
2.1.5 NVIC
- 1、代码生成:取消掉pendsv、systick。(这两个中断要被threadx使用,如果不勾选会产生重定义)
2.1.6 LED
- 1、选择对应的LED引脚,配置为输出。
2.2 cubemx时钟树配置
2.3 cubemx项目管理
- 1、项目名:threadx-basic
- 2、IDE:mdk5.32
- 3、堆栈大小:均设置为0x800
- 4、copy only the necessary library files
- 5、generate peripheral initialization as a pair of ‘.C/.H’ files per peripheral
- 6、enable full assert
2.4 生成项目
2.5 配置mdk
-
1、编译器使用AC5
-
2、使用microlib
-
3、优化等级设置为0
2.6 完善基础代码
2.6.1 main.h
添加头文件:
/* USER CODE BEGIN Includes */
#include "stdio.h"
#include "stdlib.h"
#include "stdint.h"
#include "string.h"
#include "assert.h"
/* USER CODE END Includes */
/* USER CODE BEGIN ET */
#define _Debug
#ifdef _Debug
#define debug(format, ...) printf("File: "__FILE__ \
",Line: %d," format "", \
__LINE__, ##__VA_ARGS__)
#define debug_num(num) printf("%s -> %d\r\n", #num, num)
#define debug_str(str) printf("> %s\r\n", str)
#else
#define debug(format, ...)
#define debug_num(num)
#define debug_str(str)
#endif
extern uint8_t arxbuffer;
extern uint8_t atxbuffer;
/* USER CODE END ET */
2.6.2 usart.c
添加printf重映射
/* USER CODE BEGIN 0 */
uint8_t arxbuffer = 0;
uint8_t atxbuffer = 0;
#pragma import(__use_no_semihosting)
struct __FILE
{
int handle;
};
typedef struct __FILE FILE;
FILE __stdout;
//__use_no_semihosting was requested, but _ttywrch was
void _ttywrch(int ch)
{
ch = ch;
}
void _sys_exit(int16_t x)
{
x = x;
}
// send
int fputc(int ch, FILE *f)
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xffff);
return ch;
}
// get
int fgetc(FILE *f)
{
uint8_t ch = 0;
HAL_UART_Receive(&huart1, &ch, 1, 0xffff);
return ch;
}
/* USER CODE END 0 */
2.6.3 main.c
编写测试代码
/* USER CODE BEGIN WHILE */
#define LED_TOGGLE() HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin)
while (1)
{
LED_TOGGLE();
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
2.6.4 完成
就可以实现基础代码了,具体效果是led闪烁。