Compare commits

...

2 Commits

Author SHA1 Message Date
起床就犯困 eaecfce9ad 添加软件反向充电保护,修改配置文件的读取和配置的问题,添加更多的SOE 2025-01-21 18:02:52 +08:00
起床就犯困 c184bd3407 修改数据采集和控制周期 2025-01-17 20:32:22 +08:00
42 changed files with 9897 additions and 1644 deletions

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@
#include "bl_chargControl.h"
#include "capture.h"
void chargControl(void);

View File

@ -64,10 +64,10 @@ void start(void)
startInfo();
// HAL_Delay(5000);
while (1) {
cfgTest();
HAL_Delay(1000);
}
// while (1) {
// cfgTest();
// HAL_Delay(1000);
// }
TimeSliceOffset_Start();
}

View File

@ -28,6 +28,6 @@ void checkAbnormal(void);
void WORK_VOLT_Interrupt(void);
void DSG_PROT_Interrupt(void);
void EXCHG_PROT_Interrupt(void);
#endif

View File

@ -14,7 +14,7 @@
/* SL协议读取寄存器最小地址 */
#define minReadRegAddrMacro 0x0100
/* SL协议读取寄存器最大长度 */
#define maxReadRegAddrNumMacro 10
#define maxReadRegAddrNumMacro 80
/* SL协议写入寄存器最大地址 */
@ -30,7 +30,7 @@
/* SL协议下发配置文件内容最长长度 */
#define maxDistributionCfgLen 230
/* SL协议读取配置文件内容最长长度 */
#define maxReadCfgLen 32
#define maxReadCfgLen 80
#define floatMagnification 10.0f

View File

@ -86,7 +86,7 @@ typedef struct _config_info{
uint8_t uniqueDeviceID[7]; /* 设备唯一ID */
uint32_t gw485_Baud; /* 串口波特率 */
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
uint8_t powerBoxType; /* 是否只充当电源板0x00:不是0x01是*/
float constantVoltageV; /* 恒压充电阈值电压(V) */
float floatI; /* 浮充充电阈值电流(A) */
@ -113,7 +113,8 @@ typedef struct _config_info{
float constantVoltageChargeV; /* 恒压充电时的输出电压(V) */
float FloatChargeV; /* 浮充充电时的输出电压(V) */
uint16_t collectOpenCircuitVoltageTime; /* 充电时采集开路电压的间隔时间 */
float reverseChargProtectionCurr; /* 反向充电保护电流 */
uint16_t crc; /* 校验 */
}config_info;
#define CONFIG_INFO_SIZE (sizeof(config_info))
@ -148,8 +149,8 @@ void config_info_start(void);
void readFlashContent(config_info *configInfo);
void cfgTest(void);
void saveLoopImpedance();
BOOL readLoopImpedance();
void saveLoopImpedance(float *loopImpedance);
void readLoopImpedance(float *loopImpedance);
void savetotalElectricityConsumption(float *totalElectricityConsumption);
void readtotalElectricityConsumption(float *totalElectricityConsumption);
void savetotalChargCapacity(float *totalChargCapacity);

View File

@ -14,7 +14,7 @@ typedef struct _config_parameter{
uint32_t gw485_Baud; /* 串口波特率 */
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
uint8_t powerBoxType; /* 是否只充当电源板0x00:不是0x01:是*/
uint8_t powerBoxType; /* 是否只充当电源板0x00:不是0xFF:是*/
float constantVoltageV; /* 恒压充电阈值电压(V) */
float floatI; /* 浮充充电阈值电流(A) */
float startSolarOpenCircuitV; /* 启动充电太阳能板开路电压(V) */
@ -28,7 +28,7 @@ typedef struct _config_parameter{
uint16_t firstStageProtectionValue; /* 第一段保护ADC值 */
uint16_t secondStageProtectionDelay; /* 第二段保护延时(100uS) */
float secondStageProtectionCurr; /* 第二段保护电流(A) */
uint16_t thirdStageProtectionDelay; /* 第三段保护延时(100uS) */
uint32_t thirdStageProtectionDelay; /* 第三段保护延时(100uS) */
float thirdStageProtectionCurr; /* 第三段保护电流(A) */
uint16_t inputPowerLowDetectionDelay; /* 前端输入功率不足检测延时(100uS) */
float inputPowerLowDetectionVolt; /* 前端输入功率不足检测电压(V) */
@ -41,13 +41,13 @@ typedef struct _config_parameter{
float constantVoltageChargeV; /* 恒压充电时的输出电压(V) */
float FloatChargeV; /* 浮充充电时的输出电压(V) */
uint16_t collectOpenCircuitVoltageTime; /* 充电时采集开路电压的间隔时间 */
float reverseChargProtectionCurr; /* 反向充电保护电流 */
/* SL */
uint16_t Access_Node_Type; /* 接入节点类型 */
uint16_t Communication_Methods; /* 通信方式 */
uint8_t startFlagSL[2]; /* 起始标志 */
uint8_t endFlagSL; /* 结束标志 */
} config_parameter;
extern config_parameter g_cfgParameter;
typedef struct _otherParameter{
@ -124,5 +124,7 @@ BOOL setLoopImpedance(float loopImpedance);
uint16_t getRegistrationStatus(void);
void setRegistrationStatus(uint16_t status);
void setExChargeCurr(void);
float getExChargeCurr(void);
#endif

View File

@ -30,14 +30,13 @@ void Init(void)
FM_GPIO_Init();
tim_Init();
FM_RTC_Init();
Init_debug_uart();
Init_BAT485_uart(g_cfgParameter.bat485_Baud);
Init_GW485_uart(g_cfgParameter.gw485_Baud);
// Init_BAT485_uart(115200);
// Init_GW485_uart(115200);
// Init_BAT485_uart(115200);
// Init_GW485_uart(115200);
start_gw485Rx_It();
start_bat485Rx_It();
@ -48,8 +47,11 @@ void Init(void)
// POW_OUT_PCON_Open();
HAL_Delay(100);
setPowerOutput(TRUE);
// EN_PWMOUT_Eable();
// setDutyRatio(0.5);
// while(1);
// while (1) {
// log_info("Init_debug_uart \n");
// HAL_Delay(1000);
// }
}

View File

@ -4,6 +4,7 @@
#include "parameter.h"
#include "FM_RTC.h"
#include "flash.h"
#include "capture.h"
#define eventsOrderRecordStartAddr 4096
@ -83,6 +84,7 @@ void eventsOrderRecordStartInit(void)
| overTemperature | mos管温度 |
| stopTemperature | mos管温度 |
| overchargCurr | |
| hardwareShortCircuitProtection| |
*/
void insertEventsOrderRecord(eventsOrderRecordMode mode)
{
@ -127,6 +129,18 @@ void insertEventsOrderRecord(eventsOrderRecordMode mode)
soeInfo.insertData->temp = getSolarInCircuitVoltage();
}
else if (mode == hardwareShortCircuitProtection) {
soeInfo.insertData->temp = getDischargCurrent();
}
else if (mode == hardwareInputProtection) {
soeInfo.insertData->temp = get_EXCHG_CURR();
}
else if (mode == hardwareShortCircuitProtection) {
soeInfo.insertData->temp = get_EXCHG_CURR();
}
else {
soeInfo.count++;
return;

View File

@ -443,6 +443,7 @@ void DSG_PROT_Interrupt(void)
setShortCircuit();
/* 第一次进入输出短路,启动短路任务 */
if (getShortCircuit() == 1) {
setPowerOutput(FALSE);
setShortCircuitFlag(TRUE);
startShortCircuitProtection();
}
@ -452,12 +453,13 @@ void DSG_PROT_Interrupt(void)
stopShortCircuitProtection();
setPowerOutput(FALSE);
zeroShortCircuit();
insertEventsOrderRecord(hardwareShortCircuitProtection);
}
}
void EXCHG_PROT_Interrupt(void)
{
setPowerOutput(FALSE);
insertEventsOrderRecord(hardwareInputProtection);
}

View File

@ -735,6 +735,7 @@ void bl_chargControl(void)
BatteryChargControl();
} else {
noBatteryChargControl();
}
}
// noBatteryChargControl();
}

View File

