Skip to content

Commit

Permalink
Fix failing device ID and flash tests (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickKa authored Jan 20, 2025
2 parents c1ffc6b + 609214b commit 2c470fc
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Sts1CobcSw/FileSystem/FileSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Sts1CobcSw/Hal/HardwareSpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 0 additions & 11 deletions Sts1CobcSw/Periphery/Flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -98,7 +96,6 @@ auto Initialize() -> void
writeProtectionGpioPin.Set();
auto const baudRate = 48'000'000;
Initialize(&flashSpi, baudRate);
Enter4ByteAdressMode();
}


Expand Down Expand Up @@ -193,14 +190,6 @@ auto ActualBaudRate() -> std::int32_t

// --- Private function definitions ---

auto Enter4ByteAdressMode() -> void
{
csGpioPin.Reset();
SendInstruction<enter4ByteAdressMode>();
csGpioPin.Set();
}


auto EnableWriting() -> void
{
csGpioPin.Reset();
Expand Down
3 changes: 2 additions & 1 deletion Tests/GoldenTests/SpiSupervisor.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class SpiSupervisorTest : public RODOS::StaticThread<>
rfSpi_.SetTransferEnd([]() { return transferEnd; });
rfSpi_.SetWrite(WriteThatFinishesInTime);
fram::ram::SetAllDoFunctions();
fram::Initialize();
}

void run() override
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Tests/HardwareTests/DeviceIds.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class DeviceIdsTest : public RODOS::StaticThread<stackSize>
InitializeRfLatchupDisablePins();
led1GpioPin.Direction(hal::PinDirection::out);
led1GpioPin.Reset();
flash::Initialize();
fram::Initialize();
}


Expand All @@ -55,7 +53,9 @@ class DeviceIdsTest : public RODOS::StaticThread<stackSize>

PRINTF("\nDevice IDs test\n\n");

flash::Initialize();
PRINTF("Flash initialized\n");
fram::Initialize();
PRINTF("FRAM initialized\n");
DisableRfLatchupProtection();
rf::Initialize(rf::TxType::morse);
Expand Down
2 changes: 1 addition & 1 deletion Tests/HardwareTests/Flash.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class FlashTest : public RODOS::StaticThread<stackSize>
void init() override
{
InitializeRfLatchupDisablePins();
flash::Initialize();
}


Expand All @@ -52,6 +51,7 @@ class FlashTest : public RODOS::StaticThread<stackSize>
PRINTF("\nFlash test\n\n");

PRINTF("\n");
flash::Initialize();
auto actualBaudRate = flash::ActualBaudRate();
PRINTF("Actual baud rate: %" PRIi32 "\n", actualBaudRate);

Expand Down
2 changes: 1 addition & 1 deletion Tests/HardwareTests/Fram.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class FramTest : public RODOS::StaticThread<>
void init() override
{
InitializeRfLatchupDisablePins();
fram::Initialize();
}


Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Tests/HardwareTests/Littlefs.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class LittlefsTest : public RODOS::StaticThread<stackSize>
auto init() -> void override
{
InitializeRfLatchupDisablePins();
fs::Initialize();
}


Expand All @@ -42,6 +41,7 @@ class LittlefsTest : public RODOS::StaticThread<stackSize>
PRINTF("\n\nlittlefs test\n");

PRINTF("\n");
fs::Initialize();
auto lfs = lfs_t{};
PRINTF("Formatting ...\n");
auto errorCode = lfs_format(&lfs, &fs::lfsConfig);
Expand Down

0 comments on commit 2c470fc

Please sign in to comment.