#申请原创# @21小跑堂
1.概述
RTX5是KEIL MDK-Arm集成开发环境自带的一个实时操作系统(RTOS),使用Cortex-M内核的话,RTX实时操作系统可以实现零中断延时;同时RTX实时操作系统还带有完善的中间件,如RL-FlashFS、RL-USB、RL-TCPnet等等,这些中间件可以快速嵌入到项目开发中去,加速产品开发;最重要的一点是,RTX5实时操作系统不需要移植,使用MDK5开发环境可以一键添加,进行简单的配置就可以使用了,下面来具体讲解一下。
2.基础工程
基于MM32开发板,我们先准备一个基础工程,这个基础工程实现几个首先的配置:SysTick的1ms中断作为延时,SWD利用成RTT的打印输出,以及配置一个LED灯,每间隔200ms闪烁一次,实现代码及工程如下所示:
main.c
#include "main.h"
#include "platform.h"
void InitLED(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOC, ENABLE);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStruct);
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_SET);
}
int main(void)
{
PLATFORM_Init();
InitLED();
while (1)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_13, (GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET) ? Bit_SET : Bit_RESET);
SysTick_DelayMS(200);
}
}
platform.c & platform.h
#include "platform.h"
#include "SEGGER_RTT.h"
volatile uint32_t SysTick_DelayTick = 0;
void PLATFORM_InitSysTick(void)
{
RCC_ClocksTypeDef RCC_Clocks;
RCC_GetClocksFreq(&RCC_Clocks);
if (SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000))
{
while (1)
{
}
}
NVIC_SetPriority(SysTick_IRQn, 0x0);
}
void SysTick_DelayMS(uint32_t Tick)
{
SysTick_DelayTick = Tick;
while (SysTick_DelayTick)
{
}
}
void PLATFORM_InitConsole(void)
{
SEGGER_RTT_ConfigUpBuffer(0, "RTTUP", NULL, 0, SEGGER_RTT_MODE_NO_BLOCK_SKIP);
}
int fputc(int ch, FILE *f)
{
SEGGER_RTT_PutCharSkip(0, (char)ch);
return (ch);
}
void PLATFORM_PrintInfo(void)
{
RCC_ClocksTypeDef RCC_Clocks;
printf("\r\n");
printf("\r\nMCU : MM32F3273G6P");
printf("\r\n");
switch (RCC->CFGR & RCC_CFGR_SWS)
{
case 0x00:
printf("\r\nHSI used as system clock source");
break;
case 0x04:
printf("\r\nHSE used as system clock source");
break;
case 0x08:
if (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC)
{
printf("\r\nPLL (clocked by HSE) used as system clock source");
}
else
{
printf("\r\nPLL (clocked by HSI) used as system clock source");
}
break;
case 0x0C:
printf("\r\nLSI used as system clock source");
break;
default:
break;
}
RCC_GetClocksFreq(&RCC_Clocks);
printf("\r\n");
printf("\r\nSYSCLK Frequency : %7.3f MHz", (double)RCC_Clocks.SYSCLK_Frequency / (double)1000000.0);
printf("\r\nHCLK Frequency : %7.3f MHz", (double)RCC_Clocks.HCLK_Frequency / (double)1000000.0);
printf("\r\nPCLK1 Frequency : %7.3f MHz", (double)RCC_Clocks.PCLK1_Frequency / (double)1000000.0);
printf("\r\nPCLK2 Frequency : %7.3f MHz", (double)RCC_Clocks.PCLK2_Frequency / (double)1000000.0);
printf("\r\n");
}
void PLATFORM_Init(void)
{
PLATFORM_InitSysTick();
PLATFORM_InitConsole();
PLATFORM_PrintInfo();
}
#ifndef __PLATFORM_H
#define __PLATFORM_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include "hal_conf.h"
void PLATFORM_Init(void);
void SysTick_DelayMS(uint32_t Tick);
#ifdef __cplusplus
}
#endif
#endif
mm32f3270_it.c
#include "mm32f3270_it.h"
extern volatile uint32_t SysTick_DelayTick;
void NMI_Handler(void)
{
while (1)
{
}
}
void HardFault_Handler(void)
{
while (1)
{
}
}
void MemManage_Handler(void)
{
while (1)
{
}
}
void BusFault_Handler(void)
{
while (1)
{
}
}
void UsageFault_Handler(void)
{
while (1)
{
}
}
void SVCall_Handler(void)
{
}
void DebugMon_Handler(void)
{
}
void PendSV_Handler(void)
{
}
void SysTick_Handler(void)
{
if (SysTick_DelayTick)
{
SysTick_DelayTick--;
}
}
基础工程附件:
MM32F3270_BASE.zip
(6.82 MB)
|
MDK5一键添加RTX5实时操作系统,并逐步演示如何在MM32F3270上实现运行,保姆级教学,一学就会。