From 60e990632b73795d88620c49c0119b708757f7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 18 Aug 2020 19:57:13 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#10:=20Moved=20static=20and=20global=20va?= =?UTF-8?q?riabl=C3=B6es=20that=20are=200=20initialized=20to=20CCMRAM=20in?= =?UTF-8?q?=20order=20to=20make=20room=20and=20increase=20performance.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stm-firmware/adc-meas.c | 17 +++++++++-------- stm-firmware/button.c | 5 +++-- .../include/helper-macros/helper-macros.h | 2 ++ stm-firmware/main.c | 2 +- stm-firmware/oven-driver.c | 5 +++-- stm-firmware/reflow-menu.c | 4 ++-- stm-firmware/safety/safety-adc.c | 2 -- stm-firmware/shell.c | 2 +- stm-firmware/systick.c | 7 ++++--- 9 files changed, 25 insertions(+), 21 deletions(-) diff --git a/stm-firmware/adc-meas.c b/stm-firmware/adc-meas.c index 40ae789..d96ed9e 100644 --- a/stm-firmware/adc-meas.c +++ b/stm-firmware/adc-meas.c @@ -28,25 +28,26 @@ #include #include #include +#include #include #include -static float pt1000_offset; -static float pt1000_sens_dev; -static bool calibration_active; -static float filter_alpha; +static float IN_SECTION(.ccmram) pt1000_offset; +static float IN_SECTION(.ccmram) pt1000_sens_dev; +static bool IN_SECTION(.ccmram) calibration_active; +static float IN_SECTION(.ccmram) filter_alpha; /** * @brief Filtered PT1000 resistance value. * @note This value is not yet calibrated. Use @ref adc_pt1000_get_current_resistance to get this value with calibration. */ -static volatile float pt1000_res_raw_lf; +static volatile float IN_SECTION(.ccmram) pt1000_res_raw_lf; static volatile int * volatile streaming_flag_ptr = NULL; -static uint32_t filter_startup_cnt; -static volatile float adc_pt1000_raw_reading_hf; +static uint32_t IN_SECTION(.ccmram) filter_startup_cnt; +static volatile float IN_SECTION(.ccmram) adc_pt1000_raw_reading_hf; static volatile uint16_t dma_sample_buffer[ADC_PT1000_DMA_AVG_SAMPLES]; -static volatile uint32_t adc_watchdog_counter = 0UL; +static volatile uint32_t IN_SECTION(.ccmram) adc_watchdog_counter = 0UL; volatile float * volatile stream_buffer = NULL; volatile uint32_t stream_count; diff --git a/stm-firmware/button.c b/stm-firmware/button.c index 76dc782..4d30ab1 100644 --- a/stm-firmware/button.c +++ b/stm-firmware/button.c @@ -23,11 +23,12 @@ #include #include #include +#include #include #include -static volatile uint64_t to_active_timestamp; -static volatile enum button_state int_state; +static volatile uint64_t IN_SECTION(.ccmram) to_active_timestamp; +static volatile enum button_state IN_SECTION(.ccmram) int_state; void button_init() { diff --git a/stm-firmware/include/helper-macros/helper-macros.h b/stm-firmware/include/helper-macros/helper-macros.h index 8fb4fad..bafdc91 100644 --- a/stm-firmware/include/helper-macros/helper-macros.h +++ b/stm-firmware/include/helper-macros/helper-macros.h @@ -38,4 +38,6 @@ #define is_power_of_two(num) ((num) && !((num) & ((num) - 1))) +#define IN_SECTION(sec) __attribute__((section(#sec))) + #endif /* __HELPER_MACROS_H__ */ diff --git a/stm-firmware/main.c b/stm-firmware/main.c index a7702ac..c1dfe68 100644 --- a/stm-firmware/main.c +++ b/stm-firmware/main.c @@ -115,7 +115,7 @@ static inline void setup_shell_uart(struct stm_uart *uart) static bool mount_sd_card_if_avail(bool mounted) { FRESULT res; - static uint8_t inserted_counter = 0; + static uint8_t IN_SECTION(.ccmram) inserted_counter = 0; if (sdio_check_inserted() && mounted) { memset(fs_ptr, 0, sizeof(FATFS)); diff --git a/stm-firmware/oven-driver.c b/stm-firmware/oven-driver.c index 857e230..cda37a1 100644 --- a/stm-firmware/oven-driver.c +++ b/stm-firmware/oven-driver.c @@ -24,12 +24,13 @@ #include #include #include +#include #include -static struct pid_controller oven_pid; +static struct pid_controller IN_SECTION(.ccmram) oven_pid; static bool oven_pid_running = false; static bool oven_pid_aborted = false; -static uint8_t oven_driver_power_level = 0U; +static uint8_t IN_SECTION(.ccmram) oven_driver_power_level = 0U; void oven_driver_init() { diff --git a/stm-firmware/reflow-menu.c b/stm-firmware/reflow-menu.c index dec89b1..ca5e5d9 100644 --- a/stm-firmware/reflow-menu.c +++ b/stm-firmware/reflow-menu.c @@ -34,8 +34,8 @@ #include #include -static char __attribute__((section(".ccmram"))) display_buffer[4][21] = {0}; -static struct lcd_menu reflow_menu; +static char IN_SECTION(.ccmram) display_buffer[4][21] = {0}; +static struct lcd_menu IN_SECTION(.ccmram) reflow_menu; static struct lcd_menu * const reflow_menu_ptr = &reflow_menu; static void update_display_buffer(uint8_t row, const char *data) diff --git a/stm-firmware/safety/safety-adc.c b/stm-firmware/safety/safety-adc.c index 53e2bff..5f83888 100644 --- a/stm-firmware/safety/safety-adc.c +++ b/stm-firmware/safety/safety-adc.c @@ -55,8 +55,6 @@ float safety_adc_convert_channel(enum safety_adc_meas_channel channel, uint16_t { float converted_val; - - switch (channel) { case SAFETY_ADC_MEAS_TEMP: converted_val = (((float)analog_value / 4095.0f * 2500.0f - SAFETY_ADC_TEMP_NOM_MV) / diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index f0f815d..c342b0b 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -45,7 +45,7 @@ extern struct stm_uart shell_uart; static shellmatta_instance_t shell; static char shell_buffer[512]; -static char history_buffer[600]; +static char IN_SECTION(.ccmram) history_buffer[600]; static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle, const char *arguments, diff --git a/stm-firmware/systick.c b/stm-firmware/systick.c index 6b5047c..ad801bc 100644 --- a/stm-firmware/systick.c +++ b/stm-firmware/systick.c @@ -23,12 +23,13 @@ */ #include +#include #include #include -volatile uint32_t wait_tick_ms = 0UL; -volatile uint64_t global_tick_ms = 0ULL; -volatile uint32_t lcd_tick_100us = 0UL; +volatile uint32_t IN_SECTION(.ccmram) wait_tick_ms = 0UL; +volatile uint64_t IN_SECTION(.ccmram) global_tick_ms = 0ULL; +volatile uint32_t IN_SECTION(.ccmram) lcd_tick_100us = 0UL; void systick_setup(void) {