@ -99,6 +99,7 @@ typedef enum {
constant_Voltage_Charge_V = 0x0117, /* (2字节)恒压充电时的输出电压(*10再强转u16(V)) */
float_ChargeV = 0x0118, /* (2字节)浮充充电时的输出电压(*10再强转u16(V)) */
collect_OpenCircuit_Voltage_Time = 0x0119, /* (2字节)充电时采集开路电压的间隔时间(S) */
reverse_Charge_Protection_Curr = 0x011A, /* (2字节)反向充电保护电流(A) */
}cfgFileType;
#define gw485RxBufferSize 256
@ -588,7 +589,7 @@ BOOL analysisFunctionCodeSL(void)
uint32_t tempCfgLen = 0;
tempCfgLen = (gw485RxBuffer[10] << 8) | gw485RxBuffer[11];
if (tempCfgLen < RegAddrNumMacro && tempCfgLen > 0) {
if (tempCfgLen < maxReadCfgLen && tempCfgLen > 0) {
state = readCfgLengthSL;
frameLength = 15 + tempCfgLen;
return TRUE;
@ -1194,7 +1195,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
temp->gw485_Baud = 115200;
return (pMsg + 3);
default:
return NULL;
return NULL;
}
}
@ -1228,13 +1229,13 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
else if (dataType == power_Box_Type) {
switch (pMsg[2]) {
case 0x00:
temp->bat485_Baud = 0x00;
temp->powerBoxType = 0x00;
return (pMsg + 3);
case 0xFF:
temp->bat485_Baud = 0xFF;
temp->powerBoxType = 0xFF;
return (pMsg + 3);
default:
return NULL;
return NULL;
}
}
@ -1294,6 +1295,18 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
return (pMsg + 4);
}
/* 配置 短路判断延时 */
else if (dataType == short_Circuit_Judgment_Delay) {
uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3);
if (tempU16 > 100 || tempU16 < 3) {
return NULL;
}
temp->inputPowerLowJudgmentDelay = tempU16;
return (pMsg + 4);
}
/* 配置 前端输入功率不足判断延时 */
else if (dataType == input_Power_Low_Judgment_Delay) {
uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3);
@ -1344,7 +1357,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
/* 配置 软件第二段保护延时 */
else if (dataType == second_Stage_Protection_Delay) {
uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3);
if (tempU16 > 10000 || tempU16 < 10) {
if (tempU16 > 60000 || tempU16 < 10) {
return NULL;
}
@ -1366,19 +1379,21 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
/* 配置 软件第三段保护延时 */
else if (dataType == third_Stage_Protection_Delay) {
uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3);
if (tempU16 > 10000 || tempU16 < 10) {
uint32_t tempU32 = (*(pMsg + 2) << 24) | (*(pMsg + 3) << 16) | (*(pMsg + 4) << 8) | *(pMsg + 5);
if (tempU32 > 1000000 || tempU32 < 10) {
// debug_printf("third_Stage_Protection_Delay = %d\n", tempU32);
return NULL;
}
temp->thirdStageProtectionDelay = tempU16;
return (pMsg + 4);
temp->thirdStageProtectionDelay = tempU32;
return (pMsg + 6);
}
/* 配置 软件第三段保护阈值电流 */
else if (dataType == third_Stage_Protection_Curr) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 50 || tempFloat < 1) {
// debug_printf("third_Stage_Protection_Curr\n");
return NULL;
}
@ -1390,6 +1405,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
else if (dataType == input_Power_Low_Detection_Delay) {
uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3);
if (tempU16 > 1000 || tempU16 < 2) {
// debug_printf("input_Power_Low_Detection_Delay\n");
return NULL;
}
@ -1401,6 +1417,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
else if (dataType == input_Power_Low_Detection_Volt) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 13 || tempFloat < 8) {
// debug_printf("input_Power_Low_Detection_Volt\n");
return NULL;
}
@ -1412,6 +1429,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
else if (dataType == max_Open_Solar_Output_Circuit_V) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 27 || tempFloat < 22) {
// debug_printf("max_Open_Solar_Output_Circuit_V\n");
return NULL;
}
@ -1423,17 +1441,31 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
else if (dataType == max_Charg_Curr) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 40 || tempFloat < 30) {
// debug_printf("max_Charg_Curr\n");
return NULL;
}
temp->maxChargCurr = tempFloat;
return (pMsg + 4);
}
/* 配置 检测回路阻抗时的最小充电电流 */
else if (dataType == min_Check_Loop_Impedance_Charg_Curr) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 20 || tempFloat < 2) {
// debug_printf("min_Check_Loop_Impedance_Charg_Curr\n");
return NULL;
}
temp->maxChargCurr = tempFloat;
return (pMsg + 4);
}
/* 配置 满功率输出温度 */
else if (dataType == full_Power_Output_Temperature) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 100 || tempFloat < 30) {
// debug_printf("full_Power_Output_Temperature\n");
return NULL;
}
@ -1445,6 +1477,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
else if (dataType == reduce_Power_Output_Temperature) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 100 || tempFloat < 30) {
// debug_printf("reduce_Power_Output_Temperature\n");
return NULL;
}
@ -1456,6 +1489,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
else if (dataType == stop_PowerOutput_Temperature) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 100 || tempFloat < 30) {
// debug_printf("stop_PowerOutput_Temperature\n");
return NULL;
}
@ -1467,6 +1501,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
else if (dataType == constant_Voltage_Charge_V) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 14.5f || tempFloat < 14) {
// debug_printf("constant_Voltage_Charge_V\n");
return NULL;
}
@ -1495,6 +1530,17 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp)
temp->collectOpenCircuitVoltageTime = tempU16;
return (pMsg + 4);
}
/* 配置 反向充电保护电流 */
else if (dataType == reverse_Charge_Protection_Curr) {
float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification;
if (tempFloat > 10.0f || tempFloat < 0.1f) {
return NULL;
}
temp->reverseChargProtectionCurr = tempFloat;
return (pMsg + 4);
}
return NULL;
}
@ -1811,7 +1857,7 @@ uint8_t *analysisReadProfile(uint8_t *pMsg, uint8_t **outData, uint16_t *dataLen
/* 读取 满功率输出温度 */
else if (dataType == full_Power_Output_Temperature) {
uint16_t tempU16 = (uint16_t)(g_cfgParameter.minCheckLoopImpedanceChargCurr * floatMagnification);
uint16_t tempU16 = (uint16_t)(g_cfgParameter.fullPowerOutputTemperature * floatMagnification);
*(*outData + 2) = (uint8_t)(tempU16 >> 8);
*(*outData + 3) = (uint8_t)(tempU16 & 0x00FF);
*outData += 4;
@ -1861,7 +1907,17 @@ uint8_t *analysisReadProfile(uint8_t *pMsg, uint8_t **outData, uint16_t *dataLen
/* 读取 充电时采集开路电压的间隔时间 */
else if (dataType == collect_OpenCircuit_Voltage_Time) {
uint16_t tempU16 = (uint16_t)(g_cfgParameter.collectOpenCircuitVoltageTime * floatMagnification);
uint16_t tempU16 = g_cfgParameter.collectOpenCircuitVoltageTime;
*(*outData + 2) = (uint8_t)(tempU16 >> 8);
*(*outData + 3) = (uint8_t)(tempU16 & 0x00FF);
*outData += 4;
*dataLen += 4;
return (pMsg + 2);
}
/* 读取 反向充电保护电流 */
else if (dataType == reverse_Charge_Protection_Curr) {
uint16_t tempU16 = (uint16_t)(g_cfgParameter.reverseChargProtectionCurr * floatMagnification);
*(*outData + 2) = (uint8_t)(tempU16 >> 8);
*(*outData + 3) = (uint8_t)(tempU16 & 0x00FF);
*outData += 4;
@ -2081,6 +2137,9 @@ void SL_MsgProcFunc_Distribution_Profile(device_handle device, void *pMsg, uint3
}
if (((HAL_GetTick() - tickstart1) >= 100) || (analysisData == NULL)) {
// if (analysisData == NULL) {
// debug_printf("analysisData == NULL\n");
// }
goto singlePackageError;
}
@ -2118,14 +2177,14 @@ wholePackageCorrect:
cfgInfo.crc = checkModebusCrc((uint8_t *)&cfgInfo, CONFIG_INFO_SIZE - 2);
saveConfigInfo(&cfgInfo);
// float tempF;
// tempF = getTotalElectricityConsumption();
// savetotalElectricityConsumption(&tempF);
// tempF = getTotalChargCapacity();
// savetotalChargCapacity(&tempF);
// timeInfo time;
// time = getLastTime();
// saveTime(&time);
float tempF;
tempF = getTotalElectricityConsumption();
savetotalElectricityConsumption(&tempF);
tempF = getTotalChargCapacity();
savetotalChargCapacity(&tempF);
timeInfo time;
time = getLastTime();
saveTime(&time);
return;

View File

@ -155,7 +155,7 @@ void readFlashContent(config_info *configInfo)
configInfo->gw485_Baud = 115200;
configInfo->bat485_Baud = 115200;
configInfo->powerBoxType = 0x01;
configInfo->powerBoxType = 0xFF;
configInfo->constantVoltageV = 14;
configInfo->floatI = 0.1f;
@ -189,6 +189,8 @@ void readFlashContent(config_info *configInfo)
configInfo->constantVoltageChargeV = 14.4f;
configInfo->FloatChargeV = 14.2f;
configInfo->collectOpenCircuitVoltageTime = 1800;
configInfo->reverseChargProtectionCurr = 2;
// configInfo->firstStageProtectionCurr = firstStageProtectionCurrMacro;
// configInfo->firstStageProtectionDelay = firstStageProtectionDelayMacro;
@ -227,7 +229,10 @@ void config_info_start(void)
g_cfgParameter.gw485_Baud = temp_configInfo.gw485_Baud;
g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
// g_cfgParameter.bat485_Baud = 115200;
// static volatile uint32_t tempBatBaud;
// tempBatBaud = temp_configInfo.bat485_Baud;
g_cfgParameter.uniqueDeviceID[0] = temp_configInfo.uniqueDeviceID[0];
g_cfgParameter.uniqueDeviceID[1] = temp_configInfo.uniqueDeviceID[1];
g_cfgParameter.uniqueDeviceID[2] = temp_configInfo.uniqueDeviceID[2];
@ -269,14 +274,21 @@ void config_info_start(void)
g_cfgParameter.constantVoltageChargeV = temp_configInfo.constantVoltageChargeV;
g_cfgParameter.FloatChargeV = temp_configInfo.FloatChargeV;
g_cfgParameter.collectOpenCircuitVoltageTime= temp_configInfo.collectOpenCircuitVoltageTime;
g_cfgParameter.reverseChargProtectionCurr = temp_configInfo.reverseChargProtectionCurr;
/* 读取的回路阻抗无效则回路阻抗设置为0 */
if (readLoopImpedance() == FALSE) {
setLoopImpedance(0);
saveLoopImpedance();
}
float fTemp;
// fTemp = 0.01f;
// saveLoopImpedance(&fTemp);
readLoopImpedance(&fTemp);
setLoopImpedance(fTemp);
// if (getLoopImpedance() < 0 || getLoopImpedance() > 0.3f) {
if (!setLoopImpedance(fTemp)) {
setLoopImpedance(0.01f);
fTemp = getLoopImpedance();
saveLoopImpedance(&fTemp);
}
readtotalElectricityConsumption(&fTemp);
totalElectricityConsumptionInt(fTemp);
readtotalChargCapacity(&fTemp);
@ -293,22 +305,18 @@ void config_info_start(void)
* @brief flash中
* @param
*/
void saveLoopImpedance(void)
void saveLoopImpedance(float *loopImpedance)
{
float loopImpedance;
loopImpedance = getLoopImpedance();
write_Flash((uint8_t *)&loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
write_Flash((uint8_t *)loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
}
/**
* @brief flash中的回路阻抗
* @param
*/
BOOL readLoopImpedance(void)
void readLoopImpedance(float *loopImpedance)
{
float loopImpedance;
read_Flash((uint8_t *)&loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
return setLoopImpedance(loopImpedance);
read_Flash((uint8_t *)loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
}
/**

View File

@ -14,6 +14,8 @@ static uint8_t mosTemperState = mosTemperFull; /* mos管温度状态 */
static BOOL checkImpedanceState = FALSE; /* 启动后是否进行了回路阻抗检测 */
static timeInfo lastTime = {0}; /* 上次读取充放电量参数的时间 */
static float exChargeCurr = 0;
/**
* @brief
* @param
@ -165,8 +167,10 @@ float getBatteryVoltage(void)
*/
void setBatteryVoltage(void)
{
g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage
- getChargBatteryCurrent() * getLoopImpedance();
// g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage
// - getChargBatteryCurrent() * getLoopImpedance();
g_otherParameter.Battery_Voltage = getOutputVoltage()
- getChargBatteryCurrent() * getLoopImpedance();
}
/**
@ -519,4 +523,25 @@ void setRegistrationStatus(uint16_t status)
if (status == UNREGISTER || status == REGISTER_FAIL || status == REGISTER_SUCCESS) {
g_otherParameter.Registration_Status = status;
}
}
}
/**
* @brief
* @param
* @retval
*/
void setExChargeCurr(void)
{
exChargeCurr = get_EXCHG_CURR();
}
/**
* @brief
* @param
* @retval
*/
float getExChargeCurr(void)
{
return exChargeCurr;
}

View File

@ -29,7 +29,7 @@ static STR_TimeSliceOffset m_runled;
static void Task_Runled(void);
/* 喂狗 */
#define wdi_reloadVal 3000 /* 任务执行间隔 */
#define wdi_reloadVal 1000 /* 任务执行间隔 */
#define wdi_offset 0 /* 任务执行偏移量 */
static STR_TimeSliceOffset m_wdi;
static void Task_wdi(void);
@ -211,10 +211,9 @@ void Task_wdi(void)
// debug_printf("MPPT_Mode:%d \n", getMPPT_Mode());
// debug_printf("loopImpedance:%f \n", getLoopImpedance());
// debug_printf("DutyRatio:%f \n", getDutyRatio());
// debug_printf("OUT_VOLT_IN:%f \n", get_OUT_VOLT_IN());
// // debug_printf("OUT_VOLT_IN:%f \n", get_OUT_VOLT_IN());
// debug_printf("HAL_GetTick:%d \n", HAL_GetTick());
// debug_printf("getExChargeCurr:%f \n", getExChargeCurr());
// char buf[100];
@ -291,6 +290,7 @@ void Task_refreshJudgeData(void)
/* 获取数据 */
setInputVoltage();
setHighSideMosTemperature();
setExChargeCurr();
// static float tempOutV;
// tempOutV = get_OUT_VOLT_IN();
@ -331,7 +331,13 @@ void Task_refreshJudgeData(void)
/* 停止充电 */
stopChargWork();
insertEventsOrderRecord(stopTemperature);
}
}
/* 反向充电电流检测 */
if (getExChargeCurr() > g_cfgParameter.reverseChargProtectionCurr) {
setPowerOutput(FALSE);
insertEventsOrderRecord(InputProtection);
}
}
/**
@ -474,7 +480,7 @@ void Task_impedanceCalculation(void)
// }
/* 判断回路阻抗是否合理 */
if (setLoopImpedance(tempLoopImpedance) == TRUE) {
saveLoopImpedance();
saveLoopImpedance(&tempLoopImpedance);
setCheckImpedanceState();
}
@ -636,14 +642,14 @@ void Task_shortCircuitProtection(void)
TimeSliceOffset_Unregister(&m_shortCircuitProtection);
m_shortCircuitProtection.runFlag = 0;
/* 仍然过流,彻底关闭输出 */
if (readOverCurrState() == FALSE) {
setPowerOutput(FALSE);
}
/* 不过流,则状态位复位 */
else {
setShortCircuitFlag(FALSE);
}
// /* 仍然过流,彻底关闭输出 */
// if (readOverCurrState() == FALSE) {
// setPowerOutput(FALSE);
// }
// /* 不过流,则状态位复位 */
// else {
// setShortCircuitFlag(FALSE);
// }
}
}

View File

@ -33,5 +33,8 @@ BOOL readOutputState(void);
extern void WORK_VOLT_Interrupt(void);
extern void DSG_PROT_Interrupt(void);
extern void EXCHG_PROT_Interrupt(void);
#endif

View File

@ -31,10 +31,12 @@ float get_DSG_CURR(void);
float get_PV1_VOLT_IN(void);
float get_PV_VOLT_IN1(void);
float get_MOSFET_Temper(void);
float get_OUT_VOLT_IN(void);
float get_EXCHG_CURR(void);
void adcCaptureFir();
extern void setSoftShortCircuit(uint16_t disChargCurrAdcNum);
extern void chargControl(void);
#endif

View File

@ -3,8 +3,8 @@
#define FM_FLASH_H_
#include "main.h"
// #include "w25qxx.h"
#include "w25q256.h"
#include "w25qxx.h"
// #include "w25q256.h"
void Flash_Init(void);
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);

View File

@ -167,7 +167,7 @@ BOOL readOverCurrState(void)
if (HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) {
return TRUE;
}
return FALSE;
}
@ -226,9 +226,13 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
WORK_VOLT_Interrupt();
}
// else if (GPIO_Pin == DSG_PROT_Pin) {
// DSG_PROT_Interrupt();
// }
else if (GPIO_Pin == DSG_PROT_Pin) {
DSG_PROT_Interrupt();
}
else if (GPIO_Pin == EXCHG_PROT_Pin) {
EXCHG_PROT_Interrupt();
}
}

