From b9de1918b45be7928614fec4fadaed54f52edb06 Mon Sep 17 00:00:00 2001 From: "E.T" Date: Fri, 9 Jun 2023 15:52:09 +0200 Subject: [PATCH] fix pmem -> make backup_ram_t data members volatile (#1135) * fix pmem -> make backup_ram_t data members volatile plus add calculated crc to the pmem debug screen * rename pmem debug menu to p.mem As this is how its refered to in the wiki and other screens * p.mem looked strange with capital P --------- Co-authored-by: Eisenberger Tamas --- firmware/application/apps/ui_debug.cpp | 20 ++++++++++++++++--- firmware/application/apps/ui_debug.hpp | 7 ++++--- .../common/portapack_persistent_memory.cpp | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/firmware/application/apps/ui_debug.cpp b/firmware/application/apps/ui_debug.cpp index b9467eb4..fdc5f6ca 100644 --- a/firmware/application/apps/ui_debug.cpp +++ b/firmware/application/apps/ui_debug.cpp @@ -25,6 +25,7 @@ #include "radio.hpp" #include "string_format.hpp" +#include "crc.hpp" #include "audio.hpp" @@ -381,22 +382,35 @@ DebugMenuView::DebugMenuView(NavigationView& nav) { {"Peripherals", ui::Color::dark_cyan(), &bitmap_icon_peripherals, [&nav]() { nav.push(); }}, {"Temperature", ui::Color::dark_cyan(), &bitmap_icon_temperature, [&nav]() { nav.push(); }}, {"Buttons Test", ui::Color::dark_cyan(), &bitmap_icon_controls, [&nav]() { nav.push(); }}, - {"Pmem", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push(); }}, + {"p.mem", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push(); }}, }); set_max_rows(2); // allow wider buttons } /* DebugPmemView *********************************************************/ +uint32_t pmem_checksum(volatile const uint32_t data[63]) { + CRC<32> crc{0x04c11db7, 0xffffffff, 0xffffffff}; + for (size_t i = 0; i < 63; i++) { + const auto word = data[i]; + crc.process_byte((word >> 0) & 0xff); + crc.process_byte((word >> 8) & 0xff); + crc.process_byte((word >> 16) & 0xff); + crc.process_byte((word >> 24) & 0xff); + } + return crc.checksum(); +} + DebugPmemView::DebugPmemView(NavigationView& nav) : data{*reinterpret_cast(memory::map::backup_ram.base())}, registers_widget(RegistersWidgetConfig{page_size, 8}, std::bind(&DebugPmemView::registers_widget_feed, this, std::placeholders::_1)) { static_assert(sizeof(pmem_data) == memory::map::backup_ram.size()); - add_children({&text_page, ®isters_widget, &text_checksum, &button_ok}); + add_children({&text_page, ®isters_widget, &text_checksum, &text_checksum2, &button_ok}); registers_widget.set_parent_rect({0, 32, 240, 192}); - text_checksum.set("Size: " + to_string_dec_uint(portapack::persistent_memory::data_size()) + " CRC: " + to_string_hex(data.check_value, 8)); + text_checksum.set("Size: " + to_string_dec_uint(portapack::persistent_memory::data_size(), 3) + " CRC: " + to_string_hex(data.check_value, 8)); + text_checksum2.set("Calculated CRC: " + to_string_hex(pmem_checksum(data.regfile), 8)); button_ok.on_select = [&nav](Button&) { nav.pop(); diff --git a/firmware/application/apps/ui_debug.hpp b/firmware/application/apps/ui_debug.hpp index 31158d6c..b24a9625 100644 --- a/firmware/application/apps/ui_debug.hpp +++ b/firmware/application/apps/ui_debug.hpp @@ -269,7 +269,7 @@ class DebugPmemView : public View { DebugPmemView(NavigationView& nav); void focus() override; bool on_encoder(const EncoderEvent delta) override; - std::string title() const override { return "Pmem"; } + std::string title() const override { return "p.mem"; } private: struct pmem_data { @@ -282,13 +282,14 @@ class DebugPmemView : public View { int32_t page{0}; - const pmem_data& data; + volatile const pmem_data& data; Text text_page{{16, 16, 208, 16}}; RegistersWidget registers_widget; - Text text_checksum{{16, 240, 208, 16}}; + Text text_checksum{{16, 232, 208, 16}}; + Text text_checksum2{{16, 248, 208, 16}}; Button button_ok{ {240 / 3, 270, 240 / 3, 24}, diff --git a/firmware/common/portapack_persistent_memory.cpp b/firmware/common/portapack_persistent_memory.cpp index a48d10f2..97d3bfc7 100644 --- a/firmware/common/portapack_persistent_memory.cpp +++ b/firmware/common/portapack_persistent_memory.cpp @@ -354,8 +354,8 @@ struct data_t { struct backup_ram_t { private: - uint32_t regfile[63]; - uint32_t check_value; + volatile uint32_t regfile[63]; + volatile uint32_t check_value; static void copy(const backup_ram_t& src, backup_ram_t& dst) { for (size_t i = 0; i < 63; i++) {