Improvements to main loop + build fixes
- add -lm linker flag - add fan power management
This commit is contained in:
parent
d526341b75
commit
2819ee99d6
2
Makefile
2
Makefile
|
@ -45,7 +45,7 @@ CFLAGS+=-Ifxplib/include -DPOINTPOS=16
|
||||||
LDFLAGS+=-Lfxplib/lib/$(BUILD) -lfxp_stm32l0
|
LDFLAGS+=-Lfxplib/lib/$(BUILD) -lfxp_stm32l0
|
||||||
|
|
||||||
# generic linking
|
# 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
|
# build type specific flags
|
||||||
CFLAGS_debug=-O0 -ggdb -DDEBUG
|
CFLAGS_debug=-O0 -ggdb -DDEBUG
|
||||||
|
|
18
src/main.c
18
src/main.c
|
@ -17,10 +17,11 @@ static void clock_setup(void)
|
||||||
{
|
{
|
||||||
/* We are running on MSI (2.1 MHz) after boot. */
|
/* We are running on MSI (2.1 MHz) after boot. */
|
||||||
rcc_periph_clock_enable(RCC_GPIOA); // for basically everything
|
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_USART2);
|
||||||
|
rcc_periph_clock_enable(RCC_ADC1);
|
||||||
|
rcc_periph_clock_enable(RCC_TIM21);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up systick to fire freq times per second */
|
/* 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
|
fan_ctrl_pwm_enable(); // TODO: make DC/PWM configurable
|
||||||
|
|
||||||
// triggered every 1 ms
|
uint8_t last_duty = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if(systick_triggered) {
|
if(systick_triggered) {
|
||||||
systick_triggered = false;
|
systick_triggered = false;
|
||||||
|
@ -77,7 +79,17 @@ int main(void)
|
||||||
|
|
||||||
uint8_t duty = fan_controller_update(temperature);
|
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);
|
fan_ctrl_pwm_set_duty(duty);
|
||||||
|
|
||||||
|
last_duty = duty;
|
||||||
}
|
}
|
||||||
|
|
||||||
__WFI();
|
__WFI();
|
||||||
|
|
Loading…
Reference in a new issue