diff --git a/doc/source/firmware/backup-ram.rst b/doc/source/firmware/backup-ram.rst index 2fab0d4..f24b189 100644 --- a/doc/source/firmware/backup-ram.rst +++ b/doc/source/firmware/backup-ram.rst @@ -68,19 +68,22 @@ Weight override ``0xA2`` ``Weight`` ``Flag Number`` res Persistance override ``0x8E`` ``Persistance`` ``Flag Number`` reserved don't care (written as 0xBB) ======================= ============ ================= ===================== ===================================== +All words, not matching the table above are ignored and do not cause an error. By default the firmware fills this memory area with zeroes. Error Memory ~~~~~~~~~~~~ The error memory contains error entries in form of 32 bit words. The entries are coded as stated below. -``Error Flag`` entries are used to restore error flags after boot. In theory, all flags can be set using this entry type, -however, only persistent flags are stored in the error memory by the firmware. +``Error Flag`` entries are used to restore error flags after boot. In theory, all flags can be set using this entry type. +However, only persistent flags are stored in the error memory by the firmware. ``NOP`` entries have no meaning. They are used as a filler. When adding a new error memory entry, the error memory is scanned until the first ``NOP`` entry is found. It is replaced with a valid entry. If the error memory contains a word, that is not defined below, it is considered invalid and will trigger the RAM checker on boot. -``NOP`` entries can be used to preallocate the error memory in advance. +``NOP`` entries can be used to preallocate the error memory in advance. if the end of the error memory is reached, it is expanded by 1 word to first +the new error entry, until the backup RAM is full. After this, no further errors are stored. +If the same persistent error is triggered mutliple times, the ``COUNTER`` in the error entry is incremented. ======================= ============ ================= ===================== ===================================== Entry Byte 1 (LSB) Byte 2 Byte 3 Byte 4 (MSB) diff --git a/stm-firmware/include/reflow-controller/safety/safety-memory.h b/stm-firmware/include/reflow-controller/safety/safety-memory.h index 8ef7531..d306b37 100644 --- a/stm-firmware/include/reflow-controller/safety/safety-memory.h +++ b/stm-firmware/include/reflow-controller/safety/safety-memory.h @@ -28,6 +28,11 @@ */ #define SAFETY_MEMORY_MAGIC 0x12AA5CB7 +/** + * @brief Error memory NOP entry + */ +#define SAFETY_MEMORY_NOP_ENTRY 0xC1AA1222 + /** * @brief Offset address for the safety_memory_header. * @note Any other value than 0UL doesn't really make sense. Therfore, this should not be changed. diff --git a/stm-firmware/main.c b/stm-firmware/main.c index a43e42f..93a95bd 100644 --- a/stm-firmware/main.c +++ b/stm-firmware/main.c @@ -154,14 +154,12 @@ static inline void setup_system(void) setup_nvic_priorities(); systick_setup(); - oven_driver_init(); digio_setup_default_all(); led_setup(); loudspeaker_setup(); reflow_menu_init(); - uart_gpio_config(); setup_shell_uart(&shell_uart); diff --git a/stm-firmware/safety/safety-memory.c b/stm-firmware/safety/safety-memory.c index 0cb3239..a1915b4 100644 --- a/stm-firmware/safety/safety-memory.c +++ b/stm-firmware/safety/safety-memory.c @@ -239,6 +239,35 @@ int safety_memory_set_boot_status(const struct safety_memory_boot_status *status return 0; } +static int safety_memory_check_error_entries() +{ + struct safety_memory_header header; + uint32_t addr; + uint32_t data; + int ret = 0; + int res; + + if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) { + return -2000; + } + + for (addr = header.err_memory_offset; addr < header.err_memory_end; addr++) { + res = backup_ram_get_data(addr, &data, 1UL); + if (res) + return -100; + + /* Valid flag entry */ + if ((data & 0xFF) == 0x51) + continue; + if (data == SAFETY_MEMORY_NOP_ENTRY) + continue; + + ret--; + } + + return ret; +} + int safety_memory_get_error_entry_count(uint32_t *count); int safety_memory_check(void) @@ -246,6 +275,10 @@ int safety_memory_check(void) int res; res = safety_memory_check_crc(); + if (!res) { + res |= safety_memory_check_error_entries(); + } + return -!!res; }