Improvements to main loop + build fixes

- add -lm linker flag
- add fan power management
This commit is contained in:
Thomas Kolb 2023-09-29 22:09:12 +02:00
parent d526341b75
commit 2819ee99d6
2 changed files with 16 additions and 4 deletions

View file

@ -45,7 +45,7 @@ CFLAGS+=-Ifxplib/include -DPOINTPOS=16
LDFLAGS+=-Lfxplib/lib/$(BUILD) -lfxp_stm32l0
# generic linking
LDFLAGS+=-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
LDFLAGS+=-Wl,--start-group -lc -lm -lgcc -lnosys -Wl,--end-group
# build type specific flags
CFLAGS_debug=-O0 -ggdb -DDEBUG

View file

@ -17,10 +17,11 @@ static void clock_setup(void)
{
/* We are running on MSI (2.1 MHz) after boot. */
rcc_periph_clock_enable(RCC_GPIOA); // for basically everything
rcc_periph_clock_enable(RCC_GPIOC); // for UART only
/* Enable clocks for USART2. */
/* Enable clocks for peripherals. */
rcc_periph_clock_enable(RCC_USART2);
rcc_periph_clock_enable(RCC_ADC1);
rcc_periph_clock_enable(RCC_TIM21);
}
/* Set up systick to fire freq times per second */
@ -59,7 +60,8 @@ int main(void)
fan_ctrl_pwm_enable(); // TODO: make DC/PWM configurable
// triggered every 1 ms
uint8_t last_duty = 0;
while (1) {
if(systick_triggered) {
systick_triggered = false;
@ -77,7 +79,17 @@ int main(void)
uint8_t duty = fan_controller_update(temperature);
// handle fan power-on and power-off
if(last_duty == 0 && duty != 0) {
fan_ctrl_pwm_enable();
} else if(last_duty != 0 && duty == 0) {
fan_ctrl_pwm_disable();
}
// set the updated duty cycle
fan_ctrl_pwm_set_duty(duty);
last_duty = duty;
}
__WFI();