View File

@ -19,7 +19,7 @@ void tim_Init(void)
// HAL_TIM_Base_Start(&htim3);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
HD_controlTim_Init();
// HD_controlTim_Init();
HAL_TIM_Base_Start_IT(&htim7);
HD_taskBaseTim_Init();

View File

@ -98,7 +98,9 @@ enum {
CHG_CURR_NUM = 2,
PV_VOLT_IN_NUM = 3,
};
int16_t adcBuff[4];
// int16_t adcBuff[4];
int16_t adcBuff[40];
/* 指向adcCapture中的inData16数组中的第一位也是最后一位 */
uint8_t pointer;
@ -109,11 +111,11 @@ adcCapture CHG_CURR_capture = {0};
/* 电流电压采集转换的 */
static float P_CHG_CURR = 0;
static float P_PV_VOLT_OUT = 0;
static float P_EXCHG_CURR = 0;
static float P_DSG_CURR = 0;
static float P_PV1_VOLT_IN = 0;
static float P_PV_VOLT_IN1 = 0;
static float P_OUT_VOLT_IN = 0;
static float P_PV_VOLT_OUT = 0;
/* 2.5为adc的电压4095是2^adc的位数 - 1 */
// const float32_t Proportion = 2.5 / 4095;
@ -161,7 +163,7 @@ void ADC_Capture_Init(void)
// captureFirInit();
HAL_TIM_Base_Start(&htim6);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 4);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 40);
// /* 光伏充电输出电流比例,放大倍数*电阻 */
// P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion;
@ -194,8 +196,8 @@ void proportionalInt(int mode)
P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
/* 系统电源电压比例 */
P_PV_VOLT_IN1 = ((47.0 + 4.7) / 4.7) * Proportion;
/* 输出外部电压比例 */
P_OUT_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
/* 外部输入电流比例 */
P_EXCHG_CURR = P_DSG_CURR;
}
/* 电源盒外还有网关功能 */
@ -210,8 +212,8 @@ void proportionalInt(int mode)
P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
/* 系统电源电压比例 */
P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
/* 输出外部电压比例 */
P_OUT_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
/* 外部输入电流比例 */
P_EXCHG_CURR = P_DSG_CURR;
}
@ -433,31 +435,32 @@ float get_MOSFET_Temper(void)
* @param
* @retval V
*/
float get_OUT_VOLT_IN(void)
float get_EXCHG_CURR(void)
{
float V;
uint16_t V_ADC;
static uint16_t V_ADCTemp = (uint16_t)(0.52f / 3.0f * 4095);
float I;
uint16_t I_ADC;
// static uint16_t V_ADCTemp = (uint16_t)(0.52f / 3.0f * 4095);
// static uint16_t V_ADCTemp = (uint16_t)(0.17f / 3.0f * 4095);
V_ADC = ADC2_Capture(OUT_VOLT_IN_CHANNEL);
I_ADC = ADC2_Capture(EXCHG_CURR_CHANNEL);
I = (float)(I_ADC) * P_EXCHG_CURR;
if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)) {
V = (float)(V_ADC) * P_OUT_VOLT_IN;
} else {
if (V_ADC > V_ADCTemp) {
V = (float)(V_ADC - V_ADCTemp) * P_OUT_VOLT_IN;
}
V = (float)(V_ADC) * P_OUT_VOLT_IN;
}
// if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)) {
// V = (float)(V_ADC) * P_OUT_VOLT_IN;
// } else {
// if (V_ADC > V_ADCTemp) {
// V = (float)(V_ADC - V_ADCTemp) * P_OUT_VOLT_IN;
// }
// V = (float)(V_ADC) * P_OUT_VOLT_IN;
// }
#ifdef enable_Printf_VI
debug("\n OUT_VOLT_IN ADC : %d \n", V_ADC);
debug(" OUT_VOLT_IN V : %f \n", V);
#endif
return V;
return I;
}
@ -470,42 +473,65 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma)
{
if (hdma->Instance == ADC1) {
// HAL_GPIO_TogglePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin,GPIO_PIN_SET);
// HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin,GPIO_PIN_SET);
setSoftShortCircuit(adcBuff[DSG_CURR_NUM]);
// setSoftShortCircuit(adcBuff[DSG_CURR_NUM]);
WORK_VOLT_capture.totalInData -= WORK_VOLT_capture.inData16[pointer];
DSG_CURR_capture.totalInData -= DSG_CURR_capture.inData16[pointer];
PV_VOLT_IN_capture.totalInData -= PV_VOLT_IN_capture.inData16[pointer];
CHG_CURR_capture.totalInData -= CHG_CURR_capture.inData16[pointer];
// WORK_VOLT_capture.totalInData -= WORK_VOLT_capture.inData16[pointer];
// DSG_CURR_capture.totalInData -= DSG_CURR_capture.inData16[pointer];
// PV_VOLT_IN_capture.totalInData -= PV_VOLT_IN_capture.inData16[pointer];
// CHG_CURR_capture.totalInData -= CHG_CURR_capture.inData16[pointer];
WORK_VOLT_capture.inData16[pointer] = adcBuff[WORK_VOLT_NUM];
DSG_CURR_capture.inData16[pointer] = adcBuff[DSG_CURR_NUM];
PV_VOLT_IN_capture.inData16[pointer] = adcBuff[PV_VOLT_IN_NUM];
CHG_CURR_capture.inData16[pointer] = adcBuff[CHG_CURR_NUM];
// WORK_VOLT_capture.inData16[pointer] = adcBuff[WORK_VOLT_NUM];
// DSG_CURR_capture.inData16[pointer] = adcBuff[DSG_CURR_NUM];
// PV_VOLT_IN_capture.inData16[pointer] = adcBuff[PV_VOLT_IN_NUM];
// CHG_CURR_capture.inData16[pointer] = adcBuff[CHG_CURR_NUM];
WORK_VOLT_capture.totalInData += WORK_VOLT_capture.inData16[pointer];
DSG_CURR_capture.totalInData += DSG_CURR_capture.inData16[pointer];
PV_VOLT_IN_capture.totalInData += PV_VOLT_IN_capture.inData16[pointer];
CHG_CURR_capture.totalInData += CHG_CURR_capture.inData16[pointer];
// WORK_VOLT_capture.totalInData += WORK_VOLT_capture.inData16[pointer];
// DSG_CURR_capture.totalInData += DSG_CURR_capture.inData16[pointer];
// PV_VOLT_IN_capture.totalInData += PV_VOLT_IN_capture.inData16[pointer];
// CHG_CURR_capture.totalInData += CHG_CURR_capture.inData16[pointer];
pointer++;
if (pointer >= 10) {
pointer = 0;
}
// pointer++;
// if (pointer >= 10) {
// pointer = 0;
// }
arm_copy_f32(WORK_VOLT_capture.IODataF + 1, WORK_VOLT_capture.IODataF, 3);
arm_copy_f32(DSG_CURR_capture.IODataF + 1, DSG_CURR_capture.IODataF, 3);
arm_copy_f32(PV_VOLT_IN_capture.IODataF + 1, PV_VOLT_IN_capture.IODataF, 3);
arm_copy_f32(CHG_CURR_capture.IODataF + 1, CHG_CURR_capture.IODataF, 3);
// arm_copy_f32(WORK_VOLT_capture.IODataF + 1, WORK_VOLT_capture.IODataF, 3);
// arm_copy_f32(DSG_CURR_capture.IODataF + 1, DSG_CURR_capture.IODataF, 3);
// arm_copy_f32(PV_VOLT_IN_capture.IODataF + 1, PV_VOLT_IN_capture.IODataF, 3);
// arm_copy_f32(CHG_CURR_capture.IODataF + 1, CHG_CURR_capture.IODataF, 3);
WORK_VOLT_capture.IODataF[3] = (float32_t)WORK_VOLT_capture.totalInData / indata16_size;
DSG_CURR_capture.IODataF[3] = (float32_t)DSG_CURR_capture.totalInData / indata16_size;
PV_VOLT_IN_capture.IODataF[3] = (float32_t)PV_VOLT_IN_capture.totalInData / indata16_size;
CHG_CURR_capture.IODataF[3] = (float32_t)CHG_CURR_capture.totalInData / indata16_size;
// WORK_VOLT_capture.IODataF[3] = (float32_t)WORK_VOLT_capture.totalInData / indata16_size;
// DSG_CURR_capture.IODataF[3] = (float32_t)DSG_CURR_capture.totalInData / indata16_size;
// PV_VOLT_IN_capture.IODataF[3] = (float32_t)PV_VOLT_IN_capture.totalInData / indata16_size;
// CHG_CURR_capture.IODataF[3] = (float32_t)CHG_CURR_capture.totalInData / indata16_size;
// HAL_GPIO_TogglePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin,GPIO_PIN_RESET);
// HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin,GPIO_PIN_RESET);
// WORK_VOLT_capture.outData = (float32_t)(adcBuff[0] + adcBuff[4] + adcBuff[8] + adcBuff[12] + adcBuff[16]
// + adcBuff[20] + adcBuff[24] + adcBuff[28] + adcBuff[32] + adcBuff[36]) / indata16_size;
// DSG_CURR_capture.outData = (float32_t)(adcBuff[1] + adcBuff[5] + adcBuff[9] + adcBuff[13] + adcBuff[17]
// + adcBuff[21] + adcBuff[25] + adcBuff[29] + adcBuff[33] + adcBuff[37]) / indata16_size;
// CHG_CURR_capture.outData = (float32_t)(adcBuff[2] + adcBuff[6] + adcBuff[10] + adcBuff[14] + adcBuff[18]
// + adcBuff[22] + adcBuff[26] + adcBuff[30] + adcBuff[34] + adcBuff[38]) / indata16_size;
// PV_VOLT_IN_capture.outData = (float32_t)(adcBuff[3] + adcBuff[7] + adcBuff[11] + adcBuff[15] + adcBuff[19]
// + adcBuff[23] + adcBuff[27] + adcBuff[31] + adcBuff[35] + adcBuff[39]) / indata16_size;
WORK_VOLT_capture.outData = (adcBuff[0] + adcBuff[4] + adcBuff[8] + adcBuff[12] + adcBuff[16]
+ adcBuff[20] + adcBuff[24] + adcBuff[28] + adcBuff[32] + adcBuff[36]) / indata16_size;
DSG_CURR_capture.outData = (adcBuff[1] + adcBuff[5] + adcBuff[9] + adcBuff[13] + adcBuff[17]
+ adcBuff[21] + adcBuff[25] + adcBuff[29] + adcBuff[33] + adcBuff[37]) / indata16_size;
CHG_CURR_capture.outData = (adcBuff[2] + adcBuff[6] + adcBuff[10] + adcBuff[14] + adcBuff[18]
+ adcBuff[22] + adcBuff[26] + adcBuff[30] + adcBuff[34] + adcBuff[38]) / indata16_size;
PV_VOLT_IN_capture.outData = (adcBuff[3] + adcBuff[7] + adcBuff[11] + adcBuff[15] + adcBuff[19]
+ adcBuff[23] + adcBuff[27] + adcBuff[31] + adcBuff[35] + adcBuff[39]) / indata16_size;
setSoftShortCircuit(DSG_CURR_capture.outData);
chargControl();
}
}
@ -579,15 +605,15 @@ void adcCaptureFir(void)
// PV_VOLT_IN_capture.outData = 1;
// CHG_CURR_capture.outData = 1;
static float32_t outputf;
arm_dot_prod_f32(WORK_VOLT_capture.IODataF, firLP, firLen, &outputf);
WORK_VOLT_capture.outData = (int16_t)outputf;
arm_dot_prod_f32(DSG_CURR_capture.IODataF, firLP, firLen, &outputf);
DSG_CURR_capture.outData = (int16_t)outputf;
arm_dot_prod_f32(PV_VOLT_IN_capture.IODataF, firLP, firLen, &outputf);
PV_VOLT_IN_capture.outData = (int16_t)outputf;
arm_dot_prod_f32(CHG_CURR_capture.IODataF, firLP, firLen, &outputf);
CHG_CURR_capture.outData = (int16_t)outputf;
// static float32_t outputf;
// arm_dot_prod_f32(WORK_VOLT_capture.IODataF, firLP, firLen, &outputf);
// WORK_VOLT_capture.outData = (int16_t)outputf;
// arm_dot_prod_f32(DSG_CURR_capture.IODataF, firLP, firLen, &outputf);
// DSG_CURR_capture.outData = (int16_t)outputf;
// arm_dot_prod_f32(PV_VOLT_IN_capture.IODataF, firLP, firLen, &outputf);
// PV_VOLT_IN_capture.outData = (int16_t)outputf;
// arm_dot_prod_f32(CHG_CURR_capture.IODataF, firLP, firLen, &outputf);
// CHG_CURR_capture.outData = (int16_t)outputf;
}

