diff --git a/doc/source/firmware/hw-version-detect.rst b/doc/source/firmware/hw-version-detect.rst new file mode 100644 index 0000000..6b50b1c --- /dev/null +++ b/doc/source/firmware/hw-version-detect.rst @@ -0,0 +1,31 @@ +.. _hw_version_detect: + +Automatic Hardware Version detection +==================================== + +Functional Description +---------------------- + +In order to automatically select the available hardware features, the firmware checks the PCB's version +using vertain pins on the microcontroller. + +The hardware revision is represented by the enum type :c:enum:`hw_revision`. A call to :c:func:`get_pcb_hardware_version` retrieves the revision. +When the function is called for the first time, it activates pull-up resistors on pin numbers :c:macro:`HW_REV_DETECT_PIN_LOW` to :c:macro:`HW_REV_DETECT_PIN_HIGH` +on port :c:macro:`HW_REV_DETECT_GPIO` and reads in the binary number. + +The revision is set by externally connecting the pins to ground. The bit pattern read from the port is inverted and then checked internally to derive the hardware version. +After the version is read for the first time, it is stored internally and subsequent calls to :c:func:`get_pcb_hardware_version` only retrieve the internally stored value to reduce the overhead of the function. + +Hardware Version Dependent Features +----------------------------------- + +- The settings module searches for an external EEPROM on the SPI interface to store some settings, like the calibration. This is enabled for all versions higher or equal to ``v1.3``. +- The safety controller enables the acknowledging of the external watchdog for all versions higher or equal to ``v1.3``. +- The oven driver has a separate safety enable for the solid state relay which it enables on all versions higher or equal to ``v1.3``. + + +API Documentation +----------------- + +.. doxygengroup:: hw-version-detect + :project: Reflow Controller Firmware \ No newline at end of file diff --git a/doc/source/firmware/index.rst b/doc/source/firmware/index.rst index 79776b4..882ed40 100644 --- a/doc/source/firmware/index.rst +++ b/doc/source/firmware/index.rst @@ -14,4 +14,5 @@ mechanisms and the behavior. For a detailed code documentation see the doxygen o pid-controller safety/index code/index + hw-version-detect diff --git a/doc/source/firmware/safety/index.rst b/doc/source/firmware/safety/index.rst index f47c5f8..2703d51 100644 --- a/doc/source/firmware/safety/index.rst +++ b/doc/source/firmware/safety/index.rst @@ -21,4 +21,5 @@ which are used to retain boot information across resets, for example to communic flags backup-ram error-handling + startup-tests stack-checking diff --git a/doc/source/firmware/safety/startup-tests.rst b/doc/source/firmware/safety/startup-tests.rst new file mode 100644 index 0000000..ccd96a8 --- /dev/null +++ b/doc/source/firmware/safety/startup-tests.rst @@ -0,0 +1,23 @@ +.. _safety_startup_tests: + +Startup Tests +============= + +The following tests will be performed after each reset / power cycle of the controller. + +Internal Memory Test +-------------------- +Directly after startup and after setting up the system clocks, the controller performs memory checks on the internal SRAM and the core coupled memory. + +RAM checking is performed by testing the following sequences: + +- Alternating 0x55AA55AA / 0xAA55AA55 pattern +- Alternating 0xAA55AA55 / 0x55AA55AA pattern +- 0xFFFFFFFF constant value +- 0x00000000 constant value + +The following functions implement the RAM checking: + +.. doxygenfunction:: startup_test_perform_ccm_ram_check + +.. doxygenfunction:: startup_test_perform_system_ram_check diff --git a/stm-firmware/hw-version-detect.c b/stm-firmware/hw-version-detect.c index 3e7434a..4d842aa 100644 --- a/stm-firmware/hw-version-detect.c +++ b/stm-firmware/hw-version-detect.c @@ -1,12 +1,32 @@ +/* Reflow Oven Controller +* +* Copyright (C) 2021 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 . +*/ + +/** + * @addtogroup hw-version-detect + * @{ + */ + #include #include #include -#define HW_REV_DETECT_GPIO GPIOE -#define HW_REV_DETECT_RCC_FIELD RCC_AHB1ENR_GPIOEEN -#define HW_REV_DETECT_PIN_LOW (8U) -#define HW_REV_DETECT_PIN_HIGH (15U) - enum hw_revision get_pcb_hardware_version(void) { uint8_t current_pin; @@ -46,3 +66,5 @@ enum hw_revision get_pcb_hardware_version(void) return revision; } + +/** @} */ diff --git a/stm-firmware/include/reflow-controller/hw-version-detect.h b/stm-firmware/include/reflow-controller/hw-version-detect.h index 2f7593e..65a2cc9 100644 --- a/stm-firmware/include/reflow-controller/hw-version-detect.h +++ b/stm-firmware/include/reflow-controller/hw-version-detect.h @@ -1,8 +1,54 @@ +/* Reflow Oven Controller +* +* Copyright (C) 2021 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 . +*/ + +/** + * @addtogroup hw-version-detect + * @{ + */ + #ifndef _HW_VERSION_DETECT_H_ #define _HW_VERSION_DETECT_H_ #include +/** + * @brief GPIO Port used for hardware version detection + */ +#define HW_REV_DETECT_GPIO GPIOE + +/** + * @brief RCC Clock register mask used to enable @ref HW_REV_DETECT_GPIO GPIO Port + */ +#define HW_REV_DETECT_RCC_FIELD RCC_AHB1ENR_GPIOEEN + +/** + * @brief Lowest pin on @ref HW_REV_DETECT_GPIO GPIO Port that shall be used to read in the hardware version + */ +#define HW_REV_DETECT_PIN_LOW (8U) + +/** + * @brief Highest pin on @ref HW_REV_DETECT_GPIO GPIO Port that shall be used to read in the hardware version + */ +#define HW_REV_DETECT_PIN_HIGH (15U) + + /** * @brief PCB/Hardware Revision Type */ @@ -32,3 +78,5 @@ enum hw_revision { enum hw_revision get_pcb_hardware_version(void); #endif /* _HW_VERSION_DETECT_H_ */ + +/** @} */ diff --git a/stm-firmware/include/reflow-controller/settings/settings.h b/stm-firmware/include/reflow-controller/settings/settings.h index 1742197..ca63fc5 100644 --- a/stm-firmware/include/reflow-controller/settings/settings.h +++ b/stm-firmware/include/reflow-controller/settings/settings.h @@ -18,7 +18,6 @@ * If not, see . */ - #ifndef __SETTINGS_SETTINGS_H__ #define __SETTINGS_SETTINGS_H__ diff --git a/stm-firmware/safety/fault.c b/stm-firmware/safety/fault.c index 21a9a38..44af36a 100644 --- a/stm-firmware/safety/fault.c +++ b/stm-firmware/safety/fault.c @@ -27,7 +27,6 @@ void HardFault_Handler(void) { /* This is a non recoverable fault. Stop the oven */ - oven_driver_set_power(0); oven_driver_apply_power_level();