Skip to content

Commit

Permalink
[stm32] Fix initialization of FDCAN message RAM
Browse files Browse the repository at this point in the history
After power-on the FDCAN message RAM is filled with non-zero invalid
data. In some cases the CAN filter region contains well-formed entries
which cause inadvertent reception or rejection of messages.

To prevent this message RAM sections are now zeroed out on the first
initialization of the respective FDCAN instance.
  • Loading branch information
chris-durand authored and WasabiFan committed Sep 25, 2024
1 parent 9e7bdf4 commit 3614dc0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modm/platform/can/common/fdcan/message_ram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,15 @@ class MessageRam
{
return messageRamWord(FilterListExtended(), index * ExtendedFilterSize);
}

public:
static void
zeroAllData()
{
for (uint32_t word = 0; word < Config.totalSectionWords(); ++word)
*messageRamWord(RamBase, word) = 0;
}

/// Write TX element headers to TX queue
static void
writeTxHeaders(uint8_t putIndex, CommonFifoHeader_t common, TxFifoHeader_t tx)
Expand Down
4 changes: 4 additions & 0 deletions src/modm/platform/can/stm32-fdcan/can.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ modm::platform::Fdcan{{ id }}::initializeWithPrescaler(
static_assert(MessageRam::Config.txFifoSectionOffset() + MessageRam::Config.txFifoSectionWords() == MessageRam::Config.totalSectionWords());

MessageRam::setRamBase(SRAMCAN_BASE + (messageRamBaseWords * MessageRam::RamWordSize));
if (!messageRamInitialized_) {
MessageRam::zeroAllData();
messageRamInitialized_ = true;
}

%% if target["family"] == "h7"
// Configure number of elements in each RAM section
Expand Down
1 change: 1 addition & 0 deletions src/modm/platform/can/stm32-fdcan/can.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private:
using MessageRam = fdcan::MessageRam<{{ id - 1 }}, fdcan::Fdcan{{id}}MessageRamConfig>;

static inline volatile ErrorCallback errorCallback_ = nullptr;
static inline bool messageRamInitialized_{false};

static void
initializeWithPrescaler(
Expand Down

0 comments on commit 3614dc0

Please sign in to comment.