View File

@ -8,16 +8,23 @@
*/
void Flash_Init(void)
{
// __HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
// HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
// GPIO_InitTypeDef GPIO_InitStruct = {0};
HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
GPIO_InitTypeDef GPIO_InitStruct = {0};
// // GPIO_InitStruct.Pin = FLASH_CS_Pin | FLASH_CLK_Pin | FLASH_MISO_Pin;
// // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// // GPIO_InitStruct.Pull = GPIO_NOPULL;
// // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : FLASH_CS_Pin */
GPIO_InitStruct.Pin = FLASH_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
// GPIO_InitStruct.Pin = FLASH_CS_Pin | FLASH_CLK_Pin | FLASH_MISO_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// // GPIO_InitStruct.Pin = FLASH_MOSI_Pin;
// // GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
@ -37,30 +44,30 @@ void Flash_Init(void)
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitTypeDef GPIO_InitStruct = {0};
// GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOA_CLK_ENABLE();
// __HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
// HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin, GPIO_PIN_RESET);
// /*Configure GPIO pin Output Level */
// // HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin, GPIO_PIN_RESET);
// HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : FLASH_CS_Pin FLASH_CLK_Pin FLASH_MISO_Pin */
// GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin;
GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// /*Configure GPIO pins : FLASH_CS_Pin FLASH_CLK_Pin FLASH_MISO_Pin */
// // GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin;
// GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : FLASH_MOSI_Pin */
GPIO_InitStruct.Pin = FLASH_MISO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(FLASH_MOSI_GPIO_Port, &GPIO_InitStruct);
// /*Configure GPIO pin : FLASH_MOSI_Pin */
// GPIO_InitStruct.Pin = FLASH_MISO_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
// GPIO_InitStruct.Pull = GPIO_PULLUP;
// HAL_GPIO_Init(FLASH_MOSI_GPIO_Port, &GPIO_InitStruct);
Flash_GPIO_Init();
// W25QXX_Init();
// Flash_GPIO_Init();
W25QXX_Init();
}
/**
@ -71,8 +78,8 @@ void Flash_Init(void)
*/
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
{
// W25QXX_Read(pBuffer, ReadAddr, NumByteToRead);
Flash_Read(pBuffer, ReadAddr, NumByteToRead);
W25QXX_Read(pBuffer, ReadAddr, NumByteToRead);
// Flash_Read(pBuffer, ReadAddr, NumByteToRead);
}
@ -84,7 +91,7 @@ void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
*/
void write_Flash(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
{
// W25QXX_Write(pBuffer, WriteAddr, NumByteToWrite);
W25QXX_Write(pBuffer, WriteAddr, NumByteToWrite);
// Flash_Write_MorePage(pBuffer, WriteAddr, NumByteToWrite);
W25Q128_Write(pBuffer, WriteAddr, NumByteToWrite);
// W25Q128_Write(pBuffer, WriteAddr, NumByteToWrite);
}

View File

@ -7,9 +7,9 @@ device_handle g_gw485_uart2_handle;
device_handle g_bat485_uart3_handle;
device_handle g_debug_uart4_handle;
static uint8_t Debug_in_buff[200];
static uint8_t Gw485_in_buff[200];
static uint8_t Bat485_in_buff[200];
static uint8_t Debug_in_buff[10];
static uint8_t Gw485_in_buff[300];
static uint8_t Bat485_in_buff[300];
uint8_t rx_gw485_buf[1];
uint8_t rx_bat485_buf[1];

View File

@ -10,7 +10,7 @@
#include "stm32g431xx.h"
#define SYS_VOLT_IN_CHANNEL ADC_CHANNEL_1
#define OUT_VOLT_IN_CHANNEL ADC_CHANNEL_9
#define EXCHG_CURR_CHANNEL ADC_CHANNEL_6
#define MOSFET_Temper_CHANNEL ADC_CHANNEL_15
void HD_adc_Init(void);

View File

@ -7,14 +7,14 @@
/*******************************************************************************
* & *
*******************************************************************************/
// #define FLASH_CS_GPIO_Port GPIOA
// #define FLASH_CS_Pin FLASH_CS_Pin
// #define FLASH_CLK_GPIO_Port GPIOA
// #define FLASH_CLK_Pin FLASH_CLK_Pin
// #define FLASH_MISO_GPIO_Port GPIOA
// #define FLASH_MISO_Pin FLASH_MISO_Pin
// #define FLASH_MOSI_GPIO_Port GPIOA
// #define FLASH_MOSI_Pin FLASH_MOSI_Pin
#define FLASH_CS_GPIO_Port GPIOA
#define FLASH_CS_Pin FLASH_CS_Pin
#define FLASH_CLK_GPIO_Port GPIOA
#define FLASH_CLK_Pin FLASH_CLK_Pin
#define FLASH_MISO_GPIO_Port GPIOA
#define FLASH_MISO_Pin FLASH_MISO_Pin
#define FLASH_MOSI_GPIO_Port GPIOA
#define FLASH_MOSI_Pin FLASH_MOSI_Pin
#define FLASH_CS_ENABLE HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET) /*片选使能*/
#define FLASH_CS_DISABLE HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_SET) /*片选失能*/

View File

@ -2,57 +2,118 @@
void HD_GPIO_Init(void)
{
// MX_GPIO_Init();
// // MX_GPIO_Init();
GPIO_InitTypeDef GPIO_InitStruct = {0};
// GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
// /* GPIO Ports Clock Enable */
// __HAL_RCC_GPIOC_CLK_ENABLE();
// __HAL_RCC_GPIOF_CLK_ENABLE();
// __HAL_RCC_GPIOA_CLK_ENABLE();
// __HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
// HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
// /*Configure GPIO pin Output Level */
// // HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin, GPIO_PIN_RESET);
// /*Configure GPIO pin Output Level */
// HAL_GPIO_WritePin(GPIOB, WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, EN_PWMOUT_Pin|FFMOS_CON_Pin, GPIO_PIN_SET);
// /*Configure GPIO pin Output Level */
// HAL_GPIO_WritePin(GPIOA, EN_PWMOUT_Pin|FFMOS_CON_Pin, GPIO_PIN_SET);
/*Configure GPIO pin : DSG_PROT_Pin */
GPIO_InitStruct.Pin = DSG_PROT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
// /*Configure GPIO pin : DSG_PROT_Pin */
// GPIO_InitStruct.Pin = DSG_PROT_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
// GPIO_InitStruct.Pull = GPIO_PULLUP;
// HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : FLASH_CS_Pin EN_PWMOUT_Pin FFMOS_CON_Pin */
// GPIO_InitStruct.Pin = FLASH_CS_Pin|EN_PWMOUT_Pin|FFMOS_CON_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = EN_PWMOUT_Pin|FFMOS_CON_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// /*Configure GPIO pins : FLASH_CS_Pin EN_PWMOUT_Pin FFMOS_CON_Pin */
// // GPIO_InitStruct.Pin = FLASH_CS_Pin|EN_PWMOUT_Pin|FFMOS_CON_Pin;
// // GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// // GPIO_InitStruct.Pull = GPIO_NOPULL;
// // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
// // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
// GPIO_InitStruct.Pin = EN_PWMOUT_Pin|FFMOS_CON_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
// /*Configure GPIO pins : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
// GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
// HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin : WORK_VOLT_INT_Pin */
GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
// /*Configure GPIO pin : WORK_VOLT_INT_Pin */
// GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
// GPIO_InitStruct.Pull = GPIO_PULLDOWN;
// HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
// /* EXTI interrupt init*/
// HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
// HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
// HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, EN_PWMOUT_Pin|FFMOS_CON_Pin, GPIO_PIN_SET);
/*Configure GPIO pin : DSG_PROT_Pin */
GPIO_InitStruct.Pin = DSG_PROT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : FLASH_CS_Pin */
// GPIO_InitStruct.Pin = FLASH_CS_Pin;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
// HAL_GPIO_Init(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pins : EN_PWMOUT_Pin FFMOS_CON_Pin */
GPIO_InitStruct.Pin = EN_PWMOUT_Pin|FFMOS_CON_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : WORK_VOLT_INT_Pin */
GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : EXCHG_PROT_Pin */
GPIO_InitStruct.Pin = EXCHG_PROT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(EXCHG_PROT_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}

View File

@ -60,12 +60,12 @@ void Error_Handler(void);
#define DSG_PROT_Pin GPIO_PIN_13
#define DSG_PROT_GPIO_Port GPIOC
#define DSG_PROT_EXTI_IRQn EXTI15_10_IRQn
#define EXCHG_CURR_Pin GPIO_PIN_0
#define EXCHG_CURR_GPIO_Port GPIOC
#define WORK_VOLT_Pin GPIO_PIN_1
#define WORK_VOLT_GPIO_Port GPIOC
#define DSG_CURR_Pin GPIO_PIN_2
#define DSG_CURR_GPIO_Port GPIOC
#define OUT_VOLT_IN_Pin GPIO_PIN_3
#define OUT_VOLT_IN_GPIO_Port GPIOC
#define SYS_VOLT_IN_Pin GPIO_PIN_0
#define SYS_VOLT_IN_GPIO_Port GPIOA
#define GW485_RDE_Pin GPIO_PIN_1
@ -76,8 +76,8 @@ void Error_Handler(void);
#define GW485_RX_GPIO_Port GPIOA
#define FLASH_CS_Pin GPIO_PIN_4
#define FLASH_CS_GPIO_Port GPIOA
#define FLASH_CLK_Pin GPIO_PIN_5
#define FLASH_CLK_GPIO_Port GPIOA
#define FLASH_SCK_Pin GPIO_PIN_5
#define FLASH_SCK_GPIO_Port GPIOA
#define FLASH_MISO_Pin GPIO_PIN_6
#define FLASH_MISO_GPIO_Port GPIOA
#define FLASH_MOSI_Pin GPIO_PIN_7
@ -109,6 +109,8 @@ void Error_Handler(void);
#define DEBUG_TX_GPIO_Port GPIOC
#define DEBUG_RX_Pin GPIO_PIN_11
#define DEBUG_RX_GPIO_Port GPIOC
#define EXCHG_PROT_Pin GPIO_PIN_5
#define EXCHG_PROT_GPIO_Port GPIOB
#define RUN_LED_Pin GPIO_PIN_6
#define RUN_LED_GPIO_Port GPIOB
#define POW_FF_CON_Pin GPIO_PIN_7

52
Core/Inc/spi.h Normal file
View File

@ -0,0 +1,52 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file spi.h
* @brief This file contains all the function prototypes for
* the spi.c file
******************************************************************************
* @attention
*
* Copyright (c) 2025 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.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SPI_H__
#define __SPI_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern SPI_HandleTypeDef hspi1;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_SPI1_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __SPI_H__ */

View File

@ -60,7 +60,7 @@
/*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
/*#define HAL_SRAM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED

View File

@ -267,14 +267,14 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**ADC2 GPIO Configuration
PC3 ------> ADC2_IN9
PC0 ------> ADC2_IN6
PA0 ------> ADC2_IN1
PB15 ------> ADC2_IN15
*/
GPIO_InitStruct.Pin = OUT_VOLT_IN_Pin;
GPIO_InitStruct.Pin = EXCHG_CURR_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(OUT_VOLT_IN_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_Init(EXCHG_CURR_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = SYS_VOLT_IN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
@ -334,11 +334,11 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
}
/**ADC2 GPIO Configuration
PC3 ------> ADC2_IN9
PC0 ------> ADC2_IN6
PA0 ------> ADC2_IN1
PB15 ------> ADC2_IN15
*/
HAL_GPIO_DeInit(OUT_VOLT_IN_GPIO_Port, OUT_VOLT_IN_Pin);
HAL_GPIO_DeInit(EXCHG_CURR_GPIO_Port, EXCHG_CURR_Pin);
HAL_GPIO_DeInit(SYS_VOLT_IN_GPIO_Port, SYS_VOLT_IN_Pin);

View File

@ -51,7 +51,7 @@ void MX_GPIO_Init(void)
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin, GPIO_PIN_RESET);
@ -61,22 +61,16 @@ void MX_GPIO_Init(void)
/*Configure GPIO pin : DSG_PROT_Pin */
GPIO_InitStruct.Pin = DSG_PROT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : FLASH_CS_Pin FLASH_CLK_Pin FLASH_MISO_Pin */
GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin;
/*Configure GPIO pin : FLASH_CS_Pin */
GPIO_InitStruct.Pin = FLASH_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : FLASH_MOSI_Pin */
GPIO_InitStruct.Pin = FLASH_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(FLASH_MOSI_GPIO_Port, &GPIO_InitStruct);
HAL_GPIO_Init(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin;
@ -98,6 +92,12 @@ void MX_GPIO_Init(void)
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : EXCHG_PROT_Pin */
GPIO_InitStruct.Pin = EXCHG_PROT_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(EXCHG_PROT_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

View File

@ -21,6 +21,7 @@
#include "adc.h"
#include "dma.h"
#include "rtc.h"
#include "spi.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
@ -72,7 +73,6 @@ void SystemClock_Config(void);
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
@ -94,21 +94,24 @@ int main(void)
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
// MX_GPIO_Init();
// MX_DMA_Init();
// MX_ADC1_Init();
// MX_ADC2_Init();
// MX_TIM3_Init();
// MX_TIM6_Init();
// MX_UART4_Init();
// MX_USART2_UART_Init();
// MX_USART3_UART_Init();
// MX_TIM7_Init();
// MX_TIM16_Init();
// MX_TIM15_Init();
// MX_RTC_Init();
// MX_GPIO_Init();
// MX_DMA_Init();
// MX_ADC1_Init();
// MX_ADC2_Init();
// MX_TIM3_Init();
// MX_TIM6_Init();
// MX_UART4_Init();
// MX_USART2_UART_Init();
// MX_USART3_UART_Init();
// MX_TIM7_Init();
// MX_TIM16_Init();
// MX_TIM15_Init();
// MX_RTC_Init();
// MX_SPI1_Init();
/* USER CODE BEGIN 2 */
// while (1) {
// };
start();

121
Core/Src/spi.c Normal file
View File

@ -0,0 +1,121 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file spi.c
* @brief This file provides code for the configuration
* of the SPI instances.
******************************************************************************
* @attention
*
* Copyright (c) 2025 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.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "spi.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
SPI_HandleTypeDef hspi1;
/* SPI1 init function */
void MX_SPI1_Init(void)
{
/* USER CODE BEGIN SPI1_Init 0 */
/* USER CODE END SPI1_Init 0 */
/* USER CODE BEGIN SPI1_Init 1 */
/* USER CODE END SPI1_Init 1 */
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI1_Init 2 */
/* USER CODE END SPI1_Init 2 */
}
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(spiHandle->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
/* SPI1 clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = FLASH_SCK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
}
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
{
if(spiHandle->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspDeInit 0 */
/* USER CODE END SPI1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI1_CLK_DISABLE();
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
HAL_GPIO_DeInit(GPIOA, FLASH_SCK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin);
/* USER CODE BEGIN SPI1_MspDeInit 1 */
/* USER CODE END SPI1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */

View File

@ -0,0 +1,855 @@
/**
******************************************************************************
* @file stm32g4xx_hal_spi.h
* @author MCD Application Team
* @brief Header file of SPI HAL module.
******************************************************************************
* @attention
*
* Copyright (c) 2019 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32G4xx_HAL_SPI_H
#define STM32G4xx_HAL_SPI_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_hal_def.h"
/** @addtogroup STM32G4xx_HAL_Driver
* @{
*/
/** @addtogroup SPI
* @{
*/
/* Exported types ------------------------------------------------------------*/
/** @defgroup SPI_Exported_Types SPI Exported Types
* @{
*/
/**
* @brief SPI Configuration Structure definition
*/
typedef struct
{
uint32_t Mode; /*!< Specifies the SPI operating mode.
This parameter can be a value of @ref SPI_Mode */
uint32_t Direction; /*!< Specifies the SPI bidirectional mode state.
This parameter can be a value of @ref SPI_Direction */
uint32_t DataSize; /*!< Specifies the SPI data size.
This parameter can be a value of @ref SPI_Data_Size */
uint32_t CLKPolarity; /*!< Specifies the serial clock steady state.
This parameter can be a value of @ref SPI_Clock_Polarity */
uint32_t CLKPhase; /*!< Specifies the clock active edge for the bit capture.
This parameter can be a value of @ref SPI_Clock_Phase */
uint32_t NSS; /*!< Specifies whether the NSS signal is managed by
hardware (NSS pin) or by software using the SSI bit.
This parameter can be a value of @ref SPI_Slave_Select_management */
uint32_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be
used to configure the transmit and receive SCK clock.
This parameter can be a value of @ref SPI_BaudRate_Prescaler
@note The communication clock is derived from the master
clock. The slave clock does not need to be set. */
uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
This parameter can be a value of @ref SPI_MSB_LSB_transmission */
uint32_t TIMode; /*!< Specifies if the TI mode is enabled or not.
This parameter can be a value of @ref SPI_TI_mode */
uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not.
This parameter can be a value of @ref SPI_CRC_Calculation */
uint32_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation.
This parameter must be an odd number between Min_Data = 1 and Max_Data = 65535 */
uint32_t CRCLength; /*!< Specifies the CRC Length used for the CRC calculation.
CRC Length is only used with Data8 and Data16, not other data size
This parameter can be a value of @ref SPI_CRC_length */
uint32_t NSSPMode; /*!< Specifies whether the NSSP signal is enabled or not .
This parameter can be a value of @ref SPI_NSSP_Mode
This mode is activated by the NSSP bit in the SPIx_CR2 register and
it takes effect only if the SPI interface is configured as Motorola SPI
master (FRF=0) with capture on the first edge (SPIx_CR1 CPHA = 0,
CPOL setting is ignored).. */
} SPI_InitTypeDef;
/**
* @brief HAL SPI State structure definition
*/
typedef enum
{
HAL_SPI_STATE_RESET = 0x00U, /*!< Peripheral not Initialized */
HAL_SPI_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
HAL_SPI_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
HAL_SPI_STATE_BUSY_TX = 0x03U, /*!< Data Transmission process is ongoing */
HAL_SPI_STATE_BUSY_RX = 0x04U, /*!< Data Reception process is ongoing */
HAL_SPI_STATE_BUSY_TX_RX = 0x05U, /*!< Data Transmission and Reception process is ongoing */
HAL_SPI_STATE_ERROR = 0x06U, /*!< SPI error state */
HAL_SPI_STATE_ABORT = 0x07U /*!< SPI abort is ongoing */
} HAL_SPI_StateTypeDef;
/**
* @brief SPI handle Structure definition
*/
typedef struct __SPI_HandleTypeDef
{
SPI_TypeDef *Instance; /*!< SPI registers base address */
SPI_InitTypeDef Init; /*!< SPI communication parameters */
const uint8_t *pTxBuffPtr; /*!< Pointer to SPI Tx transfer Buffer */
uint16_t TxXferSize; /*!< SPI Tx Transfer size */
__IO uint16_t TxXferCount; /*!< SPI Tx Transfer Counter */
uint8_t *pRxBuffPtr; /*!< Pointer to SPI Rx transfer Buffer */
uint16_t RxXferSize; /*!< SPI Rx Transfer size */
__IO uint16_t RxXferCount; /*!< SPI Rx Transfer Counter */
uint32_t CRCSize; /*!< SPI CRC size used for the transfer */
void (*RxISR)(struct __SPI_HandleTypeDef *hspi); /*!< function pointer on Rx ISR */
void (*TxISR)(struct __SPI_HandleTypeDef *hspi); /*!< function pointer on Tx ISR */
DMA_HandleTypeDef *hdmatx; /*!< SPI Tx DMA Handle parameters */
DMA_HandleTypeDef *hdmarx; /*!< SPI Rx DMA Handle parameters */
HAL_LockTypeDef Lock; /*!< Locking object */
__IO HAL_SPI_StateTypeDef State; /*!< SPI communication state */
__IO uint32_t ErrorCode; /*!< SPI Error code */
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
void (* TxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Tx Completed callback */
void (* RxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Rx Completed callback */
void (* TxRxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI TxRx Completed callback */
void (* TxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Tx Half Completed callback */
void (* RxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Rx Half Completed callback */
void (* TxRxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI TxRx Half Completed callback */
void (* ErrorCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Error callback */
void (* AbortCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Abort callback */
void (* MspInitCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Msp Init callback */
void (* MspDeInitCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Msp DeInit callback */
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
} SPI_HandleTypeDef;
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
/**
* @brief HAL SPI Callback ID enumeration definition
*/
typedef enum
{
HAL_SPI_TX_COMPLETE_CB_ID = 0x00U, /*!< SPI Tx Completed callback ID */
HAL_SPI_RX_COMPLETE_CB_ID = 0x01U, /*!< SPI Rx Completed callback ID */
HAL_SPI_TX_RX_COMPLETE_CB_ID = 0x02U, /*!< SPI TxRx Completed callback ID */
HAL_SPI_TX_HALF_COMPLETE_CB_ID = 0x03U, /*!< SPI Tx Half Completed callback ID */
HAL_SPI_RX_HALF_COMPLETE_CB_ID = 0x04U, /*!< SPI Rx Half Completed callback ID */
HAL_SPI_TX_RX_HALF_COMPLETE_CB_ID = 0x05U, /*!< SPI TxRx Half Completed callback ID */
HAL_SPI_ERROR_CB_ID = 0x06U, /*!< SPI Error callback ID */
HAL_SPI_ABORT_CB_ID = 0x07U, /*!< SPI Abort callback ID */
HAL_SPI_MSPINIT_CB_ID = 0x08U, /*!< SPI Msp Init callback ID */
HAL_SPI_MSPDEINIT_CB_ID = 0x09U /*!< SPI Msp DeInit callback ID */
} HAL_SPI_CallbackIDTypeDef;
/**
* @brief HAL SPI Callback pointer definition
*/
typedef void (*pSPI_CallbackTypeDef)(SPI_HandleTypeDef *hspi); /*!< pointer to an SPI callback function */
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
/**
* @}
*/
/* Exported constants --------------------------------------------------------*/
/** @defgroup SPI_Exported_Constants SPI Exported Constants
* @{
*/
/** @defgroup SPI_Error_Code SPI Error Code
* @{
*/
#define HAL_SPI_ERROR_NONE (0x00000000U) /*!< No error */
#define HAL_SPI_ERROR_MODF (0x00000001U) /*!< MODF error */
#define HAL_SPI_ERROR_CRC (0x00000002U) /*!< CRC error */
#define HAL_SPI_ERROR_OVR (0x00000004U) /*!< OVR error */
#define HAL_SPI_ERROR_FRE (0x00000008U) /*!< FRE error */
#define HAL_SPI_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
#define HAL_SPI_ERROR_FLAG (0x00000020U) /*!< Error on RXNE/TXE/BSY/FTLVL/FRLVL Flag */
#define HAL_SPI_ERROR_ABORT (0x00000040U) /*!< Error during SPI Abort procedure */
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
#define HAL_SPI_ERROR_INVALID_CALLBACK (0x00000080U) /*!< Invalid Callback error */
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
/**
* @}
*/
/** @defgroup SPI_Mode SPI Mode
* @{
*/
#define SPI_MODE_SLAVE (0x00000000U)
#define SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI)
/**
* @}
*/
/** @defgroup SPI_Direction SPI Direction Mode
* @{
*/
#define SPI_DIRECTION_2LINES (0x00000000U)
#define SPI_DIRECTION_2LINES_RXONLY SPI_CR1_RXONLY
#define SPI_DIRECTION_1LINE SPI_CR1_BIDIMODE
/**
* @}
*/
/** @defgroup SPI_Data_Size SPI Data Size
* @{
*/
#define SPI_DATASIZE_4BIT (0x00000300U)
#define SPI_DATASIZE_5BIT (0x00000400U)
#define SPI_DATASIZE_6BIT (0x00000500U)
#define SPI_DATASIZE_7BIT (0x00000600U)
#define SPI_DATASIZE_8BIT (0x00000700U)
#define SPI_DATASIZE_9BIT (0x00000800U)
#define SPI_DATASIZE_10BIT (0x00000900U)
#define SPI_DATASIZE_11BIT (0x00000A00U)
#define SPI_DATASIZE_12BIT (0x00000B00U)
#define SPI_DATASIZE_13BIT (0x00000C00U)
#define SPI_DATASIZE_14BIT (0x00000D00U)
#define SPI_DATASIZE_15BIT (0x00000E00U)
#define SPI_DATASIZE_16BIT (0x00000F00U)
/**
* @}
*/
/** @defgroup SPI_Clock_Polarity SPI Clock Polarity
* @{
*/
#define SPI_POLARITY_LOW (0x00000000U)
#define SPI_POLARITY_HIGH SPI_CR1_CPOL
/**
* @}
*/
/** @defgroup SPI_Clock_Phase SPI Clock Phase
* @{
*/
#define SPI_PHASE_1EDGE (0x00000000U)
#define SPI_PHASE_2EDGE SPI_CR1_CPHA
/**
* @}
*/
/** @defgroup SPI_Slave_Select_management SPI Slave Select Management
* @{
*/
#define SPI_NSS_SOFT SPI_CR1_SSM
#define SPI_NSS_HARD_INPUT (0x00000000U)
#define SPI_NSS_HARD_OUTPUT (SPI_CR2_SSOE << 16U)
/**
* @}
*/
/** @defgroup SPI_NSSP_Mode SPI NSS Pulse Mode
* @{
*/
#define SPI_NSS_PULSE_ENABLE SPI_CR2_NSSP
#define SPI_NSS_PULSE_DISABLE (0x00000000U)
/**
* @}
*/
/** @defgroup SPI_BaudRate_Prescaler SPI BaudRate Prescaler
* @{
*/
#define SPI_BAUDRATEPRESCALER_2 (0x00000000U)
#define SPI_BAUDRATEPRESCALER_4 (SPI_CR1_BR_0)
#define SPI_BAUDRATEPRESCALER_8 (SPI_CR1_BR_1)
#define SPI_BAUDRATEPRESCALER_16 (SPI_CR1_BR_1 | SPI_CR1_BR_0)
#define SPI_BAUDRATEPRESCALER_32 (SPI_CR1_BR_2)
#define SPI_BAUDRATEPRESCALER_64 (SPI_CR1_BR_2 | SPI_CR1_BR_0)
#define SPI_BAUDRATEPRESCALER_128 (SPI_CR1_BR_2 | SPI_CR1_BR_1)
#define SPI_BAUDRATEPRESCALER_256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0)
/**
* @}
*/
/** @defgroup SPI_MSB_LSB_transmission SPI MSB LSB Transmission
* @{
*/
#define SPI_FIRSTBIT_MSB (0x00000000U)
#define SPI_FIRSTBIT_LSB SPI_CR1_LSBFIRST
/**
* @}
*/
/** @defgroup SPI_TI_mode SPI TI Mode
* @{
*/
#define SPI_TIMODE_DISABLE (0x00000000U)
#define SPI_TIMODE_ENABLE SPI_CR2_FRF
/**
* @}
*/
/** @defgroup SPI_CRC_Calculation SPI CRC Calculation
* @{
*/
#define SPI_CRCCALCULATION_DISABLE (0x00000000U)
#define SPI_CRCCALCULATION_ENABLE SPI_CR1_CRCEN
/**
* @}
*/
/** @defgroup SPI_CRC_length SPI CRC Length
* @{
* This parameter can be one of the following values:
* SPI_CRC_LENGTH_DATASIZE: aligned with the data size
* SPI_CRC_LENGTH_8BIT : CRC 8bit
* SPI_CRC_LENGTH_16BIT : CRC 16bit
*/
#define SPI_CRC_LENGTH_DATASIZE (0x00000000U)
#define SPI_CRC_LENGTH_8BIT (0x00000001U)
#define SPI_CRC_LENGTH_16BIT (0x00000002U)
/**
* @}
*/
/** @defgroup SPI_FIFO_reception_threshold SPI FIFO Reception Threshold
* @{
* This parameter can be one of the following values:
* SPI_RXFIFO_THRESHOLD or SPI_RXFIFO_THRESHOLD_QF :
* RXNE event is generated if the FIFO
* level is greater or equal to 1/4(8-bits).
* SPI_RXFIFO_THRESHOLD_HF: RXNE event is generated if the FIFO
* level is greater or equal to 1/2(16 bits). */
#define SPI_RXFIFO_THRESHOLD SPI_CR2_FRXTH
#define SPI_RXFIFO_THRESHOLD_QF SPI_CR2_FRXTH
#define SPI_RXFIFO_THRESHOLD_HF (0x00000000U)
/**
* @}
*/
/** @defgroup SPI_Interrupt_definition SPI Interrupt Definition
* @{
*/
#define SPI_IT_TXE SPI_CR2_TXEIE
#define SPI_IT_RXNE SPI_CR2_RXNEIE
#define SPI_IT_ERR SPI_CR2_ERRIE
/**
* @}
*/
/** @defgroup SPI_Flags_definition SPI Flags Definition
* @{
*/
#define SPI_FLAG_RXNE SPI_SR_RXNE /* SPI status flag: Rx buffer not empty flag */
#define SPI_FLAG_TXE SPI_SR_TXE /* SPI status flag: Tx buffer empty flag */
#define SPI_FLAG_BSY SPI_SR_BSY /* SPI status flag: Busy flag */
#define SPI_FLAG_CRCERR SPI_SR_CRCERR /* SPI Error flag: CRC error flag */
#define SPI_FLAG_MODF SPI_SR_MODF /* SPI Error flag: Mode fault flag */
#define SPI_FLAG_OVR SPI_SR_OVR /* SPI Error flag: Overrun flag */
#define SPI_FLAG_FRE SPI_SR_FRE /* SPI Error flag: TI mode frame format error flag */
#define SPI_FLAG_FTLVL SPI_SR_FTLVL /* SPI fifo transmission level */
#define SPI_FLAG_FRLVL SPI_SR_FRLVL /* SPI fifo reception level */
#define SPI_FLAG_MASK (SPI_SR_RXNE | SPI_SR_TXE | SPI_SR_BSY | SPI_SR_CRCERR\
| SPI_SR_MODF | SPI_SR_OVR | SPI_SR_FRE | SPI_SR_FTLVL | SPI_SR_FRLVL)
/**
* @}
*/
/** @defgroup SPI_transmission_fifo_status_level SPI Transmission FIFO Status Level
* @{
*/
#define SPI_FTLVL_EMPTY (0x00000000U)
#define SPI_FTLVL_QUARTER_FULL (0x00000800U)
#define SPI_FTLVL_HALF_FULL (0x00001000U)
#define SPI_FTLVL_FULL (0x00001800U)
/**
* @}
*/
/** @defgroup SPI_reception_fifo_status_level SPI Reception FIFO Status Level
* @{
*/
#define SPI_FRLVL_EMPTY (0x00000000U)
#define SPI_FRLVL_QUARTER_FULL (0x00000200U)
#define SPI_FRLVL_HALF_FULL (0x00000400U)
#define SPI_FRLVL_FULL (0x00000600U)
/**
* @}
*/
/**
* @}
*/
/* Exported macros -----------------------------------------------------------*/
/** @defgroup SPI_Exported_Macros SPI Exported Macros
* @{
*/
/** @brief Reset SPI handle state.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
#define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) \
do{ \
(__HANDLE__)->State = HAL_SPI_STATE_RESET; \
(__HANDLE__)->MspInitCallback = NULL; \
(__HANDLE__)->MspDeInitCallback = NULL; \
} while(0)
#else
#define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SPI_STATE_RESET)
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
/** @brief Enable the specified SPI interrupts.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @param __INTERRUPT__ specifies the interrupt source to enable.
* This parameter can be one of the following values:
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
* @arg SPI_IT_ERR: Error interrupt enable
* @retval None
*/
#define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))
/** @brief Disable the specified SPI interrupts.
* @param __HANDLE__ specifies the SPI handle.
* This parameter can be SPIx where x: 1, 2, or 3 to select the SPI peripheral.
* @param __INTERRUPT__ specifies the interrupt source to disable.
* This parameter can be one of the following values:
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
* @arg SPI_IT_ERR: Error interrupt enable
* @retval None
*/
#define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))
/** @brief Check whether the specified SPI interrupt source is enabled or not.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @param __INTERRUPT__ specifies the SPI interrupt source to check.
* This parameter can be one of the following values:
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
* @arg SPI_IT_ERR: Error interrupt enable
* @retval The new state of __IT__ (TRUE or FALSE).
*/
#define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2\
& (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
/** @brief Check whether the specified SPI flag is set or not.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @param __FLAG__ specifies the flag to check.
* This parameter can be one of the following values:
* @arg SPI_FLAG_RXNE: Receive buffer not empty flag
* @arg SPI_FLAG_TXE: Transmit buffer empty flag
* @arg SPI_FLAG_CRCERR: CRC error flag
* @arg SPI_FLAG_MODF: Mode fault flag
* @arg SPI_FLAG_OVR: Overrun flag
* @arg SPI_FLAG_BSY: Busy flag
* @arg SPI_FLAG_FRE: Frame format error flag
* @arg SPI_FLAG_FTLVL: SPI fifo transmission level
* @arg SPI_FLAG_FRLVL: SPI fifo reception level
* @retval The new state of __FLAG__ (TRUE or FALSE).
*/
#define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
/** @brief Clear the SPI CRCERR pending flag.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR = (uint16_t)(~SPI_FLAG_CRCERR))
/** @brief Clear the SPI MODF pending flag.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__) \
do{ \
__IO uint32_t tmpreg_modf = 0x00U; \
tmpreg_modf = (__HANDLE__)->Instance->SR; \
CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE); \
UNUSED(tmpreg_modf); \
} while(0U)
/** @brief Clear the SPI OVR pending flag.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__) \
do{ \
__IO uint32_t tmpreg_ovr = 0x00U; \
tmpreg_ovr = (__HANDLE__)->Instance->DR; \
tmpreg_ovr = (__HANDLE__)->Instance->SR; \
UNUSED(tmpreg_ovr); \
} while(0U)
/** @brief Clear the SPI FRE pending flag.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__) \
do{ \
__IO uint32_t tmpreg_fre = 0x00U; \
tmpreg_fre = (__HANDLE__)->Instance->SR; \
UNUSED(tmpreg_fre); \
} while(0U)
/** @brief Enable the SPI peripheral.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define __HAL_SPI_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE)
/** @brief Disable the SPI peripheral.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define __HAL_SPI_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE)
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @defgroup SPI_Private_Macros SPI Private Macros
* @{
*/
/** @brief Set the SPI transmit-only mode.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define SPI_1LINE_TX(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIOE)
/** @brief Set the SPI receive-only mode.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define SPI_1LINE_RX(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIOE)
/** @brief Reset the CRC calculation of the SPI.
* @param __HANDLE__ specifies the SPI Handle.
* This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
* @retval None
*/
#define SPI_RESET_CRC(__HANDLE__) \
do{ \
CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_CRCEN); \
SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_CRCEN); \
} while(0U)
/** @brief Check whether the specified SPI flag is set or not.
* @param __SR__ copy of SPI SR register.
* @param __FLAG__ specifies the flag to check.
* This parameter can be one of the following values:
* @arg SPI_FLAG_RXNE: Receive buffer not empty flag
* @arg SPI_FLAG_TXE: Transmit buffer empty flag
* @arg SPI_FLAG_CRCERR: CRC error flag
* @arg SPI_FLAG_MODF: Mode fault flag
* @arg SPI_FLAG_OVR: Overrun flag
* @arg SPI_FLAG_BSY: Busy flag
* @arg SPI_FLAG_FRE: Frame format error flag
* @arg SPI_FLAG_FTLVL: SPI fifo transmission level
* @arg SPI_FLAG_FRLVL: SPI fifo reception level
* @retval SET or RESET.
*/
#define SPI_CHECK_FLAG(__SR__, __FLAG__) ((((__SR__) & ((__FLAG__) & SPI_FLAG_MASK)) == \
((__FLAG__) & SPI_FLAG_MASK)) ? SET : RESET)
/** @brief Check whether the specified SPI Interrupt is set or not.
* @param __CR2__ copy of SPI CR2 register.
* @param __INTERRUPT__ specifies the SPI interrupt source to check.
* This parameter can be one of the following values:
* @arg SPI_IT_TXE: Tx buffer empty interrupt enable
* @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
* @arg SPI_IT_ERR: Error interrupt enable
* @retval SET or RESET.
*/
#define SPI_CHECK_IT_SOURCE(__CR2__, __INTERRUPT__) ((((__CR2__) & (__INTERRUPT__)) == \
(__INTERRUPT__)) ? SET : RESET)
/** @brief Checks if SPI Mode parameter is in allowed range.
* @param __MODE__ specifies the SPI Mode.
* This parameter can be a value of @ref SPI_Mode
* @retval None
*/
#define IS_SPI_MODE(__MODE__) (((__MODE__) == SPI_MODE_SLAVE) || \
((__MODE__) == SPI_MODE_MASTER))
/** @brief Checks if SPI Direction Mode parameter is in allowed range.
* @param __MODE__ specifies the SPI Direction Mode.
* This parameter can be a value of @ref SPI_Direction
* @retval None
*/
#define IS_SPI_DIRECTION(__MODE__) (((__MODE__) == SPI_DIRECTION_2LINES) || \
((__MODE__) == SPI_DIRECTION_2LINES_RXONLY) || \
((__MODE__) == SPI_DIRECTION_1LINE))
/** @brief Checks if SPI Direction Mode parameter is 2 lines.
* @param __MODE__ specifies the SPI Direction Mode.
* @retval None
*/
#define IS_SPI_DIRECTION_2LINES(__MODE__) ((__MODE__) == SPI_DIRECTION_2LINES)
/** @brief Checks if SPI Direction Mode parameter is 1 or 2 lines.
* @param __MODE__ specifies the SPI Direction Mode.
* @retval None
*/
#define IS_SPI_DIRECTION_2LINES_OR_1LINE(__MODE__) (((__MODE__) == SPI_DIRECTION_2LINES) || \
((__MODE__) == SPI_DIRECTION_1LINE))
/** @brief Checks if SPI Data Size parameter is in allowed range.
* @param __DATASIZE__ specifies the SPI Data Size.
* This parameter can be a value of @ref SPI_Data_Size
* @retval None
*/
#define IS_SPI_DATASIZE(__DATASIZE__) (((__DATASIZE__) == SPI_DATASIZE_16BIT) || \
((__DATASIZE__) == SPI_DATASIZE_15BIT) || \
((__DATASIZE__) == SPI_DATASIZE_14BIT) || \
((__DATASIZE__) == SPI_DATASIZE_13BIT) || \
((__DATASIZE__) == SPI_DATASIZE_12BIT) || \
((__DATASIZE__) == SPI_DATASIZE_11BIT) || \
((__DATASIZE__) == SPI_DATASIZE_10BIT) || \
((__DATASIZE__) == SPI_DATASIZE_9BIT) || \
((__DATASIZE__) == SPI_DATASIZE_8BIT) || \
((__DATASIZE__) == SPI_DATASIZE_7BIT) || \
((__DATASIZE__) == SPI_DATASIZE_6BIT) || \
((__DATASIZE__) == SPI_DATASIZE_5BIT) || \
((__DATASIZE__) == SPI_DATASIZE_4BIT))
/** @brief Checks if SPI Serial clock steady state parameter is in allowed range.
* @param __CPOL__ specifies the SPI serial clock steady state.
* This parameter can be a value of @ref SPI_Clock_Polarity
* @retval None
*/
#define IS_SPI_CPOL(__CPOL__) (((__CPOL__) == SPI_POLARITY_LOW) || \
((__CPOL__) == SPI_POLARITY_HIGH))
/** @brief Checks if SPI Clock Phase parameter is in allowed range.
* @param __CPHA__ specifies the SPI Clock Phase.
* This parameter can be a value of @ref SPI_Clock_Phase
* @retval None
*/
#define IS_SPI_CPHA(__CPHA__) (((__CPHA__) == SPI_PHASE_1EDGE) || \
((__CPHA__) == SPI_PHASE_2EDGE))
/** @brief Checks if SPI Slave Select parameter is in allowed range.
* @param __NSS__ specifies the SPI Slave Select management parameter.
* This parameter can be a value of @ref SPI_Slave_Select_management
* @retval None
*/
#define IS_SPI_NSS(__NSS__) (((__NSS__) == SPI_NSS_SOFT) || \
((__NSS__) == SPI_NSS_HARD_INPUT) || \
((__NSS__) == SPI_NSS_HARD_OUTPUT))
/** @brief Checks if SPI NSS Pulse parameter is in allowed range.
* @param __NSSP__ specifies the SPI NSS Pulse Mode parameter.
* This parameter can be a value of @ref SPI_NSSP_Mode
* @retval None
*/
#define IS_SPI_NSSP(__NSSP__) (((__NSSP__) == SPI_NSS_PULSE_ENABLE) || \
((__NSSP__) == SPI_NSS_PULSE_DISABLE))
/** @brief Checks if SPI Baudrate prescaler parameter is in allowed range.
* @param __PRESCALER__ specifies the SPI Baudrate prescaler.
* This parameter can be a value of @ref SPI_BaudRate_Prescaler
* @retval None
*/
#define IS_SPI_BAUDRATE_PRESCALER(__PRESCALER__) (((__PRESCALER__) == SPI_BAUDRATEPRESCALER_2) || \
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_4) || \
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_8) || \
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_16) || \
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_32) || \
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_64) || \
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_128) || \
((__PRESCALER__) == SPI_BAUDRATEPRESCALER_256))
/** @brief Checks if SPI MSB LSB transmission parameter is in allowed range.
* @param __BIT__ specifies the SPI MSB LSB transmission (whether data transfer starts from MSB or LSB bit).
* This parameter can be a value of @ref SPI_MSB_LSB_transmission
* @retval None
*/
#define IS_SPI_FIRST_BIT(__BIT__) (((__BIT__) == SPI_FIRSTBIT_MSB) || \
((__BIT__) == SPI_FIRSTBIT_LSB))
/** @brief Checks if SPI TI mode parameter is in allowed range.
* @param __MODE__ specifies the SPI TI mode.
* This parameter can be a value of @ref SPI_TI_mode
* @retval None
*/
#define IS_SPI_TIMODE(__MODE__) (((__MODE__) == SPI_TIMODE_DISABLE) || \
((__MODE__) == SPI_TIMODE_ENABLE))
/** @brief Checks if SPI CRC calculation enabled state is in allowed range.
* @param __CALCULATION__ specifies the SPI CRC calculation enable state.
* This parameter can be a value of @ref SPI_CRC_Calculation
* @retval None
*/
#define IS_SPI_CRC_CALCULATION(__CALCULATION__) (((__CALCULATION__) == SPI_CRCCALCULATION_DISABLE) || \
((__CALCULATION__) == SPI_CRCCALCULATION_ENABLE))
/** @brief Checks if SPI CRC length is in allowed range.
* @param __LENGTH__ specifies the SPI CRC length.
* This parameter can be a value of @ref SPI_CRC_length
* @retval None
*/
#define IS_SPI_CRC_LENGTH(__LENGTH__) (((__LENGTH__) == SPI_CRC_LENGTH_DATASIZE) || \
((__LENGTH__) == SPI_CRC_LENGTH_8BIT) || \
((__LENGTH__) == SPI_CRC_LENGTH_16BIT))
/** @brief Checks if SPI polynomial value to be used for the CRC calculation, is in allowed range.
* @param __POLYNOMIAL__ specifies the SPI polynomial value to be used for the CRC calculation.
* This parameter must be a number between Min_Data = 0 and Max_Data = 65535
* @retval None
*/
#define IS_SPI_CRC_POLYNOMIAL(__POLYNOMIAL__) (((__POLYNOMIAL__) >= 0x1U) && \
((__POLYNOMIAL__) <= 0xFFFFU) && \
(((__POLYNOMIAL__)&0x1U) != 0U))
/** @brief Checks if DMA handle is valid.
* @param __HANDLE__ specifies a DMA Handle.
* @retval None
*/
#define IS_SPI_DMA_HANDLE(__HANDLE__) ((__HANDLE__) != NULL)
/**
* @}
*/
/* Include SPI HAL Extended module */
#include "stm32g4xx_hal_spi_ex.h"
/* Exported functions --------------------------------------------------------*/
/** @addtogroup SPI_Exported_Functions
* @{
*/
/** @addtogroup SPI_Exported_Functions_Group1
* @{
*/
/* Initialization/de-initialization functions ********************************/
HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi);
HAL_StatusTypeDef HAL_SPI_DeInit(SPI_HandleTypeDef *hspi);
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi);
void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi);
/* Callbacks Register/UnRegister functions ***********************************/
#if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
HAL_StatusTypeDef HAL_SPI_RegisterCallback(SPI_HandleTypeDef *hspi, HAL_SPI_CallbackIDTypeDef CallbackID,
pSPI_CallbackTypeDef pCallback);
HAL_StatusTypeDef HAL_SPI_UnRegisterCallback(SPI_HandleTypeDef *hspi, HAL_SPI_CallbackIDTypeDef CallbackID);
#endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
/**
* @}
*/
/** @addtogroup SPI_Exported_Functions_Group2
* @{
*/
/* I/O operation functions ***************************************************/
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, const uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, const uint8_t *pTxData, uint8_t *pRxData,
uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, const uint8_t *pData, uint16_t Size);
HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, const uint8_t *pTxData, uint8_t *pRxData,
uint16_t Size);
HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, const uint8_t *pData, uint16_t Size);
HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, const uint8_t *pTxData, uint8_t *pRxData,
uint16_t Size);
HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi);
HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi);
HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi);
/* Transfer Abort functions */
HAL_StatusTypeDef HAL_SPI_Abort(SPI_HandleTypeDef *hspi);
HAL_StatusTypeDef HAL_SPI_Abort_IT(SPI_HandleTypeDef *hspi);
void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi);
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_AbortCpltCallback(SPI_HandleTypeDef *hspi);
/**
* @}
*/
/** @addtogroup SPI_Exported_Functions_Group3
* @{
*/
/* Peripheral State and Error functions ***************************************/
HAL_SPI_StateTypeDef HAL_SPI_GetState(const SPI_HandleTypeDef *hspi);
uint32_t HAL_SPI_GetError(const SPI_HandleTypeDef *hspi);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32G4xx_HAL_SPI_H */

