From 0b01be98407ce170e392e2afb078e66b059cb5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 2 Feb 2021 18:40:52 +0100 Subject: [PATCH 01/10] Issue #26: Add ERR_FLAG_OVERTEMP Error flag * Add error flag * Set default persistence to false * Set default flag weight to stop PID controller --- stm-firmware/include/reflow-controller/safety/safety-config.h | 3 +++ stm-firmware/safety/safety-controller.c | 1 + 2 files changed, 4 insertions(+) diff --git a/stm-firmware/include/reflow-controller/safety/safety-config.h b/stm-firmware/include/reflow-controller/safety/safety-config.h index f1e3d93..740365e 100644 --- a/stm-firmware/include/reflow-controller/safety/safety-config.h +++ b/stm-firmware/include/reflow-controller/safety/safety-config.h @@ -55,6 +55,7 @@ enum safety_flag { ERR_FLAG_SAFETY_MEM_CORRUPT = (1<<15), ERR_FLAG_SAFETY_TAB_CORRUPT = (1<<16), ERR_FLAG_AMON_SUPPLY_VOLT = (1<<17), + ERR_FLAG_OVERTEMP = (1<<18), }; /** @@ -156,6 +157,7 @@ enum analog_value_monitor { ERR_FLAG_PERSIST_ENTRY(ERR_FLAG_SAFETY_MEM_CORRUPT, true), \ ERR_FLAG_PERSIST_ENTRY(ERR_FLAG_SAFETY_TAB_CORRUPT, true), \ ERR_FLAG_PERSIST_ENTRY(ERR_FLAG_AMON_SUPPLY_VOLT, false), \ + ERR_FLAG_PERSIST_ENTRY(ERR_FLAG_OVERTEMP, false), \ #define SAFETY_CONFIG_DEFAULT_WEIGHTS ERR_FLAG_WEIGHT_ENTRY(ERR_FLAG_MEAS_ADC_OFF, SAFETY_FLAG_CONFIG_WEIGHT_PID), \ ERR_FLAG_WEIGHT_ENTRY(ERR_FLAG_MEAS_ADC_WATCHDOG, SAFETY_FLAG_CONFIG_WEIGHT_PID), \ @@ -177,5 +179,6 @@ enum analog_value_monitor { ERR_FLAG_WEIGHT_ENTRY(ERR_FLAG_SAFETY_MEM_CORRUPT, SAFETY_FLAG_CONFIG_WEIGHT_PID), \ ERR_FLAG_WEIGHT_ENTRY(ERR_FLAG_SAFETY_TAB_CORRUPT, SAFETY_FLAG_CONFIG_WEIGHT_PANIC), \ ERR_FLAG_WEIGHT_ENTRY(ERR_FLAG_AMON_SUPPLY_VOLT, SAFETY_FLAG_CONFIG_WEIGHT_PID), \ + ERR_FLAG_WEIGHT_ENTRY(ERR_FLAG_OVERTEMP, SAFETY_FLAG_CONFIG_WEIGHT_PID), \ #endif /* __SAFETY_CONFIG_H__ */ diff --git a/stm-firmware/safety/safety-controller.c b/stm-firmware/safety/safety-controller.c index 17affc0..06c85fc 100644 --- a/stm-firmware/safety/safety-controller.c +++ b/stm-firmware/safety/safety-controller.c @@ -166,6 +166,7 @@ static volatile struct error_flag IN_SECTION(.ccm.data) flags[] = { ERR_FLAG_ENTRY(ERR_FLAG_SAFETY_MEM_CORRUPT), ERR_FLAG_ENTRY(ERR_FLAG_SAFETY_TAB_CORRUPT), ERR_FLAG_ENTRY(ERR_FLAG_AMON_SUPPLY_VOLT), + ERR_FLAG_ENTRY(ERR_FLAG_OVERTEMP), }; /** From 64bb06882f96883ad60a26b2c14f86513e4b9500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 2 Feb 2021 19:32:12 +0100 Subject: [PATCH 02/10] Issue #26: Add reverse lookup function to temp converter that converts a temperature to a PT1000 resistance value --- .../reflow-controller/temp-converter.h | 9 ++++ stm-firmware/temp-converter.c | 47 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/stm-firmware/include/reflow-controller/temp-converter.h b/stm-firmware/include/reflow-controller/temp-converter.h index febd392..a126b13 100644 --- a/stm-firmware/include/reflow-controller/temp-converter.h +++ b/stm-firmware/include/reflow-controller/temp-converter.h @@ -29,4 +29,13 @@ */ int temp_converter_convert_resistance_to_temp(float resistance, float *temp_out); +/** + * @brief Convert temperature to PT1000 resistance + * @param temp Temperature in degrees celsius + * @param[out] resistance_out Resistance value + * @return 0 if ok, -1 if tmeperature is below the lookup table, 1 if value is above the lookup table, -1000 in case of a pointer error, + * -100 if an internal error occured. This should never happen, if the lookup table is correct + */ +int temp_convertet_convert_temp_to_resistance(float temp, float *resistance_out); + #endif /* __TEMP_CONVERTER_H__ */ diff --git a/stm-firmware/temp-converter.c b/stm-firmware/temp-converter.c index b0649ac..0c87c41 100644 --- a/stm-firmware/temp-converter.c +++ b/stm-firmware/temp-converter.c @@ -21,6 +21,7 @@ #include #include #include +#include static const float temp_lookup[(TEMP_CONVERSION_MAX_RES-TEMP_CONVERSION_MIN_RES) / TEMP_CONVERSION_RES_STEP+1] = {TEMP_CONVERSION_ARRAY_DATA}; @@ -73,3 +74,49 @@ int temp_converter_convert_resistance_to_temp(float resistance, float *temp_out) return_ret_val: return ret_val; } + +int temp_convertet_convert_temp_to_resistance(float temp, float *resistance_out) +{ + int retcode = 0; + unsigned int i; + float lower_temp; + float upper_temp; + float lower_resistance; + float upper_resistance; + float temp_ratio; + bool found = false; + + if (!resistance_out) + return -1000; + + if (temp < temp_lookup[0]) { + /* Requested temperature is smaller than minimum value in lookup table */ + *resistance_out = temp_lookup[0]; + retcode = -1; + goto exit; + } else if (temp > temp_lookup[COUNT_OF(temp_lookup) - 1]) { + /* Requested temperature is higher than maximum value in lookup table */ + *resistance_out = temp_lookup[COUNT_OF(temp_lookup) -1]; + retcode = 1; + goto exit; + } + + for (i = 0U; i < (COUNT_OF(temp_lookup) - 1); i++) { + if (temp >= temp_lookup[i] && temp <= temp_lookup[i+1]) { + upper_temp = temp_lookup[i+1]; + lower_temp = temp_lookup[i]; + lower_resistance = TEMP_CONVERSION_MIN_RES + TEMP_CONVERSION_RES_STEP * (i); + upper_resistance = lower_resistance + TEMP_CONVERSION_RES_STEP; + found = true; + } + } + + if (!found) + return -100; + + temp_ratio = (temp - lower_temp) / (upper_temp - lower_temp); + *resistance_out = lower_resistance + (upper_resistance - lower_resistance) * temp_ratio; + +exit: + return retcode; +} From 50ad31d58ad8e7d10fbfbdccf25bd3a6b2f616e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 2 Feb 2021 20:35:45 +0100 Subject: [PATCH 03/10] Issue #26: Add configuration for overtemperature flag to safety controller and include the config in the memory checking --- stm-firmware/calibration.c | 3 + .../reflow-controller/safety/safety-config.h | 5 ++ .../safety/safety-controller.h | 17 ++++- stm-firmware/safety/safety-controller.c | 68 +++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) diff --git a/stm-firmware/calibration.c b/stm-firmware/calibration.c index 432b580..3919a29 100644 --- a/stm-firmware/calibration.c +++ b/stm-firmware/calibration.c @@ -193,6 +193,7 @@ shellmatta_retCode_t calibration_sequence_shell_cmd(shellmatta_handle_t shell, c case CAL_START: /* Clear errors of PT1000 reading */ safety_controller_ack_flag(ERR_FLAG_MEAS_ADC_WATCHDOG); + safety_controller_ack_flag(ERR_FLAG_OVERTEMP); adc_pt1000_get_resistance_calibration(&offset, &sens_dev, &cal_active); if (cal_active) { shellmatta_printf(shell, "Already calibrated.\r\n\tOffset: %f\r\n\tSens: %f\r\n", offset, sens_dev); @@ -213,6 +214,7 @@ shellmatta_retCode_t calibration_sequence_shell_cmd(shellmatta_handle_t shell, c ret_val = SHELLMATTA_BUSY; shellmatta_printf(shell, "Measurement...\r\n"); safety_controller_ack_flag(ERR_FLAG_MEAS_ADC_WATCHDOG); + safety_controller_ack_flag(ERR_FLAG_OVERTEMP); data_buffer = calibration_acquire_data_start(512UL, &flag); break; } else if (stdin_data[i] == '\x03') { @@ -264,6 +266,7 @@ shellmatta_retCode_t calibration_sequence_shell_cmd(shellmatta_handle_t shell, c ret_val = SHELLMATTA_BUSY; shellmatta_printf(shell, "Measurement...\r\n"); safety_controller_ack_flag(ERR_FLAG_MEAS_ADC_WATCHDOG); + safety_controller_ack_flag(ERR_FLAG_OVERTEMP); data_buffer = calibration_acquire_data_start(512UL, &flag); break; } else if (stdin_data[i] == '\x03') { diff --git a/stm-firmware/include/reflow-controller/safety/safety-config.h b/stm-firmware/include/reflow-controller/safety/safety-config.h index 740365e..381723c 100644 --- a/stm-firmware/include/reflow-controller/safety/safety-config.h +++ b/stm-firmware/include/reflow-controller/safety/safety-config.h @@ -129,6 +129,11 @@ enum analog_value_monitor { #define SAFETY_EXT_WATCHDOG_RCC_MASK RCC_AHB1ENR_GPIODEN #define SAFETY_EXT_WATCHDOG_PIN (12) +/** + * @brief Default Limit of the overtemperature detection + */ +#define SAFETY_DEFAULT_OVERTEMP_LIMIT_DEGC (260.0f) + /** * @brief Key used to lock the safety flags coming from the measurment ADC from external ack'ing */ diff --git a/stm-firmware/include/reflow-controller/safety/safety-controller.h b/stm-firmware/include/reflow-controller/safety/safety-controller.h index 790d58d..0279164 100644 --- a/stm-firmware/include/reflow-controller/safety/safety-controller.h +++ b/stm-firmware/include/reflow-controller/safety/safety-controller.h @@ -250,7 +250,22 @@ int safety_controller_get_timing_mon_name_by_index(uint32_t index, char *buffer, * @brief Get the count of timing monitors * @return Timing monitor count */ -uint32_t safety_controller_get_timing_monitor_count(); +uint32_t safety_controller_get_timing_monitor_count(void); + +/** + * @brief Set the overtemperature limit and store it permanently in the EEPROM + * + * If no EEPROM is present, this will fail. The default value @ref SAFETY_DEFAULT_OVERTEMP_LIMIT_DEGC will be used. + * @param over_temperature Over temperature to set + * @return 0 if successfully saved and applied, negative if error + */ +int safety_controller_configure_overtemp_limit(float over_temperature); + +/** + * @brief Read the current overtemperature limit. + * @return Over temperature limit + */ +float safety_controller_get_overtemp_limit(void); #endif /* __SAFETY_CONTROLLER_H__ */ diff --git a/stm-firmware/safety/safety-controller.c b/stm-firmware/safety/safety-controller.c index 06c85fc..3a953c9 100644 --- a/stm-firmware/safety/safety-controller.c +++ b/stm-firmware/safety/safety-controller.c @@ -41,6 +41,7 @@ #include #include #include +#include /** * @brief Macro that checks if a given @ref error_flag is persistent @@ -144,6 +145,13 @@ struct analog_mon { uint64_t timestamp; }; +struct overtemp_config { + uint32_t crc_dummy_seed; + float overtemp_deg_celsius; + float overtemp_equiv_resistance; + uint32_t crc; +}; + /** * @brief All safety error flags. */ @@ -234,6 +242,45 @@ static volatile struct safety_weight IN_SECTION(.ccm.bss) flag_weights[COUNT_OF( */ static uint32_t IN_SECTION(.ccm.bss) flag_weight_crc; +/** + * @brief Configuration struct containing the overtemperature flag configuration + */ +static struct overtemp_config IN_SECTION(.ccm.bss) safety_controller_overtemp_config; + +/** + * @brief Configure the overtemperature flag's settings + * @param over_temperature Temperature to set the limit to. + */ +static void set_overtemp_config(float over_temperature) +{ + int result; + float resistance; + + result = temp_convertet_convert_temp_to_resistance(over_temperature, &resistance); + /* An error in this function is really bad... */ + if (result < -1) + panic_mode(); + + crc_unit_reset(); + safety_controller_overtemp_config.crc_dummy_seed = 0xA4F5C7E6UL; + safety_controller_overtemp_config.overtemp_deg_celsius = over_temperature; + safety_controller_overtemp_config.overtemp_equiv_resistance = resistance; + crc_unit_input_array((const uint32_t *)&safety_controller_overtemp_config, wordsize_of(struct overtemp_config) - 1); + safety_controller_overtemp_config.crc = crc_unit_get_crc(); +} + +static bool over_temperature_config_check(void) +{ + if (safety_controller_overtemp_config.crc_dummy_seed != 0xA4F5C7E6UL) + return true; + crc_unit_reset(); + crc_unit_input_array((const uint32_t *)&safety_controller_overtemp_config, wordsize_of(struct overtemp_config) - 1); + if (crc_unit_get_crc() != safety_controller_overtemp_config.crc) + return true; + + return false; +} + /** * @brief Convert a flag enum to the flag number. * @@ -721,6 +768,9 @@ void safety_controller_init() init_safety_flag_persistencies_from_default(); apply_config_overrides(); + /* Set the default limit of the overtemperature check */ + set_overtemp_config(SAFETY_DEFAULT_OVERTEMP_LIMIT_DEGC); + if (found_memory_state == SAFETY_MEMORY_INIT_CORRUPTED) safety_controller_report_error(ERR_FLAG_SAFETY_MEM_CORRUPT); else if (found_memory_state == SAFETY_MEMORY_INIT_VALID_MEMORY) { @@ -842,6 +892,7 @@ static void safety_controller_handle_safety_adc() * Aditionally, the default flag weights are restored from Flash. * 3) The flag persistency table is CRC checked. In case of an error, the @ref ERR_FLAG_SAFETY_TAB_CORRUPT flag is set. * Aditionally, the default values of the flag persistence is restored from Flash. + * 4) Check the Overtemperature flag configuration structure */ static void safety_controller_handle_memory_checks(void) { @@ -870,6 +921,12 @@ static void safety_controller_handle_memory_checks(void) safety_controller_report_error(ERR_FLAG_SAFETY_TAB_CORRUPT); init_safety_flag_persistencies_from_default(); } + + /* check overtemp struct */ + if (over_temperature_config_check()) { + safety_controller_report_error(ERR_FLAG_SAFETY_TAB_CORRUPT); + set_overtemp_config(SAFETY_DEFAULT_OVERTEMP_LIMIT_DEGC); + } } } @@ -1220,4 +1277,15 @@ int safety_controller_get_timing_mon_by_index(uint32_t index, struct timing_moni return 0; } +int safety_controller_set_overtemp_limit(float over_temperature) +{ + set_overtemp_config(over_temperature); + return 0; +} + +float safety_controller_get_overtemp_limit(void) +{ + return safety_controller_overtemp_config.overtemp_deg_celsius; +} + /** @} */ From e614eaa23b19a005514eb00e35485065b5a105b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 2 Feb 2021 20:50:30 +0100 Subject: [PATCH 04/10] Correct version of EEPROM header for settings and write check for overtemperature --- stm-firmware/safety/safety-controller.c | 8 ++++++++ stm-firmware/settings/settings-eeprom.c | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/stm-firmware/safety/safety-controller.c b/stm-firmware/safety/safety-controller.c index 3a953c9..02f533f 100644 --- a/stm-firmware/safety/safety-controller.c +++ b/stm-firmware/safety/safety-controller.c @@ -42,6 +42,7 @@ #include #include #include +#include /** * @brief Macro that checks if a given @ref error_flag is persistent @@ -563,6 +564,7 @@ static void safety_controller_process_active_timing_mons() /** * @brief safety_controller_process_monitor_checks * Process the analog and timing monitors and set the relevant flags in case of a monitor outside its limits. + * Furthermore, the PT1000 resistance is checked for overtemperature * * The checking of the analog monitors will only be armed after a startup delay of 1000 ms to allow the values to stabilize. */ @@ -572,6 +574,7 @@ static void safety_controller_process_monitor_checks(void) struct analog_monitor_info amon_info; uint32_t idx; uint32_t analog_mon_count; + float pt1000_val = 1000000.0f; if (!startup_completed && systick_get_global_tick() >= 1000) startup_completed = true; @@ -589,6 +592,11 @@ static void safety_controller_process_monitor_checks(void) } } + adc_pt1000_get_current_resistance(&pt1000_val); + if (pt1000_val > safety_controller_overtemp_config.overtemp_equiv_resistance) { + safety_controller_report_error(ERR_FLAG_OVERTEMP); + } + safety_controller_process_active_timing_mons(); } diff --git a/stm-firmware/settings/settings-eeprom.c b/stm-firmware/settings/settings-eeprom.c index 99171bb..35e13ff 100644 --- a/stm-firmware/settings/settings-eeprom.c +++ b/stm-firmware/settings/settings-eeprom.c @@ -24,7 +24,7 @@ #include #define EEPROM_HEADER_MAGIC 0xA5 -#define EEPROM_HEADER_COMP_VER 0xFF +#define EEPROM_HEADER_COMP_VER 0x01 static const uint8_t expected_header[2] = {EEPROM_HEADER_MAGIC, EEPROM_HEADER_COMP_VER}; @@ -36,6 +36,12 @@ struct eeprom_calibration_settings { uint32_t crc; }; +#define EEPROM_OVER_TEMP_CONFIG_BASE_ADDR (EEPROM_CALIBRATION_BASE_ADDR + sizeof(struct eeprom_calibration_settings)) +struct eeprom_over_temp_config { + float over_temperature; + float over_temperature_redundant; +}; + static bool check_eeprom_header(void) { uint8_t header[2] = {0}; From 7c5b60ec6bb12d9d204091ce258fbf41740fe62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 14 Feb 2021 20:06:01 +0100 Subject: [PATCH 05/10] #26: Add over temperature monitor settings to eeprom --- .../settings/settings-eeprom.h | 4 ++ stm-firmware/settings/settings-eeprom.c | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/stm-firmware/include/reflow-controller/settings/settings-eeprom.h b/stm-firmware/include/reflow-controller/settings/settings-eeprom.h index 7fc0153..56c3aa4 100644 --- a/stm-firmware/include/reflow-controller/settings/settings-eeprom.h +++ b/stm-firmware/include/reflow-controller/settings/settings-eeprom.h @@ -29,4 +29,8 @@ int settings_eeprom_save_calibration(float sens, float offset, bool active); int settings_eeprom_load_calibration(float *sens, float *offset, bool *active); +int settings_eeprom_save_overtemp_limit(float overtemp_limit); + +int settings_eeprom_load_overtemp_limit(float *overtemp_limit); + #endif /* __SETTINGS_SETTINGS_EEPROM_H__ */ diff --git a/stm-firmware/settings/settings-eeprom.c b/stm-firmware/settings/settings-eeprom.c index 35e13ff..05d401f 100644 --- a/stm-firmware/settings/settings-eeprom.c +++ b/stm-firmware/settings/settings-eeprom.c @@ -39,7 +39,7 @@ struct eeprom_calibration_settings { #define EEPROM_OVER_TEMP_CONFIG_BASE_ADDR (EEPROM_CALIBRATION_BASE_ADDR + sizeof(struct eeprom_calibration_settings)) struct eeprom_over_temp_config { float over_temperature; - float over_temperature_redundant; + uint32_t over_temp_crc; }; static bool check_eeprom_header(void) @@ -144,3 +144,39 @@ int settings_eeprom_load_calibration(float *sens, float *offset, bool *active) return -1; } } + +int settings_eeprom_save_overtemp_limit(float overtemp_limit) +{ + int res; + struct eeprom_over_temp_config over_temp_conf_entry; + + over_temp_conf_entry.over_temperature = overtemp_limit; + crc_unit_reset(); + crc_unit_input_array((uint32_t *)&over_temp_conf_entry, 1); + over_temp_conf_entry.over_temp_crc = crc_unit_get_crc(); + res = spi_eeprom_write(EEPROM_OVER_TEMP_CONFIG_BASE_ADDR, (const uint8_t *)&over_temp_conf_entry, + sizeof(over_temp_conf_entry)); + + return res ? -1 : 0; +} + +int settings_eeprom_load_overtemp_limit(float *overtemp_limit) +{ + int res; + struct eeprom_over_temp_config over_temp_conf_entry; + + if (!overtemp_limit) + return -1001; + res = spi_eeprom_read(EEPROM_OVER_TEMP_CONFIG_BASE_ADDR, (uint8_t *)&over_temp_conf_entry, + sizeof(struct eeprom_over_temp_config)); + if (res) + return -2; + + crc_unit_reset(); + crc_unit_input_array((uint32_t *)&over_temp_conf_entry, 1); + if (crc_unit_get_crc() != over_temp_conf_entry.over_temp_crc) + return -1; + + *overtemp_limit = over_temp_conf_entry.over_temperature; + return 0; +} From 694a78982abb7d0c536bf2a82de37337472e6c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 14 Feb 2021 20:11:21 +0100 Subject: [PATCH 06/10] Add missing parameter to doxygen header of dc_pt1000_set_resistance_calibration() --- stm-firmware/include/reflow-controller/adc-meas.h | 1 + 1 file changed, 1 insertion(+) diff --git a/stm-firmware/include/reflow-controller/adc-meas.h b/stm-firmware/include/reflow-controller/adc-meas.h index b7e8b35..6f16df4 100644 --- a/stm-firmware/include/reflow-controller/adc-meas.h +++ b/stm-firmware/include/reflow-controller/adc-meas.h @@ -144,6 +144,7 @@ void adc_pt1000_set_moving_average_filter_param(float alpha); * * @param offset Offset \f$O\f$ * @param sensitivity_deviation Sensitivity Deviation \f$\sigma\f$ after offset correction + * @param active Calibration is active */ void adc_pt1000_set_resistance_calibration(float offset, float sensitivity_deviation, bool active); From b9dfe35652635c3aa357589485dda716ec877b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 15 Feb 2021 20:28:45 +0100 Subject: [PATCH 07/10] Issue #26: Add overtemp limit setting to settings module and load it from EEPROM at startup --- .../safety/safety-controller.h | 2 +- .../settings/settings-eeprom.h | 2 +- .../reflow-controller/settings/settings.h | 4 +++ stm-firmware/main.c | 7 +++++ stm-firmware/settings/settings-eeprom.c | 12 +++++++-- stm-firmware/settings/settings.c | 27 +++++++++++++++++++ 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/stm-firmware/include/reflow-controller/safety/safety-controller.h b/stm-firmware/include/reflow-controller/safety/safety-controller.h index 0279164..730628b 100644 --- a/stm-firmware/include/reflow-controller/safety/safety-controller.h +++ b/stm-firmware/include/reflow-controller/safety/safety-controller.h @@ -259,7 +259,7 @@ uint32_t safety_controller_get_timing_monitor_count(void); * @param over_temperature Over temperature to set * @return 0 if successfully saved and applied, negative if error */ -int safety_controller_configure_overtemp_limit(float over_temperature); +int safety_controller_set_overtemp_limit(float over_temperature); /** * @brief Read the current overtemperature limit. diff --git a/stm-firmware/include/reflow-controller/settings/settings-eeprom.h b/stm-firmware/include/reflow-controller/settings/settings-eeprom.h index 56c3aa4..f7b0ee7 100644 --- a/stm-firmware/include/reflow-controller/settings/settings-eeprom.h +++ b/stm-firmware/include/reflow-controller/settings/settings-eeprom.h @@ -29,7 +29,7 @@ int settings_eeprom_save_calibration(float sens, float offset, bool active); int settings_eeprom_load_calibration(float *sens, float *offset, bool *active); -int settings_eeprom_save_overtemp_limit(float overtemp_limit); +int settings_eeprom_save_overtemp_limit(float overtemp_limit, bool active); int settings_eeprom_load_overtemp_limit(float *overtemp_limit); diff --git a/stm-firmware/include/reflow-controller/settings/settings.h b/stm-firmware/include/reflow-controller/settings/settings.h index 9168991..abe0347 100644 --- a/stm-firmware/include/reflow-controller/settings/settings.h +++ b/stm-firmware/include/reflow-controller/settings/settings.h @@ -54,6 +54,10 @@ int settings_load_calibration(float *sens_dev, float *offset); enum settings_load_result settings_load_pid_oven_parameters(struct oven_pid_settings *settings); +enum settings_load_result settings_load_overtemp_limit(float *over_temp_limit); + +int settings_save_overtemp_limit(float over_temp_limit, bool active); + void settings_setup(void); #endif /* __SETTINGS_SETTINGS_H__ */ diff --git a/stm-firmware/main.c b/stm-firmware/main.c index 7c90768..dc1f805 100644 --- a/stm-firmware/main.c +++ b/stm-firmware/main.c @@ -168,6 +168,8 @@ static inline void handle_boot_status(void) static inline void setup_system(void) { + float tmp; + setup_nvic_priorities(); /* Init safety controller and safety memory */ @@ -182,6 +184,11 @@ static inline void setup_system(void) uart_gpio_config(); settings_setup(); + /* Load the overtemperature limit from eeprom if available. Otherwise the default value will be used */ + if (settings_load_overtemp_limit(&tmp) == SETT_LOAD_SUCCESS) { + safety_controller_set_overtemp_limit(tmp); + } + handle_boot_status(); setup_shell_uart(&shell_uart); diff --git a/stm-firmware/settings/settings-eeprom.c b/stm-firmware/settings/settings-eeprom.c index 05d401f..b9d7958 100644 --- a/stm-firmware/settings/settings-eeprom.c +++ b/stm-firmware/settings/settings-eeprom.c @@ -23,7 +23,7 @@ #include #include -#define EEPROM_HEADER_MAGIC 0xA5 +#define EEPROM_HEADER_MAGIC 0xC5 #define EEPROM_HEADER_COMP_VER 0x01 static const uint8_t expected_header[2] = {EEPROM_HEADER_MAGIC, EEPROM_HEADER_COMP_VER}; @@ -57,6 +57,7 @@ static bool check_eeprom_header(void) static void settings_eeprom_zero() { settings_eeprom_save_calibration(0.0f, 0.0f, false); + settings_eeprom_save_overtemp_limit(0.0, false); } bool settings_eeprom_detect_and_prepare(void) @@ -145,10 +146,17 @@ int settings_eeprom_load_calibration(float *sens, float *offset, bool *active) } } -int settings_eeprom_save_overtemp_limit(float overtemp_limit) +int settings_eeprom_save_overtemp_limit(float overtemp_limit, bool active) { int res; struct eeprom_over_temp_config over_temp_conf_entry; + const uint8_t zero_vals[sizeof(over_temp_conf_entry)] = {0}; + + if (!active) { + res = spi_eeprom_write(EEPROM_OVER_TEMP_CONFIG_BASE_ADDR, (const uint8_t *)zero_vals, + sizeof(zero_vals)); + return res ? -1 : 0; + } over_temp_conf_entry.over_temperature = overtemp_limit; crc_unit_reset(); diff --git a/stm-firmware/settings/settings.c b/stm-firmware/settings/settings.c index 7583e45..09d2ae8 100644 --- a/stm-firmware/settings/settings.c +++ b/stm-firmware/settings/settings.c @@ -64,3 +64,30 @@ void settings_setup(void) else settings_use_eeprom = false; } + +enum settings_load_result settings_load_overtemp_limit(float *over_temp_limit) +{ + int res; + float tmp; + + if (!over_temp_limit) + return SETT_LOAD_ERR; + + if (!settings_use_eeprom) + return SETT_LOAD_FILE_NOT_FOUND; + + res = settings_eeprom_load_overtemp_limit(&tmp); + if (res) + return SETT_LOAD_DISK_ERR; + *over_temp_limit = tmp; + + return SETT_LOAD_SUCCESS; +} + +int settings_save_overtemp_limit(float over_temp_limit, bool active) +{ + if (settings_use_eeprom) + return settings_eeprom_save_overtemp_limit(over_temp_limit, active); + else + return -100; +} From 8a764f599b06f0f75cb5f6af74bd35e0a9124ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 15 Feb 2021 20:35:54 +0100 Subject: [PATCH 08/10] Remove cat command from shell --- stm-firmware/shell.c | 75 +++++--------------------------------------- 1 file changed, 8 insertions(+), 67 deletions(-) diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index cbb2e30..8e31918 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -334,57 +334,6 @@ static shellmatta_retCode_t shell_cmd_reset(const shellmatta_handle_t handle, co return SHELLMATTA_BUSY; } -static shellmatta_retCode_t shell_cmd_cat(const shellmatta_handle_t handle, const char *arguments, - uint32_t length) -{ - -#ifdef IMPLEMENT_SHELL_CAT - FIL file; - char path_buff[256]; - const char *path; - UINT bytes_read; - FRESULT res; - - strncpy(path_buff, arguments, MIN(sizeof(path_buff), length)); - path_buff[MIN(length, sizeof(path_buff)-1)] = 0; - path = strtok(path_buff, " "); - path = strtok(NULL, " "); - - if (strlen(path) == 0) { - shellmatta_printf(handle, "Specify path!\r\n"); - return SHELLMATTA_OK; - } - - res = f_open(&file, path, FA_READ); - if (res == FR_OK) { - shellmatta_write(handle, "\r\n", 2U); - do { - res = f_read(&file, path_buff, sizeof(path_buff), &bytes_read); - if (bytes_read > 0) - shellmatta_write(handle, path_buff, bytes_read); - else - break; - } while (res == FR_OK); - - shellmatta_write(handle, "\r\n", 2U); - } - - if (res != FR_OK) { - shellmatta_printf(handle, "Error reading file\r\n"); - } - - f_close(&file); - -#else - (void)length; - (void)arguments; - - shellmatta_printf(handle, "cat not implemented!\r\n"); -#endif - - return SHELLMATTA_OK; -} - static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handle, const char *arguments, uint32_t length) { @@ -701,7 +650,7 @@ shellmatta_retCode_t shell_cmd_update(const shellmatta_handle_t handle, const ch // shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */ // struct shellmatta_cmd *next; /**< pointer to next command or NULL */ //} shellmatta_cmd_t; -static shellmatta_cmd_t cmd[20] = { +static shellmatta_cmd_t cmd[19] = { { .cmd = "version", .cmdAlias = "ver", @@ -790,21 +739,13 @@ static shellmatta_cmd_t cmd[20] = { .cmdFct = shell_cmd_reset, .next = &cmd[11], }, - { - .cmd = "cat", - .cmdAlias = NULL, - .helpText = "Print file contents", - .usageText = "cat ", - .cmdFct = shell_cmd_cat, - .next = &cmd[12], - }, { .cmd = "safety-flags", .cmdAlias = "flags", .helpText = "Reads and may clear safety flags", .usageText = "flags [--ack]", .cmdFct = shell_cmd_read_flags, - .next = &cmd[13], + .next = &cmd[12], }, { .cmd = "save-calibration", @@ -812,7 +753,7 @@ static shellmatta_cmd_t cmd[20] = { .helpText = "", .usageText = "", .cmdFct = shell_cmd_save_cal, - .next = &cmd[14], + .next = &cmd[13], }, { .cmd = "hang", @@ -820,7 +761,7 @@ static shellmatta_cmd_t cmd[20] = { .helpText = "", .usageText = "", .cmdFct = shell_cmd_hang, - .next = &cmd[15], + .next = &cmd[14], }, { .cmd = "ui-emulate", @@ -828,7 +769,7 @@ static shellmatta_cmd_t cmd[20] = { .helpText = "", .usageText = "", .cmdFct = shell_cmd_ui_emulation, - .next = &cmd[16], + .next = &cmd[15], }, { .cmd = "panic", @@ -836,7 +777,7 @@ static shellmatta_cmd_t cmd[20] = { .helpText = "Panic Mode!", .usageText = "", .cmdFct = shell_cmd_panic, - .next = &cmd[17], + .next = &cmd[16], }, { .cmd = "safety-mem-dump", @@ -844,7 +785,7 @@ static shellmatta_cmd_t cmd[20] = { .helpText = "", .usageText = "safety-mem-dump [output-file]", .cmdFct = shell_cmd_dump_safety_mem, - .next = &cmd[18], + .next = &cmd[17], }, { .cmd = "reset-cal", @@ -852,7 +793,7 @@ static shellmatta_cmd_t cmd[20] = { .helpText = "Reset Calibration", .usageText = "", .cmdFct = shell_cmd_reset_cal, - .next = &cmd[19], + .next = &cmd[18], }, { .cmd = "update", From d1b8e916747db3731517f5175ccb6547f9d80f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 14 Mar 2021 20:08:52 +0100 Subject: [PATCH 09/10] Fix typo in linker script --- stm-firmware/stm32f407vet6_flash.ld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stm-firmware/stm32f407vet6_flash.ld b/stm-firmware/stm32f407vet6_flash.ld index 11edd5d..cce71be 100644 --- a/stm-firmware/stm32f407vet6_flash.ld +++ b/stm-firmware/stm32f407vet6_flash.ld @@ -29,7 +29,7 @@ __stack_corruption_area_size = 128; /* END OF USER PARAMETERS */ ENTRY(Reset_Handler) -__ld_top_of_stack = 0x20020000; /* One byte above the end of the SRAM. Stack is pre-decrewmenting, so this is okay */ +__ld_top_of_stack = 0x20020000; /* One byte above the end of the SRAM. Stack is pre-decrementing, so this is okay */ /* Available memory areas */ From 64a97fa04817309bce61391baadf65a2d39baa85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 14 Mar 2021 21:56:21 +0100 Subject: [PATCH 10/10] Issue #26: Add overtemp function to shell --- stm-firmware/shell.c | 54 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index 8e31918..9405c97 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -641,6 +641,48 @@ shellmatta_retCode_t shell_cmd_update(const shellmatta_handle_t handle, const ch return SHELLMATTA_OK; } +shellmatta_retCode_t shell_cmd_overtemp_cfg(const shellmatta_handle_t handle, const char *args, uint32_t len) +{ + float overtemp_lim; + shellmatta_retCode_t ret; + char *argument; + uint32_t arg_length; + char option; + bool temp_passed = false; + bool persistent = false; + + static const shellmatta_opt_long_t options[] = { + {"persistent", 'p', SHELLMATTA_OPT_ARG_NONE}, + {NULL, '\0', SHELLMATTA_OPT_ARG_NONE}, + }; + + do { + ret = shellmatta_opt_long(handle, options, &option, &argument, &arg_length); + if (ret != SHELLMATTA_OK) + break; + switch (option) { + case 'p': + persistent = true; + break; + case '\0': + temp_passed = true; + overtemp_lim = strtof(argument, NULL); + break; + } + } while (1); + + if (temp_passed) { + safety_controller_set_overtemp_limit(overtemp_lim); + if (persistent) + settings_save_overtemp_limit(overtemp_lim, true); + } + + overtemp_lim = safety_controller_get_overtemp_limit(); + shellmatta_printf(handle, "Overtemperature configured for: %.1f °C\r\n", overtemp_lim); + + return ret; +} + //typedef struct shellmatta_cmd //{ // char *cmd; /**< command name */ @@ -650,7 +692,7 @@ shellmatta_retCode_t shell_cmd_update(const shellmatta_handle_t handle, const ch // shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */ // struct shellmatta_cmd *next; /**< pointer to next command or NULL */ //} shellmatta_cmd_t; -static shellmatta_cmd_t cmd[19] = { +static shellmatta_cmd_t cmd[20] = { { .cmd = "version", .cmdAlias = "ver", @@ -801,8 +843,16 @@ static shellmatta_cmd_t cmd[19] = { .helpText = "Update Firmware", .usageText = "", .cmdFct = shell_cmd_update, - .next = NULL, + .next = &cmd[19], + }, + { + .cmd = "overtemp", + .cmdAlias = NULL, + .helpText = "Overtemperature Config", + .usageText = "", + .cmdFct = shell_cmd_overtemp_cfg, + .next = NULL, } };