add proj
This commit is contained in:
92
B-G474E-DPOW1_Keil/Core/Inc/app_config.h
Normal file
92
B-G474E-DPOW1_Keil/Core/Inc/app_config.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef APP_CONFIG_H
|
||||
#define APP_CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* B-G474E-DPOW1 quick configuration.
|
||||
*
|
||||
* SAFETY:
|
||||
* - The project configures the buck half-bridge on PB12/PB13.
|
||||
* - Keep DCDC_POWER_STAGE_ENABLE at 0 until VIN, load and oscilloscope
|
||||
* probes are ready. With 0 the firmware prints ADC values and prepares
|
||||
* HRTIM, but does not enable HRTIM outputs.
|
||||
* - If VIN comes from USB-C/USB-PD through JP1, set
|
||||
* DCDC_CONNECT_USBPD_INPUT to 1 only after checking the board jumpers.
|
||||
*/
|
||||
#define DCDC_POWER_STAGE_ENABLE 0U
|
||||
#define DCDC_CONNECT_USBPD_INPUT 0U
|
||||
|
||||
/*
|
||||
* Clock startup.
|
||||
* 0 = safest rescue mode: run directly from HSI16, no PLL switch.
|
||||
* 1 = normal performance mode: HSI16 -> PLL -> 170 MHz.
|
||||
*
|
||||
* If the debugger hangs inside SystemClock_Config(), keep this at 0 until
|
||||
* the board is recovered and ST-LINK connects reliably.
|
||||
*/
|
||||
#define CLOCK_USE_PLL_170MHZ 1U
|
||||
|
||||
#define SYSCLK_HZ 170000000UL
|
||||
#define HSI16_HZ 16000000UL
|
||||
#define USART3_BAUDRATE 115200UL
|
||||
#define DEBUG_ATTACH_DELAY_LOOPS 8000000UL
|
||||
|
||||
/*
|
||||
* HRTIM Timer C drives the onboard buck leg:
|
||||
* PB12 = BUCKBOOST_P1_DRIVE = HRTIM1_CHC1, high-side buck MOSFET
|
||||
* PB13 = BUCKBOOST_N1_DRIVE = HRTIM1_CHC2, low-side buck MOSFET
|
||||
*
|
||||
* fHRCK = fHRTIM * 32. The firmware calculates the actual period from
|
||||
* SystemCoreClock, so rescue HSI16 mode still works.
|
||||
*/
|
||||
#define DCDC_HRTIM_PERIOD_TICKS 27200U
|
||||
#define DCDC_PWM_FREQUENCY_HZ 200000UL
|
||||
#define DCDC_MIN_DUTY_TICKS 0U
|
||||
#define DCDC_MAX_DUTY_TICKS 24000U
|
||||
#define DCDC_START_DUTY_TICKS 400U
|
||||
|
||||
/*
|
||||
* Dead-time values are expressed in HRTIM dead-time ticks.
|
||||
* They are intentionally conservative starter values; verify PB12/PB13
|
||||
* with an oscilloscope before enabling the power stage.
|
||||
*/
|
||||
#define DCDC_DEADTIME_RISING_TICKS 110U
|
||||
#define DCDC_DEADTIME_FALLING_TICKS 350U
|
||||
|
||||
/*
|
||||
* ADC measurement pins on B-G474E-DPOW1:
|
||||
* PA1 = BUCKBOOST_VIN (ADC1_IN2)
|
||||
* PA2 = BUCKBOOST_I_IN_AVG (ADC1_IN3)
|
||||
* PA3 = BUCKBOOST_VOUT (ADC1_IN4)
|
||||
*
|
||||
* ST X-CUBE-DPower reference values for this board use:
|
||||
* Vout_Scaling = 0.198795180 -> ADC pin voltage = VOUT * 0.198795180
|
||||
* Iin_Scaling = 0.721543408 -> ADC pin voltage = IIN * 0.721543408 V/A
|
||||
*
|
||||
* VIN uses the same divider value by default here. If your hardware revision
|
||||
* or solder bridge setup differs, adjust DCDC_VIN_SCALE_PPM after measuring.
|
||||
*/
|
||||
#define ADC_REFERENCE_MV 3300U
|
||||
#define ADC_FULL_SCALE_COUNTS 4095U
|
||||
#define DCDC_VOUT_SCALE_PPM 198795UL
|
||||
#define DCDC_VIN_SCALE_PPM 198795UL
|
||||
#define DCDC_IIN_UV_PER_MA 721UL
|
||||
|
||||
/* Starter setpoints and protection thresholds. */
|
||||
#define DCDC_TARGET_VOUT_MV 3300U
|
||||
#define DCDC_MIN_VIN_MV 4500U
|
||||
#define DCDC_MAX_VOUT_MV 3800U
|
||||
#define DCDC_MAX_INPUT_CURRENT_MA 300U
|
||||
#define DCDC_HARD_INPUT_CURRENT_MA 450U
|
||||
|
||||
/*
|
||||
* Simple voltage loop gains for the starter firmware.
|
||||
* Duty command = feed-forward + proportional + integral - current limiting.
|
||||
* Tune these gently with a current-limited supply and a scope.
|
||||
*/
|
||||
#define DCDC_KP_TICKS_PER_100MV 90
|
||||
#define DCDC_KI_TICKS_PER_100MV 3
|
||||
#define DCDC_CURRENT_LIMIT_KP 60
|
||||
|
||||
#endif
|
||||
11
B-G474E-DPOW1_Keil/Core/Inc/board.h
Normal file
11
B-G474E-DPOW1_Keil/Core/Inc/board.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef BOARD_H
|
||||
#define BOARD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void Board_Init(void);
|
||||
uint32_t Board_Millis(void);
|
||||
void Board_DelayMs(uint32_t delay_ms);
|
||||
void Board_FatalError(void);
|
||||
|
||||
#endif
|
||||
48
B-G474E-DPOW1_Keil/Core/Inc/dcdc.h
Normal file
48
B-G474E-DPOW1_Keil/Core/Inc/dcdc.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef DCDC_H
|
||||
#define DCDC_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t vin_raw;
|
||||
uint16_t iin_raw;
|
||||
uint16_t vout_raw;
|
||||
uint32_t vin_mv;
|
||||
uint32_t iin_ma;
|
||||
uint32_t vout_mv;
|
||||
} DCDC_Measurements;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DCDC_STATE_STOPPED = 0,
|
||||
DCDC_STATE_READY,
|
||||
DCDC_STATE_RUNNING,
|
||||
DCDC_STATE_FAULT
|
||||
} DCDC_State;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DCDC_FAULT_NONE = 0,
|
||||
DCDC_FAULT_UNDERVOLTAGE,
|
||||
DCDC_FAULT_OVERVOLTAGE,
|
||||
DCDC_FAULT_OVERCURRENT,
|
||||
DCDC_FAULT_HRTIM
|
||||
} DCDC_Fault;
|
||||
|
||||
void DCDC_Init(void);
|
||||
void DCDC_Start(void);
|
||||
void DCDC_Stop(void);
|
||||
void DCDC_ControlStep(void);
|
||||
void DCDC_ReadMeasurements(DCDC_Measurements *out);
|
||||
|
||||
DCDC_State DCDC_GetState(void);
|
||||
DCDC_Fault DCDC_GetFault(void);
|
||||
bool DCDC_IsHrtimReady(void);
|
||||
uint32_t DCDC_GetDutyTicks(void);
|
||||
uint32_t DCDC_GetPeriodTicks(void);
|
||||
const char *DCDC_StateText(DCDC_State state);
|
||||
const char *DCDC_FaultText(DCDC_Fault fault);
|
||||
|
||||
#endif
|
||||
9
B-G474E-DPOW1_Keil/Core/Inc/retarget.h
Normal file
9
B-G474E-DPOW1_Keil/Core/Inc/retarget.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef RETARGET_H
|
||||
#define RETARGET_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void Retarget_Init(uint32_t baudrate);
|
||||
void Retarget_PutChar(char ch);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user