add proj
This commit is contained in:
70
B-G474E-DPOW1_Keil/Core/Src/main.c
Normal file
70
B-G474E-DPOW1_Keil/Core/Src/main.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "app_config.h"
|
||||
#include "board.h"
|
||||
#include "dcdc.h"
|
||||
#include "retarget.h"
|
||||
#include "stm32g474xx.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint32_t last_control_ms = 0U;
|
||||
uint32_t last_print_ms = 0U;
|
||||
volatile uint32_t debug_attach_delay;
|
||||
|
||||
/*
|
||||
* Short rescue window after reset. It lets ST-LINK attach before the
|
||||
* firmware reconfigures clocks and power peripherals.
|
||||
*/
|
||||
for (debug_attach_delay = 0U; debug_attach_delay < DEBUG_ATTACH_DELAY_LOOPS; debug_attach_delay++)
|
||||
{
|
||||
__NOP();
|
||||
}
|
||||
|
||||
Board_Init();
|
||||
Retarget_Init(USART3_BAUDRATE);
|
||||
DCDC_Init();
|
||||
|
||||
printf("\nB-G474E-DPOW1 DCDC starter project\n");
|
||||
printf("USART3 retarget printf: %lu baud\n", (unsigned long)USART3_BAUDRATE);
|
||||
printf("SystemCoreClock: %lu Hz\n", (unsigned long)SystemCoreClock);
|
||||
printf("PWM: %lu Hz, period=%lu HRTIM ticks\n",
|
||||
(unsigned long)DCDC_PWM_FREQUENCY_HZ,
|
||||
(unsigned long)DCDC_GetPeriodTicks());
|
||||
printf("HRTIM DLL: %s\n", DCDC_IsHrtimReady() ? "ready" : "not ready");
|
||||
|
||||
#if DCDC_POWER_STAGE_ENABLE
|
||||
printf("Power stage: ENABLED. Check VIN/current limit before flashing.\n");
|
||||
DCDC_Start();
|
||||
#else
|
||||
printf("Power stage: disabled in app_config.h; ADC monitor only.\n");
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
{
|
||||
uint32_t now = Board_Millis();
|
||||
|
||||
if ((now - last_control_ms) >= 1U)
|
||||
{
|
||||
last_control_ms = now;
|
||||
DCDC_ControlStep();
|
||||
}
|
||||
|
||||
if ((now - last_print_ms) >= 500U)
|
||||
{
|
||||
DCDC_Measurements m;
|
||||
last_print_ms = now;
|
||||
DCDC_ReadMeasurements(&m);
|
||||
|
||||
printf("state=%s fault=%s hrtim=%s vin=%lumV iin=%lumA vout=%lumV duty=%lu/%lu\n",
|
||||
DCDC_StateText(DCDC_GetState()),
|
||||
DCDC_FaultText(DCDC_GetFault()),
|
||||
DCDC_IsHrtimReady() ? "ready" : "not-ready",
|
||||
(unsigned long)m.vin_mv,
|
||||
(unsigned long)m.iin_ma,
|
||||
(unsigned long)m.vout_mv,
|
||||
(unsigned long)DCDC_GetDutyTicks(),
|
||||
(unsigned long)DCDC_GetPeriodTicks());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user