From 2673112a9c5d77285a976ffc5de48b2011655f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 5 Sep 2020 18:03:05 +0200 Subject: [PATCH 1/8] Reflow menu: Stop rendering the menu although nothing has changed. This reduces the current consumption. --- stm-firmware/reflow-menu.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/stm-firmware/reflow-menu.c b/stm-firmware/reflow-menu.c index e058aa0..3b07dca 100644 --- a/stm-firmware/reflow-menu.c +++ b/stm-firmware/reflow-menu.c @@ -109,6 +109,7 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry static void *my_parent; static bool button_ready; static int page = 0; + static int last_page = -1; static uint32_t uptime_secs; uint32_t new_uptime_secs; uint32_t uptime_mins; @@ -121,6 +122,7 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry if (entry_type == MENU_ENTRY_FIRST_ENTER) { uptime_secs = 0ULL; page = 0; + last_page = -1; my_parent = parent; button_ready = false; menu_display_clear(menu); @@ -144,12 +146,18 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry switch (page) { case 0: + if (last_page == 0) + break; + last_page = 0; menu_lcd_output(menu, 0, LCD_SHIMATTA_STRING " Shimatta"); menu_lcd_output(menu, 1, "Oven Controller"); menu_lcd_output(menu, 2, "(c) Mario H\xF5ttel"); menu_lcd_output(menu, 3, "Page 1/5"); break; case 1: + if (last_page == 1) + break; + last_page = 1; menu_lcd_output(menu, 0, "Version Number:"); menu_lcd_outputf(menu, 1, "%.*s", LCD_CHAR_WIDTH, xstr(GIT_VER)); if (strlen(xstr(GIT_VER)) > LCD_CHAR_WIDTH) { @@ -162,12 +170,18 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry #endif break; case 2: + if (last_page == 2) + break; + last_page = 2; menu_lcd_output(menu, 0, "Compile Info"); menu_lcd_output(menu, 1, __DATE__); menu_lcd_output(menu, 2, __TIME__); menu_lcd_output(menu, 3, "Page 3/5"); break; case 3: + if (last_page == 3) + break; + last_page = 3; unique_id_get(&ser1, &ser2, &ser3); menu_lcd_outputf(menu, 0, "Serial: %08X", ser1); @@ -187,6 +201,7 @@ static void reflow_menu_about(struct lcd_menu *menu, enum menu_entry_func_entry break; default: page = 0; + last_page = -1; break; } @@ -206,7 +221,7 @@ static void reflow_menu_root_entry(struct lcd_menu *menu, enum menu_entry_func_e (void)parent; static struct menu_list list; static bool button_valid; - static bool menu_changed = true; + bool menu_changed = false; static const char * const root_entry_names[] = { "About", "Monitoring", From 95382d9ab88a4c7d789a0b51f34acff005634cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 5 Sep 2020 18:23:17 +0200 Subject: [PATCH 2/8] Make interrupt default handler trigger panic mode. --- stm-firmware/safety/fault.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stm-firmware/safety/fault.c b/stm-firmware/safety/fault.c index 79a743d..8209edc 100644 --- a/stm-firmware/safety/fault.c +++ b/stm-firmware/safety/fault.c @@ -34,6 +34,12 @@ void HardFault_Handler(void) while (1); } +/* Overwrite default handler. Go to panic mode */ +void __int_default_handler(void) +{ + panic_mode(); +} + void panic_mode(void) { /* Panic mode is esentially the same as a hardfault, From 20e2a2b84b7233958106d4d18f467f9de3fda0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 6 Sep 2020 22:09:14 +0200 Subject: [PATCH 3/8] Doxygen: Fix bug of IN_SECTION macro and __atribute__ --- stm-firmware/doxygen/Doxyconfig | 50 +++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/stm-firmware/doxygen/Doxyconfig b/stm-firmware/doxygen/Doxyconfig index fd292e2..b518394 100644 --- a/stm-firmware/doxygen/Doxyconfig +++ b/stm-firmware/doxygen/Doxyconfig @@ -1,4 +1,4 @@ -# Doxyfile 1.8.18 +# Doxyfile 1.8.20 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project. @@ -227,6 +227,14 @@ QT_AUTOBRIEF = NO MULTILINE_CPP_IS_BRIEF = NO +# By default Python docstrings are displayed as preformatted text and doxygen's +# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the +# doxygen's special commands can be used and the contents of the docstring +# documentation blocks is shown as doxygen documentation. +# The default value is: YES. + +PYTHON_DOCSTRING = YES + # If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the # documentation from any documented member that it re-implements. # The default value is: YES. @@ -449,6 +457,19 @@ TYPEDEF_HIDES_STRUCT = NO LOOKUP_CACHE_SIZE = 0 +# The NUM_PROC_THREADS specifies the number threads doxygen is allowed to use +# during processing. When set to 0 doxygen will based this on the number of +# cores available in the system. You can set it explicitly to a value larger +# than 0 to get more control over the balance between CPU load and processing +# speed. At this moment only the input processing can be done using multiple +# threads. Since this is still an experimental feature the default is set to 1, +# which efficively disables parallel processing. Please report any issues you +# encounter. Generating dot graphs in parallel is controlled by the +# DOT_NUM_THREADS setting. +# Minimum value: 0, maximum value: 32, default value: 1. + +NUM_PROC_THREADS = 1 + #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- @@ -553,7 +574,7 @@ INTERNAL_DOCS = NO # names in lower-case letters. If set to YES, upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows -# (including Cygwin) ands Mac users are advised to set this option to NO. +# (including Cygwin) and Mac users are advised to set this option to NO. # The default value is: system dependent. CASE_SENSE_NAMES = NO @@ -1375,7 +1396,7 @@ CHM_FILE = HHC_LOCATION = # The GENERATE_CHI flag controls if a separate .chi index file is generated -# (YES) or that it should be included in the master .chm file (NO). +# (YES) or that it should be included in the main .chm file (NO). # The default value is: NO. # This tag requires that the tag GENERATE_HTMLHELP is set to YES. @@ -1541,8 +1562,8 @@ EXT_LINKS_IN_WINDOW = NO # tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see # https://inkscape.org) to generate formulas as SVG images instead of PNGs for # the HTML output. These images will generally look nicer at scaled resolutions. -# Possible values are: png The default and svg Looks nicer but requires the -# pdf2svg tool. +# Possible values are: png (the default) and svg (looks nicer but requires the +# pdf2svg or inkscape tool). # The default value is: png. # This tag requires that the tag GENERATE_HTML is set to YES. @@ -1842,9 +1863,11 @@ LATEX_EXTRA_FILES = PDF_HYPERLINKS = YES -# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate -# the PDF file directly from the LaTeX files. Set this option to YES, to get a -# higher quality PDF documentation. +# If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as +# specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX +# files. Set this option to YES, to get a higher quality PDF documentation. +# +# See also section LATEX_CMD_NAME for selecting the engine. # The default value is: YES. # This tag requires that the tag GENERATE_LATEX is set to YES. @@ -2083,6 +2106,10 @@ DOCBOOK_PROGRAMLISTING = NO GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# Configuration options related to Sqlite3 output +#--------------------------------------------------------------------------- + #--------------------------------------------------------------------------- # Configuration options related to the Perl module output #--------------------------------------------------------------------------- @@ -2138,7 +2165,7 @@ ENABLE_PREPROCESSING = YES # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then # the macro expansion is limited to the macros specified with the PREDEFINED and @@ -2146,7 +2173,7 @@ MACRO_EXPANSION = NO # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -EXPAND_ONLY_PREDEF = NO +EXPAND_ONLY_PREDEF = YES # If the SEARCH_INCLUDES tag is set to YES, the include files in the # INCLUDE_PATH will be searched if a #include is found. @@ -2178,7 +2205,8 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = +PREDEFINED = __attribute__(x)= \ + IN_SECTION(x)= # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The From ab8228f7124e1b0b13892c91d8a5b4a85ae87ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 6 Sep 2020 22:11:12 +0200 Subject: [PATCH 4/8] Fix bug in doxygen xml generation for sphinx regarding the IN_SECTION() macro --- doc/source/Doxyfile.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/source/Doxyfile.in b/doc/source/Doxyfile.in index fe2dbcd..bc4c423 100644 --- a/doc/source/Doxyfile.in +++ b/doc/source/Doxyfile.in @@ -2138,7 +2138,7 @@ ENABLE_PREPROCESSING = YES # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then # the macro expansion is limited to the macros specified with the PREDEFINED and @@ -2146,7 +2146,7 @@ MACRO_EXPANSION = NO # The default value is: NO. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -EXPAND_ONLY_PREDEF = NO +EXPAND_ONLY_PREDEF = YES # If the SEARCH_INCLUDES tag is set to YES, the include files in the # INCLUDE_PATH will be searched if a #include is found. @@ -2178,7 +2178,8 @@ INCLUDE_FILE_PATTERNS = # recursively expanded use the := operator instead of the = operator. # This tag requires that the tag ENABLE_PREPROCESSING is set to YES. -PREDEFINED = +PREDEFINED = __atribute(x)__= \ + IN_SECTION(x)= # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this # tag can be used to specify a list of macro names that should be expanded. The From cbbd97e1bd1ac6c7bcdc5b4ad9e56272c7471d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 7 Sep 2020 20:47:56 +0200 Subject: [PATCH 5/8] Issue #20: Implement driver for RNG --- stm-firmware/Makefile | 1 + stm-firmware/include/stm-periph/rng.h | 42 ++++++++++++++++ stm-firmware/stm-periph/rng.c | 70 +++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 stm-firmware/include/stm-periph/rng.h create mode 100644 stm-firmware/stm-periph/rng.c diff --git a/stm-firmware/Makefile b/stm-firmware/Makefile index 701f726..ebd77b1 100644 --- a/stm-firmware/Makefile +++ b/stm-firmware/Makefile @@ -36,6 +36,7 @@ DEFINES += -DSHELLMATTA_HELP_ALIAS=\"?\" # RCC Manager CFILES += stm-periph/clock-enable-manager.c CFILES += stm-periph/uart.c stm-periph/dma-ring-buffer.c stm-periph/backup-ram.c +CFILES += stm-periph/rng.c CFILES += digio.c CFILES += stm-periph/unique-id.c CFILES += calibration.c diff --git a/stm-firmware/include/stm-periph/rng.h b/stm-firmware/include/stm-periph/rng.h new file mode 100644 index 0000000..e8d9d7a --- /dev/null +++ b/stm-firmware/include/stm-periph/rng.h @@ -0,0 +1,42 @@ +/* Reflow Oven Controller + * + * Copyright (C) 2020 Mario Hüttel + * + * This file is part of the Reflow Oven Controller Project. + * + * The reflow oven controller is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the reflow oven controller project. + * If not, see . + */ + +#ifndef __STM_RNG_H__ +#define __STM_RNG_H__ + +#include +#include + +enum random_number_error { + RNG_ERROR_OK = 0, + RNG_ERROR_INACT, + RNG_ERROR_INTERNAL_ERROR, + RNG_ERROR_NOT_READY +}; + +void random_number_gen_init(bool int_enable); + +void random_number_gen_deinit(); + +void random_number_gen_reset(bool int_en); + +enum random_number_error random_number_gen_get_number(uint32_t *random_number, bool wait_for_valid_value); + +#endif /* __STM_RNG_H__ */ diff --git a/stm-firmware/stm-periph/rng.c b/stm-firmware/stm-periph/rng.c new file mode 100644 index 0000000..042e061 --- /dev/null +++ b/stm-firmware/stm-periph/rng.c @@ -0,0 +1,70 @@ +/* Reflow Oven Controller + * + * Copyright (C) 2020 Mario Hüttel + * + * This file is part of the Reflow Oven Controller Project. + * + * The reflow oven controller is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * The Reflow Oven Control Firmware is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the reflow oven controller project. + * If not, see . + */ + +#include +#include +#include + +void random_number_gen_init(bool int_enable) +{ + rcc_manager_enable_clock(&RCC->AHB2ENR, BITMASK_TO_BITNO(RCC_AHB2ENR_RNGEN)); + __DSB(); + + random_number_gen_reset(int_enable); +} + +void random_number_gen_deinit() +{ + RNG->CR = 0; + __DSB(); + rcc_manager_disable_clock(&RCC->AHB2ENR, BITMASK_TO_BITNO(RCC_AHB2ENR_RNGEN)); +} + +void random_number_gen_reset(bool int_en) +{ + RNG->CR = 0; + __DSB(); + RNG->CR = RNG_CR_RNGEN | (int_en ? RNG_CR_IE : 0U); +} + +enum random_number_error random_number_gen_get_number(uint32_t *random_number, bool wait_for_valid_value) +{ + bool value_ready; + + if (!(RNG->CR & RNG_CR_RNGEN)) + return RNG_ERROR_INACT; + + if (RNG->SR & RNG_SR_SEIS || RNG->SR & RNG_SR_CEIS) { + /* Error detected */ + return RNG_ERROR_INTERNAL_ERROR; + } + + /* Check if the value is ready. Wait if wait_for_valid_value is true */ + do { + value_ready = !!(RNG->SR & RNG_SR_DRDY); + } while (!value_ready && wait_for_valid_value); + + /* If the value is valid, return it */ + if (value_ready && random_number) + *random_number = RNG->DR; + + /* Return from function with proper status */ + return (value_ready ? RNG_ERROR_OK : RNG_ERROR_NOT_READY); +} From ba41c0911dc70b1794e00e3974dd092cd4fe2afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 7 Sep 2020 21:03:37 +0200 Subject: [PATCH 6/8] Add necessary sections for stack protection area and implement fill function --- .../include/reflow-controller/stack-check.h | 4 ++ stm-firmware/stack-check.c | 43 ++++++++++++++++++- stm-firmware/stm32f407vet6_flash.ld | 7 +++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/stm-firmware/include/reflow-controller/stack-check.h b/stm-firmware/include/reflow-controller/stack-check.h index 8e0e290..c51a3a7 100644 --- a/stm-firmware/include/reflow-controller/stack-check.h +++ b/stm-firmware/include/reflow-controller/stack-check.h @@ -50,4 +50,8 @@ static inline uint32_t read_stack_pointer() return stack_pointer; } +int stack_check_init_corruption_detect_area(void); + +int stack_check_corruption_detect_area(void); + #endif /* __STACK_CHECK_H__ */ diff --git a/stm-firmware/stack-check.c b/stm-firmware/stack-check.c index 666014d..41e55e7 100644 --- a/stm-firmware/stack-check.c +++ b/stm-firmware/stack-check.c @@ -20,9 +20,10 @@ #include #include +#include extern char __ld_top_of_stack; -extern char __ld_eheap; +extern char __ld_end_stack; int32_t stack_check_get_usage() { @@ -41,7 +42,45 @@ int32_t stack_check_get_free() uint32_t stack_ptr; stack_ptr = read_stack_pointer(); - upper_heap_boundary = (uint32_t)&__ld_eheap; + upper_heap_boundary = (uint32_t)&__ld_end_stack; return stack_ptr - upper_heap_boundary; } + +extern uint32_t __ld_start_stack_corruption_detect_area; +extern uint32_t __ld_end_stack_corruption_detect_area; + +int stack_check_init_corruption_detect_area(void) +{ + volatile uint32_t *ptr = &__ld_start_stack_corruption_detect_area; + volatile uint32_t *end_ptr = &__ld_end_stack_corruption_detect_area; + enum random_number_error rng_stat; + uint32_t rng_number; + int ret = 0; + + end_ptr--; + + random_number_gen_init(false); + + while (ptr < end_ptr) { + rng_stat = random_number_gen_get_number(&rng_number, true); + + if (rng_stat != RNG_ERROR_OK) { + ret = -1; + goto exit_deinit_rng; + } + + *ptr = rng_number; + ptr++; + } + +exit_deinit_rng: + random_number_gen_deinit(); + + return ret; +} + +int stack_check_corruption_detect_area(void) +{ + +} diff --git a/stm-firmware/stm32f407vet6_flash.ld b/stm-firmware/stm32f407vet6_flash.ld index e1f503a..bbb2809 100644 --- a/stm-firmware/stm32f407vet6_flash.ld +++ b/stm-firmware/stm32f407vet6_flash.ld @@ -25,6 +25,7 @@ /* USER PARAMETERS */ __ld_stack_size = 0x3000; __ld_heap_size = 0x2100; +__stack_corruption_area_size = 64; /* END OF USER PARAMETERS */ ENTRY(Reset_Handler) @@ -150,6 +151,12 @@ SECTIONS __ld_sheap = .; . = . + __ld_heap_size; __ld_eheap = .; + . = ALIGN(4) + __ld_start_stack_corruption_detect_area = .; + . = . + __stack_corruption_area_size; + . = ALIGN(4); + __ld_end_stack_corruption_detect_area = .; + __ld_end_stack = . . = . + __ld_stack_size; . = ALIGN(4); } >RAM From dd0ee47d864b26b81b3627a18717a3fdec0a3656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 7 Sep 2020 21:52:53 +0200 Subject: [PATCH 7/8] Issue #20: Add stack checking based on protection area between stack and heap --- stm-firmware/safety/safety-controller.c | 8 +++++- stm-firmware/stack-check.c | 36 ++++++++++++++++++++----- stm-firmware/stm32f407vet6_flash.ld | 6 ++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/stm-firmware/safety/safety-controller.c b/stm-firmware/safety/safety-controller.c index 42396ba..115e037 100644 --- a/stm-firmware/safety/safety-controller.c +++ b/stm-firmware/safety/safety-controller.c @@ -347,6 +347,8 @@ void safety_controller_init() /* This is usually done by the safety memory already. But, since this module also uses the CRC... */ crc_unit_init(); + stack_check_init_corruption_detect_area(); + init_safety_flag_weight_table_from_default(); if (found_memory_state == SAFETY_MEMORY_INIT_CORRUPTED) @@ -374,6 +376,10 @@ static void safety_controller_check_stack() free_stack = stack_check_get_free(); if (free_stack < SAFETY_MIN_STACK_FREE) safety_controller_report_error(ERR_FLAG_STACK); + + if (stack_check_corruption_detect_area()) { + safety_controller_report_error(ERR_FLAG_STACK); + } } static void safety_controller_handle_safety_adc() @@ -430,7 +436,7 @@ static int safety_controller_handle_memory_checks(void) enum safety_memory_state found_state; int panic_request = 0; - if (systick_ticks_have_passed(ts, 1000)) { + if (systick_ticks_have_passed(ts, 250)) { ts = systick_get_global_tick(); /* Check the safety memory */ diff --git a/stm-firmware/stack-check.c b/stm-firmware/stack-check.c index 41e55e7..d1ecb2c 100644 --- a/stm-firmware/stack-check.c +++ b/stm-firmware/stack-check.c @@ -21,6 +21,7 @@ #include #include #include +#include extern char __ld_top_of_stack; extern char __ld_end_stack; @@ -47,22 +48,27 @@ int32_t stack_check_get_free() return stack_ptr - upper_heap_boundary; } + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" + extern uint32_t __ld_start_stack_corruption_detect_area; extern uint32_t __ld_end_stack_corruption_detect_area; int stack_check_init_corruption_detect_area(void) { - volatile uint32_t *ptr = &__ld_start_stack_corruption_detect_area; - volatile uint32_t *end_ptr = &__ld_end_stack_corruption_detect_area; + uint32_t *ptr = &__ld_start_stack_corruption_detect_area; + uint32_t *end_ptr = &__ld_end_stack_corruption_detect_area; + const uint32_t area_size_in_words = &__ld_end_stack_corruption_detect_area - + &__ld_start_stack_corruption_detect_area; enum random_number_error rng_stat; uint32_t rng_number; + uint32_t crc_val; int ret = 0; - end_ptr--; - random_number_gen_init(false); - while (ptr < end_ptr) { + while (ptr < &end_ptr[-1]) { rng_stat = random_number_gen_get_number(&rng_number, true); if (rng_stat != RNG_ERROR_OK) { @@ -74,13 +80,31 @@ int stack_check_init_corruption_detect_area(void) ptr++; } + /* Init CRC unit and leave it on */ + crc_unit_init(); + crc_unit_reset(); + + crc_unit_input_array(&__ld_start_stack_corruption_detect_area, area_size_in_words - 1); + crc_val = crc_unit_get_crc(); + end_ptr[-1] = crc_val; + exit_deinit_rng: random_number_gen_deinit(); return ret; } +#pragma GCC diagnostic pop + int stack_check_corruption_detect_area(void) { - + const uint32_t area_size_in_words = &__ld_end_stack_corruption_detect_area - + &__ld_start_stack_corruption_detect_area; + crc_unit_reset(); + crc_unit_input_array(&__ld_start_stack_corruption_detect_area, area_size_in_words); + if (crc_unit_get_crc() == 0UL) { + return 0; + } else { + return -1; + } } diff --git a/stm-firmware/stm32f407vet6_flash.ld b/stm-firmware/stm32f407vet6_flash.ld index bbb2809..10e0d90 100644 --- a/stm-firmware/stm32f407vet6_flash.ld +++ b/stm-firmware/stm32f407vet6_flash.ld @@ -25,7 +25,7 @@ /* USER PARAMETERS */ __ld_stack_size = 0x3000; __ld_heap_size = 0x2100; -__stack_corruption_area_size = 64; +__stack_corruption_area_size = 128; /* END OF USER PARAMETERS */ ENTRY(Reset_Handler) @@ -151,12 +151,12 @@ SECTIONS __ld_sheap = .; . = . + __ld_heap_size; __ld_eheap = .; - . = ALIGN(4) + . = ALIGN(4); __ld_start_stack_corruption_detect_area = .; . = . + __stack_corruption_area_size; . = ALIGN(4); __ld_end_stack_corruption_detect_area = .; - __ld_end_stack = . + __ld_end_stack = .; . = . + __ld_stack_size; . = ALIGN(4); } >RAM From af555aba21fb73fd8a798eabbdf7a58b30326398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 7 Sep 2020 21:56:04 +0200 Subject: [PATCH 8/8] Issue #20: Move stack checker to safety folder --- stm-firmware/Makefile | 3 +-- .../include/reflow-controller/{ => safety}/stack-check.h | 0 stm-firmware/safety/safety-controller.c | 2 +- stm-firmware/{ => safety}/stack-check.c | 2 +- stm-firmware/shell.c | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) rename stm-firmware/include/reflow-controller/{ => safety}/stack-check.h (100%) rename stm-firmware/{ => safety}/stack-check.c (98%) diff --git a/stm-firmware/Makefile b/stm-firmware/Makefile index 856fe2e..8e4e703 100644 --- a/stm-firmware/Makefile +++ b/stm-firmware/Makefile @@ -42,13 +42,12 @@ CFILES += stm-periph/unique-id.c CFILES += calibration.c CFILES += temp-converter.c CFILES += rotary-encoder.c button.c -CFILES += stack-check.c CFILES += ui/lcd.c ui/menu.c reflow-menu.c CFILES += fatfs/diskio.c fatfs/ff.c fatfs/ffsystem.c fatfs/ffunicode.c fatfs/shimatta_sdio_driver/shimatta_sdio.c CFILES += pid-controller.c oven-driver.c CFILES += settings/settings.c settings/settings-sd-card.c CFILES += stm-periph/crc-unit.c -CFILES += safety/safety-adc.c safety/safety-controller.c safety/watchdog.c safety/fault.c safety/safety-memory.c +CFILES += safety/safety-adc.c safety/safety-controller.c safety/watchdog.c safety/fault.c safety/safety-memory.c safety/stack-check.c DEBUG_DEFINES = -DDEBUGBUILD RELEASE_DEFINES = diff --git a/stm-firmware/include/reflow-controller/stack-check.h b/stm-firmware/include/reflow-controller/safety/stack-check.h similarity index 100% rename from stm-firmware/include/reflow-controller/stack-check.h rename to stm-firmware/include/reflow-controller/safety/stack-check.h diff --git a/stm-firmware/safety/safety-controller.c b/stm-firmware/safety/safety-controller.c index 115e037..79cf6db 100644 --- a/stm-firmware/safety/safety-controller.c +++ b/stm-firmware/safety/safety-controller.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/stm-firmware/stack-check.c b/stm-firmware/safety/stack-check.c similarity index 98% rename from stm-firmware/stack-check.c rename to stm-firmware/safety/stack-check.c index d1ecb2c..9940c8c 100644 --- a/stm-firmware/stack-check.c +++ b/stm-firmware/safety/stack-check.c @@ -18,7 +18,7 @@ * If not, see . */ -#include +#include #include #include #include diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index db8ef9d..e03c31c 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include