diff --git a/Sts1CobcSw/FileSystem/FileSystem.hpp b/Sts1CobcSw/FileSystem/FileSystem.hpp index 97845dfa..07f124c1 100644 --- a/Sts1CobcSw/FileSystem/FileSystem.hpp +++ b/Sts1CobcSw/FileSystem/FileSystem.hpp @@ -18,7 +18,8 @@ extern lfs_file_t lfsFile; extern const lfs_config lfsConfig; -// Must be called once in a thread's init() function +// Must not be called in a thread's init() function since HardwareSpi::DoInitialize() uses a +// semaphore that doesn't work correctly there. auto Initialize() -> void; auto Format() -> int; auto Mount() -> int; diff --git a/Sts1CobcSw/Hal/HardwareSpi.hpp b/Sts1CobcSw/Hal/HardwareSpi.hpp index c7f1948b..174d4720 100644 --- a/Sts1CobcSw/Hal/HardwareSpi.hpp +++ b/Sts1CobcSw/Hal/HardwareSpi.hpp @@ -28,6 +28,8 @@ class HardwareSpi : public Spi private: + // Do not call this in the init() function of a thread. The semaphore doesn't work correctly + // there, making other SPIs silently fail to get initialized afterwards. auto DoInitialize(std::uint32_t baudRate, bool useOpenDrainOutputs) -> void override; auto Read(void * data, std::size_t nBytes, Duration timeout) -> void override; auto Write(void const * data, std::size_t nBytes, Duration timeout) -> void override; diff --git a/Sts1CobcSw/Periphery/Flash.cpp b/Sts1CobcSw/Periphery/Flash.cpp index da39ab0e..8a328c67 100644 --- a/Sts1CobcSw/Periphery/Flash.cpp +++ b/Sts1CobcSw/Periphery/Flash.cpp @@ -50,7 +50,6 @@ constexpr auto readStatusRegister2 = SimpleInstruction{.id = 0x35_b, .answerLeng constexpr auto readStatusRegister3 = SimpleInstruction{.id = 0x15_b, .answerLength = 1}; constexpr auto writeEnable = SimpleInstruction{.id = 0x06_b, .answerLength = 0}; constexpr auto writeDisable = SimpleInstruction{.id = 0x04_b, .answerLength = 0}; -constexpr auto enter4ByteAdressMode = SimpleInstruction{.id = 0xB7_b, .answerLength = 0}; constexpr auto readData4ByteAddress = 0x13_b; constexpr auto pageProgram4ByteAddress = 0x12_b; @@ -62,7 +61,6 @@ auto writeProtectionGpioPin = hal::GpioPin(hal::flashWriteProtectionPin); // --- Private function declarations --- -auto Enter4ByteAdressMode() -> void; auto EnableWriting() -> void; auto DisableWriting() -> void; auto IsBusy() -> bool; @@ -98,7 +96,6 @@ auto Initialize() -> void writeProtectionGpioPin.Set(); auto const baudRate = 48'000'000; Initialize(&flashSpi, baudRate); - Enter4ByteAdressMode(); } @@ -193,14 +190,6 @@ auto ActualBaudRate() -> std::int32_t // --- Private function definitions --- -auto Enter4ByteAdressMode() -> void -{ - csGpioPin.Reset(); - SendInstruction(); - csGpioPin.Set(); -} - - auto EnableWriting() -> void { csGpioPin.Reset(); diff --git a/Tests/GoldenTests/SpiSupervisor.test.cpp b/Tests/GoldenTests/SpiSupervisor.test.cpp index 2f22834e..f994a045 100644 --- a/Tests/GoldenTests/SpiSupervisor.test.cpp +++ b/Tests/GoldenTests/SpiSupervisor.test.cpp @@ -57,7 +57,6 @@ class SpiSupervisorTest : public RODOS::StaticThread<> rfSpi_.SetTransferEnd([]() { return transferEnd; }); rfSpi_.SetWrite(WriteThatFinishesInTime); fram::ram::SetAllDoFunctions(); - fram::Initialize(); } void run() override @@ -66,6 +65,8 @@ class SpiSupervisorTest : public RODOS::StaticThread<> PRINTF("\nSPI supervisor test\n\n"); + // The FRAM is required for the persistent variables + fram::Initialize(); PRINTF("Writing with implementation that finishes in time ...\n"); WriteTo(&flashSpi_, Span(0x00_b), 10 * ms); WriteTo(&framEpsSpi_, Span(0x00_b), 100 * ms); diff --git a/Tests/HardwareTests/DeviceIds.test.cpp b/Tests/HardwareTests/DeviceIds.test.cpp index fc1de601..856db09a 100644 --- a/Tests/HardwareTests/DeviceIds.test.cpp +++ b/Tests/HardwareTests/DeviceIds.test.cpp @@ -44,8 +44,6 @@ class DeviceIdsTest : public RODOS::StaticThread InitializeRfLatchupDisablePins(); led1GpioPin.Direction(hal::PinDirection::out); led1GpioPin.Reset(); - flash::Initialize(); - fram::Initialize(); } @@ -55,7 +53,9 @@ class DeviceIdsTest : public RODOS::StaticThread PRINTF("\nDevice IDs test\n\n"); + flash::Initialize(); PRINTF("Flash initialized\n"); + fram::Initialize(); PRINTF("FRAM initialized\n"); DisableRfLatchupProtection(); rf::Initialize(rf::TxType::morse); diff --git a/Tests/HardwareTests/Flash.test.cpp b/Tests/HardwareTests/Flash.test.cpp index 1757960b..d66dbb99 100644 --- a/Tests/HardwareTests/Flash.test.cpp +++ b/Tests/HardwareTests/Flash.test.cpp @@ -41,7 +41,6 @@ class FlashTest : public RODOS::StaticThread void init() override { InitializeRfLatchupDisablePins(); - flash::Initialize(); } @@ -52,6 +51,7 @@ class FlashTest : public RODOS::StaticThread PRINTF("\nFlash test\n\n"); PRINTF("\n"); + flash::Initialize(); auto actualBaudRate = flash::ActualBaudRate(); PRINTF("Actual baud rate: %" PRIi32 "\n", actualBaudRate); diff --git a/Tests/HardwareTests/Fram.test.cpp b/Tests/HardwareTests/Fram.test.cpp index 1d8bcb29..2fa656f3 100644 --- a/Tests/HardwareTests/Fram.test.cpp +++ b/Tests/HardwareTests/Fram.test.cpp @@ -51,7 +51,6 @@ class FramTest : public RODOS::StaticThread<> void init() override { InitializeRfLatchupDisablePins(); - fram::Initialize(); } @@ -62,6 +61,7 @@ class FramTest : public RODOS::StaticThread<> PRINTF("\nFRAM test\n\n"); PRINTF("\n"); + fram::Initialize(); auto actualBaudRate = fram::ActualBaudRate(); PRINTF("Actual baud rate: %" PRIi32 "\n", actualBaudRate); diff --git a/Tests/HardwareTests/Littlefs.test.cpp b/Tests/HardwareTests/Littlefs.test.cpp index 90c40565..aae2d4bb 100644 --- a/Tests/HardwareTests/Littlefs.test.cpp +++ b/Tests/HardwareTests/Littlefs.test.cpp @@ -31,7 +31,6 @@ class LittlefsTest : public RODOS::StaticThread auto init() -> void override { InitializeRfLatchupDisablePins(); - fs::Initialize(); } @@ -42,6 +41,7 @@ class LittlefsTest : public RODOS::StaticThread PRINTF("\n\nlittlefs test\n"); PRINTF("\n"); + fs::Initialize(); auto lfs = lfs_t{}; PRINTF("Formatting ...\n"); auto errorCode = lfs_format(&lfs, &fs::lfsConfig);