View File

@ -0,0 +1,73 @@
/**
******************************************************************************
* @file stm32g4xx_hal_spi_ex.h
* @author MCD Application Team
* @brief Header file of SPI HAL Extended module.
******************************************************************************
* @attention
*
* Copyright (c) 2019 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.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32G4xx_HAL_SPI_EX_H
#define STM32G4xx_HAL_SPI_EX_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_hal_def.h"
/** @addtogroup STM32G4xx_HAL_Driver
* @{
*/
/** @addtogroup SPIEx
* @{
*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macros -----------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup SPIEx_Exported_Functions
* @{
*/
/* Initialization and de-initialization functions ****************************/
/* IO operation functions *****************************************************/
/** @addtogroup SPIEx_Exported_Functions_Group1
* @{
*/
HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(const SPI_HandleTypeDef *hspi);
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* STM32G4xx_HAL_SPI_EX_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,112 @@
/**
******************************************************************************
* @file stm32g4xx_hal_spi_ex.c
* @author MCD Application Team
* @brief Extended SPI HAL module driver.
* This file provides firmware functions to manage the following
* SPI peripheral extended functionalities :
* + IO operation functions
*
******************************************************************************
* @attention
*
* Copyright (c) 2019 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.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32g4xx_hal.h"
/** @addtogroup STM32G4xx_HAL_Driver
* @{
*/
/** @defgroup SPIEx SPIEx
* @brief SPI Extended HAL module driver
* @{
*/
#ifdef HAL_SPI_MODULE_ENABLED
/* Private typedef -----------------------------------------------------------*/
/* Private defines -----------------------------------------------------------*/
/** @defgroup SPIEx_Private_Constants SPIEx Private Constants
* @{
*/
#define SPI_FIFO_SIZE 4UL
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @defgroup SPIEx_Exported_Functions SPIEx Exported Functions
* @{
*/
/** @defgroup SPIEx_Exported_Functions_Group1 IO operation functions
* @brief Data transfers functions
*
@verbatim
==============================================================================
##### IO operation functions #####
===============================================================================
[..]
This subsection provides a set of extended functions to manage the SPI
data transfers.
(#) Rx data flush function:
(++) HAL_SPIEx_FlushRxFifo()
@endverbatim
* @{
*/
/**
* @brief Flush the RX fifo.
* @param hspi pointer to a SPI_HandleTypeDef structure that contains
* the configuration information for the specified SPI module.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_SPIEx_FlushRxFifo(const SPI_HandleTypeDef *hspi)
{
__IO uint32_t tmpreg;
uint8_t count = 0U;
while ((hspi->Instance->SR & SPI_FLAG_FRLVL) != SPI_FRLVL_EMPTY)
{
count++;
tmpreg = hspi->Instance->DR;
UNUSED(tmpreg); /* To avoid GCC warning */
if (count == SPI_FIFO_SIZE)
{
return HAL_TIMEOUT;
}
}
return HAL_OK;
}
/**
* @}
*/
/**
* @}
*/
#endif /* HAL_SPI_MODULE_ENABLED */
/**
* @}
*/
/**
* @}
*/

