forked from achamaikin/CCSModuleSW30Web
initial commit
first build, test
This commit is contained in:
BIN
Core/.DS_Store
vendored
Normal file
BIN
Core/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Core/Inc/.DS_Store
vendored
Normal file
BIN
Core/Inc/.DS_Store
vendored
Normal file
Binary file not shown.
52
Core/Inc/adc.h
Normal file
52
Core/Inc/adc.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file adc.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the adc.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 __ADC_H__
|
||||
#define __ADC_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_ADC1_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ADC_H__ */
|
||||
|
||||
25
Core/Inc/board.h
Normal file
25
Core/Inc/board.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* board.h
|
||||
*
|
||||
* Created on: Apr 15, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
#ifndef SRC_BOARD_H_
|
||||
#define SRC_BOARD_H_
|
||||
|
||||
void GBT_Lock(uint8_t state);
|
||||
|
||||
typedef enum{
|
||||
RELAY_AUX,
|
||||
RELAY_CC,
|
||||
|
||||
}relay_t;
|
||||
|
||||
void RELAY_Write(relay_t num, uint8_t state);
|
||||
void Init_Peripheral();
|
||||
uint8_t GBT_LockGetState();
|
||||
void GBT_Lock(uint8_t state);
|
||||
uint8_t SW_GetAddr();
|
||||
|
||||
#endif /* SRC_BOARD_H_ */
|
||||
55
Core/Inc/can.h
Normal file
55
Core/Inc/can.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file can.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the can.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 __CAN_H__
|
||||
#define __CAN_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern CAN_HandleTypeDef hcan1;
|
||||
|
||||
extern CAN_HandleTypeDef hcan2;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_CAN1_Init(void);
|
||||
void MX_CAN2_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CAN_H__ */
|
||||
|
||||
209
Core/Inc/charger_gbt.h
Normal file
209
Core/Inc/charger_gbt.h
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* charger_gbt.h
|
||||
*
|
||||
* Created on: Apr 18, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
#ifndef INC_CHARGER_GBT_H_
|
||||
#define INC_CHARGER_GBT_H_
|
||||
#include "main.h"
|
||||
|
||||
typedef enum{
|
||||
GBT_CC_UNKNOWN,
|
||||
GBT_CC_12V,
|
||||
GBT_CC_6V,
|
||||
GBT_CC_4V,
|
||||
GBT_CC_2V,
|
||||
|
||||
}gbtCcState_t;
|
||||
|
||||
typedef enum{
|
||||
GBT_DISABLED,
|
||||
GBT_S0_UNCONNECTED, //СС1 12V/6V СС2 12V
|
||||
GBT_S1_CONNECTED, //СС1 4V СС2 4V (6V)
|
||||
GBT_S2_LOCKED, //
|
||||
GBT_S3_STARTED, // 12V AUX
|
||||
GBT_S4_ISOTEST, // testing isolation, send CHM receive BHM
|
||||
GBT_S5_BAT_INFO, // identifying BMS, send CRM receive BRM (long)
|
||||
GBT_S6_BAT_STAT, // send CRM(AA), receive BCP (long)
|
||||
GBT_S7_BMS_WAIT, // wait for BMS, send CTS+CML receive BRO(00), next BRO(AA)
|
||||
GBT_S8_INIT_CHARGER,// starting power modules, send CRO(00)
|
||||
GBT_S9_WAIT_BCL, // waiting for BCL (requested voltage), send CRO(00)
|
||||
GBT_S10_CHARGING, // charging, contactor ON, send CCS, receiving BCL+BCS+BSM
|
||||
GBT_STOP, // stop
|
||||
//TODO: after stop send BSD state
|
||||
|
||||
}gbtState_t;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint16_t maxOutputVoltage;
|
||||
|
||||
}GBT_BHM_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t bmsIdentified;
|
||||
char chargerNumber[4];
|
||||
char chargerLocation[3];
|
||||
}GBT_CRM_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t maxOutputVoltage;
|
||||
uint16_t minOutputVoltage;
|
||||
uint16_t maxOutputCurrent;
|
||||
uint16_t minOutputCurrent;
|
||||
|
||||
}GBT_CML_t;
|
||||
|
||||
typedef struct{
|
||||
uint8_t version[3]; //GB/T version
|
||||
uint8_t batteryType; //battery type
|
||||
uint16_t batteryCapacity; // 0.1Ah/bit
|
||||
uint16_t batteryVoltage; // 0.1V/bit
|
||||
uint8_t batteryVendor[4]; // Battery vendor (ASCII string)
|
||||
uint32_t batterySN; // int
|
||||
uint8_t batteryManuY; // year (offset 1985)
|
||||
uint8_t batteryManuM; // month
|
||||
uint8_t batteryManuD; // day
|
||||
uint32_t batteryCycleCount:24; //uint24_t
|
||||
uint8_t ownAuto; // 0 = lizing, 1 = own auto
|
||||
uint8_t rsvd0;
|
||||
uint8_t EVIN[17]; //EVIN
|
||||
uint8_t EV_SW_VER[8];
|
||||
|
||||
}GBT_BRM_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t maxCellVoltage; // 0.01v/bit
|
||||
uint16_t maxChargingCurrent; // 0.1A/bit
|
||||
uint16_t totalEnergy; // 0.1kWh
|
||||
uint16_t maxChargingVoltage; // 0.1V/ bit
|
||||
uint8_t maxTemp; // 1C/bit, -50C offset
|
||||
uint16_t SOC; // 0.1%/bit , 0..100%
|
||||
uint16_t measVoltage; // 0.1V/bit
|
||||
}GBT_BCP_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t requestedVoltage; // 0.1V/bit
|
||||
uint16_t requestedCurrent; // 0.1A/bit
|
||||
uint8_t chargingMode; // 0x01 - CV, 0x02 - CC
|
||||
|
||||
}GBT_BCL_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t measuredChargingVoltage;
|
||||
uint16_t measuredChargingCurrent;
|
||||
uint16_t highestVoltageOfBatteryCell;
|
||||
uint8_t groupNrOfCellWithHighestVoltage;
|
||||
uint16_t currentChargeState;
|
||||
uint16_t estimatedRemainingChargingTime;
|
||||
|
||||
}GBT_BCS_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint8_t singleBatteryHighestVoltageSerNo;// SINGLE_BATTERY_HIGHEST_VOLTAGE_SER_NO
|
||||
uint8_t batteryHighestTemp; //BATTERY_HIGHEST_TEMP
|
||||
uint8_t batteryHighestTempSerNo;//BATTERY_HIGHEST_TEMP_SER_NO
|
||||
uint8_t batteryLowestTemp;//BATTERY_LOWEST_TEMP
|
||||
uint8_t batteryLowestTempSerNo;//BATTERY_LOWEST_TEMP_SER_NO
|
||||
uint8_t batteryCellVoltageState;//BATTERY_CELL_VOLTAGE_STATE
|
||||
uint8_t batteryStatus;//BATTERY_STATUS[bit-mask];
|
||||
|
||||
}GBT_BSM_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint16_t outputVoltage;
|
||||
uint16_t outputCurrent;
|
||||
uint16_t chargingTime;
|
||||
uint16_t chargingPermissible;
|
||||
|
||||
}GBT_CCS_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t enablePSU;
|
||||
uint16_t requestedVoltage; // 0.1V/bit
|
||||
uint16_t requestedCurrent; // 0.1A/bit
|
||||
uint8_t chargingMode; // 0x01 - CV, 0x02 - CC
|
||||
uint8_t chargingPercentage; //
|
||||
uint16_t chargingRemainingTimeMin; //
|
||||
uint16_t chargingElapsedTimeMin; //
|
||||
uint8_t chargingElapsedTimeSec; //
|
||||
|
||||
}GBT_EDCAN_Output_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t PSU_Status;
|
||||
uint16_t measuredVoltage; // 0.1V/bit
|
||||
uint16_t measuredCurrent; // 0.1A/bit
|
||||
|
||||
|
||||
}GBT_EDCAN_Input_t;
|
||||
|
||||
/* 500 - Power Supply
|
||||
TX
|
||||
* PSU_ENABLE
|
||||
* BMS_STATUS
|
||||
* BMS_ERRORS
|
||||
* PSU_REQUESTED_VOLTAGE[2]
|
||||
* PSU_REQUESTED_CURRENT[2]
|
||||
* BMS_CHARGE_PERCENTAGE
|
||||
// BMS_MIN_CURRENT
|
||||
* CHARGE_REMAINING_TIME_MIN
|
||||
* CHARGE_REMAINING_TIME_SEC
|
||||
* CHARGE_ELAPSED_TIME[1]
|
||||
|
||||
RX
|
||||
* MEASURED_VOLTAGE[2]
|
||||
* MEASURED_CURRENT[2]
|
||||
// MAX_VOLTAGE[2]
|
||||
// MAX_CURRENT[2]
|
||||
// MAX_POWER[2]
|
||||
* PSU_STATUS
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
|
||||
extern GBT_BRM_t GBT_EVInfo;
|
||||
extern GBT_BCP_t GBT_BATStat;
|
||||
extern GBT_BCS_t GBT_ChargingStatus;
|
||||
extern GBT_BCL_t GBT_ReqPower;
|
||||
extern GBT_CML_t GBT_MaxLoad;
|
||||
extern GBT_CCS_t GBT_ChargerCurrentStatus;
|
||||
extern GBT_CRM_t GBT_ChargerInfo;
|
||||
extern GBT_BSM_t GBT_BatteryStatus;
|
||||
|
||||
extern uint8_t GBT_BRO;
|
||||
|
||||
void GBT_Init();
|
||||
void GBT_Start();
|
||||
void GBT_Stop();
|
||||
void GBT_Stop1();
|
||||
void GBT_ChargerTask();
|
||||
float GBT_CC_GetAdc();
|
||||
void ADC_Select_Channel(uint32_t ch);
|
||||
uint8_t GBT_CC_GetState();
|
||||
void GBT_SwitchState(gbtState_t state);
|
||||
void GBT_Delay(uint32_t delay);
|
||||
uint32_t GBT_StateTick();
|
||||
void J_SendPacket(uint32_t PGN, uint8_t pri, uint8_t DLC, uint8_t *data);
|
||||
|
||||
void GBT_SendCCS();
|
||||
void GBT_SendCST();
|
||||
void GBT_SendCRO(uint8_t state);
|
||||
void GBT_SendCML();
|
||||
void GBT_SendCTS();
|
||||
void GBT_SendCHM();
|
||||
void GBT_SendCRM(uint8_t state);
|
||||
|
||||
|
||||
|
||||
#endif /* INC_CHARGER_GBT_H_ */
|
||||
16
Core/Inc/debug.h
Normal file
16
Core/Inc/debug.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* debug.h
|
||||
*
|
||||
* Created on: Apr 16, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
#ifndef SRC_DEBUG_H_
|
||||
#define SRC_DEBUG_H_
|
||||
|
||||
void debug_task();
|
||||
void debug_init();
|
||||
void debug_rx_interrupt(UART_HandleTypeDef *huart, uint16_t Size);
|
||||
|
||||
|
||||
#endif /* SRC_DEBUG_H_ */
|
||||
13
Core/Inc/edcan_config.h
Normal file
13
Core/Inc/edcan_config.h
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by Артём Чамайкин on 20.07.2024.
|
||||
//
|
||||
|
||||
#ifndef EDCAN_CONFIG_H
|
||||
#define EDCAN_CONFIG_H
|
||||
|
||||
#define DEVICE_ID 0x20
|
||||
#define FWVER 1
|
||||
//#define ED_CAN1
|
||||
#define ED_CAN2
|
||||
|
||||
#endif //EDCAN_CONFIG_H
|
||||
49
Core/Inc/gpio.h
Normal file
49
Core/Inc/gpio.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file gpio.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the gpio.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 __GPIO_H__
|
||||
#define __GPIO_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_GPIO_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /*__ GPIO_H__ */
|
||||
|
||||
39
Core/Inc/j1939.h
Normal file
39
Core/Inc/j1939.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* j1939.h
|
||||
*
|
||||
* Created on: May 3, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
#ifndef INC_J1939_H_
|
||||
#define INC_J1939_H_
|
||||
|
||||
#define J_ID_SE 0x56
|
||||
#define J_ID_EV 0xF4
|
||||
|
||||
#include "main.h"
|
||||
|
||||
extern CAN_HandleTypeDef hcan1;
|
||||
|
||||
typedef struct{
|
||||
uint8_t data[256]; //data array
|
||||
uint32_t PGN; //received PGN
|
||||
uint16_t size;
|
||||
uint8_t packets;
|
||||
uint8_t packet;
|
||||
uint8_t step;
|
||||
uint8_t step_cts_remain;
|
||||
uint8_t state; //(0 = standby, 1= receiving)
|
||||
uint32_t tick;
|
||||
}j_receive_t;
|
||||
|
||||
extern j_receive_t j_rx;
|
||||
|
||||
|
||||
void J_SendCTS(j_receive_t rx);
|
||||
void J_SendACK(j_receive_t rx);
|
||||
|
||||
|
||||
void GBT_CAN_ReInit();
|
||||
|
||||
#endif /* INC_J1939_H_ */
|
||||
91
Core/Inc/main.h
Normal file
91
Core/Inc/main.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define ADC_CC1_Pin GPIO_PIN_6
|
||||
#define ADC_CC1_GPIO_Port GPIOA
|
||||
#define LOCK_A_Pin GPIO_PIN_4
|
||||
#define LOCK_A_GPIO_Port GPIOC
|
||||
#define LOCK_B_Pin GPIO_PIN_5
|
||||
#define LOCK_B_GPIO_Port GPIOC
|
||||
#define ADC_NTC1_Pin GPIO_PIN_0
|
||||
#define ADC_NTC1_GPIO_Port GPIOB
|
||||
#define ADC_NTC2_Pin GPIO_PIN_1
|
||||
#define ADC_NTC2_GPIO_Port GPIOB
|
||||
#define LOCK_FB_Pin GPIO_PIN_9
|
||||
#define LOCK_FB_GPIO_Port GPIOE
|
||||
#define ADDR_0_Pin GPIO_PIN_10
|
||||
#define ADDR_0_GPIO_Port GPIOE
|
||||
#define ADDR_1_Pin GPIO_PIN_11
|
||||
#define ADDR_1_GPIO_Port GPIOE
|
||||
#define RELAY_CC_Pin GPIO_PIN_15
|
||||
#define RELAY_CC_GPIO_Port GPIOE
|
||||
#define USART2_DIR_Pin GPIO_PIN_4
|
||||
#define USART2_DIR_GPIO_Port GPIOD
|
||||
#define RELAY_AUX_Pin GPIO_PIN_4
|
||||
#define RELAY_AUX_GPIO_Port GPIOB
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
19
Core/Inc/soft_rtc.h
Normal file
19
Core/Inc/soft_rtc.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* soft_rtc.h
|
||||
*
|
||||
* Created on: Jul 22, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
#ifndef INC_SOFT_RTC_H_
|
||||
#define INC_SOFT_RTC_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
uint32_t get_Current_Time();
|
||||
void set_Time(uint32_t unix_time);
|
||||
void unix_to_bcd(uint32_t unix_time, uint8_t *time);
|
||||
void writeTimeReg(uint8_t reg_number, uint8_t value);
|
||||
uint8_t getTimeReg(uint8_t reg_number);
|
||||
|
||||
#endif /* INC_SOFT_RTC_H_ */
|
||||
391
Core/Inc/stm32f1xx_hal_conf.h
Normal file
391
Core/Inc/stm32f1xx_hal_conf.h
Normal file
@@ -0,0 +1,391 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_hal_conf.h
|
||||
* @brief HAL configuration file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 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 __STM32F1xx_HAL_CONF_H
|
||||
#define __STM32F1xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
|
||||
#define HAL_MODULE_ENABLED
|
||||
#define HAL_ADC_MODULE_ENABLED
|
||||
/*#define HAL_CRYP_MODULE_ENABLED */
|
||||
#define HAL_CAN_MODULE_ENABLED
|
||||
/*#define HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
/*#define HAL_CEC_MODULE_ENABLED */
|
||||
/*#define HAL_CORTEX_MODULE_ENABLED */
|
||||
/*#define HAL_CRC_MODULE_ENABLED */
|
||||
/*#define HAL_DAC_MODULE_ENABLED */
|
||||
/*#define HAL_DMA_MODULE_ENABLED */
|
||||
/*#define HAL_ETH_MODULE_ENABLED */
|
||||
/*#define HAL_FLASH_MODULE_ENABLED */
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
/*#define HAL_I2C_MODULE_ENABLED */
|
||||
/*#define HAL_I2S_MODULE_ENABLED */
|
||||
/*#define HAL_IRDA_MODULE_ENABLED */
|
||||
/*#define HAL_IWDG_MODULE_ENABLED */
|
||||
/*#define HAL_NOR_MODULE_ENABLED */
|
||||
/*#define HAL_NAND_MODULE_ENABLED */
|
||||
/*#define HAL_PCCARD_MODULE_ENABLED */
|
||||
/*#define HAL_PCD_MODULE_ENABLED */
|
||||
/*#define HAL_HCD_MODULE_ENABLED */
|
||||
/*#define HAL_PWR_MODULE_ENABLED */
|
||||
/*#define HAL_RCC_MODULE_ENABLED */
|
||||
/*#define HAL_RTC_MODULE_ENABLED */
|
||||
/*#define HAL_SD_MODULE_ENABLED */
|
||||
/*#define HAL_MMC_MODULE_ENABLED */
|
||||
/*#define HAL_SDRAM_MODULE_ENABLED */
|
||||
/*#define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/*#define HAL_SPI_MODULE_ENABLED */
|
||||
/*#define HAL_SRAM_MODULE_ENABLED */
|
||||
/*#define HAL_TIM_MODULE_ENABLED */
|
||||
#define HAL_UART_MODULE_ENABLED
|
||||
/*#define HAL_USART_MODULE_ENABLED */
|
||||
/*#define HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
#define HAL_EXTI_MODULE_ENABLED
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 25000000U /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 8000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE 40000U /*!< LSI Typical Value in Hz */
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature. */
|
||||
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
|
||||
#endif /* LSE_STARTUP_TIMEOUT */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority (lowest by default) */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 1U
|
||||
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
|
||||
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
|
||||
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
|
||||
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
|
||||
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
|
||||
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
|
||||
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
|
||||
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
|
||||
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
|
||||
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
|
||||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
|
||||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
|
||||
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
|
||||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
|
||||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## Ethernet peripheral configuration ##################### */
|
||||
|
||||
/* Section 1 : Ethernet peripheral configuration */
|
||||
|
||||
/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
|
||||
#define MAC_ADDR0 2U
|
||||
#define MAC_ADDR1 0U
|
||||
#define MAC_ADDR2 0U
|
||||
#define MAC_ADDR3 0U
|
||||
#define MAC_ADDR4 0U
|
||||
#define MAC_ADDR5 0U
|
||||
|
||||
/* Definition of the Ethernet driver buffers size and count */
|
||||
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
|
||||
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
|
||||
#define ETH_RXBUFNB 8U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
|
||||
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
|
||||
|
||||
/* Section 2: PHY configuration section */
|
||||
|
||||
/* DP83848_PHY_ADDRESS Address*/
|
||||
#define DP83848_PHY_ADDRESS 0x01U
|
||||
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
|
||||
#define PHY_RESET_DELAY 0x000000FFU
|
||||
/* PHY Configuration delay */
|
||||
#define PHY_CONFIG_DELAY 0x00000FFFU
|
||||
|
||||
#define PHY_READ_TO 0x0000FFFFU
|
||||
#define PHY_WRITE_TO 0x0000FFFFU
|
||||
|
||||
/* Section 3: Common PHY Registers */
|
||||
|
||||
#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
|
||||
#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
|
||||
|
||||
#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
|
||||
#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
|
||||
#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
|
||||
#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
|
||||
#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
|
||||
#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
|
||||
#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
|
||||
#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
|
||||
#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
|
||||
#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
|
||||
|
||||
#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
|
||||
#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
|
||||
#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
|
||||
|
||||
/* Section 4: Extended PHY Registers */
|
||||
#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */
|
||||
|
||||
#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */
|
||||
#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 0U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ETH_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_eth.h"
|
||||
#endif /* HAL_ETH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
|
||||
#include "Legacy/stm32f1xx_hal_can_legacy.h"
|
||||
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CEC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_cec.h"
|
||||
#endif /* HAL_CEC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2S_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_i2s.h"
|
||||
#endif /* HAL_I2S_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCCARD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pccard.h"
|
||||
#endif /* HAL_PCCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_mmc.h"
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F1xx_HAL_CONF_H */
|
||||
|
||||
70
Core/Inc/stm32f1xx_it.h
Normal file
70
Core/Inc/stm32f1xx_it.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_it.h
|
||||
* @brief This file contains the headers of the interrupt handlers.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 __STM32F1xx_IT_H
|
||||
#define __STM32F1xx_IT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void NMI_Handler(void);
|
||||
void HardFault_Handler(void);
|
||||
void MemManage_Handler(void);
|
||||
void BusFault_Handler(void);
|
||||
void UsageFault_Handler(void);
|
||||
void SVC_Handler(void);
|
||||
void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void CAN1_RX0_IRQHandler(void);
|
||||
void USART2_IRQHandler(void);
|
||||
void CAN2_TX_IRQHandler(void);
|
||||
void CAN2_RX1_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F1xx_IT_H */
|
||||
52
Core/Inc/usart.h
Normal file
52
Core/Inc/usart.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usart.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the usart.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 __USART_H__
|
||||
#define __USART_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern UART_HandleTypeDef huart2;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_USART2_UART_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USART_H__ */
|
||||
|
||||
BIN
Core/Src/.DS_Store
vendored
Normal file
BIN
Core/Src/.DS_Store
vendored
Normal file
Binary file not shown.
133
Core/Src/adc.c
Normal file
133
Core/Src/adc.c
Normal file
@@ -0,0 +1,133 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file adc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the ADC instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "adc.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
ADC_HandleTypeDef hadc1;
|
||||
|
||||
/* ADC1 init function */
|
||||
void MX_ADC1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 0 */
|
||||
|
||||
/* USER CODE END ADC1_Init 0 */
|
||||
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 1 */
|
||||
|
||||
/* USER CODE END ADC1_Init 1 */
|
||||
|
||||
/** Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||
hadc1.Init.ContinuousConvMode = DISABLE;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.NbrOfConversion = 1;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_8;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC1_Init 2 */
|
||||
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(adcHandle->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 0 */
|
||||
/* ADC1 clock enable */
|
||||
__HAL_RCC_ADC1_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**ADC1 GPIO Configuration
|
||||
PA6 ------> ADC1_IN6
|
||||
PB0 ------> ADC1_IN8
|
||||
PB1 ------> ADC1_IN9
|
||||
*/
|
||||
GPIO_InitStruct.Pin = ADC_CC1_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(ADC_CC1_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = ADC_NTC1_Pin|ADC_NTC2_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN ADC1_MspInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
||||
{
|
||||
|
||||
if(adcHandle->Instance==ADC1)
|
||||
{
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_ADC1_CLK_DISABLE();
|
||||
|
||||
/**ADC1 GPIO Configuration
|
||||
PA6 ------> ADC1_IN6
|
||||
PB0 ------> ADC1_IN8
|
||||
PB1 ------> ADC1_IN9
|
||||
*/
|
||||
HAL_GPIO_DeInit(ADC_CC1_GPIO_Port, ADC_CC1_Pin);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, ADC_NTC1_Pin|ADC_NTC2_Pin);
|
||||
|
||||
/* USER CODE BEGIN ADC1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END ADC1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
92
Core/Src/board.c
Normal file
92
Core/Src/board.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* board.c
|
||||
*
|
||||
* Created on: Apr 15, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
#include "main.h"
|
||||
#include "board.h"
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
|
||||
//TODO:
|
||||
//TEMP READ
|
||||
//LOCK_FB
|
||||
//GBT_TEMP_SENSORS
|
||||
//USB
|
||||
|
||||
void GBT_Lock(uint8_t state){
|
||||
if(state){//LOCK
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 1);
|
||||
HAL_Delay(50);
|
||||
HAL_GPIO_WritePin(LOCK_A_GPIO_Port, LOCK_A_Pin, 0);
|
||||
}else{ //UNLOCK
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 1);
|
||||
HAL_Delay(50);
|
||||
HAL_GPIO_WritePin(LOCK_B_GPIO_Port, LOCK_B_Pin, 0);
|
||||
}
|
||||
}
|
||||
uint8_t GBT_LockGetState(){
|
||||
return HAL_GPIO_ReadPin(LOCK_FB_GPIO_Port, LOCK_FB_Pin);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RELAY_Write(relay_t num, uint8_t state){
|
||||
if(num==RELAY_AUX)HAL_GPIO_WritePin(RELAY_AUX_GPIO_Port, RELAY_AUX_Pin, state);
|
||||
if(num==RELAY_CC)HAL_GPIO_WritePin(RELAY_CC_GPIO_Port, RELAY_CC_Pin, state);
|
||||
|
||||
}
|
||||
|
||||
uint8_t GetBoardTemp(){
|
||||
//TODO
|
||||
// HAL_ADC_Start(&hadc1); // start the adc
|
||||
//
|
||||
// HAL_ADC_PollForConversion(&hadc1, 100); // poll for conversion
|
||||
//
|
||||
// adc_val = HAL_ADC_GetValue(&hadc1); // get the adc value
|
||||
//
|
||||
// HAL_ADC_Stop(&hadc1); // stop adc
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Init_Peripheral(){
|
||||
HAL_ADCEx_Calibration_Start(&hadc1);
|
||||
RELAY_Write(RELAY_AUX, 0);
|
||||
RELAY_Write(RELAY_CC, 1);
|
||||
|
||||
}
|
||||
|
||||
uint8_t GBT_ReadTemp(){
|
||||
//TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ADC_Select_Channel(uint32_t ch) {
|
||||
ADC_ChannelConfTypeDef conf = {
|
||||
.Channel = ch,
|
||||
.Rank = 1,
|
||||
.SamplingTime = ADC_SAMPLETIME_28CYCLES_5,
|
||||
};
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &conf) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t SW_GetAddr(){
|
||||
if(!HAL_GPIO_ReadPin(ADDR_0_GPIO_Port, ADDR_0_Pin)){
|
||||
if(!HAL_GPIO_ReadPin(ADDR_1_GPIO_Port, ADDR_1_Pin)){
|
||||
return 0x23;
|
||||
}else{
|
||||
return 0x21;
|
||||
}
|
||||
|
||||
}else{
|
||||
if(!HAL_GPIO_ReadPin(ADDR_1_GPIO_Port, ADDR_1_Pin)){
|
||||
return 0x22;
|
||||
}else{
|
||||
return 0x20;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
231
Core/Src/can.c
Normal file
231
Core/Src/can.c
Normal file
@@ -0,0 +1,231 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file can.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the CAN instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "can.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
CAN_HandleTypeDef hcan1;
|
||||
CAN_HandleTypeDef hcan2;
|
||||
|
||||
/* CAN1 init function */
|
||||
void MX_CAN1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN CAN1_Init 0 */
|
||||
|
||||
/* USER CODE END CAN1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN CAN1_Init 1 */
|
||||
|
||||
/* USER CODE END CAN1_Init 1 */
|
||||
hcan1.Instance = CAN1;
|
||||
hcan1.Init.Prescaler = 8;
|
||||
hcan1.Init.Mode = CAN_MODE_NORMAL;
|
||||
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
||||
hcan1.Init.TimeSeg1 = CAN_BS1_15TQ;
|
||||
hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
|
||||
hcan1.Init.TimeTriggeredMode = DISABLE;
|
||||
hcan1.Init.AutoBusOff = ENABLE;
|
||||
hcan1.Init.AutoWakeUp = ENABLE;
|
||||
hcan1.Init.AutoRetransmission = DISABLE;
|
||||
hcan1.Init.ReceiveFifoLocked = DISABLE;
|
||||
hcan1.Init.TransmitFifoPriority = ENABLE;
|
||||
if (HAL_CAN_Init(&hcan1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN CAN1_Init 2 */
|
||||
|
||||
/* USER CODE END CAN1_Init 2 */
|
||||
|
||||
}
|
||||
/* CAN2 init function */
|
||||
void MX_CAN2_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN CAN2_Init 0 */
|
||||
|
||||
/* USER CODE END CAN2_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN CAN2_Init 1 */
|
||||
|
||||
/* USER CODE END CAN2_Init 1 */
|
||||
hcan2.Instance = CAN2;
|
||||
hcan2.Init.Prescaler = 16;
|
||||
hcan2.Init.Mode = CAN_MODE_NORMAL;
|
||||
hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ;
|
||||
hcan2.Init.TimeSeg1 = CAN_BS1_15TQ;
|
||||
hcan2.Init.TimeSeg2 = CAN_BS2_2TQ;
|
||||
hcan2.Init.TimeTriggeredMode = DISABLE;
|
||||
hcan2.Init.AutoBusOff = ENABLE;
|
||||
hcan2.Init.AutoWakeUp = ENABLE;
|
||||
hcan2.Init.AutoRetransmission = DISABLE;
|
||||
hcan2.Init.ReceiveFifoLocked = DISABLE;
|
||||
hcan2.Init.TransmitFifoPriority = ENABLE;
|
||||
if (HAL_CAN_Init(&hcan2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN CAN2_Init 2 */
|
||||
|
||||
/* USER CODE END CAN2_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
static uint32_t HAL_RCC_CAN1_CLK_ENABLED=0;
|
||||
|
||||
void HAL_CAN_MspInit(CAN_HandleTypeDef* canHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(canHandle->Instance==CAN1)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_MspInit 0 */
|
||||
|
||||
/* USER CODE END CAN1_MspInit 0 */
|
||||
/* CAN1 clock enable */
|
||||
HAL_RCC_CAN1_CLK_ENABLED++;
|
||||
if(HAL_RCC_CAN1_CLK_ENABLED==1){
|
||||
__HAL_RCC_CAN1_CLK_ENABLE();
|
||||
}
|
||||
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
/**CAN1 GPIO Configuration
|
||||
PD0 ------> CAN1_RX
|
||||
PD1 ------> CAN1_TX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
__HAL_AFIO_REMAP_CAN1_3();
|
||||
|
||||
/* CAN1 interrupt Init */
|
||||
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
|
||||
/* USER CODE BEGIN CAN1_MspInit 1 */
|
||||
|
||||
/* USER CODE END CAN1_MspInit 1 */
|
||||
}
|
||||
else if(canHandle->Instance==CAN2)
|
||||
{
|
||||
/* USER CODE BEGIN CAN2_MspInit 0 */
|
||||
|
||||
/* USER CODE END CAN2_MspInit 0 */
|
||||
/* CAN2 clock enable */
|
||||
__HAL_RCC_CAN2_CLK_ENABLE();
|
||||
HAL_RCC_CAN1_CLK_ENABLED++;
|
||||
if(HAL_RCC_CAN1_CLK_ENABLED==1){
|
||||
__HAL_RCC_CAN1_CLK_ENABLE();
|
||||
}
|
||||
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**CAN2 GPIO Configuration
|
||||
PB5 ------> CAN2_RX
|
||||
PB6 ------> CAN2_TX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
__HAL_AFIO_REMAP_CAN2_ENABLE();
|
||||
|
||||
/* CAN2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(CAN2_TX_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(CAN2_TX_IRQn);
|
||||
HAL_NVIC_SetPriority(CAN2_RX1_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(CAN2_RX1_IRQn);
|
||||
/* USER CODE BEGIN CAN2_MspInit 1 */
|
||||
|
||||
/* USER CODE END CAN2_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CAN_MspDeInit(CAN_HandleTypeDef* canHandle)
|
||||
{
|
||||
|
||||
if(canHandle->Instance==CAN1)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END CAN1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
HAL_RCC_CAN1_CLK_ENABLED--;
|
||||
if(HAL_RCC_CAN1_CLK_ENABLED==0){
|
||||
__HAL_RCC_CAN1_CLK_DISABLE();
|
||||
}
|
||||
|
||||
/**CAN1 GPIO Configuration
|
||||
PD0 ------> CAN1_RX
|
||||
PD1 ------> CAN1_TX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_0|GPIO_PIN_1);
|
||||
|
||||
/* CAN1 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(CAN1_RX0_IRQn);
|
||||
/* USER CODE BEGIN CAN1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END CAN1_MspDeInit 1 */
|
||||
}
|
||||
else if(canHandle->Instance==CAN2)
|
||||
{
|
||||
/* USER CODE BEGIN CAN2_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END CAN2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_CAN2_CLK_DISABLE();
|
||||
HAL_RCC_CAN1_CLK_ENABLED--;
|
||||
if(HAL_RCC_CAN1_CLK_ENABLED==0){
|
||||
__HAL_RCC_CAN1_CLK_DISABLE();
|
||||
}
|
||||
|
||||
/**CAN2 GPIO Configuration
|
||||
PB5 ------> CAN2_RX
|
||||
PB6 ------> CAN2_TX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_5|GPIO_PIN_6);
|
||||
|
||||
/* CAN2 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(CAN2_TX_IRQn);
|
||||
HAL_NVIC_DisableIRQ(CAN2_RX1_IRQn);
|
||||
/* USER CODE BEGIN CAN2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END CAN2_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
366
Core/Src/charger_gbt.c
Normal file
366
Core/Src/charger_gbt.c
Normal file
@@ -0,0 +1,366 @@
|
||||
/*
|
||||
* charger_gbt.c
|
||||
*
|
||||
* Created on: Apr 18, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
|
||||
#include "charger_gbt.h"
|
||||
#include "main.h"
|
||||
#include "board.h"
|
||||
#include "stdio.h"
|
||||
#include "j1939.h"
|
||||
#include "string.h"
|
||||
#include "edcan.h"
|
||||
|
||||
gbtState_t GBT_State;
|
||||
uint32_t GBT_state_tick; //Tick after state switch
|
||||
uint32_t GBT_delay;
|
||||
uint8_t GBT_BAT_INFO_recv;
|
||||
uint8_t GBT_BAT_STAT_recv;
|
||||
uint8_t EV_ready;
|
||||
|
||||
GBT_BHM_t GBT_MaxVoltage;
|
||||
GBT_CML_t GBT_MaxLoad;
|
||||
GBT_CRM_t GBT_ChargerInfo;
|
||||
|
||||
GBT_BRM_t GBT_EVInfo;
|
||||
GBT_BCP_t GBT_BATStat;
|
||||
GBT_BCL_t GBT_ReqPower;
|
||||
GBT_BCL_t GBT_CurrPower;
|
||||
|
||||
GBT_BCS_t GBT_ChargingStatus;
|
||||
|
||||
GBT_BSM_t GBT_BatteryStatus;
|
||||
|
||||
GBT_CCS_t GBT_ChargerCurrentStatus;
|
||||
|
||||
uint8_t GBT_BRO;
|
||||
|
||||
extern GBT_EDCAN_Output_t GBT_EDCAN_Output;
|
||||
|
||||
|
||||
void GBT_Init(){
|
||||
GBT_State = GBT_DISABLED;
|
||||
GBT_Lock(0);
|
||||
}
|
||||
|
||||
uint8_t GBT_CC_GetState(){
|
||||
//Vref=3.3v = 4095
|
||||
//k=1/11
|
||||
//Vin = 12v
|
||||
//Vin*k= 1.09v
|
||||
//12vin = 1353 ADC
|
||||
//TODO: Filter 100ms
|
||||
uint32_t adc;
|
||||
float volt;
|
||||
ADC_Select_Channel(ADC_CHANNEL_6);
|
||||
HAL_ADC_Start(&hadc1);
|
||||
HAL_ADC_PollForConversion(&hadc1, 100);
|
||||
adc = HAL_ADC_GetValue(&hadc1);
|
||||
HAL_ADC_Stop(&hadc1);
|
||||
|
||||
volt = (float)adc/113.4f;
|
||||
if((volt<12.6f) && (volt>11.4f)) return GBT_CC_12V;
|
||||
if((volt<6.8f) && (volt>5.2f)) return GBT_CC_6V;
|
||||
if((volt<4.8f) && (volt>3.2f)) return GBT_CC_4V;
|
||||
if((volt<2.8f) && (volt>1.2f)) return GBT_CC_2V;
|
||||
return GBT_CC_UNKNOWN;
|
||||
}
|
||||
|
||||
float GBT_CC_GetAdc(){
|
||||
//Vref=3.3v = 4095
|
||||
//k=1/11
|
||||
//Vin = 12v
|
||||
//Vin*k= 1.09v
|
||||
//12vin = 1353 ADC
|
||||
|
||||
uint32_t adc;
|
||||
float volt;
|
||||
ADC_Select_Channel(ADC_CHANNEL_6);
|
||||
HAL_ADC_Start(&hadc1);
|
||||
HAL_ADC_PollForConversion(&hadc1, 100);
|
||||
adc = HAL_ADC_GetValue(&hadc1);
|
||||
HAL_ADC_Stop(&hadc1);
|
||||
|
||||
volt = (float)adc/113.4f;
|
||||
|
||||
return volt;
|
||||
}
|
||||
|
||||
void GBT_ChargerTask(){
|
||||
|
||||
if(j_rx.state == 2){
|
||||
switch (j_rx.PGN){
|
||||
case 0x2700: //PGN BHM
|
||||
memcpy (&GBT_MaxVoltage, j_rx.data, sizeof(GBT_MaxVoltage));
|
||||
|
||||
break;
|
||||
|
||||
case 0x0200: //PGN BRM LONG
|
||||
GBT_BAT_INFO_recv = 1;
|
||||
memcpy (&GBT_EVInfo, j_rx.data, sizeof(GBT_EVInfo));
|
||||
|
||||
break;
|
||||
|
||||
case 0x0600: //PGN BCP LONG
|
||||
GBT_BAT_STAT_recv = 1;
|
||||
memcpy (&GBT_BATStat, j_rx.data, sizeof(GBT_BATStat));
|
||||
break;
|
||||
|
||||
case 0x0900: //PGN BRO
|
||||
if(j_rx.data[0] == 0xAA) EV_ready = 1;
|
||||
else EV_ready = 0;
|
||||
GBT_BRO = j_rx.data[0];
|
||||
break;
|
||||
|
||||
case 0x1000: //PGN BCL
|
||||
//TODO: power block
|
||||
memcpy (&GBT_ReqPower, j_rx.data, sizeof(GBT_ReqPower));
|
||||
uint16_t volt=GBT_ReqPower.requestedVoltage/10;
|
||||
GBT_EDCAN_Output.requestedVoltage = volt;
|
||||
uint16_t curr=(4000-GBT_ReqPower.requestedCurrent);
|
||||
GBT_EDCAN_Output.requestedCurrent = curr;
|
||||
break;
|
||||
|
||||
case 0x1100: //PGN BCS
|
||||
//TODO
|
||||
memcpy (&GBT_ChargingStatus, j_rx.data, sizeof(GBT_ChargingStatus));
|
||||
GBT_EDCAN_Output.chargingRemainingTimeMin = GBT_ChargingStatus.estimatedRemainingChargingTime;
|
||||
GBT_EDCAN_Output.chargingPercentage = GBT_ChargingStatus.currentChargeState;
|
||||
break;
|
||||
|
||||
case 0x1300: //PGN BSM
|
||||
//TODO
|
||||
memcpy (&GBT_BatteryStatus, j_rx.data, sizeof(GBT_BatteryStatus));
|
||||
break;
|
||||
|
||||
case 0x1500: //PGN BMV
|
||||
//TODO
|
||||
break;
|
||||
|
||||
case 0x1600: //PGN BMT
|
||||
//TODO
|
||||
break;
|
||||
|
||||
case 0x1700: //PGN BSP
|
||||
//TODO
|
||||
break;
|
||||
|
||||
|
||||
//BSM BMV BMT BSP BST BSD BEM
|
||||
|
||||
}
|
||||
j_rx.state = 0;
|
||||
}
|
||||
|
||||
if(GBT_delay>HAL_GetTick()){
|
||||
//waiting
|
||||
}else switch (GBT_State){
|
||||
case GBT_DISABLED:
|
||||
|
||||
break;
|
||||
case GBT_S0_UNCONNECTED:
|
||||
if(GBT_CC_GetState()==GBT_CC_4V){
|
||||
|
||||
GBT_SwitchState(GBT_S1_CONNECTED);
|
||||
GBT_Delay(500);
|
||||
}
|
||||
break;
|
||||
case GBT_S1_CONNECTED:
|
||||
if(GBT_CC_GetState()==GBT_CC_4V){
|
||||
|
||||
GBT_Lock(1);
|
||||
GBT_SwitchState(GBT_S2_LOCKED);
|
||||
GBT_Delay(500);
|
||||
}else{
|
||||
GBT_SwitchState(GBT_S0_UNCONNECTED);
|
||||
}
|
||||
break;
|
||||
case GBT_S2_LOCKED:
|
||||
if(1){ //TODO: charge permission
|
||||
RELAY_Write(RELAY_AUX, 1); // 13.8V AUX ON
|
||||
GBT_SwitchState(GBT_S3_STARTED);
|
||||
GBT_Delay(500);
|
||||
}
|
||||
break;
|
||||
|
||||
case GBT_S3_STARTED:
|
||||
GBT_SwitchState(GBT_S4_ISOTEST);
|
||||
GBT_Delay(500);
|
||||
break;
|
||||
|
||||
case GBT_S4_ISOTEST:
|
||||
if(j_rx.state == 0) GBT_SendCHM();
|
||||
GBT_Delay(250);
|
||||
//TODO: Isolation test
|
||||
//TODO: Timeout
|
||||
if(GBT_StateTick()>1500){
|
||||
//Isolation test finish
|
||||
GBT_SwitchState(GBT_S5_BAT_INFO);
|
||||
}
|
||||
break;
|
||||
|
||||
case GBT_S5_BAT_INFO:
|
||||
if(j_rx.state == 0) GBT_SendCRM(0x00);
|
||||
GBT_Delay(250);
|
||||
if(GBT_BAT_INFO_recv){
|
||||
//Got battery info
|
||||
GBT_SwitchState(GBT_S6_BAT_STAT);
|
||||
}
|
||||
break;
|
||||
|
||||
case GBT_S6_BAT_STAT:
|
||||
if(j_rx.state == 0) GBT_SendCRM(0xAA);
|
||||
GBT_Delay(250);
|
||||
if(GBT_BAT_STAT_recv){
|
||||
//Got battery status
|
||||
GBT_SwitchState(GBT_S7_BMS_WAIT);
|
||||
}
|
||||
break;
|
||||
|
||||
case GBT_S7_BMS_WAIT:
|
||||
if(j_rx.state == 0) GBT_SendCTS();
|
||||
HAL_Delay(2);
|
||||
if(j_rx.state == 0) GBT_SendCML();
|
||||
GBT_Delay(250);
|
||||
if(EV_ready){
|
||||
//EV ready (AA)
|
||||
GBT_SwitchState(GBT_S8_INIT_CHARGER);
|
||||
}
|
||||
break;
|
||||
|
||||
case GBT_S8_INIT_CHARGER:
|
||||
if(j_rx.state == 0) GBT_SendCRO(0x00);
|
||||
//TODO
|
||||
GBT_Delay(250);
|
||||
if(GBT_StateTick()>1500){
|
||||
//Power Modules initiated
|
||||
GBT_SwitchState(GBT_S9_WAIT_BCL);
|
||||
}
|
||||
break;
|
||||
|
||||
case GBT_S9_WAIT_BCL:
|
||||
if(j_rx.state == 0) GBT_SendCRO(0xAA);
|
||||
GBT_Delay(250);
|
||||
if(GBT_ReqPower.chargingMode != 0){
|
||||
//BCL power requirements received
|
||||
//write power modules
|
||||
GBT_SwitchState(GBT_S10_CHARGING);
|
||||
uint16_t curr=(4000-GBT_ReqPower.requestedCurrent);
|
||||
uint16_t volt=GBT_ReqPower.requestedVoltage/10;
|
||||
//if ((curr10>0) && (curr10<500));
|
||||
//PSU_SetVoltage(volt);
|
||||
//PSU_SetCurrent(curr);
|
||||
GBT_EDCAN_Output.requestedVoltage = volt;
|
||||
GBT_EDCAN_Output.requestedCurrent = curr;
|
||||
GBT_EDCAN_Output.enablePSU = 1;
|
||||
|
||||
|
||||
//TODO: EDCAN_SendPacketRead
|
||||
|
||||
//смещение -400а
|
||||
//RELAY_Write(RELAY_3, 1);
|
||||
//PSU_Mode(0x0200);
|
||||
}
|
||||
break;
|
||||
|
||||
case GBT_S10_CHARGING:
|
||||
//CHARGING
|
||||
if(j_rx.state == 0) GBT_SendCCS();
|
||||
// write power modules
|
||||
|
||||
|
||||
// if(mm_queue_size()==0){//TODO: hysteresis, charging mode
|
||||
// if(GBT_CurrPower.requestedCurrent != GBT_ReqPower.requestedCurrent){
|
||||
// GBT_CurrPower.requestedCurrent = GBT_ReqPower.requestedCurrent;
|
||||
// //PSU_SetVoltage(GBT_ReqPower.requestedVoltage/10);
|
||||
// uint16_t curr=(4000-GBT_ReqPower.requestedCurrent);
|
||||
// //PSU_SetCurrent(curr);
|
||||
// GBT_ChargingSummary.requestedCurrent = curr;
|
||||
// }
|
||||
// if(GBT_CurrPower.requestedVoltage != GBT_ReqPower.requestedVoltage){
|
||||
// GBT_CurrPower.requestedVoltage = GBT_ReqPower.requestedVoltage;
|
||||
// //PSU_SetCurrent(GBT_ReqPower.requestedCurrent);
|
||||
// uint16_t volt=GBT_ReqPower.requestedVoltage/10;
|
||||
// GBT_ChargingSummary.requestedVoltage = volt;
|
||||
// //PSU_SetVoltage(volt);
|
||||
// //смещение -400а
|
||||
// }
|
||||
//// }
|
||||
|
||||
GBT_Delay(50);
|
||||
|
||||
break;
|
||||
|
||||
case GBT_STOP:
|
||||
//TODO: turn off power modules
|
||||
GBT_Delay(10);
|
||||
GBT_EDCAN_Output.enablePSU = 0;
|
||||
GBT_SendCST();
|
||||
//RELAY_Write(RELAY_OUTPUT, 0);
|
||||
//GBT_SwitchState(GBT_DISABLED);
|
||||
if(GBT_StateTick()>1000){
|
||||
GBT_SwitchState(GBT_DISABLED);
|
||||
GBT_Lock(0);
|
||||
RELAY_Write(RELAY_AUX, 0);
|
||||
//PSU_Mode(0x0100);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
GBT_SwitchState(GBT_DISABLED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GBT_SwitchState(gbtState_t state){
|
||||
GBT_State = state;
|
||||
ED_status = state;
|
||||
GBT_state_tick = HAL_GetTick();
|
||||
if(GBT_State == GBT_DISABLED) printf ("GBT_DISABLED\n");
|
||||
if(GBT_State == GBT_S0_UNCONNECTED) printf ("GBT_S0_UNCONNECTED\n");
|
||||
if(GBT_State == GBT_S1_CONNECTED) printf ("GBT_S1_CONNECTED\n");
|
||||
if(GBT_State == GBT_S2_LOCKED) printf ("GBT_S2_LOCKED\n");
|
||||
if(GBT_State == GBT_S3_STARTED) printf ("GBT_S3_STARTED\n");
|
||||
if(GBT_State == GBT_S4_ISOTEST) printf ("GBT_S4_ISOTEST\n");
|
||||
if(GBT_State == GBT_S5_BAT_INFO) printf ("GBT_S5_BAT_INFO\n");
|
||||
if(GBT_State == GBT_S6_BAT_STAT) printf ("GBT_S6_BAT_STAT\n");
|
||||
if(GBT_State == GBT_S7_BMS_WAIT) printf ("GBT_S7_BMS_WAIT\n");
|
||||
if(GBT_State == GBT_S8_INIT_CHARGER)printf ("GBT_S8_INIT_CHARGER\n");
|
||||
if(GBT_State == GBT_S9_WAIT_BCL) printf ("GBT_S9_WAIT_BCL\n");
|
||||
if(GBT_State == GBT_S10_CHARGING) printf ("GBT_S10_CHARGING\n");
|
||||
if(GBT_State == GBT_STOP) printf ("GBT_STOP\n");
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint32_t GBT_StateTick(){
|
||||
return HAL_GetTick() - GBT_state_tick;
|
||||
}
|
||||
|
||||
void GBT_Delay(uint32_t delay){
|
||||
GBT_delay = HAL_GetTick()+delay;
|
||||
}
|
||||
|
||||
void GBT_Stop(){
|
||||
if(GBT_State != GBT_STOP) GBT_SwitchState(GBT_STOP);
|
||||
}
|
||||
|
||||
void GBT_Stop1(){
|
||||
GBT_SwitchState(GBT_DISABLED);
|
||||
GBT_Lock(0);
|
||||
RELAY_Write(RELAY_AUX, 0);
|
||||
}
|
||||
|
||||
void GBT_Start(){
|
||||
GBT_BAT_INFO_recv = 0;
|
||||
GBT_BAT_STAT_recv = 0;
|
||||
EV_ready = 0;
|
||||
memset(&GBT_EVInfo, 0, sizeof (GBT_EVInfo));
|
||||
memset(&GBT_BATStat, 0, sizeof (GBT_BATStat));
|
||||
memset(&GBT_ReqPower, 0, sizeof (GBT_ReqPower));
|
||||
GBT_SwitchState(GBT_S0_UNCONNECTED);
|
||||
}
|
||||
181
Core/Src/debug.c
Normal file
181
Core/Src/debug.c
Normal file
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* debug.c
|
||||
*
|
||||
* Created on: Apr 16, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "debug.h"
|
||||
#include "board.h"
|
||||
#include "charger_gbt.h"
|
||||
#include "usart.h"
|
||||
|
||||
uint8_t debug_rx_buffer[256];
|
||||
uint8_t debug_cmd_received;
|
||||
uint8_t debug_rx_buffer_size = 0;
|
||||
|
||||
extern UART_HandleTypeDef huart2;
|
||||
|
||||
#if defined(__GNUC__)
|
||||
int _write(int fd, char * ptr, int len)
|
||||
{
|
||||
HAL_UART_Transmit(&huart2, (uint8_t *) ptr, len, HAL_MAX_DELAY);
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
void debug_rx_interrupt(UART_HandleTypeDef *huart, uint16_t Size){
|
||||
debug_rx_buffer[Size] = '\0';
|
||||
debug_rx_buffer_size = Size;
|
||||
debug_cmd_received = 1;
|
||||
}
|
||||
|
||||
void debug_init(){
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart2,debug_rx_buffer,255);
|
||||
//mm_schedule_write(0x01, 0x0000, 0x0800);
|
||||
// mm_schedule_write(0x02, 0x00FF, 0xFFFF);
|
||||
//for (int i=0;i<60;i++)
|
||||
// mm_schedule_write(0x02, 0x0000, 0xFF00);
|
||||
// mm_schedule_write(0x01, 0x0000, 0x0100);
|
||||
// mm_schedule_write(0x01, 0x0000, 0x0100);
|
||||
}
|
||||
|
||||
void parse_command(uint8_t* buffer, size_t length) {
|
||||
// ignore \r \n symbols
|
||||
size_t i = 0;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (buffer[i] == '\r' || buffer[i] == '\n') {
|
||||
buffer[i] = '\0';
|
||||
length = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (strncmp((const char*)buffer, "reset", length) == 0) {
|
||||
printf("Resetting...\n");
|
||||
NVIC_SystemReset();
|
||||
|
||||
} else if (strncmp((const char*)buffer, "relayaux", length) == 0) {
|
||||
printf("Relaying...\n");
|
||||
RELAY_Write(RELAY_AUX, 1);
|
||||
HAL_Delay(200);
|
||||
RELAY_Write(RELAY_AUX, 0);
|
||||
} else if (strncmp((const char*)buffer, "relaycc", length) == 0) {
|
||||
printf("Relaying...\n");
|
||||
RELAY_Write(RELAY_CC, 1);
|
||||
HAL_Delay(200);
|
||||
RELAY_Write(RELAY_CC, 0);
|
||||
|
||||
|
||||
// } else if (strncmp((const char*)buffer, "voltage", length) == 0) {
|
||||
// printf("Voltaging...\n");
|
||||
// mm_schedule_read(0x02, 0x0001);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "adc", length) == 0) {
|
||||
printf("CC1=%.2f\n", GBT_CC_GetAdc());
|
||||
|
||||
} else if (strncmp((const char*)buffer, "lock_state", length) == 0) {
|
||||
printf("Lock state=%d\n", GBT_LockGetState());
|
||||
|
||||
} else if (strncmp((const char*)buffer, "lock_lock", length) == 0) {
|
||||
printf("Locked\n");
|
||||
GBT_Lock(1);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "lock_unlock", length) == 0) {
|
||||
printf("Unlocked\n");
|
||||
GBT_Lock(0);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "start", length) == 0) {
|
||||
printf("Started\n");
|
||||
GBT_Start();
|
||||
|
||||
} else if (strncmp((const char*)buffer, "stop", length) == 0) {
|
||||
printf("Stopped\n");
|
||||
GBT_Stop();
|
||||
|
||||
} else if (strncmp((const char*)buffer, "stop1", length) == 0) {
|
||||
printf("Stopped\n");
|
||||
GBT_Stop1();
|
||||
|
||||
} else if (strncmp((const char*)buffer, "force", length) == 0) {
|
||||
printf("Stopped\n");
|
||||
GBT_Lock(1);
|
||||
GBT_SwitchState(GBT_S2_LOCKED);
|
||||
GBT_Delay(500);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "cc_state", length) == 0) {
|
||||
switch(GBT_CC_GetState()){
|
||||
case GBT_CC_UNKNOWN:
|
||||
printf("GBT_CC_UNKNOWN\n");
|
||||
break;
|
||||
case GBT_CC_12V:
|
||||
printf("GBT_CC_12V\n");
|
||||
break;
|
||||
case GBT_CC_6V:
|
||||
printf("GBT_CC_6V\n");
|
||||
break;
|
||||
case GBT_CC_4V:
|
||||
printf("GBT_CC_4V\n");
|
||||
break;
|
||||
case GBT_CC_2V:
|
||||
printf("GBT_CC_2V\n");
|
||||
break;
|
||||
|
||||
}
|
||||
} else if (strncmp((const char*)buffer, "info1", length) == 0) {
|
||||
printf("Battery info:\n");
|
||||
printf("maxCV %dV\n",GBT_BATStat.maxCellVoltage/100); // 0.01v/bit
|
||||
printf("maxCC %dA\n",GBT_BATStat.maxChargingCurrent/10); // 0.1A/bit
|
||||
printf("totE %dkWh\n",GBT_BATStat.totalEnergy/10); // 0.1kWh
|
||||
printf("maxCV %dV\n",GBT_BATStat.maxChargingVoltage/10); // 0.1V/ bit
|
||||
printf("maxT %dC\n",(int16_t)GBT_BATStat.maxTemp-50); // 1C/bit, -50C offset
|
||||
printf("SOC %dp\n",GBT_BATStat.SOC/10); // 0.1%/bit , 0..100%
|
||||
printf("Volt. %dV\n",GBT_BATStat.measVoltage/10); // 0.1V/bit
|
||||
|
||||
} else if (strncmp((const char*)buffer, "info2", length) == 0) {
|
||||
printf("EV info:\n");
|
||||
printf("GBT_ver V%d.%d%d\n",GBT_EVInfo.version[0],GBT_EVInfo.version[1],GBT_EVInfo.version[2]);
|
||||
printf("Battery type: %d\n",GBT_EVInfo.batteryType);
|
||||
printf("Battery capacity: %d\n", GBT_EVInfo.batteryCapacity); // 0.1Ah/bit
|
||||
printf("Battery voltage: %d\n", GBT_EVInfo.batteryVoltage); // 0.1V/bit
|
||||
printf("Battery vendor: %.4s\n", GBT_EVInfo.batteryVendor); // Battery vendor (ASCII string)
|
||||
printf("Battery SN: %lu\n", GBT_EVInfo.batterySN); // int
|
||||
printf("Battery manufacture date: %02d.%02d.%04d\n", GBT_EVInfo.batteryManuD, GBT_EVInfo.batteryManuM ,GBT_EVInfo.batteryManuY+1985); // year (offset 1985)
|
||||
printf("Battery cycles: %d\n", GBT_EVInfo.batteryCycleCount); //uint24_t
|
||||
printf("Own auto: %d\n", GBT_EVInfo.ownAuto); // 0 = lizing, 1 = own auto
|
||||
printf("EVIN: %.17s\n", GBT_EVInfo.EVIN); //EVIN
|
||||
printf("EV_SW_VER: %.8s\n", GBT_EVInfo.EV_SW_VER);
|
||||
|
||||
} else if (strncmp((const char*)buffer, "help", length) == 0) {
|
||||
printf("Command list:\n");
|
||||
printf("reset\n");
|
||||
printf("help\n");
|
||||
printf("cc_state\n");
|
||||
printf("lock_lock\n");
|
||||
printf("lock_unlock\n");
|
||||
printf("lock_state\n");
|
||||
printf("adc\n");
|
||||
printf("relay(cc,aux)\n");
|
||||
printf("start\n");
|
||||
printf("stop\n");
|
||||
printf("stop1\n");
|
||||
printf("force\n");
|
||||
printf("info1\n");
|
||||
printf("info2\n");
|
||||
//TODO: info commands
|
||||
|
||||
} else {
|
||||
printf("Unknown command\n");
|
||||
}
|
||||
}
|
||||
|
||||
void debug_task(){
|
||||
if(debug_cmd_received){
|
||||
parse_command(debug_rx_buffer, debug_rx_buffer_size);
|
||||
HAL_UARTEx_ReceiveToIdle_IT(&huart2,debug_rx_buffer,255);
|
||||
debug_cmd_received = 0;
|
||||
}
|
||||
}
|
||||
259
Core/Src/edcan_handler_user.c
Normal file
259
Core/Src/edcan_handler_user.c
Normal file
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* edcan_handler.c
|
||||
*
|
||||
* В этом файле расположены обработчики приходящих пакетов для пользовательских регистров
|
||||
*
|
||||
* Created on: Jul 5, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
|
||||
#include <edcan.h>
|
||||
#include "stdio.h"
|
||||
#include "soft_rtc.h"
|
||||
#include "charger_gbt.h"
|
||||
|
||||
// * здесь объявлять внешние устройства и их регистры *
|
||||
//uint8_t edcan_register_BMS[256];//300...3FF
|
||||
|
||||
|
||||
////meter registers
|
||||
//#define EDCAN_ID_METER 0x10
|
||||
//#define EDCAN_REG_METER_VOLTAGE 0x03
|
||||
//#define EDCAN_REG_METER_CURRENT 0x04
|
||||
|
||||
|
||||
//own registers
|
||||
#define EDCAN_REG_CHARGER_ENABLE 0x100
|
||||
|
||||
|
||||
/* Charger info registers */
|
||||
#define EDCAN_REG_CHARGER_NUMBER_0 0x200
|
||||
#define EDCAN_REG_CHARGER_NUMBER_1 0x201
|
||||
#define EDCAN_REG_CHARGER_NUMBER_2 0x202
|
||||
#define EDCAN_REG_CHARGER_NUMBER_3 0x203
|
||||
|
||||
#define EDCAN_REG_CHARGER_LOCATION_0 0x204
|
||||
#define EDCAN_REG_CHARGER_LOCATION_1 0x205
|
||||
#define EDCAN_REG_CHARGER_LOCATION_2 0x206
|
||||
|
||||
//UNIX TIME
|
||||
#define EDCAN_REG_TIME_0 0x210
|
||||
#define EDCAN_REG_TIME_1 0x211
|
||||
#define EDCAN_REG_TIME_2 0x212
|
||||
#define EDCAN_REG_TIME_3 0x213
|
||||
//#define EDCAN_REG_SECONDS 0x210
|
||||
//#define EDCAN_REG_MINUTES 0x211
|
||||
//#define EDCAN_REG_HOURS 0x212
|
||||
//#define EDCAN_REG_DAYS 0x213
|
||||
//#define EDCAN_REG_MONTH 0x214
|
||||
//#define EDCAN_REG_YEARS 0x215
|
||||
//#define EDCAN_REG_CENTURIES 0x216
|
||||
//#define EDCAN_REG_TIME_SYNC 0x217
|
||||
|
||||
#define EDCAN_REG_MAX_LOAD 0x220
|
||||
|
||||
#define EDCAN_REG_BRM 0x310
|
||||
|
||||
#define EDCAN_REG_BCP 0x350
|
||||
|
||||
#define EDCAN_REG_BRO 0x35F
|
||||
|
||||
#define EDCAN_REG_BCL 0x360
|
||||
|
||||
#define EDCAN_REG_BCS 0x370
|
||||
|
||||
#define EDCAN_REG_BSM 0x380
|
||||
|
||||
|
||||
#define EDCAN_REG_OUTPUT 0x500
|
||||
|
||||
GBT_EDCAN_Output_t GBT_EDCAN_Output;
|
||||
|
||||
|
||||
#define EDCAN_REG_INPUT 0x580
|
||||
|
||||
GBT_EDCAN_Input_t GBT_EDCAN_Input;
|
||||
|
||||
|
||||
|
||||
|
||||
//extern uint8_t relay_value[8];
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handler for incoming Read packet
|
||||
* Another device reply value of its registers
|
||||
*
|
||||
* @param SourceID: Packet Source ID
|
||||
* DestinationID: Packet Destination ID
|
||||
* Addr: First register address in sequence
|
||||
* *data: pointer for data array
|
||||
* len: length of data (1..255)
|
||||
*/
|
||||
void EDCAN_ReadHandler(uint8_t SourceID, uint8_t DestinationID, uint16_t Addr, uint8_t *data, uint8_t len){
|
||||
//Получили пакет Read (запрошенное значение регистров)
|
||||
// printf("Received packet: Read\n");
|
||||
// printf("Source ID = %d\n", SourceID);
|
||||
// printf("Destination ID = %d\n", DestinationID);
|
||||
// printf("Address = %d\n", Addr);
|
||||
// printf("Len = %d\n", len);
|
||||
// printf("\n");
|
||||
|
||||
for (uint16_t AddrOffset = 0; AddrOffset < len; AddrOffset++){ //по очереди перебираем все полученные регистры через Handler
|
||||
|
||||
// * добавить сюда новые устройства *
|
||||
|
||||
// if(SourceID == EDCAN_ID_METER){
|
||||
// printf ("register[%d] = %d\n", Addr+AddrOffset, data[AddrOffset]);
|
||||
// switch(Addr+AddrOffset){
|
||||
//
|
||||
// // * добавить сюда внешние регистры этого устройства *
|
||||
// case EDCAN_REG_METER_VOLTAGE:
|
||||
// printf ("Voltage = %d\n", data[AddrOffset]);
|
||||
// break;
|
||||
//
|
||||
// case EDCAN_REG_METER_CURRENT:
|
||||
// printf ("Current = %d\n", data[AddrOffset]);
|
||||
// break;
|
||||
// default:
|
||||
// printf ("Unknown register\n");
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
// printf("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Handler for incoming Read packet
|
||||
* Another device reply value of its registers
|
||||
*
|
||||
* @param SourceID: Packet Source ID
|
||||
* DestinationID: Packet Destination ID
|
||||
* Addr: First register address in sequence
|
||||
* *data: pointer for data array
|
||||
* len: length of data (1..255)
|
||||
*/
|
||||
void EDCAN_WriteUserRegister(uint16_t addr, uint8_t value){
|
||||
switch(addr){
|
||||
//edcan_register[addr] = value;
|
||||
// case EDCAN_REG_K0:
|
||||
// printf ("K0 = %d\n", value);
|
||||
// HAL_GPIO_WritePin (K0_GPIO_Port, K0_Pin, (value == 0));
|
||||
// break;
|
||||
case EDCAN_REG_CHARGER_ENABLE:
|
||||
if(value){
|
||||
GBT_Start();//TODO IF protections
|
||||
}else{
|
||||
GBT_Stop();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EDCAN_REG_TIME_0:
|
||||
writeTimeReg(0, value);
|
||||
break;
|
||||
case EDCAN_REG_TIME_1:
|
||||
writeTimeReg(1, value);
|
||||
break;
|
||||
case EDCAN_REG_TIME_2:
|
||||
writeTimeReg(2, value);
|
||||
break;
|
||||
case EDCAN_REG_TIME_3:
|
||||
writeTimeReg(3, value);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
//0x220
|
||||
case EDCAN_REG_MAX_LOAD ... (EDCAN_REG_MAX_LOAD+sizeof(GBT_CML_t)):
|
||||
((uint8_t*)&GBT_MaxLoad)[addr - EDCAN_REG_MAX_LOAD] = value;
|
||||
break;
|
||||
|
||||
//0x580
|
||||
case EDCAN_REG_INPUT ... (EDCAN_REG_INPUT+sizeof(GBT_EDCAN_Input_t)):
|
||||
((uint8_t*)&GBT_EDCAN_Input)[addr - EDCAN_REG_INPUT] = value;
|
||||
|
||||
//TODO
|
||||
//GBT_EDCAN_Input.measuredCurrent;
|
||||
break;
|
||||
|
||||
|
||||
|
||||
default:
|
||||
printf ("Unknown register\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
uint8_t EDCAN_GetUserRegisterValue(uint16_t addr){
|
||||
switch (addr){
|
||||
|
||||
// /* регистры 256..2047 используются пользовательских нужд */
|
||||
|
||||
|
||||
case EDCAN_REG_TIME_0:
|
||||
return getTimeReg(0);
|
||||
break;
|
||||
|
||||
case EDCAN_REG_TIME_1:
|
||||
return getTimeReg(1);
|
||||
break;
|
||||
|
||||
case EDCAN_REG_TIME_2:
|
||||
return getTimeReg(2);
|
||||
break;
|
||||
|
||||
case EDCAN_REG_TIME_3:
|
||||
return getTimeReg(3);
|
||||
break;
|
||||
|
||||
|
||||
//0x220
|
||||
case EDCAN_REG_MAX_LOAD ... (EDCAN_REG_MAX_LOAD+sizeof(GBT_CML_t)):
|
||||
return ((uint8_t*)&GBT_MaxLoad)[addr - EDCAN_REG_MAX_LOAD];
|
||||
|
||||
//0x310
|
||||
case EDCAN_REG_BRM ... (EDCAN_REG_BRM+sizeof(GBT_BRM_t)-1):
|
||||
return ((uint8_t*)&GBT_EVInfo)[addr - EDCAN_REG_BRM];
|
||||
|
||||
//0x340
|
||||
case EDCAN_REG_BCP ... (EDCAN_REG_BCP+sizeof(GBT_BCP_t)):
|
||||
return ((uint8_t*)&GBT_BATStat)[addr - EDCAN_REG_BCP];
|
||||
|
||||
//0x34F
|
||||
case EDCAN_REG_BRO:
|
||||
return GBT_BRO;
|
||||
|
||||
//0x350
|
||||
case EDCAN_REG_BCL ... (EDCAN_REG_BCL+sizeof(GBT_BCL_t)):
|
||||
return ((uint8_t*)&GBT_ReqPower)[addr - EDCAN_REG_BCL];
|
||||
|
||||
//0x360
|
||||
case EDCAN_REG_BCS ... (EDCAN_REG_BCS+sizeof(GBT_BCS_t)):
|
||||
return ((uint8_t*)&GBT_ChargingStatus)[addr - EDCAN_REG_BCS];
|
||||
|
||||
//0x370
|
||||
case EDCAN_REG_BSM ... (EDCAN_REG_BSM+sizeof(GBT_BSM_t)):
|
||||
return ((uint8_t*)&GBT_BatteryStatus)[addr - EDCAN_REG_BSM];
|
||||
|
||||
|
||||
//0x500
|
||||
case EDCAN_REG_OUTPUT ... (EDCAN_REG_OUTPUT+sizeof(GBT_EDCAN_Output_t)):
|
||||
return ((uint8_t*)&GBT_EDCAN_Output)[addr - EDCAN_REG_OUTPUT];
|
||||
|
||||
//0x580
|
||||
case EDCAN_REG_INPUT ... (EDCAN_REG_INPUT+sizeof(GBT_EDCAN_Input_t)):
|
||||
return ((uint8_t*)&GBT_EDCAN_Input)[addr - EDCAN_REG_INPUT];
|
||||
|
||||
|
||||
default:
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
109
Core/Src/gbt_packet.c
Normal file
109
Core/Src/gbt_packet.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* gbt_packet.c
|
||||
*
|
||||
* Created on: Jul 23, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
|
||||
// GB/T Time Synchronization Packet
|
||||
#include "main.h"
|
||||
#include "soft_rtc.h"
|
||||
#include "charger_gbt.h"
|
||||
|
||||
void GBT_SendCTS(){
|
||||
|
||||
uint8_t data[7];
|
||||
unix_to_bcd(get_Current_Time(), data);
|
||||
// data[0] = 0x00; //seconds
|
||||
// data[1] = 0x30; //minutes
|
||||
// data[2] = 0x23; //hours
|
||||
// data[3] = 0x05; //days
|
||||
// data[4] = 0x05; //month
|
||||
// data[5] = 0x24; //years
|
||||
// data[6] = 0x20; //centuries
|
||||
|
||||
J_SendPacket(0x000700, 6, 7, data);
|
||||
}
|
||||
|
||||
//TODO
|
||||
//GB/T Max Load Packet
|
||||
void GBT_SendCML(){
|
||||
// uint8_t data[8];
|
||||
// data[0] = 0x94; //450V max output voltage
|
||||
// data[1] = 0x11; //
|
||||
// data[2] = 0xB0; //120V min output voltage
|
||||
// data[3] = 0x04; //
|
||||
// data[4] = 0xC4; //-150A maximum output current
|
||||
// data[5] = 0x09; //
|
||||
// data[6] = 0x8C; //-2A minimum output current
|
||||
// data[7] = 0x0F; //
|
||||
|
||||
J_SendPacket(0x000800, 6, 8, (uint8_t*)&GBT_MaxLoad);
|
||||
|
||||
}
|
||||
|
||||
//GB/T Version packet
|
||||
void GBT_SendCHM(){
|
||||
uint8_t data[3];
|
||||
data[0] = 0x01;
|
||||
data[1] = 0x01;
|
||||
data[2] = 0x00;
|
||||
J_SendPacket(0x2600, 6, 3, data);
|
||||
}
|
||||
|
||||
//TODO
|
||||
//GB/T CRM Packet (state=BMS identified)
|
||||
void GBT_SendCRM(uint8_t state){
|
||||
// uint8_t data[8];
|
||||
// data[0] = state; // 0x00 / 0xAA
|
||||
// data[1] = 0x40; //TODO: Charger Number 123456
|
||||
// data[2] = 0xE2;
|
||||
// data[3] = 0x01;
|
||||
// data[4] = 0x00;
|
||||
// data[5] = 0x42; //TODO: location BFG
|
||||
// data[6] = 0x46;
|
||||
// data[7] = 0x47;
|
||||
GBT_ChargerInfo.bmsIdentified = state;
|
||||
J_SendPacket(0x100, 6, 8, (uint8_t *)&GBT_ChargerInfo);
|
||||
}
|
||||
|
||||
//GB/T CRO packet (Charger ready)
|
||||
void GBT_SendCRO(uint8_t state){
|
||||
uint8_t data[1];
|
||||
data[0] = state;
|
||||
J_SendPacket(0xA00, 4, 1, data);
|
||||
}
|
||||
|
||||
|
||||
//TODO: Send measured voltage current
|
||||
//GB/T CCS packet (Charger current status)
|
||||
void GBT_SendCCS(){
|
||||
// uint8_t data[8];
|
||||
// data[0] = GBT_CurrPower.requestedVoltage; //
|
||||
// data[1] = GBT_CurrPower.requestedVoltage>>8; //output voltage
|
||||
// data[2] = GBT_CurrPower.requestedCurrent; //смещение 400а, границы
|
||||
// //-400A = 0
|
||||
// // 0A = 4000
|
||||
// // -100A = 3000
|
||||
// data[3] = GBT_CurrPower.requestedCurrent>>8; //TODO: current
|
||||
// data[4] = GBT_StateTick()/60000; //charging time (min)
|
||||
// data[5] = 0; //TODO: 255 min+
|
||||
// data[6] = 0b11111101; //charging not permitted
|
||||
// data[7] = 0xFF;
|
||||
J_SendPacket(0x1200, 6, 8, (uint8_t *)&GBT_ChargerCurrentStatus);
|
||||
}
|
||||
|
||||
//TODO: stop cause
|
||||
// GB/T Charging Stop packet
|
||||
void GBT_SendCST(){
|
||||
uint8_t data[8];
|
||||
data[0] = 0x04; // Artificially stop charging
|
||||
data[1] = 0x00; //TODO: Cause stop
|
||||
data[2] = 0xF0; //
|
||||
data[3] = 0xF0; //
|
||||
|
||||
J_SendPacket(0x1A00, 4, 4, data);
|
||||
}
|
||||
|
||||
//TODO CSD priority 6
|
||||
110
Core/Src/gpio.c
Normal file
110
Core/Src/gpio.c
Normal file
@@ -0,0 +1,110 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file gpio.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of all used GPIO pins.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "gpio.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Configure GPIO */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/** Configure pins as
|
||||
* Analog
|
||||
* Input
|
||||
* Output
|
||||
* EVENT_OUT
|
||||
* EXTI
|
||||
*/
|
||||
void MX_GPIO_Init(void)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, LOCK_A_Pin|LOCK_B_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(RELAY_CC_GPIO_Port, RELAY_CC_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(USART2_DIR_GPIO_Port, USART2_DIR_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(RELAY_AUX_GPIO_Port, RELAY_AUX_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : PCPin PCPin */
|
||||
GPIO_InitStruct.Pin = LOCK_A_Pin|LOCK_B_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = LOCK_FB_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(LOCK_FB_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PEPin PEPin */
|
||||
GPIO_InitStruct.Pin = ADDR_0_Pin|ADDR_1_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = RELAY_CC_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(RELAY_CC_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = USART2_DIR_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(USART2_DIR_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = RELAY_AUX_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(RELAY_AUX_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
163
Core/Src/j1939.c
Normal file
163
Core/Src/j1939.c
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* j1939.c
|
||||
*
|
||||
* Created on: May 3, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "j1939.h"
|
||||
#include "charger_gbt.h"
|
||||
#include "string.h"
|
||||
#include "can.h"
|
||||
|
||||
extern GBT_BCL_t GBT_ReqPower;
|
||||
extern GBT_BCL_t GBT_CurrPower;
|
||||
|
||||
j_receive_t j_rx;
|
||||
|
||||
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
{
|
||||
CAN_RxHeaderTypeDef RxHeader;
|
||||
uint8_t RxData[8] = {0,};
|
||||
|
||||
if(HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader, RxData) == HAL_OK)
|
||||
{
|
||||
if((RxHeader.ExtId & 0x00FFFF) == ((J_ID_SE << 8) | J_ID_EV)){ // SA, DA match
|
||||
switch ((RxHeader.ExtId>>8) & 0x00FF00){
|
||||
|
||||
case 0xEC00: //PGN Connection Management Message
|
||||
if(RxData[0] == 16){ //Request to Send
|
||||
/* Set the RTS values */
|
||||
j_rx.size = RxData[1] | (RxData[2]<<8);
|
||||
j_rx.packet = 1;
|
||||
j_rx.packets = RxData[3];
|
||||
j_rx.step = 2; //TODO
|
||||
j_rx.step_cts_remain = j_rx.step;
|
||||
j_rx.PGN = (RxData[7] << 16) | (RxData[6] << 8) | RxData[5];
|
||||
if(j_rx.size<256) { //TODO: valid check
|
||||
J_SendCTS(j_rx);
|
||||
j_rx.state = 1;
|
||||
}
|
||||
}
|
||||
if(RxData[0] == 255){ //Connection Abort
|
||||
j_rx.state = 0;
|
||||
}
|
||||
|
||||
//if(RxData[0] == 32){}//Broadcast Announce Message
|
||||
/*
|
||||
* 1CEC56F4 10 31 00 07 07 00 02 00
|
||||
* 1CECF456 11 02 01 FF FF 00 02 00
|
||||
* 1CEB56F4 01 01 01 00 03 46 05 40
|
||||
* 1CEC56F4 FF FF FF FF FF 00 00 00
|
||||
*/
|
||||
|
||||
break;
|
||||
|
||||
case 0xEB00: //PGN Data Message
|
||||
if(j_rx.state != 1) break;
|
||||
if((RxData[0]>0) && (RxData[0]<35)){ //Array limit check
|
||||
if(j_rx.packet == RxData[0]){ //step check
|
||||
memcpy (&j_rx.data[(RxData[0]-1)*7], &RxData[1],7);
|
||||
j_rx.packet++;
|
||||
if(j_rx.packet > j_rx.packets){
|
||||
//End of transmission
|
||||
J_SendACK(j_rx);
|
||||
|
||||
j_rx.state = 2;
|
||||
}else{
|
||||
if(j_rx.step_cts_remain > 0) j_rx.step_cts_remain--;
|
||||
if(j_rx.step_cts_remain == 0){
|
||||
J_SendCTS(j_rx);
|
||||
j_rx.step_cts_remain = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x1E00: //PGN BEM (ERROR)
|
||||
GBT_Stop();
|
||||
break;
|
||||
|
||||
case 0x1900: //PGN BST (STOP)
|
||||
GBT_Stop();
|
||||
break;
|
||||
|
||||
default:
|
||||
if(j_rx.state == 0){//TODO protections
|
||||
//Short packet
|
||||
j_rx.size = RxHeader.DLC;
|
||||
j_rx.packet = 1;
|
||||
j_rx.packets = 1;
|
||||
j_rx.step = 1;
|
||||
j_rx.step_cts_remain = 0;
|
||||
j_rx.PGN = (RxHeader.ExtId>>8) & 0x00FF00;
|
||||
j_rx.state = 2;
|
||||
memcpy (j_rx.data, RxData, j_rx.size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GBT_CAN_ReInit(){
|
||||
HAL_CAN_Stop(&hcan1);
|
||||
MX_CAN1_Init();
|
||||
HAL_CAN_Start(&hcan1);
|
||||
HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
|
||||
}
|
||||
|
||||
void J_SendPacket(uint32_t PGN, uint8_t pri, uint8_t DLC, uint8_t *data){
|
||||
|
||||
CAN_TxHeaderTypeDef tx_header;
|
||||
uint32_t tx_mailbox;
|
||||
|
||||
tx_header.ExtId = (pri << 26) | (PGN << 8) | (J_ID_EV << 8) | J_ID_SE;
|
||||
tx_header.RTR = CAN_RTR_DATA;
|
||||
tx_header.IDE = CAN_ID_EXT;
|
||||
tx_header.DLC = DLC;
|
||||
|
||||
HAL_CAN_AddTxMessage(&hcan1, &tx_header, data, &tx_mailbox);
|
||||
//HAL_Delay(2);
|
||||
|
||||
}
|
||||
|
||||
//void J_SendPacketLong(){
|
||||
// //TODO (no need)
|
||||
//}
|
||||
|
||||
// J1939 sequence Clear To Send packet
|
||||
void J_SendCTS(j_receive_t rx){
|
||||
|
||||
//if(rx.packets <= rx.packet) return; TODO
|
||||
uint8_t data[8];
|
||||
data[0] = 17; //CONTROL_BYTE_TP_CM_CTS
|
||||
data[1] = rx.step;//total_number_of_packages_transmitted
|
||||
if (rx.step > (rx.packets - rx.packet+1)) data[1] = rx.packets - rx.packet+1;
|
||||
data[2] = rx.packet;//next_packet_number_transmitted
|
||||
data[3] = 0xFF; /* Reserved */
|
||||
data[4] = 0xFF;
|
||||
data[5] = rx.PGN;
|
||||
data[6] = rx.PGN >> 8;
|
||||
data[7] = rx.PGN >> 16;
|
||||
|
||||
J_SendPacket(0x00EC00, 7, 8, data);
|
||||
}
|
||||
|
||||
// J1939 sequence ACK packet
|
||||
void J_SendACK(j_receive_t rx){//uint32_t PGN, uint8_t step, uint8_t packet){
|
||||
|
||||
uint8_t data[8];
|
||||
data[0] = 19; //CONTROL_BYTE_TP_CM_ACK
|
||||
data[1] = j_rx.size;
|
||||
data[2] = j_rx.size>>8;
|
||||
data[3] = j_rx.packets;
|
||||
data[4] = 0xFF;//TODO
|
||||
data[5] = rx.PGN;
|
||||
data[6] = rx.PGN >> 8;
|
||||
data[7] = rx.PGN >> 16;
|
||||
|
||||
J_SendPacket(0x00EC00, 7, 8, data);
|
||||
}
|
||||
|
||||
223
Core/Src/main.c
Normal file
223
Core/Src/main.c
Normal file
@@ -0,0 +1,223 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "main.h"
|
||||
#include "adc.h"
|
||||
#include "can.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "can.h"
|
||||
#include "board.h"
|
||||
#include <stdio.h>
|
||||
#include "debug.h"
|
||||
#include "charger_gbt.h"
|
||||
#include "soft_rtc.h"
|
||||
#include "j1939.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
#include "edcan_config.h"
|
||||
#include "edcan_defines.h"
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_CAN1_Init();
|
||||
MX_CAN2_Init();
|
||||
MX_USART2_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
CAN_ReInit();
|
||||
Init_Peripheral();
|
||||
|
||||
HAL_Delay(300);
|
||||
GBT_Init();
|
||||
set_Time(1721651966); //2024-07-22T12:39:26+00:00
|
||||
printf("Startup (type \'help\' for command list)\n");
|
||||
debug_init();
|
||||
//EDCAN_Init(SW_GetAddr()); //0x20..0x23
|
||||
EDCAN_Init(0x20); //Адрес EDCAN
|
||||
CAN_ReInit();
|
||||
GBT_CAN_ReInit();
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
// HAL_Delay(1);
|
||||
EDCAN_Loop();
|
||||
// can_task();
|
||||
debug_task();
|
||||
GBT_ChargerTask();
|
||||
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV5;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_PLL2;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||
RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL2_ON;
|
||||
RCC_OscInitStruct.PLL2.PLL2MUL = RCC_PLL2_MUL8;
|
||||
RCC_OscInitStruct.PLL2.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV5;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
||||
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure the Systick interrupt time
|
||||
*/
|
||||
__HAL_RCC_PLLI2S_ENABLE();
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
74
Core/Src/soft_rtc.c
Normal file
74
Core/Src/soft_rtc.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* rtc.c
|
||||
*
|
||||
* Created on: Jul 22, 2024
|
||||
* Author: colorbass
|
||||
*/
|
||||
|
||||
#include <soft_rtc.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
uint32_t GBT_time_offset; //current time = offset+HAL_GetTick()/1000;
|
||||
uint8_t tmp_time[4];
|
||||
uint8_t tmp_time32;
|
||||
|
||||
uint32_t get_Current_Time(){
|
||||
return GBT_time_offset + (HAL_GetTick()/1000);
|
||||
}
|
||||
|
||||
void set_Time(uint32_t unix_time){
|
||||
if(unix_time <= (HAL_GetTick()/1000)) return; //invalid time
|
||||
GBT_time_offset = unix_time - (HAL_GetTick()/1000);
|
||||
}
|
||||
|
||||
uint8_t to_bcd(int value) {
|
||||
return ((value / 10) << 4) | (value % 10);
|
||||
}
|
||||
|
||||
void unix_to_bcd(uint32_t unix_time, uint8_t *time) {
|
||||
struct tm *tm_info;
|
||||
time_t raw_time = (time_t)unix_time;
|
||||
tm_info = gmtime(&raw_time);
|
||||
|
||||
time[0] = to_bcd(tm_info->tm_sec);
|
||||
time[1] = to_bcd(tm_info->tm_min);
|
||||
time[2] = to_bcd(tm_info->tm_hour);
|
||||
time[3] = to_bcd(tm_info->tm_mday);
|
||||
time[4] = to_bcd(tm_info->tm_mon + 1); // tm_mon is 0-11
|
||||
time[5] = to_bcd((tm_info->tm_year + 1900) % 100); // Year in 2 digits
|
||||
time[6] = to_bcd((tm_info->tm_year + 1900) / 100); // Century in 2 digits
|
||||
}
|
||||
|
||||
void writeTimeReg(uint8_t reg_number, uint8_t value){
|
||||
tmp_time[reg_number] = value;
|
||||
if(reg_number == 3) set_Time((tmp_time[0])+(tmp_time[1]<<8)+(tmp_time[2]<<16)+(tmp_time[3]<<24));
|
||||
};
|
||||
|
||||
uint8_t getTimeReg(uint8_t reg_number){
|
||||
if(reg_number == 0){
|
||||
tmp_time32 = get_Current_Time();
|
||||
return tmp_time32 & 0xFF;
|
||||
}else if(reg_number == 1){
|
||||
return (tmp_time32>>8) & 0xFF;
|
||||
}else if(reg_number == 2){
|
||||
return (tmp_time32>>16) & 0xFF;
|
||||
}else if(reg_number == 3){
|
||||
return (tmp_time32>>24) & 0xFF;
|
||||
}else{
|
||||
return 0x00;
|
||||
}
|
||||
};
|
||||
//int main() {
|
||||
// uint32_t unix_time = 1672531199; // Example Unix timestamp
|
||||
// uint8_t time[8];
|
||||
//
|
||||
// unix_to_bcd(unix_time, time);
|
||||
//
|
||||
// // Print the BCD values for verification
|
||||
// for (int i = 0; i < 8; i++) {
|
||||
// printf("time[%d]: %02X\n", i, time[i]);
|
||||
// }
|
||||
//
|
||||
// return 0;
|
||||
//}
|
||||
85
Core/Src/stm32f1xx_hal_msp.c
Normal file
85
Core/Src/stm32f1xx_hal_msp.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_hal_msp.c
|
||||
* @brief This file provides code for the MSP Initialization
|
||||
* and de-Initialization codes.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "main.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Define */
|
||||
|
||||
/* USER CODE END Define */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Macro */
|
||||
|
||||
/* USER CODE END Macro */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* External functions --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ExternalFunctions */
|
||||
|
||||
/* USER CODE END ExternalFunctions */
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void)
|
||||
{
|
||||
/* USER CODE BEGIN MspInit 0 */
|
||||
|
||||
/* USER CODE END MspInit 0 */
|
||||
|
||||
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* System interrupt init*/
|
||||
|
||||
/** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
|
||||
*/
|
||||
__HAL_AFIO_REMAP_SWJ_NOJTAG();
|
||||
|
||||
/* USER CODE BEGIN MspInit 1 */
|
||||
|
||||
/* USER CODE END MspInit 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
261
Core/Src/stm32f1xx_it.c
Normal file
261
Core/Src/stm32f1xx_it.c
Normal file
@@ -0,0 +1,261 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f1xx_it.c
|
||||
* @brief Interrupt Service Routines.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "main.h"
|
||||
#include "stm32f1xx_it.h"
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN TD */
|
||||
|
||||
/* USER CODE END TD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern CAN_HandleTypeDef hcan1;
|
||||
extern CAN_HandleTypeDef hcan2;
|
||||
extern UART_HandleTypeDef huart2;
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
*/
|
||||
void NMI_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
|
||||
|
||||
/* USER CODE END NonMaskableInt_IRQn 0 */
|
||||
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
|
||||
while (1)
|
||||
{
|
||||
}
|
||||
/* USER CODE END NonMaskableInt_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Hard fault interrupt.
|
||||
*/
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
|
||||
/* USER CODE END W1_HardFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Memory management fault.
|
||||
*/
|
||||
void MemManage_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
|
||||
|
||||
/* USER CODE END MemoryManagement_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
|
||||
/* USER CODE END W1_MemoryManagement_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Prefetch fault, memory access fault.
|
||||
*/
|
||||
void BusFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN BusFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END BusFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
|
||||
/* USER CODE END W1_BusFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Undefined instruction or illegal state.
|
||||
*/
|
||||
void UsageFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN UsageFault_IRQn 0 */
|
||||
|
||||
/* USER CODE END UsageFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
|
||||
/* USER CODE END W1_UsageFault_IRQn 0 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System service call via SWI instruction.
|
||||
*/
|
||||
void SVC_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SVCall_IRQn 0 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 0 */
|
||||
/* USER CODE BEGIN SVCall_IRQn 1 */
|
||||
|
||||
/* USER CODE END SVCall_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Debug monitor.
|
||||
*/
|
||||
void DebugMon_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 0 */
|
||||
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
|
||||
|
||||
/* USER CODE END DebugMonitor_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles Pendable request for system service.
|
||||
*/
|
||||
void PendSV_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN PendSV_IRQn 0 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 0 */
|
||||
/* USER CODE BEGIN PendSV_IRQn 1 */
|
||||
|
||||
/* USER CODE END PendSV_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles System tick timer.
|
||||
*/
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN SysTick_IRQn 0 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 0 */
|
||||
HAL_IncTick();
|
||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||
|
||||
/* USER CODE END SysTick_IRQn 1 */
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32F1xx Peripheral Interrupt Handlers */
|
||||
/* Add here the Interrupt Handlers for the used peripherals. */
|
||||
/* For the available peripheral interrupt handler names, */
|
||||
/* please refer to the startup file (startup_stm32f1xx.s). */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function handles CAN1 RX0 interrupt.
|
||||
*/
|
||||
void CAN1_RX0_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN CAN1_RX0_IRQn 0 */
|
||||
|
||||
/* USER CODE END CAN1_RX0_IRQn 0 */
|
||||
HAL_CAN_IRQHandler(&hcan1);
|
||||
/* USER CODE BEGIN CAN1_RX0_IRQn 1 */
|
||||
|
||||
/* USER CODE END CAN1_RX0_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USART2 global interrupt.
|
||||
*/
|
||||
void USART2_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_IRQn 0 */
|
||||
|
||||
/* USER CODE END USART2_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart2);
|
||||
/* USER CODE BEGIN USART2_IRQn 1 */
|
||||
|
||||
/* USER CODE END USART2_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles CAN2 TX interrupt.
|
||||
*/
|
||||
void CAN2_TX_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN CAN2_TX_IRQn 0 */
|
||||
|
||||
/* USER CODE END CAN2_TX_IRQn 0 */
|
||||
HAL_CAN_IRQHandler(&hcan2);
|
||||
/* USER CODE BEGIN CAN2_TX_IRQn 1 */
|
||||
|
||||
/* USER CODE END CAN2_TX_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles CAN2 RX1 interrupt.
|
||||
*/
|
||||
void CAN2_RX1_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN CAN2_RX1_IRQn 0 */
|
||||
|
||||
/* USER CODE END CAN2_RX1_IRQn 0 */
|
||||
HAL_CAN_IRQHandler(&hcan2);
|
||||
/* USER CODE BEGIN CAN2_RX1_IRQn 1 */
|
||||
|
||||
/* USER CODE END CAN2_RX1_IRQn 1 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
176
Core/Src/syscalls.c
Normal file
176
Core/Src/syscalls.c
Normal file
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file syscalls.c
|
||||
* @author Auto-generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE Minimal System calls file
|
||||
*
|
||||
* For more information about which c-functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the Newlib libc-manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2020-2023 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 <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
|
||||
/* Variables */
|
||||
extern int __io_putchar(int ch) __attribute__((weak));
|
||||
extern int __io_getchar(void) __attribute__((weak));
|
||||
|
||||
|
||||
char *__env[1] = { 0 };
|
||||
char **environ = __env;
|
||||
|
||||
|
||||
/* Functions */
|
||||
void initialise_monitor_handles()
|
||||
{
|
||||
}
|
||||
|
||||
int _getpid(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _kill(int pid, int sig)
|
||||
{
|
||||
(void)pid;
|
||||
(void)sig;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void _exit (int status)
|
||||
{
|
||||
_kill(status, -1);
|
||||
while (1) {} /* Make sure we hang here */
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
||||
{
|
||||
(void)file;
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
*ptr++ = __io_getchar();
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
||||
{
|
||||
(void)file;
|
||||
int DataIdx;
|
||||
|
||||
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
||||
{
|
||||
__io_putchar(*ptr++);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int _close(int file)
|
||||
{
|
||||
(void)file;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int _fstat(int file, struct stat *st)
|
||||
{
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty(int file)
|
||||
{
|
||||
(void)file;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _lseek(int file, int ptr, int dir)
|
||||
{
|
||||
(void)file;
|
||||
(void)ptr;
|
||||
(void)dir;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _open(char *path, int flags, ...)
|
||||
{
|
||||
(void)path;
|
||||
(void)flags;
|
||||
/* Pretend like we always fail */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _wait(int *status)
|
||||
{
|
||||
(void)status;
|
||||
errno = ECHILD;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _unlink(char *name)
|
||||
{
|
||||
(void)name;
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _times(struct tms *buf)
|
||||
{
|
||||
(void)buf;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _stat(char *file, struct stat *st)
|
||||
{
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _link(char *old, char *new)
|
||||
{
|
||||
(void)old;
|
||||
(void)new;
|
||||
errno = EMLINK;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fork(void)
|
||||
{
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _execve(char *name, char **argv, char **env)
|
||||
{
|
||||
(void)name;
|
||||
(void)argv;
|
||||
(void)env;
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
79
Core/Src/sysmem.c
Normal file
79
Core/Src/sysmem.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file sysmem.c
|
||||
* @author Generated by STM32CubeIDE
|
||||
* @brief STM32CubeIDE System Memory calls file
|
||||
*
|
||||
* For more information about which C functions
|
||||
* need which of these lowlevel functions
|
||||
* please consult the newlib libc manual
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2023 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 <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Pointer to the current high watermark of the heap usage
|
||||
*/
|
||||
static uint8_t *__sbrk_heap_end = NULL;
|
||||
|
||||
/**
|
||||
* @brief _sbrk() allocates memory to the newlib heap and is used by malloc
|
||||
* and others from the C library
|
||||
*
|
||||
* @verbatim
|
||||
* ############################################################################
|
||||
* # .data # .bss # newlib heap # MSP stack #
|
||||
* # # # # Reserved by _Min_Stack_Size #
|
||||
* ############################################################################
|
||||
* ^-- RAM start ^-- _end _estack, RAM end --^
|
||||
* @endverbatim
|
||||
*
|
||||
* This implementation starts allocating at the '_end' linker symbol
|
||||
* The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack
|
||||
* The implementation considers '_estack' linker symbol to be RAM end
|
||||
* NOTE: If the MSP stack, at any point during execution, grows larger than the
|
||||
* reserved size, please increase the '_Min_Stack_Size'.
|
||||
*
|
||||
* @param incr Memory size
|
||||
* @return Pointer to allocated memory
|
||||
*/
|
||||
void *_sbrk(ptrdiff_t incr)
|
||||
{
|
||||
extern uint8_t _end; /* Symbol defined in the linker script */
|
||||
extern uint8_t _estack; /* Symbol defined in the linker script */
|
||||
extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */
|
||||
const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size;
|
||||
const uint8_t *max_heap = (uint8_t *)stack_limit;
|
||||
uint8_t *prev_heap_end;
|
||||
|
||||
/* Initialize heap end at first call */
|
||||
if (NULL == __sbrk_heap_end)
|
||||
{
|
||||
__sbrk_heap_end = &_end;
|
||||
}
|
||||
|
||||
/* Protect heap from growing into the reserved MSP stack */
|
||||
if (__sbrk_heap_end + incr > max_heap)
|
||||
{
|
||||
errno = ENOMEM;
|
||||
return (void *)-1;
|
||||
}
|
||||
|
||||
prev_heap_end = __sbrk_heap_end;
|
||||
__sbrk_heap_end += incr;
|
||||
|
||||
return (void *)prev_heap_end;
|
||||
}
|
||||
406
Core/Src/system_stm32f1xx.c
Normal file
406
Core/Src/system_stm32f1xx.c
Normal file
@@ -0,0 +1,406 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32f1xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
|
||||
*
|
||||
* 1. This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
|
||||
* factors, AHB/APBx prescalers and Flash settings).
|
||||
* This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32f1xx_xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
|
||||
* Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
|
||||
* configure the system clock before to branch to main program.
|
||||
*
|
||||
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
|
||||
* the product used), refer to "HSE_VALUE".
|
||||
* When HSE is used as system clock source, directly or through PLL, and you
|
||||
* are using different crystal you have to adapt the HSE value to your own
|
||||
* configuration.
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017-2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32f1xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32f1xx.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/*!< Uncomment the following line if you need to use external SRAM */
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/* #define DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/* Note: Following vector table addresses must be defined in line with linker
|
||||
configuration. */
|
||||
/*!< Uncomment the following line if you need to relocate the vector table
|
||||
anywhere in Flash or Sram, else the vector table is kept at the automatic
|
||||
remap of boot address selected */
|
||||
/* #define USER_VECT_TAB_ADDRESS */
|
||||
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||
in Sram else user remap will be done in Flash. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#if defined(VECT_TAB_SRAM)
|
||||
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#else
|
||||
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x200. */
|
||||
#endif /* VECT_TAB_SRAM */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* This variable is updated in three ways:
|
||||
1) by calling CMSIS function SystemCoreClockUpdate()
|
||||
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
|
||||
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
|
||||
Note: If you use this function to configure the system clock; then there
|
||||
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||
variable is updated automatically.
|
||||
*/
|
||||
uint32_t SystemCoreClock = 16000000;
|
||||
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
static void SystemInit_ExtMemCtl(void);
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32F1xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
* Initialize the Embedded Flash Interface, the PLL and update the
|
||||
* SystemCoreClock variable.
|
||||
* @note This function should be used only after reset.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit (void)
|
||||
{
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
SystemInit_ExtMemCtl();
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif
|
||||
|
||||
/* Configure the Vector Table location -------------------------------------*/
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock (HCLK), it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock (HCLK) changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
|
||||
*
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
*
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
|
||||
* or HSI_VALUE(*) multiplied by the PLL factors.
|
||||
*
|
||||
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||
* 8 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
|
||||
* 8 MHz or 25 MHz, depending on the product used), user has to ensure
|
||||
* that HSE_VALUE is same as the real frequency of the crystal used.
|
||||
* Otherwise, this function may have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate (void)
|
||||
{
|
||||
uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U;
|
||||
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
|
||||
#endif /* STM32F105xC */
|
||||
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||
uint32_t prediv1factor = 0U;
|
||||
#endif /* STM32F100xB or STM32F100xE */
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
tmp = RCC->CFGR & RCC_CFGR_SWS;
|
||||
|
||||
switch (tmp)
|
||||
{
|
||||
case 0x00U: /* HSI used as system clock */
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
case 0x04U: /* HSE used as system clock */
|
||||
SystemCoreClock = HSE_VALUE;
|
||||
break;
|
||||
case 0x08U: /* PLL used as system clock */
|
||||
|
||||
/* Get PLL clock source and multiplication factor ----------------------*/
|
||||
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
|
||||
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
|
||||
|
||||
#if !defined(STM32F105xC) && !defined(STM32F107xC)
|
||||
pllmull = ( pllmull >> 18U) + 2U;
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE)
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
#else
|
||||
/* HSE selected as PLL clock entry */
|
||||
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
|
||||
{/* HSE oscillator clock divided by 2 */
|
||||
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemCoreClock = HSE_VALUE * pllmull;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
pllmull = pllmull >> 18U;
|
||||
|
||||
if (pllmull != 0x0DU)
|
||||
{
|
||||
pllmull += 2U;
|
||||
}
|
||||
else
|
||||
{ /* PLL multiplication factor = PLL input clock * 6.5 */
|
||||
pllmull = 13U / 2U;
|
||||
}
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PREDIV1 selected as PLL clock entry */
|
||||
|
||||
/* Get PREDIV1 clock source and division factor */
|
||||
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
|
||||
if (prediv1source == 0U)
|
||||
{
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PLL2 clock selected as PREDIV1 clock entry */
|
||||
|
||||
/* Get PREDIV2 division factor and PLL2 multiplication factor */
|
||||
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
|
||||
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U;
|
||||
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
|
||||
}
|
||||
}
|
||||
#endif /* STM32F105xC */
|
||||
break;
|
||||
|
||||
default:
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Compute HCLK clock frequency ----------------*/
|
||||
/* Get HCLK prescaler */
|
||||
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
|
||||
/* HCLK clock frequency */
|
||||
SystemCoreClock >>= tmp;
|
||||
}
|
||||
|
||||
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/**
|
||||
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
|
||||
* before jump to __main
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
/**
|
||||
* @brief Setup the external memory controller.
|
||||
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
|
||||
* This function configures the external SRAM mounted on STM3210E-EVAL
|
||||
* board (STM32 High density devices). This SRAM will be used as program
|
||||
* data memory (including heap and stack).
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit_ExtMemCtl(void)
|
||||
{
|
||||
__IO uint32_t tmpreg;
|
||||
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
|
||||
required, then adjust the Register Addresses */
|
||||
|
||||
/* Enable FSMC clock */
|
||||
RCC->AHBENR = 0x00000114U;
|
||||
|
||||
/* Delay after an RCC peripheral clock enabling */
|
||||
tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
|
||||
|
||||
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
|
||||
RCC->APB2ENR = 0x000001E0U;
|
||||
|
||||
/* Delay after an RCC peripheral clock enabling */
|
||||
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
|
||||
|
||||
(void)(tmpreg);
|
||||
|
||||
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
|
||||
/*---------------- SRAM Address lines configuration -------------------------*/
|
||||
/*---------------- NOE and NWE configuration --------------------------------*/
|
||||
/*---------------- NE3 configuration ----------------------------------------*/
|
||||
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
|
||||
|
||||
GPIOD->CRL = 0x44BB44BBU;
|
||||
GPIOD->CRH = 0xBBBBBBBBU;
|
||||
|
||||
GPIOE->CRL = 0xB44444BBU;
|
||||
GPIOE->CRH = 0xBBBBBBBBU;
|
||||
|
||||
GPIOF->CRL = 0x44BBBBBBU;
|
||||
GPIOF->CRH = 0xBBBB4444U;
|
||||
|
||||
GPIOG->CRL = 0x44BBBBBBU;
|
||||
GPIOG->CRH = 0x444B4B44U;
|
||||
|
||||
/*---------------- FSMC Configuration ---------------------------------------*/
|
||||
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
|
||||
|
||||
FSMC_Bank1->BTCR[4U] = 0x00001091U;
|
||||
FSMC_Bank1->BTCR[5U] = 0x00110212U;
|
||||
}
|
||||
#endif /* DATA_IN_ExtSRAM */
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
124
Core/Src/usart.c
Normal file
124
Core/Src/usart.c
Normal file
@@ -0,0 +1,124 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usart.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the USART instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 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 "usart.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
UART_HandleTypeDef huart2;
|
||||
|
||||
/* USART2 init function */
|
||||
|
||||
void MX_USART2_UART_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN USART2_Init 0 */
|
||||
|
||||
/* USER CODE END USART2_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN USART2_Init 1 */
|
||||
|
||||
/* USER CODE END USART2_Init 1 */
|
||||
huart2.Instance = USART2;
|
||||
huart2.Init.BaudRate = 115200;
|
||||
huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
huart2.Init.StopBits = UART_STOPBITS_1;
|
||||
huart2.Init.Parity = UART_PARITY_NONE;
|
||||
huart2.Init.Mode = UART_MODE_TX_RX;
|
||||
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||
if (HAL_UART_Init(&huart2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USART2_Init 2 */
|
||||
|
||||
/* USER CODE END USART2_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(uartHandle->Instance==USART2)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_MspInit 0 */
|
||||
|
||||
/* USER CODE END USART2_MspInit 0 */
|
||||
/* USART2 clock enable */
|
||||
__HAL_RCC_USART2_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
/**USART2 GPIO Configuration
|
||||
PD5 ------> USART2_TX
|
||||
PD6 ------> USART2_RX
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
__HAL_AFIO_REMAP_USART2_ENABLE();
|
||||
|
||||
/* USART2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(USART2_IRQn);
|
||||
/* USER CODE BEGIN USART2_MspInit 1 */
|
||||
|
||||
/* USER CODE END USART2_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
|
||||
{
|
||||
|
||||
if(uartHandle->Instance==USART2)
|
||||
{
|
||||
/* USER CODE BEGIN USART2_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END USART2_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_USART2_CLK_DISABLE();
|
||||
|
||||
/**USART2 GPIO Configuration
|
||||
PD5 ------> USART2_TX
|
||||
PD6 ------> USART2_RX
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_5|GPIO_PIN_6);
|
||||
|
||||
/* USART2 interrupt Deinit */
|
||||
HAL_NVIC_DisableIRQ(USART2_IRQn);
|
||||
/* USER CODE BEGIN USART2_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END USART2_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
472
Core/Startup/startup_stm32f107vctx.s
Normal file
472
Core/Startup/startup_stm32f107vctx.s
Normal file
@@ -0,0 +1,472 @@
|
||||
/**
|
||||
*************** (C) COPYRIGHT 2017 STMicroelectronics ************************
|
||||
* @file startup_stm32f107xc.s
|
||||
* @author MCD Application Team
|
||||
* @brief STM32F107xC Devices vector table for Atollic toolchain.
|
||||
* This module performs:
|
||||
* - Set the initial SP
|
||||
* - Set the initial PC == Reset_Handler,
|
||||
* - Set the vector table entries with the exceptions ISR address
|
||||
* - Configure the clock system
|
||||
* - Branches to main in the C library (which eventually
|
||||
* calls main()).
|
||||
* After Reset the Cortex-M3 processor is in Thread mode,
|
||||
* priority is Privileged, and the Stack is set to Main.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017-2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
.syntax unified
|
||||
.cpu cortex-m3
|
||||
.fpu softvfp
|
||||
.thumb
|
||||
|
||||
.global g_pfnVectors
|
||||
.global Default_Handler
|
||||
|
||||
/* start address for the initialization values of the .data section.
|
||||
defined in linker script */
|
||||
.word _sidata
|
||||
/* start address for the .data section. defined in linker script */
|
||||
.word _sdata
|
||||
/* end address for the .data section. defined in linker script */
|
||||
.word _edata
|
||||
/* start address for the .bss section. defined in linker script */
|
||||
.word _sbss
|
||||
/* end address for the .bss section. defined in linker script */
|
||||
.word _ebss
|
||||
|
||||
.equ BootRAM, 0xF1E0F85F
|
||||
/**
|
||||
* @brief This is the code that gets called when the processor first
|
||||
* starts execution following a reset event. Only the absolutely
|
||||
* necessary set is performed, after which the application
|
||||
* supplied main() routine is called.
|
||||
* @param None
|
||||
* @retval : None
|
||||
*/
|
||||
|
||||
.section .text.Reset_Handler
|
||||
.weak Reset_Handler
|
||||
.type Reset_Handler, %function
|
||||
Reset_Handler:
|
||||
|
||||
/* Call the clock system initialization function.*/
|
||||
bl SystemInit
|
||||
|
||||
/* Copy the data segment initializers from flash to SRAM */
|
||||
ldr r0, =_sdata
|
||||
ldr r1, =_edata
|
||||
ldr r2, =_sidata
|
||||
movs r3, #0
|
||||
b LoopCopyDataInit
|
||||
|
||||
CopyDataInit:
|
||||
ldr r4, [r2, r3]
|
||||
str r4, [r0, r3]
|
||||
adds r3, r3, #4
|
||||
|
||||
LoopCopyDataInit:
|
||||
adds r4, r0, r3
|
||||
cmp r4, r1
|
||||
bcc CopyDataInit
|
||||
|
||||
/* Zero fill the bss segment. */
|
||||
ldr r2, =_sbss
|
||||
ldr r4, =_ebss
|
||||
movs r3, #0
|
||||
b LoopFillZerobss
|
||||
|
||||
FillZerobss:
|
||||
str r3, [r2]
|
||||
adds r2, r2, #4
|
||||
|
||||
LoopFillZerobss:
|
||||
cmp r2, r4
|
||||
bcc FillZerobss
|
||||
|
||||
|
||||
/* Call static constructors */
|
||||
bl __libc_init_array
|
||||
/* Call the application's entry point.*/
|
||||
bl main
|
||||
bx lr
|
||||
.size Reset_Handler, .-Reset_Handler
|
||||
|
||||
/**
|
||||
* @brief This is the code that gets called when the processor receives an
|
||||
* unexpected interrupt. This simply enters an infinite loop, preserving
|
||||
* the system state for examination by a debugger.
|
||||
*
|
||||
* @param None
|
||||
* @retval : None
|
||||
*/
|
||||
.section .text.Default_Handler,"ax",%progbits
|
||||
Default_Handler:
|
||||
Infinite_Loop:
|
||||
b Infinite_Loop
|
||||
.size Default_Handler, .-Default_Handler
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* The minimal vector table for a Cortex M3. Note that the proper constructs
|
||||
* must be placed on this to ensure that it ends up at physical address
|
||||
* 0x0000.0000.
|
||||
*
|
||||
******************************************************************************/
|
||||
.section .isr_vector,"a",%progbits
|
||||
.type g_pfnVectors, %object
|
||||
.size g_pfnVectors, .-g_pfnVectors
|
||||
|
||||
|
||||
g_pfnVectors:
|
||||
|
||||
.word _estack
|
||||
.word Reset_Handler
|
||||
.word NMI_Handler
|
||||
.word HardFault_Handler
|
||||
.word MemManage_Handler
|
||||
.word BusFault_Handler
|
||||
.word UsageFault_Handler
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word SVC_Handler
|
||||
.word DebugMon_Handler
|
||||
.word 0
|
||||
.word PendSV_Handler
|
||||
.word SysTick_Handler
|
||||
.word WWDG_IRQHandler
|
||||
.word PVD_IRQHandler
|
||||
.word TAMPER_IRQHandler
|
||||
.word RTC_IRQHandler
|
||||
.word FLASH_IRQHandler
|
||||
.word RCC_IRQHandler
|
||||
.word EXTI0_IRQHandler
|
||||
.word EXTI1_IRQHandler
|
||||
.word EXTI2_IRQHandler
|
||||
.word EXTI3_IRQHandler
|
||||
.word EXTI4_IRQHandler
|
||||
.word DMA1_Channel1_IRQHandler
|
||||
.word DMA1_Channel2_IRQHandler
|
||||
.word DMA1_Channel3_IRQHandler
|
||||
.word DMA1_Channel4_IRQHandler
|
||||
.word DMA1_Channel5_IRQHandler
|
||||
.word DMA1_Channel6_IRQHandler
|
||||
.word DMA1_Channel7_IRQHandler
|
||||
.word ADC1_2_IRQHandler
|
||||
.word CAN1_TX_IRQHandler
|
||||
.word CAN1_RX0_IRQHandler
|
||||
.word CAN1_RX1_IRQHandler
|
||||
.word CAN1_SCE_IRQHandler
|
||||
.word EXTI9_5_IRQHandler
|
||||
.word TIM1_BRK_IRQHandler
|
||||
.word TIM1_UP_IRQHandler
|
||||
.word TIM1_TRG_COM_IRQHandler
|
||||
.word TIM1_CC_IRQHandler
|
||||
.word TIM2_IRQHandler
|
||||
.word TIM3_IRQHandler
|
||||
.word TIM4_IRQHandler
|
||||
.word I2C1_EV_IRQHandler
|
||||
.word I2C1_ER_IRQHandler
|
||||
.word I2C2_EV_IRQHandler
|
||||
.word I2C2_ER_IRQHandler
|
||||
.word SPI1_IRQHandler
|
||||
.word SPI2_IRQHandler
|
||||
.word USART1_IRQHandler
|
||||
.word USART2_IRQHandler
|
||||
.word USART3_IRQHandler
|
||||
.word EXTI15_10_IRQHandler
|
||||
.word RTC_Alarm_IRQHandler
|
||||
.word OTG_FS_WKUP_IRQHandler
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word TIM5_IRQHandler
|
||||
.word SPI3_IRQHandler
|
||||
.word UART4_IRQHandler
|
||||
.word UART5_IRQHandler
|
||||
.word TIM6_IRQHandler
|
||||
.word TIM7_IRQHandler
|
||||
.word DMA2_Channel1_IRQHandler
|
||||
.word DMA2_Channel2_IRQHandler
|
||||
.word DMA2_Channel3_IRQHandler
|
||||
.word DMA2_Channel4_IRQHandler
|
||||
.word DMA2_Channel5_IRQHandler
|
||||
.word ETH_IRQHandler
|
||||
.word ETH_WKUP_IRQHandler
|
||||
.word CAN2_TX_IRQHandler
|
||||
.word CAN2_RX0_IRQHandler
|
||||
.word CAN2_RX1_IRQHandler
|
||||
.word CAN2_SCE_IRQHandler
|
||||
.word OTG_FS_IRQHandler
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word 0
|
||||
.word BootRAM /* @0x1E0. This is for boot in RAM mode for
|
||||
STM32F10x Connectivity line Devices. */
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Provide weak aliases for each Exception handler to the Default_Handler.
|
||||
* As they are weak aliases, any function with the same name will override
|
||||
* this definition.
|
||||
*
|
||||
*******************************************************************************/
|
||||
.weak NMI_Handler
|
||||
.thumb_set NMI_Handler,Default_Handler
|
||||
|
||||
.weak HardFault_Handler
|
||||
.thumb_set HardFault_Handler,Default_Handler
|
||||
|
||||
.weak MemManage_Handler
|
||||
.thumb_set MemManage_Handler,Default_Handler
|
||||
|
||||
.weak BusFault_Handler
|
||||
.thumb_set BusFault_Handler,Default_Handler
|
||||
|
||||
.weak UsageFault_Handler
|
||||
.thumb_set UsageFault_Handler,Default_Handler
|
||||
|
||||
.weak SVC_Handler
|
||||
.thumb_set SVC_Handler,Default_Handler
|
||||
|
||||
.weak DebugMon_Handler
|
||||
.thumb_set DebugMon_Handler,Default_Handler
|
||||
|
||||
.weak PendSV_Handler
|
||||
.thumb_set PendSV_Handler,Default_Handler
|
||||
|
||||
.weak SysTick_Handler
|
||||
.thumb_set SysTick_Handler,Default_Handler
|
||||
|
||||
.weak WWDG_IRQHandler
|
||||
.thumb_set WWDG_IRQHandler,Default_Handler
|
||||
|
||||
.weak PVD_IRQHandler
|
||||
.thumb_set PVD_IRQHandler,Default_Handler
|
||||
|
||||
.weak TAMPER_IRQHandler
|
||||
.thumb_set TAMPER_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_IRQHandler
|
||||
.thumb_set RTC_IRQHandler,Default_Handler
|
||||
|
||||
.weak FLASH_IRQHandler
|
||||
.thumb_set FLASH_IRQHandler,Default_Handler
|
||||
|
||||
.weak RCC_IRQHandler
|
||||
.thumb_set RCC_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI0_IRQHandler
|
||||
.thumb_set EXTI0_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI1_IRQHandler
|
||||
.thumb_set EXTI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI2_IRQHandler
|
||||
.thumb_set EXTI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI3_IRQHandler
|
||||
.thumb_set EXTI3_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI4_IRQHandler
|
||||
.thumb_set EXTI4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel1_IRQHandler
|
||||
.thumb_set DMA1_Channel1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel2_IRQHandler
|
||||
.thumb_set DMA1_Channel2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel3_IRQHandler
|
||||
.thumb_set DMA1_Channel3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel4_IRQHandler
|
||||
.thumb_set DMA1_Channel4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel5_IRQHandler
|
||||
.thumb_set DMA1_Channel5_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel6_IRQHandler
|
||||
.thumb_set DMA1_Channel6_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA1_Channel7_IRQHandler
|
||||
.thumb_set DMA1_Channel7_IRQHandler,Default_Handler
|
||||
|
||||
.weak ADC1_2_IRQHandler
|
||||
.thumb_set ADC1_2_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_TX_IRQHandler
|
||||
.thumb_set CAN1_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_RX0_IRQHandler
|
||||
.thumb_set CAN1_RX0_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_RX1_IRQHandler
|
||||
.thumb_set CAN1_RX1_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN1_SCE_IRQHandler
|
||||
.thumb_set CAN1_SCE_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI9_5_IRQHandler
|
||||
.thumb_set EXTI9_5_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_BRK_IRQHandler
|
||||
.thumb_set TIM1_BRK_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_UP_IRQHandler
|
||||
.thumb_set TIM1_UP_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_TRG_COM_IRQHandler
|
||||
.thumb_set TIM1_TRG_COM_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM1_CC_IRQHandler
|
||||
.thumb_set TIM1_CC_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM2_IRQHandler
|
||||
.thumb_set TIM2_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM3_IRQHandler
|
||||
.thumb_set TIM3_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM4_IRQHandler
|
||||
.thumb_set TIM4_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_EV_IRQHandler
|
||||
.thumb_set I2C1_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C1_ER_IRQHandler
|
||||
.thumb_set I2C1_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C2_EV_IRQHandler
|
||||
.thumb_set I2C2_EV_IRQHandler,Default_Handler
|
||||
|
||||
.weak I2C2_ER_IRQHandler
|
||||
.thumb_set I2C2_ER_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI1_IRQHandler
|
||||
.thumb_set SPI1_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI2_IRQHandler
|
||||
.thumb_set SPI2_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART1_IRQHandler
|
||||
.thumb_set USART1_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART2_IRQHandler
|
||||
.thumb_set USART2_IRQHandler,Default_Handler
|
||||
|
||||
.weak USART3_IRQHandler
|
||||
.thumb_set USART3_IRQHandler,Default_Handler
|
||||
|
||||
.weak EXTI15_10_IRQHandler
|
||||
.thumb_set EXTI15_10_IRQHandler,Default_Handler
|
||||
|
||||
.weak RTC_Alarm_IRQHandler
|
||||
.thumb_set RTC_Alarm_IRQHandler,Default_Handler
|
||||
|
||||
.weak OTG_FS_WKUP_IRQHandler
|
||||
.thumb_set OTG_FS_WKUP_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM5_IRQHandler
|
||||
.thumb_set TIM5_IRQHandler,Default_Handler
|
||||
|
||||
.weak SPI3_IRQHandler
|
||||
.thumb_set SPI3_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART4_IRQHandler
|
||||
.thumb_set UART4_IRQHandler,Default_Handler
|
||||
|
||||
.weak UART5_IRQHandler
|
||||
.thumb_set UART5_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM6_IRQHandler
|
||||
.thumb_set TIM6_IRQHandler,Default_Handler
|
||||
|
||||
.weak TIM7_IRQHandler
|
||||
.thumb_set TIM7_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel1_IRQHandler
|
||||
.thumb_set DMA2_Channel1_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel2_IRQHandler
|
||||
.thumb_set DMA2_Channel2_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel3_IRQHandler
|
||||
.thumb_set DMA2_Channel3_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel4_IRQHandler
|
||||
.thumb_set DMA2_Channel4_IRQHandler,Default_Handler
|
||||
|
||||
.weak DMA2_Channel5_IRQHandler
|
||||
.thumb_set DMA2_Channel5_IRQHandler,Default_Handler
|
||||
|
||||
.weak ETH_IRQHandler
|
||||
.thumb_set ETH_IRQHandler,Default_Handler
|
||||
|
||||
.weak ETH_WKUP_IRQHandler
|
||||
.thumb_set ETH_WKUP_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_TX_IRQHandler
|
||||
.thumb_set CAN2_TX_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_RX0_IRQHandler
|
||||
.thumb_set CAN2_RX0_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_RX1_IRQHandler
|
||||
.thumb_set CAN2_RX1_IRQHandler,Default_Handler
|
||||
|
||||
.weak CAN2_SCE_IRQHandler
|
||||
.thumb_set CAN2_SCE_IRQHandler,Default_Handler
|
||||
|
||||
.weak OTG_FS_IRQHandler
|
||||
.thumb_set OTG_FS_IRQHandler ,Default_Handler
|
||||
|
||||
Reference in New Issue
Block a user