1.添加了必要的注释和readme文件以提高代码可读性和项目文档化。2.增加了按键按下时LCD屏幕显示功能
This commit is contained in:
@@ -1319,28 +1319,45 @@ void FillBoxScreen(uint8_t x, uint8_t y, uint8_t len, uint8_t high, uint8_t byte
|
||||
y++; /* 移动到下一行 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LCD 控制与背光 GPIO 初始化
|
||||
* @note 初始化 UC1698U 控制器所需的 GPIO 引脚,分为两组:
|
||||
* GPIOB 组(控制信号与背光):
|
||||
* | 引脚 | 功能 | 说明 |
|
||||
* |------|----------|----------------|
|
||||
* | PB0 | 背光 | 背光开关 |
|
||||
* | PB10 | RST | 复位信号 |
|
||||
* | PB11 | CS | 片选 |
|
||||
* | PB12 | RD | 读使能 |
|
||||
* | PB13 | WR | 写使能 |
|
||||
* | PB14 | CD | 命令/数据选择 |
|
||||
* GPIOE 组(数据总线):
|
||||
* | 引脚 | 功能 | 说明 |
|
||||
* |-----------|----------|-------------------------|
|
||||
* | PE8~PE15 | D0~D7 | 8 位并行数据总线 |
|
||||
* 配置为推挽输出、上拉、高速模式
|
||||
* @retval 无
|
||||
*/
|
||||
void LCD_GPIO_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef gpio_init_struct;
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE(); // 时钟初始化
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE(); // 时钟初始化
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE(); /**< 使能 GPIOB 时钟 */
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE(); /**< 使能 GPIOE 时钟 */
|
||||
|
||||
// 配置 LCD 引脚
|
||||
/* ========== GPIOB:控制信号与背光 ========== */
|
||||
gpio_init_struct.Pin = GPIO_PIN_14 | GPIO_PIN_13 | GPIO_PIN_12 | GPIO_PIN_11 | GPIO_PIN_10 | GPIO_PIN_0;
|
||||
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP; /*推挽输出模式*/
|
||||
gpio_init_struct.Pull = GPIO_PULLUP;
|
||||
gpio_init_struct.Speed = GPIO_SPEED_HIGH;
|
||||
// 初始化 LCD 选引脚
|
||||
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP; /**< 推挽输出 */
|
||||
gpio_init_struct.Pull = GPIO_PULLUP; /**< 上拉 */
|
||||
gpio_init_struct.Speed = GPIO_SPEED_HIGH; /**< 高速 */
|
||||
HAL_GPIO_Init(GPIOB, &gpio_init_struct);
|
||||
|
||||
// 配置 LCD 引脚
|
||||
/* ========== GPIOE:8 位数据总线 ========== */
|
||||
gpio_init_struct.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP; /*推挽输出模式*/
|
||||
gpio_init_struct.Pull = GPIO_PULLUP;
|
||||
gpio_init_struct.Speed = GPIO_SPEED_HIGH;
|
||||
// 初始化 LCD 选引脚
|
||||
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP; /**< 推挽输出 */
|
||||
gpio_init_struct.Pull = GPIO_PULLUP; /**< 上拉 */
|
||||
gpio_init_struct.Speed = GPIO_SPEED_HIGH; /**< 高速 */
|
||||
HAL_GPIO_Init(GPIOE, &gpio_init_struct);
|
||||
}
|
||||
/**
|
||||
@@ -1422,64 +1439,66 @@ void DisplayNANRUI_LOGO(void)
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* FunctionName : Display_Picture()
|
||||
* Description : 图片显示程序
|
||||
* EntryParameter : none
|
||||
* ReturnValue : none
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief 在 LCD 上显示指定尺寸的位图
|
||||
* @param Width 位图宽度(像素,不超过 160)
|
||||
* @param Height 位图高度(像素,不超过 160)
|
||||
* @param picture 位图数据指针(每像素 1 位,每行 Width/8 字节,行内取反显示)
|
||||
* @note 使用 4K 色(RGB444)模式;位图居中显示
|
||||
* X 坐标按每 3 像素递增;每行末尾补 0 使点数能被 3 整除
|
||||
* 若 Width 或 Height 大于 160 则直接返回
|
||||
* @retval 无
|
||||
*/
|
||||
void Display_BMP(uint32_t Width, uint32_t Height, const uint8_t* picture)
|
||||
{
|
||||
uint8_t i,n;
|
||||
uint8_t disp_point[4]={0x00,0x0f,0xf0,0xff};
|
||||
uint8_t x, y;
|
||||
uint32_t bytesNumOfRow;
|
||||
set_color_mode(COLOR_4K_444);//设置4.4.4.模式
|
||||
|
||||
if(Width>160 || Height>160)
|
||||
return ; //设置4.4.4.模式
|
||||
|
||||
x = ((160-Width)/2)/3; //x坐标为每3个像素点递增
|
||||
y = (160-Height)/2 + Height; //x坐标为每3个像素点递增
|
||||
|
||||
bytesNumOfRow = Width/8;
|
||||
for(i=0;i<Height;i++)
|
||||
{
|
||||
SetAddress(x, y-i);
|
||||
for(n=0;n<bytesNumOfRow;n++)
|
||||
{
|
||||
WriteData(disp_point[(~picture[i*bytesNumOfRow+n]>>6)&0x03]);
|
||||
WriteData(disp_point[(~picture[i*bytesNumOfRow+n]>>4)&0x03]);
|
||||
WriteData(disp_point[(~picture[i*bytesNumOfRow+n]>>2)&0x03]);
|
||||
WriteData(disp_point[(~picture[i*bytesNumOfRow+n]>>0)&0x03]);
|
||||
}
|
||||
WriteData(0x00); //补全每行末尾的数据,使总点数能被三整除
|
||||
}
|
||||
uint8_t i, n;
|
||||
uint8_t disp_point[4] = {0x00, 0x0f, 0xf0, 0xff}; /**< 4K 色像素值映射 */
|
||||
uint8_t x, y;
|
||||
uint32_t bytesNumOfRow;
|
||||
|
||||
set_color_mode(COLOR_4K_444); /**< 设置 4K 色模式 */
|
||||
|
||||
if (Width > 160 || Height > 160)
|
||||
return;
|
||||
|
||||
x = ((160 - Width) / 2) / 3; /**< 居中 X,每 3 像素为一单位 */
|
||||
y = (160 - Height) / 2 + Height; /**< 居中 Y,自下而上绘制 */
|
||||
|
||||
bytesNumOfRow = Width / 8;
|
||||
for (i = 0; i < Height; i++)
|
||||
{
|
||||
SetAddress(x, y - i);
|
||||
for (n = 0; n < bytesNumOfRow; n++)
|
||||
{
|
||||
WriteData(disp_point[(~picture[i * bytesNumOfRow + n] >> 6) & 0x03]);
|
||||
WriteData(disp_point[(~picture[i * bytesNumOfRow + n] >> 4) & 0x03]);
|
||||
WriteData(disp_point[(~picture[i * bytesNumOfRow + n] >> 2) & 0x03]);
|
||||
WriteData(disp_point[(~picture[i * bytesNumOfRow + n] >> 0) & 0x03]);
|
||||
}
|
||||
WriteData(0x00); /**< 补足使每行点数能被 3 整除 */
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* FunctionName : DisplayNANRUI_BMP()
|
||||
* Description : BMP格式显示测试
|
||||
* EntryParameter : none
|
||||
* ReturnValue : none
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief 显示南瑞(NANRUI)Logo 位图
|
||||
* @note 调用 Display_BMP,尺寸 128×50 像素,数据源为 NANRUI_BMP
|
||||
* @retval 无
|
||||
*/
|
||||
void DisplayNANRUI_BMP(void)
|
||||
{
|
||||
const uint32_t xmax=128, ymax=50;
|
||||
Display_BMP(xmax, ymax, NANRUI_BMP);
|
||||
const uint32_t xmax = 128, ymax = 50;
|
||||
Display_BMP(xmax, ymax, NANRUI_BMP);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* FunctionName : DisplayNANRUI_BMP()
|
||||
* Description : BMP格式显示测试
|
||||
* EntryParameter : none
|
||||
* ReturnValue : none
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief 显示 QQ Logo 位图
|
||||
* @note 调用 Display_BMP,尺寸 96×94 像素,数据源为 QQ_BMP
|
||||
* @retval 无
|
||||
*/
|
||||
void DisplayQQ_BMP(void)
|
||||
{
|
||||
const uint32_t xmax=96, ymax=94;
|
||||
|
||||
Display_BMP(xmax, ymax, QQ_BMP);
|
||||
const uint32_t xmax = 96, ymax = 94;
|
||||
Display_BMP(xmax, ymax, QQ_BMP);
|
||||
}
|
||||
/**
|
||||
* @brief 绘制单条水平线(内部函数)
|
||||
@@ -1589,58 +1608,6 @@ void DiaplayHeadGraph(void)
|
||||
/* 绘制左侧垂直边框(从第18行开始,高度142) */
|
||||
DisplayVerticalLine(0, 18, 142, 0x80);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 绘制带阴影效果的方框(内部函数)
|
||||
* @param x 起始列坐标(X坐标)
|
||||
* @param y 起始行坐标(Y坐标)
|
||||
* @param len 方框宽度(像素单位)
|
||||
* @param high 方框高度(行数)
|
||||
* @note 绘制一个带3D阴影效果的方框
|
||||
* 包括:左边框、上边框、下边框(带阴影)、右边框(带渐变阴影效果)
|
||||
* @retval 无
|
||||
*/
|
||||
static void DrawBox(uint8_t x, uint8_t y, uint8_t len, uint8_t high)
|
||||
{
|
||||
/* 绘制左边框 */
|
||||
DisplayVerticalLine(x, y, high, 0x80);
|
||||
|
||||
/* 绘制上边框 */
|
||||
DisplayHorizontalLine(x, y, len);
|
||||
|
||||
/* 绘制下边框 */
|
||||
DisplayHorizontalLine(x, y + high, len);
|
||||
/* 绘制第一层阴影 */
|
||||
writebyte(x, y + high + 1, 0x7F, RESET);
|
||||
DisplayHorizontalLine(x + 1, y + high + 1, len);
|
||||
/* 绘制第二层阴影 */
|
||||
writebyte(x, y + high + 2, 0x3F, RESET);
|
||||
DisplayHorizontalLine(x + 1, y + high + 2, len);
|
||||
|
||||
/* 绘制右边框(带渐变阴影效果) */
|
||||
DisplayVerticalLine(x + len, y, high + 3, 0x80); /* 主边框 */
|
||||
DisplayVerticalLine(x + len, y + 1, high + 2, 0xC0); /* 第一层阴影 */
|
||||
DisplayVerticalLine(x + len, y + 2, high + 1, 0xE0); /* 第二层阴影 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 绘制无阴影效果的方框(内部函数)
|
||||
* @param x 起始列坐标(X坐标)
|
||||
* @param y 起始行坐标(Y坐标)
|
||||
* @param len 方框宽度(像素单位)
|
||||
* @param high 方框高度(行数)
|
||||
* @note 绘制一个简单的方框,无阴影效果
|
||||
* 包括:左边框、上边框、下边框、右边框
|
||||
* @retval 无
|
||||
*/
|
||||
static void DrawBox_NoShadow(uint8_t x, uint8_t y, uint8_t len, uint8_t high)
|
||||
{
|
||||
DisplayVerticalLine(x, y, high, 0x80); /* 左边框 */
|
||||
DisplayHorizontalLine(x, y, len); /* 上边框 */
|
||||
DisplayHorizontalLine(x, y + high, len); /* 下边框 */
|
||||
DisplayVerticalLine(x + len - 1, y, high, 0x20); /* 右边框 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 绘制一个像素点(带渐变效果)
|
||||
* @param x 列坐标(X坐标)
|
||||
@@ -1665,168 +1632,3 @@ void DrawPoint(uint8_t x, uint8_t y)
|
||||
DisplayVerticalLine(x + 1, y + 4, 1, 0x60);
|
||||
DisplayHorizontalLine(x + 1, y + 5, 1);
|
||||
}
|
||||
/**
|
||||
* @brief 显示消息提示框(静态模式)
|
||||
* @note 在屏幕指定位置显示一个带阴影的消息提示框
|
||||
* 位置:坐标(10,40),尺寸:33x50像素
|
||||
* 先清除背景区域,然后绘制方框
|
||||
* 动态框模式代码已注释(需要定义DYNAMIC_BOX)
|
||||
* @retval 无
|
||||
*/
|
||||
void MessageBox(void)
|
||||
{
|
||||
/* 静态框模式 */
|
||||
FillBoxScreen(9, 37, 35, 59, 0x00); /* 清除背景区域 */
|
||||
DrawBox(10, 40, 33, 50); /* 绘制带阴影的方框 */
|
||||
}
|
||||
/**
|
||||
* @brief 清除消息提示框
|
||||
* @note 清除消息提示框的整个显示区域
|
||||
* 位置和尺寸与MessageBox函数对应
|
||||
* @retval 无
|
||||
*/
|
||||
void ClrMessageBox(void)
|
||||
{
|
||||
FillBoxScreen(9, 37, 35, 59, 0x00); /* 清除消息框区域 */
|
||||
}
|
||||
/**
|
||||
* @brief 清除消息提示框内容区域
|
||||
* @note 只清除消息框内部的内容区域,保留边框
|
||||
* 用于刷新消息内容而不重新绘制边框
|
||||
* @retval 无
|
||||
*/
|
||||
void ClrMessageBoxContent(void)
|
||||
{
|
||||
FillBoxScreen(11, 41, 31, 48, 0x00); /* 清除内容区域(保留边框) */
|
||||
}
|
||||
/**
|
||||
* @brief 显示可编程消息提示框(支持静态和动态模式)
|
||||
* @param x 起始列坐标(X坐标)
|
||||
* @param y 起始行坐标(Y坐标)
|
||||
* @param size 方框大小参数(影响方框尺寸)
|
||||
* @note 根据编译选项显示静态或动态消息框
|
||||
* 静态模式:直接绘制完整方框
|
||||
* 动态模式:逐步绘制方框,产生动画效果
|
||||
* 方框尺寸:宽度=size,高度=size*3/2+9
|
||||
* @retval 无
|
||||
*/
|
||||
void ProgramableMessageBox(uint8_t x, uint8_t y, uint8_t size)
|
||||
{
|
||||
#ifdef STATIC_BOX /* 静态框模式 */
|
||||
FillBoxScreen(x - 1, y - 3, size + 2, size * 3 / 2 + 9, 0x00); /* 清除背景 */
|
||||
DrawBox(x, y, size, size * 3 / 2 + 9); /* 绘制方框 */
|
||||
#endif //#ifdef STATIC_BOX
|
||||
|
||||
#ifdef DYNAMIC_BOX /* 动态框模式 */
|
||||
FillBoxScreen(x - 1, y - 3, size * 2 + 2, size * 3 + 9, 0x00); /* 清除背景 */
|
||||
/* 逐步绘制方框,产生动画效果 */
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
EraseLine(x, y, i * 2, i * 3); /* 擦除旧线条 */
|
||||
DrawBox(x, y, (i + 1) * 2, (i + 1) * 3); /* 绘制新方框 */
|
||||
delay_ms(5); /* 延时,产生动画效果 */
|
||||
}
|
||||
#endif //#ifdef DYNAMIC_BOX
|
||||
}
|
||||
/**
|
||||
* @brief 绘制下拉菜单组合框
|
||||
* @param x 起始列坐标(X坐标)
|
||||
* @param y 起始行坐标(Y坐标)
|
||||
* @param len 菜单框宽度(像素单位)
|
||||
* @param items 菜单项数量
|
||||
* @note 根据编译选项显示静态或动态菜单框
|
||||
* 静态模式:直接绘制完整菜单框
|
||||
* 动态模式:逐步绘制菜单框,产生下拉动画效果
|
||||
* 每个菜单项高度:20像素
|
||||
* @retval 无
|
||||
*/
|
||||
void DrawMenuComboBox(uint8_t x, uint8_t y, uint8_t len, uint8_t items)
|
||||
{
|
||||
#ifdef STATIC_BOX /* 静态框模式 */
|
||||
FillBoxScreen(x - 1, y - 6, len + 3, items * 20 + 9, 0x00); /* 清除背景 */
|
||||
DrawBox(x - 1, y - 3, len + 2, items * 20); /* 绘制菜单框 */
|
||||
#endif //#ifdef STATIC_BOX
|
||||
|
||||
#ifdef DYNAMIC_BOX /* 动态框模式 */
|
||||
FillBoxScreen(x - 2, y - 6, len + 3, items * 20 + 9, 0x00); /* 清除背景 */
|
||||
/* 逐步绘制菜单框,产生下拉动画效果 */
|
||||
for(int i = 0; i < items; i++)
|
||||
{
|
||||
EraseLine(x - 1, y - 6, len + 2, i * 20 + 3); /* 擦除旧线条 */
|
||||
DrawBox(x - 1, y - 3, len + 2, (i + 1) * 20); /* 绘制新菜单框 */
|
||||
delay_ms(15); /* 延时,产生动画效果 */
|
||||
}
|
||||
#endif //#ifdef DYNAMIC_BOX
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 显示消息设置提示框(带标题栏,清除背景)
|
||||
* @param title 标题字符串指针(GB2312编码)
|
||||
* @note 显示一个带标题栏的消息设置框
|
||||
* 先清除背景区域,然后绘制无阴影方框
|
||||
* 标题栏区域填充白色,标题文字反显
|
||||
* 位置:坐标(8,40),尺寸:37x70像素
|
||||
* @retval 无
|
||||
*/
|
||||
void MessageSetBox(const uint8_t *title)
|
||||
{
|
||||
FillBoxScreen(7, 37, 39, 79, 0x00); /* 清除背景区域 */
|
||||
DrawBox_NoShadow(8, 40, 37, 70); /* 绘制无阴影方框 */
|
||||
FillBoxScreen(8, 40, 37, 20, 0xFF); /* 填充标题栏区域(白色) */
|
||||
HZ12AndChar_Printf(18, 43, title, SET); /* 显示标题(反显) */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 显示消息设置提示框(带标题栏,不清除背景)
|
||||
* @param title 标题字符串指针(GB2312编码)
|
||||
* @note 功能与MessageSetBox类似,但不清除背景区域
|
||||
* 用于在已有内容上叠加显示消息框
|
||||
* @retval 无
|
||||
*/
|
||||
void MessageSetBox_NoClear(const uint8_t *title)
|
||||
{
|
||||
DrawBox_NoShadow(8, 40, 37, 70); /* 绘制无阴影方框 */
|
||||
FillBoxScreen(8, 40, 37, 20, 0xFF); /* 填充标题栏区域(白色) */
|
||||
HZ12AndChar_Printf(18, 43, title, SET); /* 显示标题(反显) */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 清除消息设置框的内容显示区域
|
||||
* @note 只清除消息框内部的内容区域,保留标题栏和边框
|
||||
* 用于刷新消息内容而不重新绘制整个框
|
||||
* @retval 无
|
||||
*/
|
||||
void ClrMessageSetBox(void)
|
||||
{
|
||||
FillBoxScreen(9, 61, 34, 48, 0x00); /* 清除内容区域(保留标题栏和边框) */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 删除消息设置提示框
|
||||
* @note 清除整个消息设置框的显示区域
|
||||
* 包括标题栏、边框和内容区域
|
||||
* @retval 无
|
||||
*/
|
||||
void DeleteMessageSetBox(void)
|
||||
{
|
||||
FillBoxScreen(7, 37, 39, 79, 0x00); /* 清除整个消息框区域 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 绘制记录框(用于显示记录列表)
|
||||
* @param x 起始列坐标(X坐标)
|
||||
* @param y 起始行坐标(Y坐标)
|
||||
* @param len 框宽度(像素单位)
|
||||
* @param items 记录项数量
|
||||
* @note 绘制一个带阴影的记录列表框
|
||||
* 每个记录项高度:16像素(显示区域),19像素(包括间距)
|
||||
* 先清除背景,然后绘制方框
|
||||
* @retval 无
|
||||
*/
|
||||
void DrawRecordBox(uint8_t x, uint8_t y, uint8_t len, uint8_t items)
|
||||
{
|
||||
FillBoxScreen(x - 1, y - 3, len + 2, items * 16 + 6, 0x00); /* 清除背景 */
|
||||
DrawBox(x - 1, y - 3, len + 2, items * 19); /* 绘制记录框 */
|
||||
}
|
||||
|
||||
|
||||
@@ -1,117 +1,116 @@
|
||||
/******************************************************************************
|
||||
* @file 160160D.h
|
||||
* @brief UC1698U控制器驱动的 160x160 像素 LCD 显示屏驱动头文件
|
||||
* @details 本文件定义了 LCD 驱动的接口函数、状态码宏定义以及 ASCII 字体数据。
|
||||
* 包含显示控制、字符显示、图形显示、菜单操作等功能的函数声明。
|
||||
* @author 阜阳师范大学物电学院
|
||||
* @version V0.1
|
||||
* @date 2026.1.19
|
||||
* @note 控制器: UC1698U
|
||||
* 显示屏: 160x160像素
|
||||
* 颜色模式: 4K色(RGB444)和 64K色(RGB565)
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __160160D_H__
|
||||
#define __160160D_H__
|
||||
|
||||
#include "./SYSTEM/sys/sys.h"
|
||||
#include "./SYSTEM/delay/delay.h"
|
||||
|
||||
#define LCD_EXT extern
|
||||
/* ============================================================================
|
||||
* 显示状态码定义
|
||||
* ============================================================================ */
|
||||
#define DISPLAY_BLANK 0x00 /**< 显示空白 */
|
||||
#define PROTEC_ON 0x01 /**< 保护开启 */
|
||||
#define PROTEC_EXIT 0x02 /**< 保护退出 */
|
||||
#define PROTEC_START 0x03 /**< 保护启动 */
|
||||
#define PROTECT_TRIP 0x04 /**< 保护跳闸 */
|
||||
#define HEART_ACCUM 0x05 /**< 心跳累加 */
|
||||
#define HEART_REDUCE 0x06 /**< 心跳减少 */
|
||||
#define NEXT_MENU 0x07 /**< 下一菜单 */
|
||||
#define UP_DOWN 0x08 /**< 上下键 */
|
||||
#define LEFT_RIGHT 0x09 /**< 左右键 */
|
||||
#define DERECTION_KEY 0x0a /**< 方向键 */
|
||||
#define ENTER_KEY 0x0b /**< 确认键 */
|
||||
#define ESC_KEY 0x0c /**< 取消键 */
|
||||
#define ADD_DEC 0x0d /**< 加减键 */
|
||||
#define DI_CLOSE 0x0e /**< 数字输入关闭 */
|
||||
#define DI_OPEN 0x0f /**< 数字输入开启 */
|
||||
#define DI_UNCERT 0x10 /**< 数字输入不确定 */
|
||||
#define DELET_MESS 0x11 /**< 删除消息 */
|
||||
#define HAVE_MESS 0x12 /**< 有消息 */
|
||||
#define CODE_PASS 0x13 /**< 密码通过 */
|
||||
#define CODE_ERROR 0x14 /**< 密码错误 */
|
||||
|
||||
/* ============================================================================
|
||||
* 函数声明(仅包含 160160D.C 中实际定义的函数)
|
||||
* ============================================================================ */
|
||||
|
||||
|
||||
|
||||
#define DISPLAY_BLANK 0x00
|
||||
#define PROTEC_ON 0x01
|
||||
#define PROTEC_EXIT 0x02
|
||||
#define PROTEC_START 0x03
|
||||
#define PROTECT_TRIP 0x04
|
||||
#define HEART_ACCUM 0x05
|
||||
#define HEART_REDUCE 0x06
|
||||
#define NEXT_MENU 0x07
|
||||
#define UP_DOWN 0x08
|
||||
#define LEFT_RIGHT 0x09
|
||||
#define DERECTION_KEY 0x0a
|
||||
#define ENTER_KEY 0x0b
|
||||
#define ESC_KEY 0x0c
|
||||
#define ADD_DEC 0x0d
|
||||
#define DI_CLOSE 0x0e
|
||||
#define DI_OPEN 0x0f
|
||||
#define DI_UNCERT 0x10
|
||||
#define DELET_MESS 0x11
|
||||
#define HAVE_MESS 0x12
|
||||
#define CODE_PASS 0x13
|
||||
#define CODE_ERROR 0x14
|
||||
|
||||
|
||||
|
||||
LCD_EXT void display_datas(unsigned char datas); //R-G-B=4-4-4
|
||||
LCD_EXT void display_line(unsigned char datas);
|
||||
LCD_EXT void ReverseShow88(uint8_t column ,uint8_t lin,uint8_t const *address);
|
||||
LCD_EXT void ReverseShow916(uint8_t column ,uint8_t lin,uint8_t const *address);
|
||||
LCD_EXT void DisplayOneByteS(uint8_t ox, uint8_t oy, uint8_t byte1);
|
||||
LCD_EXT void DisplayOneText(uint8_t ox,uint8_t oy,uint8_t ascii_code);
|
||||
LCD_EXT void Clear_Line(uint8_t ox1,uint8_t ox2,uint8_t oy,uint8_t number1,uint8_t number2,uint8_t language);
|
||||
LCD_EXT void DisplayBrokenLine(uint8_t ox,uint8_t oy,uint8_t num);
|
||||
LCD_EXT void DisplaySolidLine(uint8_t ox,uint8_t oy,uint8_t num);
|
||||
LCD_EXT void DisplayLineText2(uint8_t ox,uint8_t oy,uint8_t number,uint8_t const *ptr);
|
||||
LCD_EXT void DisplayOneChinesetest(uint8_t column,uint8_t lin);
|
||||
LCD_EXT void REDisplayOneChinesetest(uint8_t column,uint8_t lin);
|
||||
LCD_EXT void ReverseDispOne(uint8_t ox,uint8_t oy,uint8_t ascii_code);
|
||||
LCD_EXT void ReverseLineText(uint8_t ox,uint8_t oy,uint8_t number,uint8_t const *ptr);
|
||||
LCD_EXT void ReverseDispLine(uint8_t ox,uint8_t oy,uint8_t number,uint8_t const *ptr);
|
||||
LCD_EXT void ReverseOneGraphics(uint8_t column,uint8_t lin,uint16_t hzcode,uint8_t tb_index);
|
||||
LCD_EXT void display_pic(unsigned char *p);
|
||||
LCD_EXT void display_pic1(unsigned char *p);
|
||||
LCD_EXT void DisplayOneGraphics(uint8_t column,uint8_t lin, uint16_t hzcode,uint8_t tb_index);
|
||||
LCD_EXT void DisplayConnectGraphics(uint8_t column,uint8_t lin,uint16_t hzcode);
|
||||
LCD_EXT void DisplayOneChinese(uint8_t column,uint8_t lin,uint8_t const *HzCode);
|
||||
LCD_EXT void DisplayLineChinese(uint8_t ox1,uint8_t oy1,uint8_t number1,uint8_t const *ptr1,uint8_t ox2,uint8_t oy2,uint8_t number2,uint8_t const *ptr2,uint8_t language);
|
||||
LCD_EXT void DeleteMenuCursor(uint8_t x1,uint8_t y1,uint8_t const *ptr1,uint8_t x2,uint8_t y2,uint8_t const *ptr2,uint8_t num,uint8_t num2,uint8_t language);
|
||||
LCD_EXT void DisplayMenuCursor(uint8_t x1,uint8_t y1,uint8_t const *ptr1,uint8_t x2,uint8_t y2,uint8_t const *ptr2,uint8_t num,uint8_t num2,uint8_t language);
|
||||
LCD_EXT void ClearScreen(void);
|
||||
void ReverseScreen(void);
|
||||
LCD_EXT void CloseDataCursor(void);
|
||||
LCD_EXT void DisplayDataCursor2(void);
|
||||
LCD_EXT void DisplayDataCursor(void);
|
||||
LCD_EXT void DisplayOneInt(uint8_t ox,uint8_t oy, uint16_t int_value);
|
||||
LCD_EXT void DisplayOneText2(uint8_t ox,uint8_t oy,uint8_t ascii_code);
|
||||
LCD_EXT void DisplayHoriLine(uint8_t column,uint8_t lin,uint8_t num);
|
||||
LCD_EXT void DisplayOneByte(uint8_t ox, uint8_t oy, uint8_t byte1);
|
||||
LCD_EXT void DisplayGraphicsScreen(void);
|
||||
LCD_EXT void DisplayLineText(uint8_t ox,uint8_t oy,uint8_t number,uint8_t const *ptr);
|
||||
LCD_EXT void DisplayOneInt2(uint8_t ox,uint8_t oy, uint16_t int_value);
|
||||
LCD_EXT void DisplayLongInt(uint8_t ox,uint8_t oy, uint32_t value,uint8_t redixs_point);
|
||||
LCD_EXT void DisplayOneByte2(uint8_t ox, uint8_t oy, uint8_t byte1);
|
||||
LCD_EXT void LcdInit(void);
|
||||
LCD_EXT void ReverseDispNum2(uint8_t ox,uint8_t oy,uint8_t ascii_code);
|
||||
LCD_EXT void DisplayCount(uint8_t ox, uint8_t oy, uint8_t byte1);
|
||||
LCD_EXT void DisplayHex(uint8_t ox,uint8_t oy,uint16_t number);
|
||||
LCD_EXT void ReverseDispOne2(uint8_t ox,uint8_t oy,uint8_t ascii_code);
|
||||
void Fault_Disp(void);
|
||||
void KeyRun_Disp(uint32_t Flag);
|
||||
void IP_Sprintf(uint8_t *buf, uint32_t IPdata);
|
||||
void IP_Printf(uint8_t x, uint32_t y, uint32_t IPdata, FlagStatus SetFlag, uint32_t cursor);
|
||||
void HZ12AndChar_Printf(uint8_t x, uint8_t y, const uint8_t *ptr, FlagStatus Flag);
|
||||
void HZ12AndChar_SignPrintf(uint8_t x, uint8_t y, const uint8_t *ptr, uint32_t SignNUM );
|
||||
void DisplayNL_LOGO(void);
|
||||
void DisplayNANRUI_LOGO(void);
|
||||
void DisplayNANRUI_BMP(void);
|
||||
void Display_BMP(uint32_t Width, uint32_t Height, const uint8_t* picture);
|
||||
void DisplayQQ_BMP(void);
|
||||
void ASCII_Printf(uint8_t x, uint32_t y, uint32_t data, FlagStatus Flag);
|
||||
void ASCII_SignPrintf(uint8_t x, uint32_t y, uint32_t data, uint32_t SignNUM);
|
||||
void IntValue_Printf(uint8_t x, uint32_t y, int32_t data, FlagStatus Flag);
|
||||
void FloatValue_Printf(uint8_t x, uint32_t y, float data, FlagStatus Flag);
|
||||
void FixLenIToF_Printf(uint32_t x, uint32_t y, int32_t data, uint32_t len, uint32_t dot, FlagStatus Flag, uint32_t cursor);
|
||||
void FixLenIToF_Sprintf(uint8_t* str, int32_t data, uint32_t len, uint32_t dot);
|
||||
void DisplayHorizontalLine(uint8_t x,uint8_t y,uint8_t len);
|
||||
void DisplayVerticalLine(uint8_t x,uint8_t y,uint8_t high, uint8_t value);
|
||||
void ClearMenuScreen(void);
|
||||
void ScreenPrintf(uint8_t* ptr);
|
||||
void Char6_Write(uint8_t x,uint8_t y, uint8_t CharCode, FlagStatus Flag);
|
||||
void MessageBox(void);
|
||||
void ClrMessageBox(void);
|
||||
void ClrMessageBoxContent(void);
|
||||
void MeunItem_Printf(uint8_t x, uint32_t y, int32_t data, FlagStatus Flag);
|
||||
void MessageSetBox(const uint8_t *title);
|
||||
void MessageSetBox_NoClear(const uint8_t *title);
|
||||
void ClrMessageSetBox(void);
|
||||
void DeleteMessageSetBox(void);
|
||||
void ProgramableMessageBox(uint8_t x, uint8_t y, uint8_t size);
|
||||
void DrawMenuComboBox(uint8_t x, uint8_t y, uint8_t len, uint8_t items);
|
||||
void DrawRecordBox(uint8_t x, uint8_t y, uint8_t len, uint8_t items);
|
||||
/* ---------- 硬件初始化函数 ---------- */
|
||||
void LCD_GPIO_Init(void);
|
||||
void LCD_Reset(void);
|
||||
void LCD_InitXRD(void);
|
||||
void LcdInit(void);
|
||||
void BackLight_Close(void);
|
||||
void BackLight_ON(void);
|
||||
|
||||
/* ---------- 屏幕控制函数 ---------- */
|
||||
void ClearScreen(void);
|
||||
void ReverseScreen(void);
|
||||
void ClearMenuScreen(void);
|
||||
void DisplayGraphicsScreen(void);
|
||||
|
||||
/* ---------- 字符显示函数 ---------- */
|
||||
void Char6_Write(uint8_t x, uint8_t y, uint8_t CharCode, FlagStatus Flag);
|
||||
void Char8_Write(uint8_t x, uint8_t y, uint8_t CharCode, FlagStatus Flag);
|
||||
void Char12_Write(uint8_t x, uint8_t y, uint8_t CharCode, FlagStatus Flag);
|
||||
void HZ12_Write(uint8_t x, uint8_t y, const uint8_t *HzCode, FlagStatus Flag);
|
||||
void HZ12AndChar_Printf(uint8_t x, uint8_t y, const uint8_t *ptr, FlagStatus Flag);
|
||||
void HZ12AndChar_SignPrintf(uint8_t x, uint8_t y, const uint8_t *ptr, uint32_t SignNUM);
|
||||
void ASCII_Printf(uint8_t x, uint32_t y, uint32_t data, FlagStatus Flag);
|
||||
void ASCII_SignPrintf(uint8_t x, uint32_t y, uint32_t data, uint32_t SignNUM);
|
||||
void ScreenPrintf(uint8_t* ptr);
|
||||
|
||||
/* ---------- 数值显示函数 ---------- */
|
||||
void IntValue_Printf(uint8_t x, uint32_t y, int32_t data, FlagStatus Flag);
|
||||
void FloatValue_Printf(uint8_t x, uint32_t y, float data, FlagStatus Flag);
|
||||
void FixLenIntValue_Printf(uint32_t x, uint32_t y, int32_t data, uint32_t len, FlagStatus Flag);
|
||||
void FixLenIToF_Sprintf(uint8_t* str, int32_t data, uint32_t len, uint32_t dot);
|
||||
void FixLenIToF_Printf(uint32_t x, uint32_t y, int32_t data, uint32_t len, uint32_t dot, FlagStatus Flag, uint32_t cursor);
|
||||
void FixLenFloatValue_Printf(uint32_t x, uint32_t y, float data, uint32_t len, uint32_t dot, FlagStatus Flag);
|
||||
void MeunItem_Printf(uint8_t x, uint32_t y, int32_t data, FlagStatus Flag);
|
||||
|
||||
/* ---------- IP 地址显示函数 ---------- */
|
||||
void IP_Sprintf(uint8_t *buf, uint32_t IPdata);
|
||||
void IP_Printf(uint8_t x, uint32_t y, uint32_t IPdata, FlagStatus SetFlag, uint32_t cursor);
|
||||
|
||||
/* ---------- 图形显示函数 ---------- */
|
||||
void DisplayOneGraphics(uint8_t column, uint8_t lin, uint16_t hzcode, uint8_t tb_index);
|
||||
void DisplayNL_LOGO(void);
|
||||
void DisplayNANRUI_LOGO(void);
|
||||
void Display_BMP(uint32_t Width, uint32_t Height, const uint8_t* picture);
|
||||
void DisplayNANRUI_BMP(void);
|
||||
void DisplayQQ_BMP(void);
|
||||
void DiaplayHeadGraph(void);
|
||||
void DrawPoint(uint8_t x, uint8_t y);
|
||||
|
||||
/* ---------- 线条绘制函数 ---------- */
|
||||
void DisplayHorizontalLine(uint8_t x, uint8_t y, uint8_t len);
|
||||
void DisplayVerticalLine(uint8_t x, uint8_t y, uint8_t high, uint8_t value);
|
||||
|
||||
/* ---------- 状态显示函数 ---------- */
|
||||
void Fault_Disp(void);
|
||||
void KeyRun_Disp(uint32_t Flag);
|
||||
|
||||
/* ============================================================================
|
||||
* ASCII 字体数据
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief 6x12 点阵 ASCII 字体数据
|
||||
* @note 包含 95 个 ASCII 字符(空格到波浪号),每个字符 6 列 x 12 行 = 72 位 = 9 字节
|
||||
* 字符索引:0=' ', 1='!', ..., 94='~'
|
||||
*/
|
||||
static const uint8_t ASCII6x12[] =
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
|
||||
@@ -305,6 +304,11 @@ static const uint8_t ASCII6x12[] =
|
||||
0x40,0xA4,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"~",94*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 8x12 点阵 ASCII 字体数据
|
||||
* @note 包含 95 个 ASCII 字符(空格到波浪号),每个字符 8 列 x 12 行 = 96 位 = 12 字节
|
||||
* 字符索引:0=' ', 1='!', ..., 94='~'
|
||||
*/
|
||||
static const uint8_t ASCII8x12[] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
|
||||
|
||||
@@ -497,6 +501,11 @@ static const uint8_t ASCII8x12[] = {
|
||||
0x30,0x4C,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"~",94*/
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 12x12 点阵 ASCII 字体数据
|
||||
* @note 包含 95 个 ASCII 字符(空格到波浪号),每个字符 12 列 x 12 行 = 144 位 = 18 字节
|
||||
* 字符索引:0=' ', 1='!', ..., 94='~'
|
||||
*/
|
||||
static const uint8_t ASCII12x12[] =
|
||||
{
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,57 +0,0 @@
|
||||
/****************************************************************************************
|
||||
* 文件名:FONT5_7.H
|
||||
* 功能:5*7 ASCII码字体显示函数。(头文件)
|
||||
* 作者:黄绍斌
|
||||
* 日期:2004.02.26
|
||||
* 备注:使用GUI_SetColor()函数设置前景颜色及背景色。
|
||||
****************************************************************************************/
|
||||
#ifndef FONT5_7_H
|
||||
#define FONT5_7_H
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* 名称:GUI_PutChar()
|
||||
* 功能:显示ASCII码,显示值为20H-7FH(若为其它值,则显示' ')。
|
||||
* 入口参数: x 指定显示位置,x坐标
|
||||
* y 指定显示位置,y坐标
|
||||
* ch 要显示的ASCII码值。
|
||||
* 出口参数:返回值为1时表示操作成功,为0时表示操作失败。
|
||||
* 说明:操作失败原因是指定地址超出有效范围。
|
||||
****************************************************************************/
|
||||
extern unsigned char GUI_PutChar(unsigned int x, unsigned int y, unsigned char ch);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* 名称:GUI_PutString()
|
||||
* 功能:输出显示字符串(没有自动换行功能)。
|
||||
* 入口参数: x 指定显示位置,x坐标
|
||||
* y 指定显示位置,y坐标
|
||||
* str 要显示的ASCII码字符串
|
||||
* 出口参数:无
|
||||
* 说明:操作失败原因是指定地址超出有效范围。
|
||||
****************************************************************************/
|
||||
extern void GUI_PutString(unsigned int x, unsigned int y, char *str);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* 名称:GUI_PutNoStr()
|
||||
* 功能:输出显示字符串(没有自动换行功能),若显示的字符个数大于指定个数,则直接退出。
|
||||
* 入口参数: x 指定显示位置,x坐标
|
||||
* y 指定显示位置,y坐标
|
||||
* str 要显示的ASCII码字符串。
|
||||
* no 最大显示字符的个数
|
||||
* 出口参数:无
|
||||
* 说明:操作失败原因是指定地址超出有效范围。
|
||||
****************************************************************************/
|
||||
extern void GUI_PutNoStr(unsigned int x, unsigned int y, char *str, unsigned char no);
|
||||
|
||||
/****************************************************************************
|
||||
* 名称:GUI_PutHex()
|
||||
* 功能:显示HEX码,显示值为00H-FFH(若为其它值,则显示' ')。
|
||||
* 入口参数: x 指定显示位置,x坐标
|
||||
* y 指定显示位置,y坐标
|
||||
* v 要显示的HEX。
|
||||
*出口参数:无
|
||||
****************************************************************************/
|
||||
extern void GUI_PutHex(unsigned char x, unsigned char y,unsigned char v);
|
||||
#endif
|
||||
10240
Drivers/BSP/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h
Normal file
10240
Drivers/BSP/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h
Normal file
File diff suppressed because it is too large
Load Diff
11767
Drivers/BSP/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h
Normal file
11767
Drivers/BSP/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h
Normal file
File diff suppressed because it is too large
Load Diff
273
Drivers/BSP/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h
Normal file
273
Drivers/BSP/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h
Normal file
@@ -0,0 +1,273 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx.h
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS STM32F1xx Device Peripheral Access Layer Header File.
|
||||
*
|
||||
* The file is the unique include file that the application programmer
|
||||
* is using in the C source code, usually in main.c. This file contains:
|
||||
* - Configuration section that allows to select:
|
||||
* - The STM32F1xx device used in the target application
|
||||
* - To use or not the peripheral's drivers in application code(i.e.
|
||||
* code will be based on direct access to peripheral's registers
|
||||
* rather than drivers API), this option is controlled by
|
||||
* "#define USE_HAL_DRIVER"
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017-2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f1xx
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef __STM32F1XX_H
|
||||
#define __STM32F1XX_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/** @addtogroup Library_configuration_section
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief STM32 Family
|
||||
*/
|
||||
#if !defined (STM32F1)
|
||||
#define STM32F1
|
||||
#endif /* STM32F1 */
|
||||
|
||||
/* Uncomment the line below according to the target STM32L device used in your
|
||||
application
|
||||
*/
|
||||
|
||||
#if !defined (STM32F100xB) && !defined (STM32F100xE) && !defined (STM32F101x6) && \
|
||||
!defined (STM32F101xB) && !defined (STM32F101xE) && !defined (STM32F101xG) && !defined (STM32F102x6) && !defined (STM32F102xB) && !defined (STM32F103x6) && \
|
||||
!defined (STM32F103xB) && !defined (STM32F103xE) && !defined (STM32F103xG) && !defined (STM32F105xC) && !defined (STM32F107xC)
|
||||
/* #define STM32F100xB */ /*!< STM32F100C4, STM32F100R4, STM32F100C6, STM32F100R6, STM32F100C8, STM32F100R8, STM32F100V8, STM32F100CB, STM32F100RB and STM32F100VB */
|
||||
/* #define STM32F100xE */ /*!< STM32F100RC, STM32F100VC, STM32F100ZC, STM32F100RD, STM32F100VD, STM32F100ZD, STM32F100RE, STM32F100VE and STM32F100ZE */
|
||||
/* #define STM32F101x6 */ /*!< STM32F101C4, STM32F101R4, STM32F101T4, STM32F101C6, STM32F101R6 and STM32F101T6 Devices */
|
||||
/* #define STM32F101xB */ /*!< STM32F101C8, STM32F101R8, STM32F101T8, STM32F101V8, STM32F101CB, STM32F101RB, STM32F101TB and STM32F101VB */
|
||||
/* #define STM32F101xE */ /*!< STM32F101RC, STM32F101VC, STM32F101ZC, STM32F101RD, STM32F101VD, STM32F101ZD, STM32F101RE, STM32F101VE and STM32F101ZE */
|
||||
/* #define STM32F101xG */ /*!< STM32F101RF, STM32F101VF, STM32F101ZF, STM32F101RG, STM32F101VG and STM32F101ZG */
|
||||
/* #define STM32F102x6 */ /*!< STM32F102C4, STM32F102R4, STM32F102C6 and STM32F102R6 */
|
||||
/* #define STM32F102xB */ /*!< STM32F102C8, STM32F102R8, STM32F102CB and STM32F102RB */
|
||||
/* #define STM32F103x6 */ /*!< STM32F103C4, STM32F103R4, STM32F103T4, STM32F103C6, STM32F103R6 and STM32F103T6 */
|
||||
/* #define STM32F103xB */ /*!< STM32F103C8, STM32F103R8, STM32F103T8, STM32F103V8, STM32F103CB, STM32F103RB, STM32F103TB and STM32F103VB */
|
||||
/* #define STM32F103xE */ /*!< STM32F103RC, STM32F103VC, STM32F103ZC, STM32F103RD, STM32F103VD, STM32F103ZD, STM32F103RE, STM32F103VE and STM32F103ZE */
|
||||
/* #define STM32F103xG */ /*!< STM32F103RF, STM32F103VF, STM32F103ZF, STM32F103RG, STM32F103VG and STM32F103ZG */
|
||||
/* #define STM32F105xC */ /*!< STM32F105R8, STM32F105V8, STM32F105RB, STM32F105VB, STM32F105RC and STM32F105VC */
|
||||
/* #define STM32F107xC */ /*!< STM32F107RB, STM32F107VB, STM32F107RC and STM32F107VC */
|
||||
#endif
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to switch between these
|
||||
devices, you can define the device in your toolchain compiler preprocessor.
|
||||
*/
|
||||
|
||||
#if !defined (USE_HAL_DRIVER)
|
||||
/**
|
||||
* @brief Comment the line below if you will not use the peripherals drivers.
|
||||
In this case, these drivers will not be included and the application code will
|
||||
be based on direct access to peripherals registers
|
||||
*/
|
||||
/*#define USE_HAL_DRIVER */
|
||||
#endif /* USE_HAL_DRIVER */
|
||||
|
||||
/**
|
||||
* @brief CMSIS Device version number
|
||||
*/
|
||||
#define __STM32F1_CMSIS_VERSION_MAIN (0x04) /*!< [31:24] main version */
|
||||
#define __STM32F1_CMSIS_VERSION_SUB1 (0x03) /*!< [23:16] sub1 version */
|
||||
#define __STM32F1_CMSIS_VERSION_SUB2 (0x05) /*!< [15:8] sub2 version */
|
||||
#define __STM32F1_CMSIS_VERSION_RC (0x00) /*!< [7:0] release candidate */
|
||||
#define __STM32F1_CMSIS_VERSION ((__STM32F1_CMSIS_VERSION_MAIN << 24)\
|
||||
|(__STM32F1_CMSIS_VERSION_SUB1 << 16)\
|
||||
|(__STM32F1_CMSIS_VERSION_SUB2 << 8 )\
|
||||
|(__STM32F1_CMSIS_VERSION_RC))
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Device_Included
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(STM32F100xB)
|
||||
#include "stm32f100xb.h"
|
||||
#elif defined(STM32F100xE)
|
||||
#include "stm32f100xe.h"
|
||||
#elif defined(STM32F101x6)
|
||||
#include "stm32f101x6.h"
|
||||
#elif defined(STM32F101xB)
|
||||
#include "stm32f101xb.h"
|
||||
#elif defined(STM32F101xE)
|
||||
#include "stm32f101xe.h"
|
||||
#elif defined(STM32F101xG)
|
||||
#include "stm32f101xg.h"
|
||||
#elif defined(STM32F102x6)
|
||||
#include "stm32f102x6.h"
|
||||
#elif defined(STM32F102xB)
|
||||
#include "stm32f102xb.h"
|
||||
#elif defined(STM32F103x6)
|
||||
#include "stm32f103x6.h"
|
||||
#elif defined(STM32F103xB)
|
||||
#include "stm32f103xb.h"
|
||||
#elif defined(STM32F103xE)
|
||||
#include "stm32f103xe.h"
|
||||
#elif defined(STM32F103xG)
|
||||
#include "stm32f103xg.h"
|
||||
#elif defined(STM32F105xC)
|
||||
#include "stm32f105xc.h"
|
||||
#elif defined(STM32F107xC)
|
||||
#include "stm32f107xc.h"
|
||||
#else
|
||||
#error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup Exported_types
|
||||
* @{
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
RESET = 0,
|
||||
SET = !RESET
|
||||
} FlagStatus, ITStatus;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DISABLE = 0,
|
||||
ENABLE = !DISABLE
|
||||
} FunctionalState;
|
||||
#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SUCCESS = 0U,
|
||||
ERROR = !SUCCESS
|
||||
} ErrorStatus;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup Exported_macros
|
||||
* @{
|
||||
*/
|
||||
#define SET_BIT(REG, BIT) ((REG) |= (BIT))
|
||||
|
||||
#define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
|
||||
|
||||
#define READ_BIT(REG, BIT) ((REG) & (BIT))
|
||||
|
||||
#define CLEAR_REG(REG) ((REG) = (0x0))
|
||||
|
||||
#define WRITE_REG(REG, VAL) ((REG) = (VAL))
|
||||
|
||||
#define READ_REG(REG) ((REG))
|
||||
|
||||
#define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
|
||||
|
||||
#define POSITION_VAL(VAL) (__CLZ(__RBIT(VAL)))
|
||||
|
||||
/* Use of CMSIS compiler intrinsics for register exclusive access */
|
||||
/* Atomic 32-bit register access macro to set one or several bits */
|
||||
#define ATOMIC_SET_BIT(REG, BIT) \
|
||||
do { \
|
||||
uint32_t val; \
|
||||
do { \
|
||||
val = __LDREXW((__IO uint32_t *)&(REG)) | (BIT); \
|
||||
} while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
|
||||
} while(0)
|
||||
|
||||
/* Atomic 32-bit register access macro to clear one or several bits */
|
||||
#define ATOMIC_CLEAR_BIT(REG, BIT) \
|
||||
do { \
|
||||
uint32_t val; \
|
||||
do { \
|
||||
val = __LDREXW((__IO uint32_t *)&(REG)) & ~(BIT); \
|
||||
} while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
|
||||
} while(0)
|
||||
|
||||
/* Atomic 32-bit register access macro to clear and set one or several bits */
|
||||
#define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
|
||||
do { \
|
||||
uint32_t val; \
|
||||
do { \
|
||||
val = (__LDREXW((__IO uint32_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
|
||||
} while ((__STREXW(val,(__IO uint32_t *)&(REG))) != 0U); \
|
||||
} while(0)
|
||||
|
||||
/* Atomic 16-bit register access macro to set one or several bits */
|
||||
#define ATOMIC_SETH_BIT(REG, BIT) \
|
||||
do { \
|
||||
uint16_t val; \
|
||||
do { \
|
||||
val = __LDREXH((__IO uint16_t *)&(REG)) | (BIT); \
|
||||
} while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
|
||||
} while(0)
|
||||
|
||||
/* Atomic 16-bit register access macro to clear one or several bits */
|
||||
#define ATOMIC_CLEARH_BIT(REG, BIT) \
|
||||
do { \
|
||||
uint16_t val; \
|
||||
do { \
|
||||
val = __LDREXH((__IO uint16_t *)&(REG)) & ~(BIT); \
|
||||
} while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
|
||||
} while(0)
|
||||
|
||||
/* Atomic 16-bit register access macro to clear and set one or several bits */
|
||||
#define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) \
|
||||
do { \
|
||||
uint16_t val; \
|
||||
do { \
|
||||
val = (__LDREXH((__IO uint16_t *)&(REG)) & ~(CLEARMSK)) | (SETMASK); \
|
||||
} while ((__STREXH(val,(__IO uint16_t *)&(REG))) != 0U); \
|
||||
} while(0)
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined (USE_HAL_DRIVER)
|
||||
#include "stm32f1xx_hal.h"
|
||||
#endif /* USE_HAL_DRIVER */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __STM32F1xx_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f1xx.h
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017-2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f10x_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Define to prevent recursive inclusion
|
||||
*/
|
||||
#ifndef __SYSTEM_STM32F10X_H
|
||||
#define __SYSTEM_STM32F10X_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup STM32F10x_System_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup STM32F10x_System_Exported_types
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
|
||||
extern const uint8_t AHBPrescTable[16U]; /*!< AHB prescalers table values */
|
||||
extern const uint8_t APBPrescTable[8U]; /*!< APB prescalers table values */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F10x_System_Exported_Constants
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F10x_System_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F10x_System_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern void SystemInit(void);
|
||||
extern void SystemCoreClockUpdate(void);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__SYSTEM_STM32F10X_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -0,0 +1,307 @@
|
||||
;******************** (C) COPYRIGHT 2017 STMicroelectronics ********************
|
||||
;* File Name : startup_stm32f103xb.s
|
||||
;* Author : MCD Application Team
|
||||
;* Description : STM32F103xB Devices vector table for MDK-ARM toolchain.
|
||||
;* This module performs:
|
||||
;* - Set the initial SP
|
||||
;* - Set the initial PC == Reset_Handler
|
||||
;* - Set the vector table entries with the exceptions ISR address
|
||||
;* - Configure the clock system
|
||||
;* - Branches to __main in the C library (which eventually
|
||||
;* calls main()).
|
||||
;* After Reset the Cortex-M3 processor is in Thread mode,
|
||||
;* priority is Privileged, and the Stack is set to Main.
|
||||
;******************************************************************************
|
||||
;* @attention
|
||||
;*
|
||||
;* Copyright (c) 2017 STMicroelectronics.
|
||||
;* All rights reserved.
|
||||
;*
|
||||
;* This software component is licensed by ST under BSD 3-Clause license,
|
||||
;* the "License"; You may not use this file except in compliance with the
|
||||
;* License. You may obtain a copy of the License at:
|
||||
;* opensource.org/licenses/BSD-3-Clause
|
||||
;*
|
||||
;******************************************************************************
|
||||
|
||||
; Amount of memory (in bytes) allocated for Stack
|
||||
; Tailor this value to your application needs
|
||||
; <h> Stack Configuration
|
||||
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
||||
; </h>
|
||||
|
||||
Stack_Size EQU 0x00000400
|
||||
|
||||
AREA STACK, NOINIT, READWRITE, ALIGN=3
|
||||
Stack_Mem SPACE Stack_Size
|
||||
__initial_sp
|
||||
|
||||
|
||||
; <h> Heap Configuration
|
||||
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
||||
; </h>
|
||||
|
||||
Heap_Size EQU 0x00000200
|
||||
|
||||
AREA HEAP, NOINIT, READWRITE, ALIGN=3
|
||||
__heap_base
|
||||
Heap_Mem SPACE Heap_Size
|
||||
__heap_limit
|
||||
|
||||
PRESERVE8
|
||||
THUMB
|
||||
|
||||
|
||||
; Vector Table Mapped to Address 0 at Reset
|
||||
AREA RESET, DATA, READONLY
|
||||
EXPORT __Vectors
|
||||
EXPORT __Vectors_End
|
||||
EXPORT __Vectors_Size
|
||||
|
||||
__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 DebugMon_Handler ; Debug Monitor Handler
|
||||
DCD 0 ; Reserved
|
||||
DCD PendSV_Handler ; PendSV Handler
|
||||
DCD SysTick_Handler ; SysTick Handler
|
||||
|
||||
; External Interrupts
|
||||
DCD WWDG_IRQHandler ; Window Watchdog
|
||||
DCD PVD_IRQHandler ; PVD through EXTI Line detect
|
||||
DCD TAMPER_IRQHandler ; Tamper
|
||||
DCD RTC_IRQHandler ; RTC
|
||||
DCD FLASH_IRQHandler ; Flash
|
||||
DCD RCC_IRQHandler ; RCC
|
||||
DCD EXTI0_IRQHandler ; EXTI Line 0
|
||||
DCD EXTI1_IRQHandler ; EXTI Line 1
|
||||
DCD EXTI2_IRQHandler ; EXTI Line 2
|
||||
DCD EXTI3_IRQHandler ; EXTI Line 3
|
||||
DCD EXTI4_IRQHandler ; EXTI Line 4
|
||||
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
|
||||
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
|
||||
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
|
||||
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
|
||||
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
|
||||
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
|
||||
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
|
||||
DCD ADC1_2_IRQHandler ; ADC1_2
|
||||
DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX
|
||||
DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0
|
||||
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
|
||||
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
|
||||
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
|
||||
DCD TIM1_BRK_IRQHandler ; TIM1 Break
|
||||
DCD TIM1_UP_IRQHandler ; TIM1 Update
|
||||
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
|
||||
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
|
||||
DCD TIM2_IRQHandler ; TIM2
|
||||
DCD TIM3_IRQHandler ; TIM3
|
||||
DCD TIM4_IRQHandler ; TIM4
|
||||
DCD I2C1_EV_IRQHandler ; I2C1 Event
|
||||
DCD I2C1_ER_IRQHandler ; I2C1 Error
|
||||
DCD I2C2_EV_IRQHandler ; I2C2 Event
|
||||
DCD I2C2_ER_IRQHandler ; I2C2 Error
|
||||
DCD SPI1_IRQHandler ; SPI1
|
||||
DCD SPI2_IRQHandler ; SPI2
|
||||
DCD USART1_IRQHandler ; USART1
|
||||
DCD USART2_IRQHandler ; USART2
|
||||
DCD USART3_IRQHandler ; USART3
|
||||
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
|
||||
DCD RTC_Alarm_IRQHandler ; RTC Alarm through EXTI Line
|
||||
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
|
||||
__Vectors_End
|
||||
|
||||
__Vectors_Size EQU __Vectors_End - __Vectors
|
||||
|
||||
AREA |.text|, CODE, READONLY
|
||||
|
||||
; Reset handler
|
||||
Reset_Handler PROC
|
||||
EXPORT Reset_Handler [WEAK]
|
||||
IMPORT __main
|
||||
IMPORT SystemInit
|
||||
LDR R0, =SystemInit
|
||||
BLX R0
|
||||
LDR R0, =__main
|
||||
BX R0
|
||||
ENDP
|
||||
|
||||
; Dummy Exception Handlers (infinite loops which can be modified)
|
||||
|
||||
NMI_Handler PROC
|
||||
EXPORT NMI_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
HardFault_Handler\
|
||||
PROC
|
||||
EXPORT HardFault_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
MemManage_Handler\
|
||||
PROC
|
||||
EXPORT MemManage_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
BusFault_Handler\
|
||||
PROC
|
||||
EXPORT BusFault_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
UsageFault_Handler\
|
||||
PROC
|
||||
EXPORT UsageFault_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
SVC_Handler PROC
|
||||
EXPORT SVC_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
DebugMon_Handler\
|
||||
PROC
|
||||
EXPORT DebugMon_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
PendSV_Handler PROC
|
||||
EXPORT PendSV_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
SysTick_Handler PROC
|
||||
EXPORT SysTick_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
|
||||
Default_Handler PROC
|
||||
|
||||
EXPORT WWDG_IRQHandler [WEAK]
|
||||
EXPORT PVD_IRQHandler [WEAK]
|
||||
EXPORT TAMPER_IRQHandler [WEAK]
|
||||
EXPORT RTC_IRQHandler [WEAK]
|
||||
EXPORT FLASH_IRQHandler [WEAK]
|
||||
EXPORT RCC_IRQHandler [WEAK]
|
||||
EXPORT EXTI0_IRQHandler [WEAK]
|
||||
EXPORT EXTI1_IRQHandler [WEAK]
|
||||
EXPORT EXTI2_IRQHandler [WEAK]
|
||||
EXPORT EXTI3_IRQHandler [WEAK]
|
||||
EXPORT EXTI4_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel1_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel2_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel3_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel4_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel5_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel6_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel7_IRQHandler [WEAK]
|
||||
EXPORT ADC1_2_IRQHandler [WEAK]
|
||||
EXPORT USB_HP_CAN1_TX_IRQHandler [WEAK]
|
||||
EXPORT USB_LP_CAN1_RX0_IRQHandler [WEAK]
|
||||
EXPORT CAN1_RX1_IRQHandler [WEAK]
|
||||
EXPORT CAN1_SCE_IRQHandler [WEAK]
|
||||
EXPORT EXTI9_5_IRQHandler [WEAK]
|
||||
EXPORT TIM1_BRK_IRQHandler [WEAK]
|
||||
EXPORT TIM1_UP_IRQHandler [WEAK]
|
||||
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
|
||||
EXPORT TIM1_CC_IRQHandler [WEAK]
|
||||
EXPORT TIM2_IRQHandler [WEAK]
|
||||
EXPORT TIM3_IRQHandler [WEAK]
|
||||
EXPORT TIM4_IRQHandler [WEAK]
|
||||
EXPORT I2C1_EV_IRQHandler [WEAK]
|
||||
EXPORT I2C1_ER_IRQHandler [WEAK]
|
||||
EXPORT I2C2_EV_IRQHandler [WEAK]
|
||||
EXPORT I2C2_ER_IRQHandler [WEAK]
|
||||
EXPORT SPI1_IRQHandler [WEAK]
|
||||
EXPORT SPI2_IRQHandler [WEAK]
|
||||
EXPORT USART1_IRQHandler [WEAK]
|
||||
EXPORT USART2_IRQHandler [WEAK]
|
||||
EXPORT USART3_IRQHandler [WEAK]
|
||||
EXPORT EXTI15_10_IRQHandler [WEAK]
|
||||
EXPORT RTC_Alarm_IRQHandler [WEAK]
|
||||
EXPORT USBWakeUp_IRQHandler [WEAK]
|
||||
|
||||
WWDG_IRQHandler
|
||||
PVD_IRQHandler
|
||||
TAMPER_IRQHandler
|
||||
RTC_IRQHandler
|
||||
FLASH_IRQHandler
|
||||
RCC_IRQHandler
|
||||
EXTI0_IRQHandler
|
||||
EXTI1_IRQHandler
|
||||
EXTI2_IRQHandler
|
||||
EXTI3_IRQHandler
|
||||
EXTI4_IRQHandler
|
||||
DMA1_Channel1_IRQHandler
|
||||
DMA1_Channel2_IRQHandler
|
||||
DMA1_Channel3_IRQHandler
|
||||
DMA1_Channel4_IRQHandler
|
||||
DMA1_Channel5_IRQHandler
|
||||
DMA1_Channel6_IRQHandler
|
||||
DMA1_Channel7_IRQHandler
|
||||
ADC1_2_IRQHandler
|
||||
USB_HP_CAN1_TX_IRQHandler
|
||||
USB_LP_CAN1_RX0_IRQHandler
|
||||
CAN1_RX1_IRQHandler
|
||||
CAN1_SCE_IRQHandler
|
||||
EXTI9_5_IRQHandler
|
||||
TIM1_BRK_IRQHandler
|
||||
TIM1_UP_IRQHandler
|
||||
TIM1_TRG_COM_IRQHandler
|
||||
TIM1_CC_IRQHandler
|
||||
TIM2_IRQHandler
|
||||
TIM3_IRQHandler
|
||||
TIM4_IRQHandler
|
||||
I2C1_EV_IRQHandler
|
||||
I2C1_ER_IRQHandler
|
||||
I2C2_EV_IRQHandler
|
||||
I2C2_ER_IRQHandler
|
||||
SPI1_IRQHandler
|
||||
SPI2_IRQHandler
|
||||
USART1_IRQHandler
|
||||
USART2_IRQHandler
|
||||
USART3_IRQHandler
|
||||
EXTI15_10_IRQHandler
|
||||
RTC_Alarm_IRQHandler
|
||||
USBWakeUp_IRQHandler
|
||||
|
||||
B .
|
||||
|
||||
ENDP
|
||||
|
||||
ALIGN
|
||||
|
||||
;*******************************************************************************
|
||||
; User Stack and Heap initialization
|
||||
;*******************************************************************************
|
||||
IF :DEF:__MICROLIB
|
||||
|
||||
EXPORT __initial_sp
|
||||
EXPORT __heap_base
|
||||
EXPORT __heap_limit
|
||||
|
||||
ELSE
|
||||
|
||||
IMPORT __use_two_region_memory
|
||||
EXPORT __user_initial_stackheap
|
||||
|
||||
__user_initial_stackheap
|
||||
|
||||
LDR R0, = Heap_Mem
|
||||
LDR R1, =(Stack_Mem + Stack_Size)
|
||||
LDR R2, = (Heap_Mem + Heap_Size)
|
||||
LDR R3, = Stack_Mem
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
|
||||
ENDIF
|
||||
|
||||
END
|
||||
|
||||
;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE*****
|
||||
@@ -0,0 +1,356 @@
|
||||
;******************** (C) COPYRIGHT 2017 STMicroelectronics ********************
|
||||
;* File Name : startup_stm32f103xe.s
|
||||
;* Author : MCD Application Team
|
||||
;* Description : STM32F103xE Devices vector table for MDK-ARM toolchain.
|
||||
;* This module performs:
|
||||
;* - Set the initial SP
|
||||
;* - Set the initial PC == Reset_Handler
|
||||
;* - Set the vector table entries with the exceptions ISR address
|
||||
;* - Configure the clock system
|
||||
;* - Branches to __main in the C library (which eventually
|
||||
;* calls main()).
|
||||
;* After Reset the Cortex-M3 processor is in Thread mode,
|
||||
;* priority is Privileged, and the Stack is set to Main.
|
||||
;******************************************************************************
|
||||
;* @attention
|
||||
;*
|
||||
;* Copyright (c) 2017 STMicroelectronics.
|
||||
;* All rights reserved.
|
||||
;*
|
||||
;* This software component is licensed by ST under BSD 3-Clause license,
|
||||
;* the "License"; You may not use this file except in compliance with the
|
||||
;* License. You may obtain a copy of the License at:
|
||||
;* opensource.org/licenses/BSD-3-Clause
|
||||
;*
|
||||
;******************************************************************************
|
||||
|
||||
; Amount of memory (in bytes) allocated for Stack
|
||||
; Tailor this value to your application needs
|
||||
; <h> Stack Configuration
|
||||
; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
||||
; </h>
|
||||
|
||||
Stack_Size EQU 0x00000400
|
||||
|
||||
AREA STACK, NOINIT, READWRITE, ALIGN=3
|
||||
Stack_Mem SPACE Stack_Size
|
||||
__initial_sp
|
||||
|
||||
; <h> Heap Configuration
|
||||
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
|
||||
; </h>
|
||||
|
||||
Heap_Size EQU 0x00000200
|
||||
|
||||
AREA HEAP, NOINIT, READWRITE, ALIGN=3
|
||||
__heap_base
|
||||
Heap_Mem SPACE Heap_Size
|
||||
__heap_limit
|
||||
|
||||
PRESERVE8
|
||||
THUMB
|
||||
|
||||
|
||||
; Vector Table Mapped to Address 0 at Reset
|
||||
AREA RESET, DATA, READONLY
|
||||
EXPORT __Vectors
|
||||
EXPORT __Vectors_End
|
||||
EXPORT __Vectors_Size
|
||||
|
||||
__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 DebugMon_Handler ; Debug Monitor Handler
|
||||
DCD 0 ; Reserved
|
||||
DCD PendSV_Handler ; PendSV Handler
|
||||
DCD SysTick_Handler ; SysTick Handler
|
||||
|
||||
; External Interrupts
|
||||
DCD WWDG_IRQHandler ; Window Watchdog
|
||||
DCD PVD_IRQHandler ; PVD through EXTI Line detect
|
||||
DCD TAMPER_IRQHandler ; Tamper
|
||||
DCD RTC_IRQHandler ; RTC
|
||||
DCD FLASH_IRQHandler ; Flash
|
||||
DCD RCC_IRQHandler ; RCC
|
||||
DCD EXTI0_IRQHandler ; EXTI Line 0
|
||||
DCD EXTI1_IRQHandler ; EXTI Line 1
|
||||
DCD EXTI2_IRQHandler ; EXTI Line 2
|
||||
DCD EXTI3_IRQHandler ; EXTI Line 3
|
||||
DCD EXTI4_IRQHandler ; EXTI Line 4
|
||||
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
|
||||
DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2
|
||||
DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3
|
||||
DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4
|
||||
DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5
|
||||
DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6
|
||||
DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7
|
||||
DCD ADC1_2_IRQHandler ; ADC1 & ADC2
|
||||
DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX
|
||||
DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0
|
||||
DCD CAN1_RX1_IRQHandler ; CAN1 RX1
|
||||
DCD CAN1_SCE_IRQHandler ; CAN1 SCE
|
||||
DCD EXTI9_5_IRQHandler ; EXTI Line 9..5
|
||||
DCD TIM1_BRK_IRQHandler ; TIM1 Break
|
||||
DCD TIM1_UP_IRQHandler ; TIM1 Update
|
||||
DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation
|
||||
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
|
||||
DCD TIM2_IRQHandler ; TIM2
|
||||
DCD TIM3_IRQHandler ; TIM3
|
||||
DCD TIM4_IRQHandler ; TIM4
|
||||
DCD I2C1_EV_IRQHandler ; I2C1 Event
|
||||
DCD I2C1_ER_IRQHandler ; I2C1 Error
|
||||
DCD I2C2_EV_IRQHandler ; I2C2 Event
|
||||
DCD I2C2_ER_IRQHandler ; I2C2 Error
|
||||
DCD SPI1_IRQHandler ; SPI1
|
||||
DCD SPI2_IRQHandler ; SPI2
|
||||
DCD USART1_IRQHandler ; USART1
|
||||
DCD USART2_IRQHandler ; USART2
|
||||
DCD USART3_IRQHandler ; USART3
|
||||
DCD EXTI15_10_IRQHandler ; EXTI Line 15..10
|
||||
DCD RTC_Alarm_IRQHandler ; RTC Alarm through EXTI Line
|
||||
DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend
|
||||
DCD TIM8_BRK_IRQHandler ; TIM8 Break
|
||||
DCD TIM8_UP_IRQHandler ; TIM8 Update
|
||||
DCD TIM8_TRG_COM_IRQHandler ; TIM8 Trigger and Commutation
|
||||
DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare
|
||||
DCD ADC3_IRQHandler ; ADC3
|
||||
DCD FSMC_IRQHandler ; FSMC
|
||||
DCD SDIO_IRQHandler ; SDIO
|
||||
DCD TIM5_IRQHandler ; TIM5
|
||||
DCD SPI3_IRQHandler ; SPI3
|
||||
DCD UART4_IRQHandler ; UART4
|
||||
DCD UART5_IRQHandler ; UART5
|
||||
DCD TIM6_IRQHandler ; TIM6
|
||||
DCD TIM7_IRQHandler ; TIM7
|
||||
DCD DMA2_Channel1_IRQHandler ; DMA2 Channel1
|
||||
DCD DMA2_Channel2_IRQHandler ; DMA2 Channel2
|
||||
DCD DMA2_Channel3_IRQHandler ; DMA2 Channel3
|
||||
DCD DMA2_Channel4_5_IRQHandler ; DMA2 Channel4 & Channel5
|
||||
__Vectors_End
|
||||
|
||||
__Vectors_Size EQU __Vectors_End - __Vectors
|
||||
|
||||
AREA |.text|, CODE, READONLY
|
||||
|
||||
; Reset handler
|
||||
Reset_Handler PROC
|
||||
EXPORT Reset_Handler [WEAK]
|
||||
IMPORT __main
|
||||
IMPORT SystemInit
|
||||
LDR R0, =SystemInit
|
||||
BLX R0
|
||||
LDR R0, =__main
|
||||
BX R0
|
||||
ENDP
|
||||
|
||||
; Dummy Exception Handlers (infinite loops which can be modified)
|
||||
|
||||
NMI_Handler PROC
|
||||
EXPORT NMI_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
HardFault_Handler\
|
||||
PROC
|
||||
EXPORT HardFault_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
MemManage_Handler\
|
||||
PROC
|
||||
EXPORT MemManage_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
BusFault_Handler\
|
||||
PROC
|
||||
EXPORT BusFault_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
UsageFault_Handler\
|
||||
PROC
|
||||
EXPORT UsageFault_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
SVC_Handler PROC
|
||||
EXPORT SVC_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
DebugMon_Handler\
|
||||
PROC
|
||||
EXPORT DebugMon_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
PendSV_Handler PROC
|
||||
EXPORT PendSV_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
SysTick_Handler PROC
|
||||
EXPORT SysTick_Handler [WEAK]
|
||||
B .
|
||||
ENDP
|
||||
|
||||
Default_Handler PROC
|
||||
|
||||
EXPORT WWDG_IRQHandler [WEAK]
|
||||
EXPORT PVD_IRQHandler [WEAK]
|
||||
EXPORT TAMPER_IRQHandler [WEAK]
|
||||
EXPORT RTC_IRQHandler [WEAK]
|
||||
EXPORT FLASH_IRQHandler [WEAK]
|
||||
EXPORT RCC_IRQHandler [WEAK]
|
||||
EXPORT EXTI0_IRQHandler [WEAK]
|
||||
EXPORT EXTI1_IRQHandler [WEAK]
|
||||
EXPORT EXTI2_IRQHandler [WEAK]
|
||||
EXPORT EXTI3_IRQHandler [WEAK]
|
||||
EXPORT EXTI4_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel1_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel2_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel3_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel4_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel5_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel6_IRQHandler [WEAK]
|
||||
EXPORT DMA1_Channel7_IRQHandler [WEAK]
|
||||
EXPORT ADC1_2_IRQHandler [WEAK]
|
||||
EXPORT USB_HP_CAN1_TX_IRQHandler [WEAK]
|
||||
EXPORT USB_LP_CAN1_RX0_IRQHandler [WEAK]
|
||||
EXPORT CAN1_RX1_IRQHandler [WEAK]
|
||||
EXPORT CAN1_SCE_IRQHandler [WEAK]
|
||||
EXPORT EXTI9_5_IRQHandler [WEAK]
|
||||
EXPORT TIM1_BRK_IRQHandler [WEAK]
|
||||
EXPORT TIM1_UP_IRQHandler [WEAK]
|
||||
EXPORT TIM1_TRG_COM_IRQHandler [WEAK]
|
||||
EXPORT TIM1_CC_IRQHandler [WEAK]
|
||||
EXPORT TIM2_IRQHandler [WEAK]
|
||||
EXPORT TIM3_IRQHandler [WEAK]
|
||||
EXPORT TIM4_IRQHandler [WEAK]
|
||||
EXPORT I2C1_EV_IRQHandler [WEAK]
|
||||
EXPORT I2C1_ER_IRQHandler [WEAK]
|
||||
EXPORT I2C2_EV_IRQHandler [WEAK]
|
||||
EXPORT I2C2_ER_IRQHandler [WEAK]
|
||||
EXPORT SPI1_IRQHandler [WEAK]
|
||||
EXPORT SPI2_IRQHandler [WEAK]
|
||||
EXPORT USART1_IRQHandler [WEAK]
|
||||
EXPORT USART2_IRQHandler [WEAK]
|
||||
EXPORT USART3_IRQHandler [WEAK]
|
||||
EXPORT EXTI15_10_IRQHandler [WEAK]
|
||||
EXPORT RTC_Alarm_IRQHandler [WEAK]
|
||||
EXPORT USBWakeUp_IRQHandler [WEAK]
|
||||
EXPORT TIM8_BRK_IRQHandler [WEAK]
|
||||
EXPORT TIM8_UP_IRQHandler [WEAK]
|
||||
EXPORT TIM8_TRG_COM_IRQHandler [WEAK]
|
||||
EXPORT TIM8_CC_IRQHandler [WEAK]
|
||||
EXPORT ADC3_IRQHandler [WEAK]
|
||||
EXPORT FSMC_IRQHandler [WEAK]
|
||||
EXPORT SDIO_IRQHandler [WEAK]
|
||||
EXPORT TIM5_IRQHandler [WEAK]
|
||||
EXPORT SPI3_IRQHandler [WEAK]
|
||||
EXPORT UART4_IRQHandler [WEAK]
|
||||
EXPORT UART5_IRQHandler [WEAK]
|
||||
EXPORT TIM6_IRQHandler [WEAK]
|
||||
EXPORT TIM7_IRQHandler [WEAK]
|
||||
EXPORT DMA2_Channel1_IRQHandler [WEAK]
|
||||
EXPORT DMA2_Channel2_IRQHandler [WEAK]
|
||||
EXPORT DMA2_Channel3_IRQHandler [WEAK]
|
||||
EXPORT DMA2_Channel4_5_IRQHandler [WEAK]
|
||||
|
||||
WWDG_IRQHandler
|
||||
PVD_IRQHandler
|
||||
TAMPER_IRQHandler
|
||||
RTC_IRQHandler
|
||||
FLASH_IRQHandler
|
||||
RCC_IRQHandler
|
||||
EXTI0_IRQHandler
|
||||
EXTI1_IRQHandler
|
||||
EXTI2_IRQHandler
|
||||
EXTI3_IRQHandler
|
||||
EXTI4_IRQHandler
|
||||
DMA1_Channel1_IRQHandler
|
||||
DMA1_Channel2_IRQHandler
|
||||
DMA1_Channel3_IRQHandler
|
||||
DMA1_Channel4_IRQHandler
|
||||
DMA1_Channel5_IRQHandler
|
||||
DMA1_Channel6_IRQHandler
|
||||
DMA1_Channel7_IRQHandler
|
||||
ADC1_2_IRQHandler
|
||||
USB_HP_CAN1_TX_IRQHandler
|
||||
USB_LP_CAN1_RX0_IRQHandler
|
||||
CAN1_RX1_IRQHandler
|
||||
CAN1_SCE_IRQHandler
|
||||
EXTI9_5_IRQHandler
|
||||
TIM1_BRK_IRQHandler
|
||||
TIM1_UP_IRQHandler
|
||||
TIM1_TRG_COM_IRQHandler
|
||||
TIM1_CC_IRQHandler
|
||||
TIM2_IRQHandler
|
||||
TIM3_IRQHandler
|
||||
TIM4_IRQHandler
|
||||
I2C1_EV_IRQHandler
|
||||
I2C1_ER_IRQHandler
|
||||
I2C2_EV_IRQHandler
|
||||
I2C2_ER_IRQHandler
|
||||
SPI1_IRQHandler
|
||||
SPI2_IRQHandler
|
||||
USART1_IRQHandler
|
||||
USART2_IRQHandler
|
||||
USART3_IRQHandler
|
||||
EXTI15_10_IRQHandler
|
||||
RTC_Alarm_IRQHandler
|
||||
USBWakeUp_IRQHandler
|
||||
TIM8_BRK_IRQHandler
|
||||
TIM8_UP_IRQHandler
|
||||
TIM8_TRG_COM_IRQHandler
|
||||
TIM8_CC_IRQHandler
|
||||
ADC3_IRQHandler
|
||||
FSMC_IRQHandler
|
||||
SDIO_IRQHandler
|
||||
TIM5_IRQHandler
|
||||
SPI3_IRQHandler
|
||||
UART4_IRQHandler
|
||||
UART5_IRQHandler
|
||||
TIM6_IRQHandler
|
||||
TIM7_IRQHandler
|
||||
DMA2_Channel1_IRQHandler
|
||||
DMA2_Channel2_IRQHandler
|
||||
DMA2_Channel3_IRQHandler
|
||||
DMA2_Channel4_5_IRQHandler
|
||||
B .
|
||||
|
||||
ENDP
|
||||
|
||||
ALIGN
|
||||
|
||||
;*******************************************************************************
|
||||
; User Stack and Heap initialization
|
||||
;*******************************************************************************
|
||||
IF :DEF:__MICROLIB
|
||||
|
||||
EXPORT __initial_sp
|
||||
EXPORT __heap_base
|
||||
EXPORT __heap_limit
|
||||
|
||||
ELSE
|
||||
|
||||
IMPORT __use_two_region_memory
|
||||
EXPORT __user_initial_stackheap
|
||||
|
||||
__user_initial_stackheap
|
||||
|
||||
LDR R0, = Heap_Mem
|
||||
LDR R1, =(Stack_Mem + Stack_Size)
|
||||
LDR R2, = (Heap_Mem + Heap_Size)
|
||||
LDR R3, = Stack_Mem
|
||||
BX LR
|
||||
|
||||
ALIGN
|
||||
|
||||
ENDIF
|
||||
|
||||
END
|
||||
|
||||
;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE*****
|
||||
@@ -0,0 +1,408 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f1xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
|
||||
*
|
||||
* 1. This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
|
||||
* factors, AHB/APBx prescalers and Flash settings).
|
||||
* This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32f1xx_xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
|
||||
* the product used), refer to "HSE_VALUE".
|
||||
* When HSE is used as system clock source, directly or through PLL, and you
|
||||
* are using different crystal you have to adapt the HSE value to your own
|
||||
* configuration.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f1xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32f1xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/*!< Uncomment the following line if you need to use external SRAM */
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/* Note: Following vector table addresses must be defined in line with linker
|
||||
configuration. */
|
||||
/*!< Uncomment the following line if you need to relocate the vector table
|
||||
anywhere in Flash or Sram, else the vector table is kept at the automatic
|
||||
remap of boot address selected */
|
||||
/* #define USER_VECT_TAB_ADDRESS */
|
||||
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||
in Sram else user remap will be done in Flash. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#if defined(VECT_TAB_SRAM)
|
||||
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#else
|
||||
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#endif /* VECT_TAB_SRAM */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* This variable is updated in three ways:
|
||||
1) by calling CMSIS function SystemCoreClockUpdate()
|
||||
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
|
||||
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
|
||||
Note: If you use this function to configure the system clock; then there
|
||||
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||
variable is updated automatically.
|
||||
*/
|
||||
uint32_t SystemCoreClock = 16000000;
|
||||
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
static void SystemInit_ExtMemCtl(void);
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
* Initialize the Embedded Flash Interface, the PLL and update the
|
||||
* SystemCoreClock variable.
|
||||
* @note This function should be used only after reset.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit (void)
|
||||
{
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
SystemInit_ExtMemCtl();
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif
|
||||
|
||||
/* Configure the Vector Table location -------------------------------------*/
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
* or HSI_VALUE(*) multiplied by the PLL factors.
|
||||
*
|
||||
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||
* 8 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||
* 8 MHz or 25 MHz, depending on the product used), user has to ensure
|
||||
* that HSE_VALUE is same as the real frequency of the crystal used.
|
||||
* Otherwise, this function may have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate (void)
|
||||
{
|
||||
uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U;
|
||||
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
|
||||
#endif /* STM32F105xC */
|
||||
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||
uint32_t prediv1factor = 0U;
|
||||
#endif /* STM32F100xB or STM32F100xE */
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case 0x00U: /* HSI used as system clock */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case 0x04U: /* HSE used as system clock */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case 0x08U: /* PLL used as system clock */
|
||||
|
||||
/* Get PLL clock source and multiplication factor ----------------------*/
|
||||
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
|
||||
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
|
||||
|
||||
#if !defined(STM32F105xC) && !defined(STM32F107xC)
|
||||
pllmull = ( pllmull >> 18U) + 2U;
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
#else
|
||||
/* HSE selected as PLL clock entry */
|
||||
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
|
||||
{/* HSE oscillator clock divided by 2 */
|
||||
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemCoreClock = HSE_VALUE * pllmull;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
pllmull = pllmull >> 18U;
|
||||
|
||||
if (pllmull != 0x0DU)
|
||||
{
|
||||
pllmull += 2U;
|
||||
}
|
||||
else
|
||||
{ /* PLL multiplication factor = PLL input clock * 6.5 */
|
||||
pllmull = 13U / 2U;
|
||||
}
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PREDIV1 selected as PLL clock entry */
|
||||
|
||||
/* Get PREDIV1 clock source and division factor */
|
||||
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
|
||||
if (prediv1source == 0U)
|
||||
{
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PLL2 clock selected as PREDIV1 clock entry */
|
||||
|
||||
/* Get PREDIV2 division factor and PLL2 multiplication factor */
|
||||
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
|
||||
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U;
|
||||
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
|
||||
}
|
||||
}
|
||||
#endif /* STM32F105xC */
|
||||
break;
|
||||
|
||||
default:
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Compute HCLK clock frequency ----------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/**
|
||||
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
|
||||
* before jump to __main
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
/**
|
||||
* @brief Setup the external memory controller.
|
||||
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
|
||||
* This function configures the external SRAM mounted on STM3210E-EVAL
|
||||
* board (STM32 High density devices). This SRAM will be used as program
|
||||
* data memory (including heap and stack).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit_ExtMemCtl(void)
|
||||
{
|
||||
__IO uint32_t tmpreg;
|
||||
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
|
||||
required, then adjust the Register Addresses */
|
||||
|
||||
/* Enable FSMC clock */
|
||||
RCC->AHBENR = 0x00000114U;
|
||||
|
||||
/* Delay after an RCC peripheral clock enabling */
|
||||
tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
|
||||
|
||||
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
|
||||
RCC->APB2ENR = 0x000001E0U;
|
||||
|
||||
/* Delay after an RCC peripheral clock enabling */
|
||||
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
|
||||
|
||||
(void)(tmpreg);
|
||||
|
||||
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
|
||||
/*---------------- SRAM Address lines configuration -------------------------*/
|
||||
/*---------------- NOE and NWE configuration --------------------------------*/
|
||||
/*---------------- NE3 configuration ----------------------------------------*/
|
||||
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
|
||||
|
||||
GPIOD->CRL = 0x44BB44BBU;
|
||||
GPIOD->CRH = 0xBBBBBBBBU;
|
||||
|
||||
GPIOE->CRL = 0xB44444BBU;
|
||||
GPIOE->CRH = 0xBBBBBBBBU;
|
||||
|
||||
GPIOF->CRL = 0x44BBBBBBU;
|
||||
GPIOF->CRH = 0xBBBB4444U;
|
||||
|
||||
GPIOG->CRL = 0x44BBBBBBU;
|
||||
GPIOG->CRH = 0x444B4B44U;
|
||||
|
||||
/*---------------- FSMC Configuration ---------------------------------------*/
|
||||
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
|
||||
|
||||
FSMC_Bank1->BTCR[4U] = 0x00001091U;
|
||||
FSMC_Bank1->BTCR[5U] = 0x00110212U;
|
||||
}
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
865
Drivers/BSP/CMSIS/Include/cmsis_armcc.h
Normal file
865
Drivers/BSP/CMSIS/Include/cmsis_armcc.h
Normal file
@@ -0,0 +1,865 @@
|
||||
/**************************************************************************//**
|
||||
* @file cmsis_armcc.h
|
||||
* @brief CMSIS compiler ARMCC (Arm Compiler 5) header file
|
||||
* @version V5.0.4
|
||||
* @date 10. January 2018
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __CMSIS_ARMCC_H
|
||||
#define __CMSIS_ARMCC_H
|
||||
|
||||
|
||||
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
|
||||
#error "Please use Arm Compiler Toolchain V4.0.677 or later!"
|
||||
#endif
|
||||
|
||||
/* CMSIS compiler control architecture macros */
|
||||
#if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \
|
||||
(defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) )
|
||||
#define __ARM_ARCH_6M__ 1
|
||||
#endif
|
||||
|
||||
#if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1))
|
||||
#define __ARM_ARCH_7M__ 1
|
||||
#endif
|
||||
|
||||
#if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1))
|
||||
#define __ARM_ARCH_7EM__ 1
|
||||
#endif
|
||||
|
||||
/* __ARM_ARCH_8M_BASE__ not applicable */
|
||||
/* __ARM_ARCH_8M_MAIN__ not applicable */
|
||||
|
||||
|
||||
/* CMSIS compiler specific defines */
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE __inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static __inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE static __forceinline
|
||||
#endif
|
||||
#ifndef __NO_RETURN
|
||||
#define __NO_RETURN __declspec(noreturn)
|
||||
#endif
|
||||
#ifndef __USED
|
||||
#define __USED __attribute__((used))
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __attribute__((packed))
|
||||
#endif
|
||||
#ifndef __PACKED_STRUCT
|
||||
#define __PACKED_STRUCT __packed struct
|
||||
#endif
|
||||
#ifndef __PACKED_UNION
|
||||
#define __PACKED_UNION __packed union
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||
#define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x)))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT16_WRITE
|
||||
#define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT16_READ
|
||||
#define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr)))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32_WRITE
|
||||
#define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32_READ
|
||||
#define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
#ifndef __RESTRICT
|
||||
#define __RESTRICT __restrict
|
||||
#endif
|
||||
|
||||
/* ########################### Core Function Access ########################### */
|
||||
/** \ingroup CMSIS_Core_FunctionInterface
|
||||
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
|
||||
@{
|
||||
*/
|
||||
|
||||
/**
|
||||
\brief Enable IRQ Interrupts
|
||||
\details Enables IRQ interrupts by clearing the I-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
/* intrinsic void __enable_irq(); */
|
||||
|
||||
|
||||
/**
|
||||
\brief Disable IRQ Interrupts
|
||||
\details Disables IRQ interrupts by setting the I-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
/* intrinsic void __disable_irq(); */
|
||||
|
||||
/**
|
||||
\brief Get Control Register
|
||||
\details Returns the content of the Control Register.
|
||||
\return Control Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_CONTROL(void)
|
||||
{
|
||||
register uint32_t __regControl __ASM("control");
|
||||
return(__regControl);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set Control Register
|
||||
\details Writes the given value to the Control Register.
|
||||
\param [in] control Control Register value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_CONTROL(uint32_t control)
|
||||
{
|
||||
register uint32_t __regControl __ASM("control");
|
||||
__regControl = control;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get IPSR Register
|
||||
\details Returns the content of the IPSR Register.
|
||||
\return IPSR Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_IPSR(void)
|
||||
{
|
||||
register uint32_t __regIPSR __ASM("ipsr");
|
||||
return(__regIPSR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get APSR Register
|
||||
\details Returns the content of the APSR Register.
|
||||
\return APSR Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_APSR(void)
|
||||
{
|
||||
register uint32_t __regAPSR __ASM("apsr");
|
||||
return(__regAPSR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get xPSR Register
|
||||
\details Returns the content of the xPSR Register.
|
||||
\return xPSR Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_xPSR(void)
|
||||
{
|
||||
register uint32_t __regXPSR __ASM("xpsr");
|
||||
return(__regXPSR);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get Process Stack Pointer
|
||||
\details Returns the current value of the Process Stack Pointer (PSP).
|
||||
\return PSP Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_PSP(void)
|
||||
{
|
||||
register uint32_t __regProcessStackPointer __ASM("psp");
|
||||
return(__regProcessStackPointer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set Process Stack Pointer
|
||||
\details Assigns the given value to the Process Stack Pointer (PSP).
|
||||
\param [in] topOfProcStack Process Stack Pointer value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
|
||||
{
|
||||
register uint32_t __regProcessStackPointer __ASM("psp");
|
||||
__regProcessStackPointer = topOfProcStack;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get Main Stack Pointer
|
||||
\details Returns the current value of the Main Stack Pointer (MSP).
|
||||
\return MSP Register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_MSP(void)
|
||||
{
|
||||
register uint32_t __regMainStackPointer __ASM("msp");
|
||||
return(__regMainStackPointer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set Main Stack Pointer
|
||||
\details Assigns the given value to the Main Stack Pointer (MSP).
|
||||
\param [in] topOfMainStack Main Stack Pointer value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
|
||||
{
|
||||
register uint32_t __regMainStackPointer __ASM("msp");
|
||||
__regMainStackPointer = topOfMainStack;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get Priority Mask
|
||||
\details Returns the current state of the priority mask bit from the Priority Mask Register.
|
||||
\return Priority Mask value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_PRIMASK(void)
|
||||
{
|
||||
register uint32_t __regPriMask __ASM("primask");
|
||||
return(__regPriMask);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set Priority Mask
|
||||
\details Assigns the given value to the Priority Mask Register.
|
||||
\param [in] priMask Priority Mask
|
||||
*/
|
||||
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
|
||||
{
|
||||
register uint32_t __regPriMask __ASM("primask");
|
||||
__regPriMask = (priMask);
|
||||
}
|
||||
|
||||
|
||||
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||
|
||||
/**
|
||||
\brief Enable FIQ
|
||||
\details Enables FIQ interrupts by clearing the F-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
#define __enable_fault_irq __enable_fiq
|
||||
|
||||
|
||||
/**
|
||||
\brief Disable FIQ
|
||||
\details Disables FIQ interrupts by setting the F-bit in the CPSR.
|
||||
Can only be executed in Privileged modes.
|
||||
*/
|
||||
#define __disable_fault_irq __disable_fiq
|
||||
|
||||
|
||||
/**
|
||||
\brief Get Base Priority
|
||||
\details Returns the current value of the Base Priority register.
|
||||
\return Base Priority register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_BASEPRI(void)
|
||||
{
|
||||
register uint32_t __regBasePri __ASM("basepri");
|
||||
return(__regBasePri);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set Base Priority
|
||||
\details Assigns the given value to the Base Priority register.
|
||||
\param [in] basePri Base Priority value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
|
||||
{
|
||||
register uint32_t __regBasePri __ASM("basepri");
|
||||
__regBasePri = (basePri & 0xFFU);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set Base Priority with condition
|
||||
\details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
|
||||
or the new value increases the BASEPRI priority level.
|
||||
\param [in] basePri Base Priority value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
|
||||
{
|
||||
register uint32_t __regBasePriMax __ASM("basepri_max");
|
||||
__regBasePriMax = (basePri & 0xFFU);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Get Fault Mask
|
||||
\details Returns the current value of the Fault Mask register.
|
||||
\return Fault Mask register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_FAULTMASK(void)
|
||||
{
|
||||
register uint32_t __regFaultMask __ASM("faultmask");
|
||||
return(__regFaultMask);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set Fault Mask
|
||||
\details Assigns the given value to the Fault Mask register.
|
||||
\param [in] faultMask Fault Mask value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
|
||||
{
|
||||
register uint32_t __regFaultMask __ASM("faultmask");
|
||||
__regFaultMask = (faultMask & (uint32_t)1U);
|
||||
}
|
||||
|
||||
#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
|
||||
|
||||
|
||||
/**
|
||||
\brief Get FPSCR
|
||||
\details Returns the current value of the Floating Point Status/Control register.
|
||||
\return Floating Point Status/Control register value
|
||||
*/
|
||||
__STATIC_INLINE uint32_t __get_FPSCR(void)
|
||||
{
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||
register uint32_t __regfpscr __ASM("fpscr");
|
||||
return(__regfpscr);
|
||||
#else
|
||||
return(0U);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set FPSCR
|
||||
\details Assigns the given value to the Floating Point Status/Control register.
|
||||
\param [in] fpscr Floating Point Status/Control value to set
|
||||
*/
|
||||
__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
|
||||
{
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||
register uint32_t __regfpscr __ASM("fpscr");
|
||||
__regfpscr = (fpscr);
|
||||
#else
|
||||
(void)fpscr;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*@} end of CMSIS_Core_RegAccFunctions */
|
||||
|
||||
|
||||
/* ########################## Core Instruction Access ######################### */
|
||||
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
|
||||
Access to dedicated instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
/**
|
||||
\brief No Operation
|
||||
\details No Operation does nothing. This instruction can be used for code alignment purposes.
|
||||
*/
|
||||
#define __NOP __nop
|
||||
|
||||
|
||||
/**
|
||||
\brief Wait For Interrupt
|
||||
\details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
|
||||
*/
|
||||
#define __WFI __wfi
|
||||
|
||||
|
||||
/**
|
||||
\brief Wait For Event
|
||||
\details Wait For Event is a hint instruction that permits the processor to enter
|
||||
a low-power state until one of a number of events occurs.
|
||||
*/
|
||||
#define __WFE __wfe
|
||||
|
||||
|
||||
/**
|
||||
\brief Send Event
|
||||
\details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
|
||||
*/
|
||||
#define __SEV __sev
|
||||
|
||||
|
||||
/**
|
||||
\brief Instruction Synchronization Barrier
|
||||
\details Instruction Synchronization Barrier flushes the pipeline in the processor,
|
||||
so that all instructions following the ISB are fetched from cache or memory,
|
||||
after the instruction has been completed.
|
||||
*/
|
||||
#define __ISB() do {\
|
||||
__schedule_barrier();\
|
||||
__isb(0xF);\
|
||||
__schedule_barrier();\
|
||||
} while (0U)
|
||||
|
||||
/**
|
||||
\brief Data Synchronization Barrier
|
||||
\details Acts as a special kind of Data Memory Barrier.
|
||||
It completes when all explicit memory accesses before this instruction complete.
|
||||
*/
|
||||
#define __DSB() do {\
|
||||
__schedule_barrier();\
|
||||
__dsb(0xF);\
|
||||
__schedule_barrier();\
|
||||
} while (0U)
|
||||
|
||||
/**
|
||||
\brief Data Memory Barrier
|
||||
\details Ensures the apparent order of the explicit memory operations before
|
||||
and after the instruction, without ensuring their completion.
|
||||
*/
|
||||
#define __DMB() do {\
|
||||
__schedule_barrier();\
|
||||
__dmb(0xF);\
|
||||
__schedule_barrier();\
|
||||
} while (0U)
|
||||
|
||||
|
||||
/**
|
||||
\brief Reverse byte order (32 bit)
|
||||
\details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#define __REV __rev
|
||||
|
||||
|
||||
/**
|
||||
\brief Reverse byte order (16 bit)
|
||||
\details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#ifndef __NO_EMBEDDED_ASM
|
||||
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
|
||||
{
|
||||
rev16 r0, r0
|
||||
bx lr
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief Reverse byte order (16 bit)
|
||||
\details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#ifndef __NO_EMBEDDED_ASM
|
||||
__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value)
|
||||
{
|
||||
revsh r0, r0
|
||||
bx lr
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief Rotate Right in unsigned value (32 bit)
|
||||
\details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
|
||||
\param [in] op1 Value to rotate
|
||||
\param [in] op2 Number of Bits to rotate
|
||||
\return Rotated value
|
||||
*/
|
||||
#define __ROR __ror
|
||||
|
||||
|
||||
/**
|
||||
\brief Breakpoint
|
||||
\details Causes the processor to enter Debug state.
|
||||
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
|
||||
\param [in] value is ignored by the processor.
|
||||
If required, a debugger can use it to store additional information about the breakpoint.
|
||||
*/
|
||||
#define __BKPT(value) __breakpoint(value)
|
||||
|
||||
|
||||
/**
|
||||
\brief Reverse bit order of value
|
||||
\details Reverses the bit order of the given value.
|
||||
\param [in] value Value to reverse
|
||||
\return Reversed value
|
||||
*/
|
||||
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||
#define __RBIT __rbit
|
||||
#else
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
|
||||
{
|
||||
uint32_t result;
|
||||
uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
|
||||
|
||||
result = value; /* r will be reversed bits of v; first get LSB of v */
|
||||
for (value >>= 1U; value != 0U; value >>= 1U)
|
||||
{
|
||||
result <<= 1U;
|
||||
result |= value & 1U;
|
||||
s--;
|
||||
}
|
||||
result <<= s; /* shift when v's highest bits are zero */
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief Count leading zeros
|
||||
\details Counts the number of leading zeros of a data value.
|
||||
\param [in] value Value to count the leading zeros
|
||||
\return number of leading zeros in value
|
||||
*/
|
||||
#define __CLZ __clz
|
||||
|
||||
|
||||
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||
|
||||
/**
|
||||
\brief LDR Exclusive (8 bit)
|
||||
\details Executes a exclusive LDR instruction for 8 bit value.
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
|
||||
#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
|
||||
#else
|
||||
#define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop")
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief LDR Exclusive (16 bit)
|
||||
\details Executes a exclusive LDR instruction for 16 bit values.
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
|
||||
#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
|
||||
#else
|
||||
#define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop")
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief LDR Exclusive (32 bit)
|
||||
\details Executes a exclusive LDR instruction for 32 bit values.
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
|
||||
#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
|
||||
#else
|
||||
#define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop")
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief STR Exclusive (8 bit)
|
||||
\details Executes a exclusive STR instruction for 8 bit values.
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
|
||||
#define __STREXB(value, ptr) __strex(value, ptr)
|
||||
#else
|
||||
#define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief STR Exclusive (16 bit)
|
||||
\details Executes a exclusive STR instruction for 16 bit values.
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
|
||||
#define __STREXH(value, ptr) __strex(value, ptr)
|
||||
#else
|
||||
#define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief STR Exclusive (32 bit)
|
||||
\details Executes a exclusive STR instruction for 32 bit values.
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
\return 0 Function succeeded
|
||||
\return 1 Function failed
|
||||
*/
|
||||
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
|
||||
#define __STREXW(value, ptr) __strex(value, ptr)
|
||||
#else
|
||||
#define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief Remove the exclusive lock
|
||||
\details Removes the exclusive lock which is created by LDREX.
|
||||
*/
|
||||
#define __CLREX __clrex
|
||||
|
||||
|
||||
/**
|
||||
\brief Signed Saturate
|
||||
\details Saturates a signed value.
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (1..32)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __SSAT __ssat
|
||||
|
||||
|
||||
/**
|
||||
\brief Unsigned Saturate
|
||||
\details Saturates an unsigned value.
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (0..31)
|
||||
\return Saturated value
|
||||
*/
|
||||
#define __USAT __usat
|
||||
|
||||
|
||||
/**
|
||||
\brief Rotate Right with Extend (32 bit)
|
||||
\details Moves each bit of a bitstring right by one bit.
|
||||
The carry input is shifted in at the left end of the bitstring.
|
||||
\param [in] value Value to rotate
|
||||
\return Rotated value
|
||||
*/
|
||||
#ifndef __NO_EMBEDDED_ASM
|
||||
__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
|
||||
{
|
||||
rrx r0, r0
|
||||
bx lr
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
\brief LDRT Unprivileged (8 bit)
|
||||
\details Executes a Unprivileged LDRT instruction for 8 bit value.
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint8_t at (*ptr)
|
||||
*/
|
||||
#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
|
||||
|
||||
|
||||
/**
|
||||
\brief LDRT Unprivileged (16 bit)
|
||||
\details Executes a Unprivileged LDRT instruction for 16 bit values.
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint16_t at (*ptr)
|
||||
*/
|
||||
#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
|
||||
|
||||
|
||||
/**
|
||||
\brief LDRT Unprivileged (32 bit)
|
||||
\details Executes a Unprivileged LDRT instruction for 32 bit values.
|
||||
\param [in] ptr Pointer to data
|
||||
\return value of type uint32_t at (*ptr)
|
||||
*/
|
||||
#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
|
||||
|
||||
|
||||
/**
|
||||
\brief STRT Unprivileged (8 bit)
|
||||
\details Executes a Unprivileged STRT instruction for 8 bit values.
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
#define __STRBT(value, ptr) __strt(value, ptr)
|
||||
|
||||
|
||||
/**
|
||||
\brief STRT Unprivileged (16 bit)
|
||||
\details Executes a Unprivileged STRT instruction for 16 bit values.
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
#define __STRHT(value, ptr) __strt(value, ptr)
|
||||
|
||||
|
||||
/**
|
||||
\brief STRT Unprivileged (32 bit)
|
||||
\details Executes a Unprivileged STRT instruction for 32 bit values.
|
||||
\param [in] value Value to store
|
||||
\param [in] ptr Pointer to location
|
||||
*/
|
||||
#define __STRT(value, ptr) __strt(value, ptr)
|
||||
|
||||
#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
|
||||
|
||||
/**
|
||||
\brief Signed Saturate
|
||||
\details Saturates a signed value.
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (1..32)
|
||||
\return Saturated value
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
|
||||
{
|
||||
if ((sat >= 1U) && (sat <= 32U))
|
||||
{
|
||||
const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
|
||||
const int32_t min = -1 - max ;
|
||||
if (val > max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
else if (val < min)
|
||||
{
|
||||
return min;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Unsigned Saturate
|
||||
\details Saturates an unsigned value.
|
||||
\param [in] value Value to be saturated
|
||||
\param [in] sat Bit position to saturate to (0..31)
|
||||
\return Saturated value
|
||||
*/
|
||||
__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
|
||||
{
|
||||
if (sat <= 31U)
|
||||
{
|
||||
const uint32_t max = ((1U << sat) - 1U);
|
||||
if (val > (int32_t)max)
|
||||
{
|
||||
return max;
|
||||
}
|
||||
else if (val < 0)
|
||||
{
|
||||
return 0U;
|
||||
}
|
||||
}
|
||||
return (uint32_t)val;
|
||||
}
|
||||
|
||||
#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
|
||||
|
||||
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
|
||||
|
||||
|
||||
/* ################### Compiler specific Intrinsics ########################### */
|
||||
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
|
||||
Access to dedicated SIMD instructions
|
||||
@{
|
||||
*/
|
||||
|
||||
#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
|
||||
|
||||
#define __SADD8 __sadd8
|
||||
#define __QADD8 __qadd8
|
||||
#define __SHADD8 __shadd8
|
||||
#define __UADD8 __uadd8
|
||||
#define __UQADD8 __uqadd8
|
||||
#define __UHADD8 __uhadd8
|
||||
#define __SSUB8 __ssub8
|
||||
#define __QSUB8 __qsub8
|
||||
#define __SHSUB8 __shsub8
|
||||
#define __USUB8 __usub8
|
||||
#define __UQSUB8 __uqsub8
|
||||
#define __UHSUB8 __uhsub8
|
||||
#define __SADD16 __sadd16
|
||||
#define __QADD16 __qadd16
|
||||
#define __SHADD16 __shadd16
|
||||
#define __UADD16 __uadd16
|
||||
#define __UQADD16 __uqadd16
|
||||
#define __UHADD16 __uhadd16
|
||||
#define __SSUB16 __ssub16
|
||||
#define __QSUB16 __qsub16
|
||||
#define __SHSUB16 __shsub16
|
||||
#define __USUB16 __usub16
|
||||
#define __UQSUB16 __uqsub16
|
||||
#define __UHSUB16 __uhsub16
|
||||
#define __SASX __sasx
|
||||
#define __QASX __qasx
|
||||
#define __SHASX __shasx
|
||||
#define __UASX __uasx
|
||||
#define __UQASX __uqasx
|
||||
#define __UHASX __uhasx
|
||||
#define __SSAX __ssax
|
||||
#define __QSAX __qsax
|
||||
#define __SHSAX __shsax
|
||||
#define __USAX __usax
|
||||
#define __UQSAX __uqsax
|
||||
#define __UHSAX __uhsax
|
||||
#define __USAD8 __usad8
|
||||
#define __USADA8 __usada8
|
||||
#define __SSAT16 __ssat16
|
||||
#define __USAT16 __usat16
|
||||
#define __UXTB16 __uxtb16
|
||||
#define __UXTAB16 __uxtab16
|
||||
#define __SXTB16 __sxtb16
|
||||
#define __SXTAB16 __sxtab16
|
||||
#define __SMUAD __smuad
|
||||
#define __SMUADX __smuadx
|
||||
#define __SMLAD __smlad
|
||||
#define __SMLADX __smladx
|
||||
#define __SMLALD __smlald
|
||||
#define __SMLALDX __smlaldx
|
||||
#define __SMUSD __smusd
|
||||
#define __SMUSDX __smusdx
|
||||
#define __SMLSD __smlsd
|
||||
#define __SMLSDX __smlsdx
|
||||
#define __SMLSLD __smlsld
|
||||
#define __SMLSLDX __smlsldx
|
||||
#define __SEL __sel
|
||||
#define __QADD __qadd
|
||||
#define __QSUB __qsub
|
||||
|
||||
#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
|
||||
((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
|
||||
|
||||
#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
|
||||
((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
|
||||
|
||||
#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
|
||||
((int64_t)(ARG3) << 32U) ) >> 32U))
|
||||
|
||||
#endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
|
||||
/*@} end of group CMSIS_SIMD_intrinsics */
|
||||
|
||||
|
||||
#endif /* __CMSIS_ARMCC_H */
|
||||
1869
Drivers/BSP/CMSIS/Include/cmsis_armclang.h
Normal file
1869
Drivers/BSP/CMSIS/Include/cmsis_armclang.h
Normal file
File diff suppressed because it is too large
Load Diff
266
Drivers/BSP/CMSIS/Include/cmsis_compiler.h
Normal file
266
Drivers/BSP/CMSIS/Include/cmsis_compiler.h
Normal file
@@ -0,0 +1,266 @@
|
||||
/**************************************************************************//**
|
||||
* @file cmsis_compiler.h
|
||||
* @brief CMSIS compiler generic header file
|
||||
* @version V5.0.4
|
||||
* @date 10. January 2018
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __CMSIS_COMPILER_H
|
||||
#define __CMSIS_COMPILER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* Arm Compiler 4/5
|
||||
*/
|
||||
#if defined ( __CC_ARM )
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
|
||||
/*
|
||||
* Arm Compiler 6 (armclang)
|
||||
*/
|
||||
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||
#include "cmsis_armclang.h"
|
||||
|
||||
|
||||
/*
|
||||
* GNU Compiler
|
||||
*/
|
||||
#elif defined ( __GNUC__ )
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
|
||||
/*
|
||||
* IAR Compiler
|
||||
*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
#include <cmsis_iccarm.h>
|
||||
|
||||
|
||||
/*
|
||||
* TI Arm Compiler
|
||||
*/
|
||||
#elif defined ( __TI_ARM__ )
|
||||
#include <cmsis_ccs.h>
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||
#endif
|
||||
#ifndef __NO_RETURN
|
||||
#define __NO_RETURN __attribute__((noreturn))
|
||||
#endif
|
||||
#ifndef __USED
|
||||
#define __USED __attribute__((used))
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __attribute__((packed))
|
||||
#endif
|
||||
#ifndef __PACKED_STRUCT
|
||||
#define __PACKED_STRUCT struct __attribute__((packed))
|
||||
#endif
|
||||
#ifndef __PACKED_UNION
|
||||
#define __PACKED_UNION union __attribute__((packed))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||
struct __attribute__((packed)) T_UINT32 { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT16_WRITE
|
||||
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
|
||||
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT16_READ
|
||||
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
|
||||
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32_WRITE
|
||||
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32_READ
|
||||
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __attribute__((aligned(x)))
|
||||
#endif
|
||||
#ifndef __RESTRICT
|
||||
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
|
||||
#define __RESTRICT
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* TASKING Compiler
|
||||
*/
|
||||
#elif defined ( __TASKING__ )
|
||||
/*
|
||||
* The CMSIS functions have been implemented as intrinsics in the compiler.
|
||||
* Please use "carm -?i" to get an up to date list of all intrinsics,
|
||||
* Including the CMSIS ones.
|
||||
*/
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||
#endif
|
||||
#ifndef __NO_RETURN
|
||||
#define __NO_RETURN __attribute__((noreturn))
|
||||
#endif
|
||||
#ifndef __USED
|
||||
#define __USED __attribute__((used))
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __attribute__((weak))
|
||||
#endif
|
||||
#ifndef __PACKED
|
||||
#define __PACKED __packed__
|
||||
#endif
|
||||
#ifndef __PACKED_STRUCT
|
||||
#define __PACKED_STRUCT struct __packed__
|
||||
#endif
|
||||
#ifndef __PACKED_UNION
|
||||
#define __PACKED_UNION union __packed__
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||
struct __packed__ T_UINT32 { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT16_WRITE
|
||||
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
|
||||
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT16_READ
|
||||
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
|
||||
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32_WRITE
|
||||
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32_READ
|
||||
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#define __ALIGNED(x) __align(x)
|
||||
#endif
|
||||
#ifndef __RESTRICT
|
||||
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
|
||||
#define __RESTRICT
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* COSMIC Compiler
|
||||
*/
|
||||
#elif defined ( __CSMC__ )
|
||||
#include <cmsis_csm.h>
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM _asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
#ifndef __STATIC_FORCEINLINE
|
||||
#define __STATIC_FORCEINLINE __STATIC_INLINE
|
||||
#endif
|
||||
#ifndef __NO_RETURN
|
||||
// NO RETURN is automatically detected hence no warning here
|
||||
#define __NO_RETURN
|
||||
#endif
|
||||
#ifndef __USED
|
||||
#warning No compiler specific solution for __USED. __USED is ignored.
|
||||
#define __USED
|
||||
#endif
|
||||
#ifndef __WEAK
|
||||
#define __WEAK __weak
|
||||
#endif
|
||||
#ifndef __PACKED
|
||||
#define __PACKED @packed
|
||||
#endif
|
||||
#ifndef __PACKED_STRUCT
|
||||
#define __PACKED_STRUCT @packed struct
|
||||
#endif
|
||||
#ifndef __PACKED_UNION
|
||||
#define __PACKED_UNION @packed union
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32 /* deprecated */
|
||||
@packed struct T_UINT32 { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT16_WRITE
|
||||
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
|
||||
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT16_READ
|
||||
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
|
||||
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32_WRITE
|
||||
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
|
||||
#endif
|
||||
#ifndef __UNALIGNED_UINT32_READ
|
||||
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
|
||||
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
|
||||
#endif
|
||||
#ifndef __ALIGNED
|
||||
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
|
||||
#define __ALIGNED(x)
|
||||
#endif
|
||||
#ifndef __RESTRICT
|
||||
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
|
||||
#define __RESTRICT
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __CMSIS_COMPILER_H */
|
||||
|
||||
39
Drivers/BSP/CMSIS/Include/cmsis_version.h
Normal file
39
Drivers/BSP/CMSIS/Include/cmsis_version.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/**************************************************************************//**
|
||||
* @file cmsis_version.h
|
||||
* @brief CMSIS Core(M) Version definitions
|
||||
* @version V5.0.2
|
||||
* @date 19. April 2017
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Copyright (c) 2009-2017 ARM Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined (__clang__)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef __CMSIS_VERSION_H
|
||||
#define __CMSIS_VERSION_H
|
||||
|
||||
/* CMSIS Version definitions */
|
||||
#define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
|
||||
#define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */
|
||||
#define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
|
||||
__CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
|
||||
#endif
|
||||
1941
Drivers/BSP/CMSIS/Include/core_cm3.h
Normal file
1941
Drivers/BSP/CMSIS/Include/core_cm3.h
Normal file
File diff suppressed because it is too large
Load Diff
2671
Drivers/BSP/CMSIS/Include/core_cm7.h
Normal file
2671
Drivers/BSP/CMSIS/Include/core_cm7.h
Normal file
File diff suppressed because it is too large
Load Diff
270
Drivers/BSP/CMSIS/Include/mpu_armv7.h
Normal file
270
Drivers/BSP/CMSIS/Include/mpu_armv7.h
Normal file
@@ -0,0 +1,270 @@
|
||||
/******************************************************************************
|
||||
* @file mpu_armv7.h
|
||||
* @brief CMSIS MPU API for Armv7-M MPU
|
||||
* @version V5.0.4
|
||||
* @date 10. January 2018
|
||||
******************************************************************************/
|
||||
/*
|
||||
* Copyright (c) 2017-2018 Arm Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if defined ( __ICCARM__ )
|
||||
#pragma system_include /* treat file as system include file for MISRA check */
|
||||
#elif defined (__clang__)
|
||||
#pragma clang system_header /* treat file as system include file */
|
||||
#endif
|
||||
|
||||
#ifndef ARM_MPU_ARMV7_H
|
||||
#define ARM_MPU_ARMV7_H
|
||||
|
||||
#define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes
|
||||
#define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes
|
||||
#define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes
|
||||
#define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes
|
||||
#define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes
|
||||
#define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte
|
||||
#define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes
|
||||
#define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte
|
||||
#define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes
|
||||
#define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte
|
||||
#define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes
|
||||
#define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes
|
||||
|
||||
#define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access
|
||||
#define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only
|
||||
#define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only
|
||||
#define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access
|
||||
#define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only
|
||||
#define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access
|
||||
|
||||
/** MPU Region Base Address Register Value
|
||||
*
|
||||
* \param Region The region to be configured, number 0 to 15.
|
||||
* \param BaseAddress The base address for the region.
|
||||
*/
|
||||
#define ARM_MPU_RBAR(Region, BaseAddress) \
|
||||
(((BaseAddress) & MPU_RBAR_ADDR_Msk) | \
|
||||
((Region) & MPU_RBAR_REGION_Msk) | \
|
||||
(MPU_RBAR_VALID_Msk))
|
||||
|
||||
/**
|
||||
* MPU Memory Access Attributes
|
||||
*
|
||||
* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
|
||||
* \param IsShareable Region is shareable between multiple bus masters.
|
||||
* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
|
||||
* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
|
||||
*/
|
||||
#define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \
|
||||
((((TypeExtField ) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \
|
||||
(((IsShareable ) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \
|
||||
(((IsCacheable ) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \
|
||||
(((IsBufferable ) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk))
|
||||
|
||||
/**
|
||||
* MPU Region Attribute and Size Register Value
|
||||
*
|
||||
* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
|
||||
* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
|
||||
* \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_.
|
||||
* \param SubRegionDisable Sub-region disable field.
|
||||
* \param Size Region size of the region to be configured, for example 4K, 8K.
|
||||
*/
|
||||
#define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \
|
||||
((((DisableExec ) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \
|
||||
(((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \
|
||||
(((AccessAttributes) ) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk)))
|
||||
|
||||
/**
|
||||
* MPU Region Attribute and Size Register Value
|
||||
*
|
||||
* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
|
||||
* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
|
||||
* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
|
||||
* \param IsShareable Region is shareable between multiple bus masters.
|
||||
* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
|
||||
* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
|
||||
* \param SubRegionDisable Sub-region disable field.
|
||||
* \param Size Region size of the region to be configured, for example 4K, 8K.
|
||||
*/
|
||||
#define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \
|
||||
ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size)
|
||||
|
||||
/**
|
||||
* MPU Memory Access Attribute for strongly ordered memory.
|
||||
* - TEX: 000b
|
||||
* - Shareable
|
||||
* - Non-cacheable
|
||||
* - Non-bufferable
|
||||
*/
|
||||
#define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U)
|
||||
|
||||
/**
|
||||
* MPU Memory Access Attribute for device memory.
|
||||
* - TEX: 000b (if non-shareable) or 010b (if shareable)
|
||||
* - Shareable or non-shareable
|
||||
* - Non-cacheable
|
||||
* - Bufferable (if shareable) or non-bufferable (if non-shareable)
|
||||
*
|
||||
* \param IsShareable Configures the device memory as shareable or non-shareable.
|
||||
*/
|
||||
#define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U))
|
||||
|
||||
/**
|
||||
* MPU Memory Access Attribute for normal memory.
|
||||
* - TEX: 1BBb (reflecting outer cacheability rules)
|
||||
* - Shareable or non-shareable
|
||||
* - Cacheable or non-cacheable (reflecting inner cacheability rules)
|
||||
* - Bufferable or non-bufferable (reflecting inner cacheability rules)
|
||||
*
|
||||
* \param OuterCp Configures the outer cache policy.
|
||||
* \param InnerCp Configures the inner cache policy.
|
||||
* \param IsShareable Configures the memory as shareable or non-shareable.
|
||||
*/
|
||||
#define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) & 2U), ((InnerCp) & 1U))
|
||||
|
||||
/**
|
||||
* MPU Memory Access Attribute non-cacheable policy.
|
||||
*/
|
||||
#define ARM_MPU_CACHEP_NOCACHE 0U
|
||||
|
||||
/**
|
||||
* MPU Memory Access Attribute write-back, write and read allocate policy.
|
||||
*/
|
||||
#define ARM_MPU_CACHEP_WB_WRA 1U
|
||||
|
||||
/**
|
||||
* MPU Memory Access Attribute write-through, no write allocate policy.
|
||||
*/
|
||||
#define ARM_MPU_CACHEP_WT_NWA 2U
|
||||
|
||||
/**
|
||||
* MPU Memory Access Attribute write-back, no write allocate policy.
|
||||
*/
|
||||
#define ARM_MPU_CACHEP_WB_NWA 3U
|
||||
|
||||
|
||||
/**
|
||||
* Struct for a single MPU Region
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t RBAR; //!< The region base address register value (RBAR)
|
||||
uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR
|
||||
} ARM_MPU_Region_t;
|
||||
|
||||
/** Enable the MPU.
|
||||
* \param MPU_Control Default access permissions for unconfigured regions.
|
||||
*/
|
||||
__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
|
||||
{
|
||||
__DSB();
|
||||
__ISB();
|
||||
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
||||
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
|
||||
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Disable the MPU.
|
||||
*/
|
||||
__STATIC_INLINE void ARM_MPU_Disable(void)
|
||||
{
|
||||
__DSB();
|
||||
__ISB();
|
||||
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
|
||||
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
#endif
|
||||
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
/** Clear and disable the given MPU region.
|
||||
* \param rnr Region number to be cleared.
|
||||
*/
|
||||
__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
|
||||
{
|
||||
MPU->RNR = rnr;
|
||||
MPU->RASR = 0U;
|
||||
}
|
||||
|
||||
/** Configure an MPU region.
|
||||
* \param rbar Value for RBAR register.
|
||||
* \param rsar Value for RSAR register.
|
||||
*/
|
||||
__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr)
|
||||
{
|
||||
MPU->RBAR = rbar;
|
||||
MPU->RASR = rasr;
|
||||
}
|
||||
|
||||
/** Configure the given MPU region.
|
||||
* \param rnr Region number to be configured.
|
||||
* \param rbar Value for RBAR register.
|
||||
* \param rsar Value for RSAR register.
|
||||
*/
|
||||
__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr)
|
||||
{
|
||||
MPU->RNR = rnr;
|
||||
MPU->RBAR = rbar;
|
||||
MPU->RASR = rasr;
|
||||
}
|
||||
|
||||
/** Memcopy with strictly ordered memory access, e.g. for register targets.
|
||||
* \param dst Destination data is copied to.
|
||||
* \param src Source data is copied from.
|
||||
* \param len Amount of data words to be copied.
|
||||
*/
|
||||
__STATIC_INLINE void orderedCpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0U; i < len; ++i)
|
||||
{
|
||||
dst[i] = src[i];
|
||||
}
|
||||
}
|
||||
|
||||
/** Load the given number of MPU regions from a table.
|
||||
* \param table Pointer to the MPU configuration table.
|
||||
* \param cnt Amount of regions to be configured.
|
||||
*/
|
||||
__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt)
|
||||
{
|
||||
const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
|
||||
while (cnt > MPU_TYPE_RALIASES) {
|
||||
orderedCpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize);
|
||||
table += MPU_TYPE_RALIASES;
|
||||
cnt -= MPU_TYPE_RALIASES;
|
||||
}
|
||||
orderedCpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,63 +1,82 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @文件 key.c
|
||||
* @作者 阜阳师范大学物电学院
|
||||
* @版本 V0.1
|
||||
* @日期 2026-01-15
|
||||
* @简介 按键驱动 - 基于 MultiButton 的高可移植性实现
|
||||
* @说明
|
||||
*
|
||||
****
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file key.c
|
||||
* @brief 按键驱动模块 - 基于 MultiButton 库的高可移植性实现
|
||||
* @details 本文件实现了基于 MultiButton 库的按键驱动功能,支持多按键配置、
|
||||
* 按键状态检测、按键事件回调等功能。采用配置表方式管理按键,
|
||||
* 便于扩展和维护。支持单次点击事件检测。
|
||||
* @author 阜阳师范大学物电学院
|
||||
* @version V0.1
|
||||
* @date 2026.1.19
|
||||
* @note 依赖库: MultiButton
|
||||
* 支持按键: ENTER, UP, DOWN, LEFT, RIGHT, ESC, ADD, DEC, RESET
|
||||
* 按键模式: 输入模式,无上拉/下拉
|
||||
* 特殊处理: PB3 需要禁用 JTAG 才能作为普通 GPIO 使用
|
||||
******************************************************************************/
|
||||
|
||||
#include "key.h"
|
||||
#include "160160D.h"
|
||||
|
||||
// 按键配置结构体
|
||||
/* ============================================================================
|
||||
* 按键配置结构体定义
|
||||
* ============================================================================ */
|
||||
/**
|
||||
* @brief 按键配置结构体
|
||||
* @details 用于存储每个按键的硬件配置信息,包括 GPIO 端口、引脚和按键类型
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t pin; // GPIO引脚
|
||||
GPIO_TypeDef* port; // GPIO端口
|
||||
KEY_TYPE key_type; // 按键ID
|
||||
uint16_t pin; /**< GPIO 引脚编号(如 GPIO_PIN_12) */
|
||||
GPIO_TypeDef* port; /**< GPIO 端口(如 GPIOD) */
|
||||
KEY_TYPE key_type; /**< 按键类型标识(如 KEY_ENTER) */
|
||||
} KeyConfig_t;
|
||||
|
||||
/*
|
||||
*******************详细引脚映射*****************************
|
||||
| 按键名称 | 端口 | 引脚 | 位定义 | 功能说明 |
|
||||
|---------|------|------|--------|----------|
|
||||
| KEY_ENTER | GPIOB | PB15 | KEY_ENTER_BIT | 确认键 |
|
||||
| KEY_UP | GPIOD | PD11 | KEY_UP_BIT | 上键 |
|
||||
| KEY_DOWN | GPIOD | PD10 | KET_DOWN_BIT | 下键 |
|
||||
| KEY_LEFT | GPIOD | PD13 | KET_LEFT_BIT | 左键 |
|
||||
| KEY_RIGHT | GPIOD | PD8 | KET_RIGHT_BIT | 右键 |
|
||||
| KEY_ESC | GPIOD | PD12 | KET_ESC_BIT | 取消键 |
|
||||
| KEY_ADD | GPIOD | PD14 | KET_ADD_BIT | 加键 |
|
||||
| KEY_DEC | GPIOD | PD9 | KET_DEC_BIT | 减键 |
|
||||
| KEY_RESET | GPIOD | PD15 | KET_RESET_BIT | 复位键 |
|
||||
***************************************************************
|
||||
*/
|
||||
// 按键配置表
|
||||
/* ============================================================================
|
||||
* 按键硬件引脚映射表
|
||||
* ============================================================================ */
|
||||
/**
|
||||
* @brief 按键硬件引脚映射表
|
||||
* @details 详细引脚映射关系如下:
|
||||
* | 按键名称 | 端口 | 引脚 | 按键类型 | 功能说明 |
|
||||
* |---------|------|------|----------|----------|
|
||||
* | KEY_ENTER | GPIOD | PD12 | KEY_ENTER | 确认键 |
|
||||
* | KEY_UP | GPIOD | PD11 | KEY_UP | 上键 |
|
||||
* | KEY_DOWN | GPIOD | PD10 | KEY_DOWN | 下键 |
|
||||
* | KEY_LEFT | GPIOD | PD13 | KEY_LEFT | 左键 |
|
||||
* | KEY_RIGHT | GPIOD | PD8 | KEY_RIGHT | 右键 |
|
||||
* | KEY_ESC | GPIOB | PB15 | KEY_ESC | 取消键 |
|
||||
* | KEY_ADD | GPIOB | PB3 | KEY_ADD | 加键(需禁用 JTAG) |
|
||||
* | KEY_RESET | GPIOD | PD15 | KEY_RESET | 复位键 |
|
||||
* @note PB3 引脚默认被 JTAG 占用,需要禁用 JTAG 才能作为普通 GPIO 使用
|
||||
*/
|
||||
static const KeyConfig_t key_configs[] = {
|
||||
{GPIO_PIN_12, GPIOD, KEY_ENTER},
|
||||
{GPIO_PIN_11, GPIOD, KEY_UP},
|
||||
{GPIO_PIN_10, GPIOD, KEY_DOWN},
|
||||
{GPIO_PIN_13, GPIOD, KEY_LEFT},
|
||||
{GPIO_PIN_8, GPIOD, KEY_RIGHT},
|
||||
{GPIO_PIN_15, GPIOB, KEY_ESC},
|
||||
{GPIO_PIN_3, GPIOB, KEY_ADD},
|
||||
{GPIO_PIN_15, GPIOD, KEY_RESET},
|
||||
{GPIO_PIN_12, GPIOD, KEY_ENTER}, /**< 确认键:PD12 */
|
||||
{GPIO_PIN_11, GPIOD, KEY_UP}, /**< 上键:PD11 */
|
||||
{GPIO_PIN_10, GPIOD, KEY_DOWN}, /**< 下键:PD10 */
|
||||
{GPIO_PIN_13, GPIOD, KEY_LEFT}, /**< 左键:PD13 */
|
||||
{GPIO_PIN_8, GPIOD, KEY_RIGHT}, /**< 右键:PD8 */
|
||||
{GPIO_PIN_15, GPIOB, KEY_ESC}, /**< 取消键:PB15 */
|
||||
{GPIO_PIN_3, GPIOB, KEY_ADD}, /**< 加键:PB3(需禁用 JTAG) */
|
||||
{GPIO_PIN_15, GPIOD, KEY_RESET}, /**< 复位键:PD15 */
|
||||
};
|
||||
#define KEY_COUNT (sizeof(key_configs) / sizeof(key_configs[0]))
|
||||
|
||||
// 按键句柄数组
|
||||
static Button btn_handles[KEY_COUNT];
|
||||
// 业务逻辑回调函数指针(由main.c注册)
|
||||
static KeyCallback key_callback = NULL;
|
||||
#define KEY_COUNT (sizeof(key_configs) / sizeof(key_configs[0])) /**< 按键总数 */
|
||||
|
||||
/* ============================================================================
|
||||
* 全局变量定义
|
||||
* ============================================================================ */
|
||||
static Button btn_handles[KEY_COUNT]; /**< MultiButton 按键句柄数组 */
|
||||
static KeyCallback key_callback = NULL; /**< 业务逻辑层注册的回调函数指针 */
|
||||
|
||||
/* ============================================================================
|
||||
* 内部函数实现
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief 读取按键GPIO电平
|
||||
* @param button_id 按键ID
|
||||
* @retval 0:按下, 1:释放
|
||||
* @brief 读取按键 GPIO 电平状态
|
||||
* @param button_id 按键 ID(对应 key_configs 数组索引,0 到 KEY_COUNT-1)
|
||||
* @note 该函数由 MultiButton 库调用,用于读取按键的硬件状态
|
||||
* 返回值:0 表示按下(低电平),1 表示释放(高电平)
|
||||
* @retval 0: 按键按下(低电平)
|
||||
* @retval 1: 按键释放(高电平)
|
||||
*/
|
||||
static uint8_t button_read_level(uint8_t button_id)
|
||||
{
|
||||
@@ -66,82 +85,117 @@ static uint8_t button_read_level(uint8_t button_id)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 统一的按键回调函数(内部使用,调用业务逻辑回调)
|
||||
* @param btn 按键句柄指针
|
||||
* @brief 统一的按键事件回调函数(内部使用)
|
||||
* @param btn MultiButton 库的按键句柄指针
|
||||
* @note 当 MultiButton 库检测到按键事件时,会调用此函数
|
||||
* 此函数将按键事件转换为业务逻辑层的按键类型,并调用注册的回调函数
|
||||
* 处理流程:
|
||||
* 1. 检查按键句柄和回调函数是否有效
|
||||
* 2. 从按键句柄中获取 button_id
|
||||
* 3. 通过 button_id 查找对应的按键类型
|
||||
* 4. 调用业务逻辑层注册的回调函数
|
||||
* @retval 无
|
||||
*/
|
||||
static void button_callback(Button* btn)
|
||||
{
|
||||
if (btn != NULL && key_callback != NULL)
|
||||
{
|
||||
// 通过button_id获取对应的按键类型
|
||||
/* 通过 button_id 获取对应的按键类型 */
|
||||
uint8_t button_id = btn->button_id;
|
||||
if (button_id < KEY_COUNT)
|
||||
{
|
||||
// 调用业务逻辑层注册的回调函数
|
||||
/* 调用业务逻辑层注册的回调函数 */
|
||||
key_callback(key_configs[button_id].key_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 注册按键回调函数(供业务逻辑层调用)
|
||||
* @param callback 回调函数指针
|
||||
* @brief 使能指定 GPIO 端口的时钟
|
||||
* @param port GPIO 端口指针(如 GPIOA, GPIOB, GPIOD 等)
|
||||
* @note 使用 switch-case 结构实现,代码简洁清晰
|
||||
* 支持所有 GPIO 端口(A-G)
|
||||
* 在初始化 GPIO 之前必须使能对应的时钟
|
||||
* @retval 无
|
||||
*/
|
||||
static void KEY_GPIO_ClockEnable(GPIO_TypeDef *port)
|
||||
{
|
||||
switch ((uint32_t)port) {
|
||||
case (uint32_t)GPIOA: __HAL_RCC_GPIOA_CLK_ENABLE(); break; /**< 使能 GPIOA 时钟 */
|
||||
case (uint32_t)GPIOB: __HAL_RCC_GPIOB_CLK_ENABLE(); break; /**< 使能 GPIOB 时钟 */
|
||||
case (uint32_t)GPIOC: __HAL_RCC_GPIOC_CLK_ENABLE(); break; /**< 使能 GPIOC 时钟 */
|
||||
case (uint32_t)GPIOD: __HAL_RCC_GPIOD_CLK_ENABLE(); break; /**< 使能 GPIOD 时钟 */
|
||||
case (uint32_t)GPIOE: __HAL_RCC_GPIOE_CLK_ENABLE(); break; /**< 使能 GPIOE 时钟 */
|
||||
case (uint32_t)GPIOF: __HAL_RCC_GPIOF_CLK_ENABLE(); break; /**< 使能 GPIOF 时钟 */
|
||||
case (uint32_t)GPIOG: __HAL_RCC_GPIOG_CLK_ENABLE(); break; /**< 使能 GPIOG 时钟 */
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* 外部接口函数实现
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief 按键硬件初始化函数
|
||||
* @note 初始化流程:
|
||||
* 1. 使能 AFIO 时钟(修改 AFIO 寄存器前必须)
|
||||
* 2. 禁用 JTAG,保留 SWD(释放 PA15、PB3、PB4 作为普通 GPIO)
|
||||
* 3. 遍历按键配置表,对每个按键进行初始化:
|
||||
* a. 使能对应 GPIO 端口时钟
|
||||
* b. 配置 GPIO 为输入模式,无上拉/下拉,高速模式
|
||||
* c. 初始化 MultiButton 按键句柄
|
||||
* d. 绑定单次点击事件到回调函数
|
||||
* e. 启动按键检测
|
||||
* @note 特殊处理:由于使用了 PB3 引脚,需要禁用 JTAG 功能
|
||||
* JTAG 禁用后,PA13、PA14 仍可用于 SWD 调试
|
||||
* @retval 无
|
||||
*/
|
||||
void Key_Init(void)
|
||||
{
|
||||
/* ========== AFIO 和 JTAG 配置 ========== */
|
||||
__HAL_RCC_AFIO_CLK_ENABLE(); /**< 使能 AFIO 时钟(修改 AFIO 寄存器前必须) */
|
||||
|
||||
/* 禁用 JTAG,保留 SWD(PA13、PA14 仍可用于调试) */
|
||||
/* 这会释放 PA15、PB3、PB4 作为普通 GPIO */
|
||||
__HAL_AFIO_REMAP_SWJ_NOJTAG();
|
||||
|
||||
/* ========== GPIO 和按键初始化 ========== */
|
||||
GPIO_InitTypeDef gpio_init_struct = {0};
|
||||
|
||||
/* 批量初始化所有按键 */
|
||||
for (uint8_t button_id = 0; button_id < KEY_COUNT; button_id++)
|
||||
{
|
||||
/* 使能对应 GPIO 端口时钟 */
|
||||
KEY_GPIO_ClockEnable(key_configs[button_id].port);
|
||||
|
||||
/* 配置 GPIO 为输入模式 */
|
||||
gpio_init_struct.Pin = key_configs[button_id].pin;
|
||||
gpio_init_struct.Mode = GPIO_MODE_INPUT; /**< 输入模式 */
|
||||
gpio_init_struct.Pull = GPIO_NOPULL; /**< 无上拉/下拉(外部电路处理) */
|
||||
gpio_init_struct.Speed = GPIO_SPEED_HIGH; /**< 高速模式,提高响应速度 */
|
||||
HAL_GPIO_Init(key_configs[button_id].port, &gpio_init_struct);
|
||||
|
||||
/* 初始化 MultiButton 按键句柄 */
|
||||
button_init(&btn_handles[button_id], button_read_level, 0, button_id);
|
||||
|
||||
/* 绑定单次点击事件到回调函数 */
|
||||
button_attach(&btn_handles[button_id], BTN_SINGLE_CLICK, button_callback);
|
||||
|
||||
/* 启动按键检测 */
|
||||
button_start(&btn_handles[button_id]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 注册按键回调函数(供业务逻辑层调用)
|
||||
* @param callback 按键回调函数指针,当检测到按键事件时会调用此函数
|
||||
* @note 业务逻辑层通过此函数注册按键处理回调
|
||||
* 回调函数参数为 KEY_TYPE 类型,表示被按下的按键类型
|
||||
* 如果传入 NULL,则取消已注册的回调函数
|
||||
* @retval 无
|
||||
*/
|
||||
void Key_RegisterCallback(KeyCallback callback)
|
||||
{
|
||||
key_callback = callback;
|
||||
}
|
||||
/**
|
||||
* @brief 使能GPIO时钟
|
||||
* @param port: GPIO端口
|
||||
* @retval 无
|
||||
* @note 使用switch-case结构,代码更简洁清晰,支持所有GPIO端口(A-G)
|
||||
*/
|
||||
static void KEY_GPIO_ClockEnable(GPIO_TypeDef *port)
|
||||
{
|
||||
switch ((uint32_t)port) {
|
||||
case (uint32_t)GPIOA: __HAL_RCC_GPIOA_CLK_ENABLE(); break;
|
||||
case (uint32_t)GPIOB: __HAL_RCC_GPIOB_CLK_ENABLE(); break;
|
||||
case (uint32_t)GPIOC: __HAL_RCC_GPIOC_CLK_ENABLE(); break;
|
||||
case (uint32_t)GPIOD: __HAL_RCC_GPIOD_CLK_ENABLE(); break;
|
||||
case (uint32_t)GPIOE: __HAL_RCC_GPIOE_CLK_ENABLE(); break;
|
||||
case (uint32_t)GPIOF: __HAL_RCC_GPIOF_CLK_ENABLE(); break;
|
||||
case (uint32_t)GPIOG: __HAL_RCC_GPIOG_CLK_ENABLE(); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
/**************************************************************************************
|
||||
* FunctionName : Key_Init()
|
||||
* Description : 按键硬件初始化(使用MultiButton库)
|
||||
* EntryParameter : none
|
||||
* ReturnValue : none
|
||||
**************************************************************************************/
|
||||
void Key_Init(void)
|
||||
{
|
||||
/*由于使用了 PB3 才需要特殊加的*/
|
||||
__HAL_RCC_AFIO_CLK_ENABLE(); // AFIO时钟(修改AFIO寄存器前必须)
|
||||
|
||||
/* 禁用JTAG,保留SWD(PA13、PA14仍可用于调试)*/
|
||||
/* 这会释放 PA15、PB3、PB4 作为普通GPIO */
|
||||
__HAL_AFIO_REMAP_SWJ_NOJTAG();
|
||||
|
||||
|
||||
GPIO_InitTypeDef gpio_init_struct = {0};
|
||||
// 批量初始化GPIO
|
||||
for (uint8_t button_id = 0; button_id < KEY_COUNT; button_id++)
|
||||
{
|
||||
/* 使能对应GPIO时钟 */
|
||||
KEY_GPIO_ClockEnable(key_configs[button_id].port);
|
||||
|
||||
// 配置并初始化引脚
|
||||
gpio_init_struct.Pin = key_configs[button_id].pin;
|
||||
gpio_init_struct.Mode = GPIO_MODE_INPUT;
|
||||
gpio_init_struct.Pull = GPIO_NOPULL;
|
||||
gpio_init_struct.Speed = GPIO_SPEED_HIGH;
|
||||
HAL_GPIO_Init(key_configs[button_id].port, &gpio_init_struct);
|
||||
|
||||
button_init(&btn_handles[button_id], button_read_level, 0, button_id);
|
||||
button_attach(&btn_handles[button_id], BTN_SINGLE_CLICK, button_callback);
|
||||
button_start(&btn_handles[button_id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,86 @@
|
||||
/******************************************************************************
|
||||
* @file key.h
|
||||
* @brief 按键驱动模块头文件
|
||||
* @details 本文件定义了按键驱动的接口和数据结构,包括按键类型枚举、
|
||||
* 按键回调函数类型定义以及外部接口函数声明。
|
||||
* @author 阜阳师范大学物电学院
|
||||
* @version V0.1
|
||||
* @date 2026.1.19
|
||||
* @note 依赖库: MultiButton
|
||||
* 使用方式:
|
||||
* 1. 调用 Key_Init() 初始化按键硬件
|
||||
* 2. 调用 Key_RegisterCallback() 注册按键回调函数
|
||||
* 3. 在定时器中调用 Button_Ticks() 进行按键扫描
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __KEY_H__
|
||||
#define __KEY_H__
|
||||
|
||||
|
||||
|
||||
#include "./SYSTEM/sys/sys.h"
|
||||
#include "MultiButton.h"
|
||||
|
||||
/* ============================================================================
|
||||
* 按键类型枚举定义
|
||||
* ============================================================================ */
|
||||
/**
|
||||
* @brief 按键类型枚举
|
||||
* @details 定义了系统中所有支持的按键类型
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
KEY_NONE = 0, // 没有按键
|
||||
|
||||
KEY_ENTER, // 确认
|
||||
KEY_UP, // 向上
|
||||
KEY_DOWN, // 向下
|
||||
KEY_ESC, //取消
|
||||
KEY_ADD, //加
|
||||
KEY_DEC, //减
|
||||
KEY_LEFT, //左
|
||||
KEY_RIGHT, //右
|
||||
KEY_RESET, //复位
|
||||
KEY_FACTORY, //工厂
|
||||
KEY_NONE = 0, /**< 无按键按下 */
|
||||
KEY_ENTER, /**< 确认键 */
|
||||
KEY_UP, /**< 向上键 */
|
||||
KEY_DOWN, /**< 向下键 */
|
||||
KEY_ESC, /**< 取消键 */
|
||||
KEY_ADD, /**< 加键 */
|
||||
KEY_DEC, /**< 减键 */
|
||||
KEY_LEFT, /**< 向左键 */
|
||||
KEY_RIGHT, /**< 向右键 */
|
||||
KEY_RESET, /**< 复位键 */
|
||||
KEY_FACTORY, /**< 工厂模式键 */
|
||||
} KEY_TYPE;
|
||||
|
||||
// 按键回调函数类型定义(业务逻辑层使用)
|
||||
// 参数: key_type - 按键类型
|
||||
/* ============================================================================
|
||||
* 回调函数类型定义
|
||||
* ============================================================================ */
|
||||
/**
|
||||
* @brief 按键回调函数类型定义
|
||||
* @param key_type 按键类型(KEY_TYPE 枚举值)
|
||||
* @note 业务逻辑层需要实现此类型的回调函数,用于处理按键事件
|
||||
* 当检测到按键按下时,会调用注册的回调函数
|
||||
* @retval 无
|
||||
*/
|
||||
typedef void (*KeyCallback)(KEY_TYPE key_type);
|
||||
|
||||
/* ============================================================================
|
||||
* 外部接口函数声明
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief 按键硬件初始化函数
|
||||
* @note 初始化所有按键的 GPIO 配置和 MultiButton 库
|
||||
* 特殊处理:禁用 JTAG 以释放 PB3 等引脚
|
||||
* 必须在系统初始化时调用一次
|
||||
* @retval 无
|
||||
*/
|
||||
void Key_Init(void);
|
||||
|
||||
// 按键驱动函数(在key.c中实现,使用MultiButton库)
|
||||
void Key_Init(void); // 按键初始化
|
||||
void Key_RegisterCallback(KeyCallback callback); // 注册按键回调函数(业务逻辑层调用)
|
||||
#define Button_Ticks() button_ticks()
|
||||
#endif
|
||||
/**
|
||||
* @brief 注册按键回调函数(供业务逻辑层调用)
|
||||
* @param callback 按键回调函数指针,当检测到按键事件时会调用此函数
|
||||
* @note 业务逻辑层通过此函数注册按键处理回调
|
||||
* 如果传入 NULL,则取消已注册的回调函数
|
||||
* @retval 无
|
||||
*/
|
||||
void Key_RegisterCallback(KeyCallback callback);
|
||||
|
||||
/**
|
||||
* @brief MultiButton 库的按键扫描函数宏定义
|
||||
* @note 需要在定时器中周期性调用此函数(建议 5-10ms 调用一次)
|
||||
* 用于 MultiButton 库进行按键状态扫描和事件检测
|
||||
* @retval 无
|
||||
*/
|
||||
#define Button_Ticks() button_ticks()
|
||||
|
||||
#endif /* __KEY_H__ */
|
||||
|
||||
@@ -1,127 +1,134 @@
|
||||
/******************************************************************************
|
||||
* @file rs485.c
|
||||
* @brief rs485串口配置,主要配置两种模式 中断接收模式 和 DMA 接收模式
|
||||
* @details
|
||||
* 1. DMA模式是主要工作模式
|
||||
* 2. 中断模式用于错误恢复和接收第一个短帧
|
||||
* 3. 中断处理完后自动切换回DMA模式
|
||||
* 4. 中断接收主要用于异常情况处理
|
||||
* @brief RS485 串口驱动 - DMA 与中断接收
|
||||
* @details 本文件实现 RS485 串口通信驱动,支持两种模式:
|
||||
* 1. DMA 模式:主工作模式,使用 ReceiveToIdle 接收不定长帧
|
||||
* 2. 中断模式:用于错误恢复或短帧接收,RXNE 逐字节接收
|
||||
* 收发通过 DE 引脚(PA1)切换:低电平发送,高电平接收。
|
||||
* @author 阜阳师范大学物电学院
|
||||
* @version V0.01
|
||||
* @date 2026.1.24
|
||||
* @note 通信协议:Modbus RTU
|
||||
* 通信接口:RS485
|
||||
* 主站地址:0x01
|
||||
* @note USART2,TX=PA2,RX=PA3,DE=PA1;波特率 700000
|
||||
******************************************************************************/
|
||||
|
||||
#include "rs485.h"
|
||||
|
||||
/* ============================================================================
|
||||
* USART 与引脚宏定义
|
||||
* ============================================================================ */
|
||||
#define RS485_UX USART2
|
||||
#define RS485_UX_IRQn USART2_IRQn
|
||||
#define RS485_UX_IRQHandler USART2_IRQHandler
|
||||
#define RS485_UX_CLK_ENABLE() do{ __HAL_RCC_USART2_CLK_ENABLE(); }while(0) /* 时钟使能 */
|
||||
#define RS485_UX_CLK_ENABLE() do{ __HAL_RCC_USART2_CLK_ENABLE(); }while(0) /**< USART2 时钟使能 */
|
||||
|
||||
#define RS485_SEND_ENABLE() do{HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);}while(0)
|
||||
#define RS485_RECEIVE_ENABLE() do{HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);}while(0)
|
||||
#define RS485_SEND_ENABLE() do{HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);}while(0) /**< DE 低:发送 */
|
||||
#define RS485_RECEIVE_ENABLE() do{HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);}while(0) /**< DE 高:接收 */
|
||||
|
||||
#define RS485_ENABLE_GPIO_PORT GPIOA
|
||||
#define RS485_ENABLE_GPIO_PIN GPIO_PIN_1
|
||||
#define RS485_ENABLE_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0) /* PA口时钟使能 */
|
||||
#define RS485_ENABLE_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0)
|
||||
|
||||
#define RS485_TX_GPIO_PORT GPIOA
|
||||
#define RS485_TX_GPIO_PIN GPIO_PIN_2
|
||||
#define RS485_TX_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0) /* PA口时钟使能 */
|
||||
#define RS485_TX_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0)
|
||||
|
||||
#define RS485_RX_GPIO_PORT GPIOA
|
||||
#define RS485_RX_GPIO_PIN GPIO_PIN_3
|
||||
#define RS485_RX_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0) /* PA口时钟使能 */
|
||||
#define RS485_RX_GPIO_CLK_ENABLE() do{ __HAL_RCC_GPIOA_CLK_ENABLE(); }while(0)
|
||||
|
||||
RS485_REGISTER_TYPE RS485REG = {RESET, {0}, {0}}; /* 零初始化定义 */
|
||||
#define BAUDRATE (700000) /**< 波特率 */
|
||||
|
||||
// HAL库UART句柄
|
||||
UART_HandleTypeDef rs485_handle; /* UART句柄 */
|
||||
// HAL库DMA句柄(接收)
|
||||
DMA_HandleTypeDef hdma_rs485_rx;
|
||||
// HAL库DMA句柄(发送)
|
||||
DMA_HandleTypeDef hdma_rs485_tx;
|
||||
/* ============================================================================
|
||||
* 全局变量定义
|
||||
* ============================================================================ */
|
||||
RS485_REGISTER_TYPE RS485REG = {RESET, {0}, {0}}; /**< RS485 收发寄存器,零初始化 */
|
||||
|
||||
UART_HandleTypeDef rs485_handle; /**< HAL UART 句柄 */
|
||||
DMA_HandleTypeDef hdma_rs485_rx; /**< HAL DMA 接收句柄(DMA1 Channel6) */
|
||||
DMA_HandleTypeDef hdma_rs485_tx; /**< HAL DMA 发送句柄(未使用,保留) */
|
||||
|
||||
#define BAUDRATE (700000)
|
||||
/* ============================================================================
|
||||
* 初始化函数
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief 串口X初始化函数
|
||||
* @param baudrate: 波特率, 根据自己需要设置波特率值
|
||||
* @note 注意: 必须设置正确的时钟源, 否则串口波特率就会设置异常.
|
||||
* 这里的USART的时钟源在sys_stm32_clock_init()函数中已经设置过了.
|
||||
* @retval 无
|
||||
* @brief RS485 初始化(DMA 接收模式)
|
||||
* @note 配置流程:
|
||||
* 1. 使能 GPIO、USART 时钟
|
||||
* 2. 配置 TX(PA2)、RX(PA3)、DE(PA1)
|
||||
* 3. 配置 DMA1 Channel6 接收,关联 UART
|
||||
* 4. 使能 DMA、USART 中断
|
||||
* 5. 初始化 UART(8N1,无流控,波特率 BAUDRATE)
|
||||
* 6. 切换为接收,启动 ReceiveToIdle DMA
|
||||
* USART 时钟源需在 sys_stm32_clock_init 中已配置。
|
||||
* @retval 无
|
||||
*/
|
||||
void RS485_DMA_init()
|
||||
void RS485_DMA_init(void)
|
||||
{
|
||||
/* 开启时钟 */
|
||||
RS485_TX_GPIO_CLK_ENABLE(); /* 使能串口TX脚时钟 */
|
||||
RS485_RX_GPIO_CLK_ENABLE(); /* 使能串口RX脚时钟 */
|
||||
RS485_ENABLE_GPIO_CLK_ENABLE(); /* 使能串口RX脚时钟 */
|
||||
RS485_UX_CLK_ENABLE(); /* 使能串口时钟 */
|
||||
/* 使能时钟 */
|
||||
RS485_TX_GPIO_CLK_ENABLE();
|
||||
RS485_RX_GPIO_CLK_ENABLE();
|
||||
RS485_ENABLE_GPIO_CLK_ENABLE();
|
||||
RS485_UX_CLK_ENABLE();
|
||||
|
||||
/*GPIO 初始化设置*/
|
||||
/* GPIO 初始化 */
|
||||
GPIO_InitTypeDef gpio_init_struct = {0};
|
||||
gpio_init_struct.Pin = RS485_TX_GPIO_PIN; /* 串口发送引脚号 */
|
||||
gpio_init_struct.Mode = GPIO_MODE_AF_PP; /* 复用推挽输出 */
|
||||
gpio_init_struct.Pull = GPIO_PULLUP; /* 上拉 */
|
||||
gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH; /* IO速度设置为高速 */
|
||||
gpio_init_struct.Pin = RS485_TX_GPIO_PIN;
|
||||
gpio_init_struct.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_struct.Pull = GPIO_PULLUP;
|
||||
gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(RS485_TX_GPIO_PORT, &gpio_init_struct);
|
||||
|
||||
gpio_init_struct.Pin = RS485_RX_GPIO_PIN; /* 串口RX脚 模式设置 */
|
||||
gpio_init_struct.Mode = GPIO_MODE_AF_INPUT;
|
||||
HAL_GPIO_Init(RS485_RX_GPIO_PORT, &gpio_init_struct); /* 串口RX脚 必须设置成输入模式 */
|
||||
|
||||
gpio_init_struct.Pin = RS485_ENABLE_GPIO_PIN;
|
||||
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_Init(RS485_ENABLE_GPIO_PORT, &gpio_init_struct);
|
||||
gpio_init_struct.Pin = RS485_RX_GPIO_PIN;
|
||||
gpio_init_struct.Mode = GPIO_MODE_AF_INPUT;
|
||||
HAL_GPIO_Init(RS485_RX_GPIO_PORT, &gpio_init_struct);
|
||||
|
||||
/* 配置DMA接收句柄 */
|
||||
gpio_init_struct.Pin = RS485_ENABLE_GPIO_PIN;
|
||||
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_Init(RS485_ENABLE_GPIO_PORT, &gpio_init_struct);
|
||||
|
||||
/* DMA 接收配置 */
|
||||
hdma_rs485_rx.Instance = DMA1_Channel6;
|
||||
hdma_rs485_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; // 外设到内存
|
||||
hdma_rs485_rx.Init.PeriphInc = DMA_PINC_DISABLE; // 外设地址不递增
|
||||
hdma_rs485_rx.Init.MemInc = DMA_MINC_ENABLE; // 内存地址递增
|
||||
hdma_rs485_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; // 外设数据对齐:字节
|
||||
hdma_rs485_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; // 内存数据对齐:字节
|
||||
hdma_rs485_rx.Init.Mode = DMA_NORMAL; // 正常模式
|
||||
hdma_rs485_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH; // 最高优先级
|
||||
HAL_DMA_Init(&hdma_rs485_rx); /*初始化DMA 接收*/
|
||||
hdma_rs485_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||||
hdma_rs485_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||||
hdma_rs485_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||||
hdma_rs485_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
|
||||
hdma_rs485_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
||||
hdma_rs485_rx.Init.Mode = DMA_NORMAL;
|
||||
hdma_rs485_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;
|
||||
HAL_DMA_Init(&hdma_rs485_rx);
|
||||
|
||||
/* 关联 DMA 到 UART(重要!)*/
|
||||
__HAL_LINKDMA(&rs485_handle, hdmarx, hdma_rs485_rx);
|
||||
|
||||
/* 使能DMA传输完成中断 */
|
||||
HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
|
||||
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0);
|
||||
|
||||
/* UART 初始化设置 */
|
||||
rs485_handle.Instance = RS485_UX; /* USART_UX */
|
||||
rs485_handle.Init.BaudRate = BAUDRATE; /* 波特率 */
|
||||
rs485_handle.Init.WordLength = UART_WORDLENGTH_8B; /* 字长为8位数据格式 */
|
||||
rs485_handle.Init.StopBits = UART_STOPBITS_1; /* 一个停止位 */
|
||||
rs485_handle.Init.Parity = UART_PARITY_NONE; /* 无奇偶校验位 */
|
||||
rs485_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; /* 无硬件流控 */
|
||||
rs485_handle.Init.Mode = UART_MODE_TX_RX; /* 收发模式 */
|
||||
/* UART 初始化 */
|
||||
rs485_handle.Instance = RS485_UX;
|
||||
rs485_handle.Init.BaudRate = BAUDRATE;
|
||||
rs485_handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
rs485_handle.Init.StopBits = UART_STOPBITS_1;
|
||||
rs485_handle.Init.Parity = UART_PARITY_NONE;
|
||||
rs485_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
rs485_handle.Init.Mode = UART_MODE_TX_RX;
|
||||
rs485_handle.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
HAL_UART_Init(&rs485_handle); /* 初始化UART */
|
||||
HAL_UART_Init(&rs485_handle);
|
||||
|
||||
HAL_NVIC_EnableIRQ(RS485_UX_IRQn); /* 使能USART中断通道 */
|
||||
HAL_NVIC_SetPriority(RS485_UX_IRQn, 1, 0); /* 组2,抢占优先级1,子优先级0 */
|
||||
|
||||
/* 启动DMA接收 */
|
||||
RS485_RECEIVE_ENABLE();
|
||||
HAL_NVIC_EnableIRQ(RS485_UX_IRQn);
|
||||
HAL_NVIC_SetPriority(RS485_UX_IRQn, 1, 0);
|
||||
|
||||
/* 启动 DMA 接收 */
|
||||
RS485_RECEIVE_ENABLE();
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&rs485_handle, (uint8_t *)RS485REG.DR, UART_RX_LEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 串口X初始化函数
|
||||
* @note 注意: 必须设置正确的时钟源, 否则串口波特率就会设置异常.
|
||||
*
|
||||
* @retval 无
|
||||
* @brief RS485 初始化(中断接收模式)
|
||||
* @note 配置 GPIO、UART,使能 RXNE 中断。不启用 DMA。
|
||||
* 用于错误恢复或接收短帧。USART 时钟源需已配置。
|
||||
* @retval 无
|
||||
*/
|
||||
void RS485_init()
|
||||
void RS485_init(void)
|
||||
{
|
||||
/* 开启时钟 */
|
||||
RS485_TX_GPIO_CLK_ENABLE(); /* 使能串口TX脚时钟 */
|
||||
@@ -129,80 +136,94 @@ void RS485_init()
|
||||
RS485_ENABLE_GPIO_CLK_ENABLE(); /* 使能串口RX脚时钟 */
|
||||
RS485_UX_CLK_ENABLE(); /* 使能串口时钟 */
|
||||
|
||||
/*GPIO 初始化设置*/
|
||||
GPIO_InitTypeDef gpio_init_struct;
|
||||
gpio_init_struct.Pin = RS485_TX_GPIO_PIN; /* 串口发送引脚号 */
|
||||
gpio_init_struct.Mode = GPIO_MODE_AF_PP; /* 复用推挽输出 */
|
||||
gpio_init_struct.Pull = GPIO_PULLUP; /* 上拉 */
|
||||
gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH; /* IO速度设置为高速 */
|
||||
/* GPIO 初始化 */
|
||||
GPIO_InitTypeDef gpio_init_struct = {0};
|
||||
gpio_init_struct.Pin = RS485_TX_GPIO_PIN;
|
||||
gpio_init_struct.Mode = GPIO_MODE_AF_PP;
|
||||
gpio_init_struct.Pull = GPIO_PULLUP;
|
||||
gpio_init_struct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(RS485_TX_GPIO_PORT, &gpio_init_struct);
|
||||
|
||||
gpio_init_struct.Pin = RS485_RX_GPIO_PIN; /* 串口RX脚 模式设置 */
|
||||
gpio_init_struct.Mode = GPIO_MODE_AF_INPUT;
|
||||
HAL_GPIO_Init(RS485_RX_GPIO_PORT, &gpio_init_struct); /* 串口RX脚 必须设置成输入模式 */
|
||||
|
||||
gpio_init_struct.Pin = RS485_ENABLE_GPIO_PIN;
|
||||
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_Init(RS485_ENABLE_GPIO_PORT, &gpio_init_struct);
|
||||
gpio_init_struct.Pin = RS485_RX_GPIO_PIN;
|
||||
gpio_init_struct.Mode = GPIO_MODE_AF_INPUT;
|
||||
HAL_GPIO_Init(RS485_RX_GPIO_PORT, &gpio_init_struct);
|
||||
|
||||
gpio_init_struct.Pin = RS485_ENABLE_GPIO_PIN;
|
||||
gpio_init_struct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
HAL_GPIO_Init(RS485_ENABLE_GPIO_PORT, &gpio_init_struct);
|
||||
|
||||
/*UART 初始化设置*/
|
||||
rs485_handle.Instance = RS485_UX; /* USART_UX */
|
||||
rs485_handle.Init.BaudRate = BAUDRATE; /* 波特率 */
|
||||
rs485_handle.Init.WordLength = UART_WORDLENGTH_8B; /* 字长为8位数据格式 */
|
||||
rs485_handle.Init.StopBits = UART_STOPBITS_1; /* 一个停止位 */
|
||||
rs485_handle.Init.Parity = UART_PARITY_NONE; /* 无奇偶校验位 */
|
||||
rs485_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; /* 无硬件流控 */
|
||||
rs485_handle.Init.Mode = UART_MODE_TX_RX; /* 收发模式 */
|
||||
HAL_UART_Init(&rs485_handle); /* 使能UART */
|
||||
/* UART 初始化 */
|
||||
rs485_handle.Instance = RS485_UX;
|
||||
rs485_handle.Init.BaudRate = BAUDRATE;
|
||||
rs485_handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
rs485_handle.Init.StopBits = UART_STOPBITS_1;
|
||||
rs485_handle.Init.Parity = UART_PARITY_NONE;
|
||||
rs485_handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
rs485_handle.Init.Mode = UART_MODE_TX_RX;
|
||||
rs485_handle.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
HAL_UART_Init(&rs485_handle);
|
||||
|
||||
/* 该函数会开启接收中断:标志位UART_IT_RXNE,并且设置接收缓冲以及接收缓冲接收最大数据量 */
|
||||
__HAL_UART_ENABLE_IT(&rs485_handle, UART_IT_RXNE);
|
||||
HAL_NVIC_EnableIRQ(RS485_UX_IRQn); /* 使能USART中断通道 */
|
||||
HAL_NVIC_SetPriority(RS485_UX_IRQn, 1, 0); /* 组2,抢占优先级1,子优先级0 */
|
||||
__HAL_UART_ENABLE_IT(&rs485_handle, UART_IT_RXNE);
|
||||
HAL_NVIC_EnableIRQ(RS485_UX_IRQn);
|
||||
HAL_NVIC_SetPriority(RS485_UX_IRQn, 1, 0);
|
||||
RS485_RECEIVE_ENABLE();
|
||||
}
|
||||
|
||||
/* ============================================================================
|
||||
* 回调与中断服务函数
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief UART 接收事件回调(ReceiveToIdle 完成时由 HAL 调用)
|
||||
* @param huart UART 句柄
|
||||
* @param Size 本帧接收到的字节数
|
||||
* @note 当为 RS485 所用 UART 时:置位 NewMessageFlag,并重新启动 ReceiveToIdle DMA。
|
||||
* @retval 无
|
||||
*/
|
||||
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
||||
{
|
||||
if(huart->Instance == RS485_UX)
|
||||
if (huart->Instance == RS485_UX)
|
||||
{
|
||||
RS485REG.NewMessageFlag = SET;
|
||||
HAL_UARTEx_ReceiveToIdle_DMA(&rs485_handle, (uint8_t *)RS485REG.DR, UART_RX_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 485串口中断服务函数
|
||||
* @param 无
|
||||
* @retval 无
|
||||
* @brief RS485 所用 USART 中断服务函数
|
||||
* @note 调用 HAL_UART_IRQHandler 处理 UART 及关联 DMA 中断。
|
||||
* @retval 无
|
||||
*/
|
||||
void RS485_UX_IRQHandler(void)
|
||||
{
|
||||
HAL_UART_IRQHandler(&rs485_handle);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* FunctionName : DMA1_Channel6_IRQHandler()
|
||||
* Description : 串口接收中断
|
||||
* EntryParameter : none
|
||||
* ReturnValue : none
|
||||
********************************************************************************/
|
||||
/**
|
||||
* @brief DMA1 Channel6 中断服务函数(RS485 接收 DMA)
|
||||
* @note 调用 HAL_DMA_IRQHandler,在 ReceiveToIdle 完成等事件时触发。
|
||||
* @retval 无
|
||||
*/
|
||||
void DMA1_Channel6_IRQHandler(void)
|
||||
{
|
||||
HAL_DMA_IRQHandler(&hdma_rs485_rx);
|
||||
HAL_DMA_IRQHandler(&hdma_rs485_rx);
|
||||
}
|
||||
/***********************************************************************
|
||||
* FunctionName : RS485_SendBuff()
|
||||
* Description : 485发送数组
|
||||
* EntryParameter : *ptr:待发送的字符串, len:待发送的数据个数
|
||||
* ReturnValue : ptrLen:发送的数据个数
|
||||
**************************************************************************/
|
||||
|
||||
/* ============================================================================
|
||||
* 发送接口
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief RS485 发送数据
|
||||
* @param ptr 待发送数据指针
|
||||
* @param len 待发送字节数
|
||||
* @note 切换为发送(DE 低)→ 阻塞发送 → 切换回接收(DE 高)。超时 1000ms。
|
||||
* @retval 无
|
||||
*/
|
||||
void RS485_SendBuff(uint8_t *ptr, uint32_t len)
|
||||
{
|
||||
RS485_SEND_ENABLE();
|
||||
|
||||
HAL_UART_Transmit(&rs485_handle, ptr,len, 1000);
|
||||
|
||||
HAL_UART_Transmit(&rs485_handle, ptr, len, 1000);
|
||||
RS485_RECEIVE_ENABLE();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +1,70 @@
|
||||
/******************************************************************************
|
||||
* @file rs485.h
|
||||
* @brief RS485 串口通信驱动头文件
|
||||
* @details 本文件声明 RS485 通信相关接口与数据结构,支持 DMA 接收与中断接收两种模式。
|
||||
* 使用 USART2,收发切换通过 DE 引脚(PA1)控制。
|
||||
* @author 阜阳师范大学物电学院
|
||||
* @version V0.01
|
||||
* @date 2026.1.24
|
||||
* @note USART:USART2
|
||||
* TX:PA2,RX:PA3,DE:PA1
|
||||
* 波特率:700000
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __RS485_H__
|
||||
#define __RS485_H__
|
||||
|
||||
|
||||
|
||||
#include "./SYSTEM/sys/sys.h"
|
||||
#include "./SYSTEM/delay/delay.h"
|
||||
|
||||
#define UART_RX_LEN (3208)
|
||||
#define UART_TX_LEN (8)
|
||||
/* ============================================================================
|
||||
* 宏定义
|
||||
* ============================================================================ */
|
||||
#define UART_RX_LEN (3208) /**< 接收缓冲区长度(字节),与 Modbus 数据帧长度一致 */
|
||||
#define UART_TX_LEN (8) /**< 发送缓冲区长度(字节) */
|
||||
|
||||
/* ============================================================================
|
||||
* 数据结构定义
|
||||
* ============================================================================ */
|
||||
|
||||
/**
|
||||
* @brief RS485 收发寄存器结构体
|
||||
* @note 用于存放一帧接收数据及发送缓存,与 Modbus 处理模块配合使用
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
volatile FlagStatus NewMessageFlag; //一帧数据接收完整
|
||||
volatile uint8_t DR[UART_RX_LEN]; //接收缓存
|
||||
volatile uint8_t TDR[UART_TX_LEN]; //发送缓存
|
||||
{
|
||||
volatile FlagStatus NewMessageFlag; /**< 新消息标志:一帧数据接收完成时置位 */
|
||||
volatile uint8_t DR[UART_RX_LEN]; /**< 接收缓存 */
|
||||
volatile uint8_t TDR[UART_TX_LEN]; /**< 发送缓存 */
|
||||
} RS485_REGISTER_TYPE;
|
||||
|
||||
extern RS485_REGISTER_TYPE RS485REG;
|
||||
extern RS485_REGISTER_TYPE RS485REG; /**< 全局 RS485 收发寄存器 */
|
||||
|
||||
/* ============================================================================
|
||||
* 函数声明
|
||||
* ============================================================================ */
|
||||
|
||||
|
||||
|
||||
void USART2_Init(void);
|
||||
/**
|
||||
* @brief RS485 初始化(DMA 接收模式)
|
||||
* @note 配置 GPIO、UART、DMA,启动 ReceiveToIdle DMA 接收。为主工作模式。
|
||||
* @retval 无
|
||||
*/
|
||||
void RS485_DMA_init(void);
|
||||
|
||||
/**
|
||||
* @brief RS485 初始化(中断接收模式)
|
||||
* @note 配置 GPIO、UART,使能 RXNE 中断接收。用于异常恢复或短帧接收。
|
||||
* @retval 无
|
||||
*/
|
||||
void RS485_init(void);
|
||||
|
||||
/**
|
||||
* @brief RS485 发送数据
|
||||
* @param ptr 待发送数据指针
|
||||
* @param len 待发送字节数
|
||||
* @note 先切换为发送(DE 高),发送完成后切回接收(DE 低)。使用阻塞方式发送。
|
||||
* @retval 无
|
||||
*/
|
||||
void RS485_SendBuff(uint8_t *ptr, uint32_t len);
|
||||
|
||||
|
||||
#endif
|
||||
#endif /* __RS485_H__ */
|
||||
|
||||
Reference in New Issue
Block a user