极海APM32F411V Tiny开发板评测 嵌入式框架Zorb Framework移植
本帖最后由 lemonhub 于 2024-5-22 10:06 编辑极海APM32F411V Tiny开发板评测07 嵌入式框架Zorb Framework移植 Zorb Framework Zorb Framework是一个轻量级的嵌入式框架,搭建目的是为在不能运行Linux的芯片上快速开发应用,不用反复造轮子。 Zorb Framework的初步设计功能有 1、时间系统功能zf_time 2、环形缓冲区功能zf_buffer 3、列表功能zf_list 4、状态机功能zf_fsm 5、事件功能zf_event 6、定时器功能zf_timer 7、任务功能zf_task 前6个功能,就可以实现纯事件驱动的程序,基本可以满足中小型嵌入式应用程序开发的需求。加上任务功能,是为了满足部分程序对实时性要求较高的需求。当然,也可以将前6个功能裁剪出来,然后运行在现有的嵌入式系统上面,这样子也可以满足实时性的需求。一、移植前的准备1. 准备目标硬件(开发板/芯片/模组)Zorb Framework支持ARM Cortex M3/M4的内核的芯片的移植。本教程将使用立创开发板极海APM32F411V Tiny开发板进行示例移植,其他 ARM Cortex M3/M4系列开发板和芯片移植方法类似。调试ARM Cortex M核还需要仿真器,如果您的开发板或者芯片模组没有板载仿真器,就需要连接外置的仿真器,如J-Link、DAPLink之类的。2.准备编译器环境本移植指南针对的是Keil编译器,所以我们移植内核前需要先安装Keil编译器,能编译ARM Cortex M核的Keil编译器现在也叫MDK。下载地址为:https://www.keil.com/demo/eval/arm.htm3. 准备芯片对应的裸机工程移植Zorb Framework基础内核需要您提前准备一个芯片对应的裸机工程,裸机工程包含基本的芯片启动文件、基础配置(时钟、主频等)、以及串口1和systick,其中串口1提供调试打印功能,systick提供系统时间计数功能。
4. 准备Zorb Framework的源码Zorb Framework的源码已经开源,github仓库地址 https://github.com/54zorb/Zorb-Framework二、移植打开keil工程,开始添加Zorb Framework的内核代码。1. 添加Zorb Framework源代码文件2. 添加Zorb Framework头文件目录3. 系统滴答计数器 中断相关配置
[*]配置SysTick_Handler
[*]配置SystemTick_init
[*]初始化SystemTick_init 初始化系统时基
[*]注释PendSV_Handler Zorb Framework提供的任务功能比较简单,状态也只有运行和关闭两种状态。任务功能实现的关键在于任务调度,而任务调度的核心又在于任务堆栈的保存和恢复。这部分需要根据使用的芯片进行修改,在APM32中,通过触发PendSV异常进行任务切换:Zorb Framework重写了endSV_Handler
这样Zorb Framework源码就全部添加完毕了。三、测试移植结果1. 添加app_test测试代码2. 编写测试代码main.c
/**
*****************************************************************************
* @file main.c
* @authorCoderEnd
* @version V1.0.0
* @date 2024-05-21
* @brief 主程序的实现
*****************************************************************************
* @history
* 1.嵌入式框架Zorb Framework
https://www.cnblogs.com/54zorb/p/9277802.html
*****************************************************************************
**/
#include "main.h"
#include "zf_includes.h"
/******************************************************************************
* 描述:SystemTick初始化
* 参数:无
* 返回:无
******************************************************************************/
void SystemTick_init(void)
{
if (SysTick_Config(SystemCoreClock / 1000)) /* 1ms */
{
ZF_DEBUG(LOG_E, "systemtick init error\r\n");
while(1);
}
}
/**
* @briefboard_hardware_init
* @paramnone
* @retval none
**/
static void board_hardware_init(void)
{
SystemTick_init(); //系统时基初始化
APM_LEDInit(LED2); //LED2初始化
APM_LEDInit(LED3); //LED3初始化
USART1_Init(115200); //UART1初始化
}
int main()
{
board_hardware_init();
ZF_DEBUG(LOG_D,"Hardware_Init \r\n");
ZF_DEBUG(LOG_D,"apm32f411tiny board testing 2024-05-21 \r\n");
ZF_DEBUG(LOG_D,"gapm32f411tiny board zf-framework \r\n");
ZF_DEBUG(LOG_D, "init time used:%dms\r\n", ZF_SYSTIME_MS());
ZF_DEBUG(LOG_D, "zorb framework run\r\n");
//测试 app_test 需要打开main.h 中的宏定义
#if USE_APP_BUFFER
App_Buffer_init();
App_Buffer_process();
#endif
#if USE_APP_LIST
App_List_init();
App_List_process();
#endif
#if USE_APP_FSM
App_Fsm_init();
App_Fsm_process();
#endif
#if USE_APP_EVENT
App_Event_init();
App_Event_process();
#endif
#if USE_APP_TIMER
App_Timer_init();
App_Timer_process();
#endif
#if USE_APP_TASK
App_Task_init();
#endif
while(1)
{
APM_LEDOn(LED2);
ZF_DELAY_MS(500);
ZF_DEBUG(LOG_D, "init time used:%dms \r\n", ZF_SYSTIME_MS());
ZF_DEBUG(LOG_D, "drv_bsp_led2 on \r\n");
APM_LEDOff(LED2);
ZF_DELAY_MS(500);
ZF_DEBUG(LOG_D, "init time used:%dms \r\n", ZF_SYSTIME_MS());
ZF_DEBUG(LOG_D, "drv_bsp_led2 off \r\n");
APM_LEDOn(LED3);
ZF_DELAY_MS(1000);
ZF_DEBUG(LOG_D, "init time used:%dms \r\n", ZF_SYSTIME_MS());
ZF_DEBUG(LOG_D, "drv_bsp_led3 on \r\n");
APM_LEDOff(LED3);
ZF_DELAY_MS(1000);
ZF_DEBUG(LOG_D, "init time used:%dms \r\n", ZF_SYSTIME_MS());
ZF_DEBUG(LOG_D, "drv_bsp_led3 off \r\n");
}
}
main.h
#ifndef __MAIN_H
#define __MAIN_H
//--------------------------------------------------------------------------------------------------
//C库函数调用头文件 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
//--------------------------------------------------------------------------------------------------
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
//--------------------------------------------------------------------------------------------------
//数据类型重定义 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
//--------------------------------------------------------------------------------------------------
/**************************************************************************************************
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long int uint64_t;
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int32_t;
typedef long long int int64_t;
C语言数据类型
整型(int)、单精度浮点型(float)
双精度浮点型(double)、字符型(char)
整型(int)类型又划分了
long int(也可以直接写为long) 、long long int(可以直接写为long long) 、short int(可以直接写为short)
指针类型:void *;
空类型:void;
构造类型:数组、结构体(strtuct)、共用体类型(union)、枚举类型(enum);
1字节(Byte) = 8位(bit) 1Byte=8bi
******************************************************************************************************/
//--------------------------------------------------------------------------------------------------
// APM32库文件 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
//--------------------------------------------------------------------------------------------------
#include "apm32f4xx.h"
#include "apm32f4xx_int.h"
#include "apm32f4xx_gpio.h"
#include "apm32f4xx_rcm.h"
#include "apm32f4xx_usart.h"
//--------------------------------------------------------------------------------------------------
//中间件驱动文件 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
//--------------------------------------------------------------------------------------------------
#include "log_printf.h"
//--------------------------------------------------------------------------------------------------
//Drv_Drivers文件 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//BSP_Drivers文件 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
//--------------------------------------------------------------------------------------------------
#include "bsp_delay.h"
#include "bsp_led.h"
#include "bsp_usart.h"
//--------------------------------------------------------------------------------------------------
//自定义函数声明 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
//--------------------------------------------------------------------------------------------------
#include "app_zf_buffer.h"
#include "app_zf_list.h"
#include "app_zf_fsm.h"
#include "app_zf_event.h"
#include "app_zf_timer.h"
#include "app_zf_task.h"
#defineUSE_APP_BUFFER 0
#defineUSE_APP_LIST 0
#defineUSE_APP_FSM 0
#defineUSE_APP_EVENT 0
#defineUSE_APP_TIMER 0
#defineUSE_APP_TASK 0
#endif
3. 编译下载观察效果
[*]测试时基释放正常输出(ZF_DEBUG,ZF_TIME)
[*]测试zf_buffer#defineUSE_APP_BUFFER 1
[*]测试zf_list#defineUSE_APP_LIST 1
[*]测试zf_fsm#defineUSE_APP_FSM 1
[*]测试zf_event#defineUSE_APP_EVENT 1
[*]测试zf_task#defineUSE_APP_TASK 1
[*]测试zf_timer#defineUSE_APP_TIMER 1事件和事件处理器已经设计好了,再把定时器的处理程序添加到系统滴答程序中即可:
[*]
嵌入式框架Zorb Framework有哪些具体的特点?
页:
[1]