diff --git a/application.c b/application.c index f9dfa52..3087694 100644 --- a/application.c +++ b/application.c @@ -89,6 +89,13 @@ size_t putc(char c) return length; // return number of characters printed } +// only print when debug is enabled +#if DEBUG +#define puts_debug(x) puts(x) +#else +#define puts_debug(x) {} +#endif + /** print float with fixed precision * @param[in] fpu float to print * @param[in] precision number of digits after comma to print @@ -663,7 +670,7 @@ void main(void) #endif // setup RTC - puts("setup RTC: "); + puts_debug("setup RTC: "); rcc_periph_clock_enable(RCC_RTC); // enable clock for RTC peripheral rcc_osc_on(RCC_LSI); // enable LSI clock while (!rcc_is_osc_ready(RCC_LSI)); // wait until clock is ready @@ -677,10 +684,10 @@ void main(void) pwr_enable_backup_domain_write_protect(); // re-enable protection now that we configured the RTC clock } boot_time = rtc_to_seconds(); // remember the start time - puts("OK\n"); + puts_debug("OK\n"); // setup wakeup timer for periodic checks - puts("setup wakeup: "); + puts_debug("setup wakeup: "); // RTC needs to be configured beforehand pwr_disable_backup_domain_write_protect(); // disable backup protection so we can write to the RTC registers rtc_unlock(); // enable writing RTC registers @@ -689,9 +696,9 @@ void main(void) rtc_enable_wakeup_timer_interrupt(); // enable interrupt rtc_lock(); // disable writing RTC registers // important: do not re-enable backup_domain_write_protect, since this will prevent clearing flags (but RTC registers do not need to be unlocked) - puts("OK\n"); + puts_debug("OK\n"); - puts("setup voltage control: "); + puts_debug("setup voltage control: "); rcc_periph_clock_enable(GPIO_RCC(SIGNAL_PD_PIN)); // enable clock for port domain gpio_set(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // ensure we are not draining it gpio_set_output_options(GPIO_PORT(SIGNAL_PD_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_2MHZ, GPIO_PIN(SIGNAL_PD_PIN)); // set output as open-drain @@ -712,9 +719,9 @@ void main(void) gpio_set(GPIO_PORT(TARGET_RST_PIN), GPIO_PIN(TARGET_RST_PIN)); // to not pull down (asserting reset) gpio_set_output_options(GPIO_PORT(TARGET_RST_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_2MHZ, GPIO_PIN(TARGET_RST_PIN)); // set output as open-drain gpio_mode_setup(GPIO_PORT(TARGET_RST_PIN), GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN(TARGET_RST_PIN)); // configure pin as output - puts("OK\n"); + puts_debug("OK\n"); - puts("setup analog multiplexer: "); + puts_debug("setup analog multiplexer: "); rcc_periph_clock_enable(GPIO_RCC(MUX_EN_PIN)); // enable clock for port domain gpio_set(GPIO_PORT(MUX_EN_PIN), GPIO_PIN(MUX_EN_PIN)); // ensure multiplexer is disabled gpio_set_output_options(GPIO_PORT(MUX_EN_PIN), GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO_PIN(MUX_EN_PIN)); // set output as push-pull to drive correctly @@ -736,16 +743,16 @@ void main(void) gpio_set_output_options(GPIO_PORT(MUX_S3_PIN), GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO_PIN(MUX_S3_PIN)); // set output as push-pull to drive correctly gpio_mode_setup(GPIO_PORT(MUX_S3_PIN), GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN(MUX_S3_PIN)); // configure pin as output mux_select(-1); // ensure it is disabled - puts("OK\n"); + puts_debug("OK\n"); - puts("setup signal pins: "); + puts_debug("setup signal pins: "); for (uint8_t i = 0; i < CHANNEL_NUMBERS; i++) { rcc_periph_clock_enable(port2rcc(channel_ports[i])); // enable clock for port domain gpio_mode_setup(channel_ports[i], GPIO_MODE_INPUT, GPIO_PUPD_NONE, channel_pins[i]); // ensure pin is floating input } - puts("OK\n"); + puts_debug("OK\n"); - puts("setup ADC to measure voltages: "); + puts_debug("setup ADC to measure voltages: "); rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC domain adc_power_off(ADC1); // switch off ADC while configuring it adc_set_right_aligned(ADC1); // ensure it is right aligned to get the actual value in the 16-bit register @@ -763,7 +770,7 @@ void main(void) rcc_periph_clock_enable(RCC_ADC1_IN(SIGNAL_CHANNEL)); // enable clock for GPIO domain for signal channel gpio_mode_setup(ADC1_IN_PORT(SIGNAL_CHANNEL), GPIO_MODE_ANALOG, GPIO_PUPD_NONE, ADC1_IN_PIN(SIGNAL_CHANNEL)); // set signal channel as analog input for the ADC measure_voltages(); // try to measure voltages - puts("OK\n"); + puts_debug("OK\n"); // setup terminal terminal_prefix = ""; // set default prefix