File diff suppressed because it is too large Load Diff

View File

@ -1512,7 +1512,7 @@
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\w25q256.c</name>
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\w25qxx.c</name>
</file>
</group>
</group>
@ -1543,6 +1543,9 @@
<file>
<name>$PROJ_DIR$\..\Core\Src\rtc.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\Core\Src\spi.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\Core\Src\stm32g4xx_hal_msp.c</name>
</file>
@ -1619,6 +1622,12 @@
<file>
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rtc_ex.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi_ex.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_tim.c</name>
</file>

View File

@ -67,20 +67,21 @@ Mcu.CPN=STM32G431RBT6
Mcu.Family=STM32G4
Mcu.IP0=ADC1
Mcu.IP1=ADC2
Mcu.IP10=TIM15
Mcu.IP11=TIM16
Mcu.IP12=UART4
Mcu.IP13=USART2
Mcu.IP14=USART3
Mcu.IP10=TIM7
Mcu.IP11=TIM15
Mcu.IP12=TIM16
Mcu.IP13=UART4
Mcu.IP14=USART2
Mcu.IP15=USART3
Mcu.IP2=DMA
Mcu.IP3=NVIC
Mcu.IP4=RCC
Mcu.IP5=RTC
Mcu.IP6=SYS
Mcu.IP7=TIM3
Mcu.IP8=TIM6
Mcu.IP9=TIM7
Mcu.IPNb=15
Mcu.IP6=SPI1
Mcu.IP7=SYS
Mcu.IP8=TIM3
Mcu.IP9=TIM6
Mcu.IPNb=16
Mcu.Name=STM32G431R(6-8-B)Tx
Mcu.Package=LQFP64
Mcu.Pin0=PC13
@ -108,25 +109,26 @@ Mcu.Pin28=PA14
Mcu.Pin29=PC10
Mcu.Pin3=PF0-OSC_IN
Mcu.Pin30=PC11
Mcu.Pin31=PB6
Mcu.Pin32=PB7
Mcu.Pin33=PB9
Mcu.Pin34=VP_RTC_VS_RTC_Activate
Mcu.Pin35=VP_RTC_VS_RTC_Calendar
Mcu.Pin36=VP_SYS_VS_Systick
Mcu.Pin37=VP_SYS_VS_DBSignals
Mcu.Pin38=VP_TIM6_VS_ClockSourceINT
Mcu.Pin39=VP_TIM7_VS_ClockSourceINT
Mcu.Pin31=PB5
Mcu.Pin32=PB6
Mcu.Pin33=PB7
Mcu.Pin34=PB9
Mcu.Pin35=VP_RTC_VS_RTC_Activate
Mcu.Pin36=VP_RTC_VS_RTC_Calendar
Mcu.Pin37=VP_SYS_VS_Systick
Mcu.Pin38=VP_SYS_VS_DBSignals
Mcu.Pin39=VP_TIM6_VS_ClockSourceINT
Mcu.Pin4=PF1-OSC_OUT
Mcu.Pin40=VP_TIM15_VS_ClockSourceINT
Mcu.Pin41=VP_TIM16_VS_ClockSourceINT
Mcu.Pin42=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0
Mcu.Pin5=PC1
Mcu.Pin6=PC2
Mcu.Pin7=PC3
Mcu.Pin40=VP_TIM7_VS_ClockSourceINT
Mcu.Pin41=VP_TIM15_VS_ClockSourceINT
Mcu.Pin42=VP_TIM16_VS_ClockSourceINT
Mcu.Pin43=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0
Mcu.Pin5=PC0
Mcu.Pin6=PC1
Mcu.Pin7=PC2
Mcu.Pin8=PA0
Mcu.Pin9=PA1
Mcu.PinsNb=43
Mcu.PinsNb=44
Mcu.ThirdParty0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0
Mcu.ThirdPartyNb=1
Mcu.UserConstants=
@ -199,20 +201,20 @@ PA4.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
PA4.Locked=true
PA4.Signal=GPIO_Output
PA5.GPIOParameters=GPIO_Speed,GPIO_Label
PA5.GPIO_Label=FLASH_CLK
PA5.GPIO_Label=FLASH_SCK
PA5.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
PA5.Locked=true
PA5.Signal=GPIO_Output
PA5.Mode=Full_Duplex_Master
PA5.Signal=SPI1_SCK
PA6.GPIOParameters=GPIO_Speed,GPIO_Label
PA6.GPIO_Label=FLASH_MISO
PA6.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
PA6.Locked=true
PA6.Signal=GPIO_Output
PA7.GPIOParameters=GPIO_PuPd,GPIO_Label
PA6.Mode=Full_Duplex_Master
PA6.Signal=SPI1_MISO
PA7.GPIOParameters=GPIO_Speed,GPIO_Label
PA7.GPIO_Label=FLASH_MOSI
PA7.GPIO_PuPd=GPIO_PULLUP
PA7.Locked=true
PA7.Signal=GPIO_Input
PA7.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
PA7.Mode=Full_Duplex_Master
PA7.Signal=SPI1_MOSI
PB0.GPIOParameters=GPIO_Label
PB0.GPIO_Label=PV_VOLT_IN
PB0.Mode=IN15-Single-Ended
@ -245,6 +247,12 @@ PB15.GPIOParameters=GPIO_Label
PB15.GPIO_Label=MOSFET_Temper
PB15.Mode=IN15-Single-Ended
PB15.Signal=ADC2_IN15
PB5.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
PB5.GPIO_Label=EXCHG_PROT
PB5.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING
PB5.GPIO_PuPd=GPIO_PULLDOWN
PB5.Locked=true
PB5.Signal=GPXTI5
PB6.GPIOParameters=GPIO_Label
PB6.GPIO_Label=RUN_LED
PB6.Locked=true
@ -257,6 +265,11 @@ PB9.GPIOParameters=GPIO_Label
PB9.GPIO_Label=POW_OUT_CON
PB9.Locked=true
PB9.Signal=GPIO_Output
PC0.GPIOParameters=GPIO_Label
PC0.GPIO_Label=EXCHG_CURR
PC0.Locked=true
PC0.Mode=IN6-Single-Ended
PC0.Signal=ADC2_IN6
PC1.GPIOParameters=GPIO_Label
PC1.GPIO_Label=WORK_VOLT
PC1.Locked=true
@ -272,8 +285,8 @@ PC11.Mode=Asynchronous
PC11.Signal=UART4_RX
PC13.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
PC13.GPIO_Label=DSG_PROT
PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
PC13.GPIO_PuPd=GPIO_PULLUP
PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING
PC13.GPIO_PuPd=GPIO_PULLDOWN
PC13.Locked=true
PC13.Signal=GPXTI13
PC14-OSC32_IN.Mode=LSE-External-Oscillator
@ -284,11 +297,6 @@ PC2.GPIOParameters=GPIO_Label
PC2.GPIO_Label=DSG_CURR
PC2.Mode=IN8-Single-Ended
PC2.Signal=ADC1_IN8
PC3.GPIOParameters=GPIO_Label
PC3.GPIO_Label=OUT_VOLT_IN
PC3.Locked=true
PC3.Mode=IN9-Single-Ended
PC3.Signal=ADC2_IN9
PC9.GPIOParameters=GPIO_Speed,GPIO_Label
PC9.GPIO_Label=CHG_CONH
PC9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
@ -329,7 +337,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_UART4_Init-UART4-false-HAL-true,10-MX_USART2_UART_Init-USART2-false-HAL-true,11-MX_USART3_UART_Init-USART3-false-HAL-true,12-MX_TIM7_Init-TIM7-false-HAL-true,13-MX_TIM16_Init-TIM16-false-HAL-true,14-MX_TIM15_Init-TIM15-false-HAL-true,15-MX_RTC_Init-RTC-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_TIM3_Init-TIM3-false-HAL-true,7-MX_TIM6_Init-TIM6-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USART2_UART_Init-USART2-false-HAL-true,10-MX_USART3_UART_Init-USART3-false-HAL-true,11-MX_TIM7_Init-TIM7-false-HAL-true,12-MX_TIM16_Init-TIM16-false-HAL-true,13-MX_TIM15_Init-TIM15-false-HAL-true,14-MX_RTC_Init-RTC-false-HAL-true,15-MX_SPI1_Init-SPI1-false-HAL-true
RCC.ADC12Freq_Value=72000000
RCC.AHBFreq_Value=72000000
RCC.APB1Freq_Value=72000000
@ -381,8 +389,16 @@ SH.GPXTI12.0=GPIO_EXTI12
SH.GPXTI12.ConfNb=1
SH.GPXTI13.0=GPIO_EXTI13
SH.GPXTI13.ConfNb=1
SH.GPXTI5.0=GPIO_EXTI5
SH.GPXTI5.ConfNb=1
SH.S_TIM3_CH4.0=TIM3_CH4,PWM Generation4 CH4
SH.S_TIM3_CH4.ConfNb=1
SPI1.CalculateBaudRate=36.0 MBits/s
SPI1.DataSize=SPI_DATASIZE_8BIT
SPI1.Direction=SPI_DIRECTION_2LINES
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize
SPI1.Mode=SPI_MODE_MASTER
SPI1.VirtualType=VM_MASTER
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.DSPOoLibraryJjLibrary_Checked=true
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.IPParameters=LibraryCcDSPOoLibraryJjDSPOoLibrary
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.LibraryCcDSPOoLibraryJjDSPOoLibrary=true

View File

@ -65,6 +65,9 @@ typedef enum {
stopTemperature, //停止温度保护
overchargCurr, //充电电流过大保护
overInputVolt, //太阳能输入电压过大保护
hardwareShortCircuitProtection, //硬件短路保护
hardwareInputProtection, //硬件防反输入保护
InputProtection, //软件防反输入保护
}eventsOrderRecordMode;