Skip to content

Commit 3614dc0

Browse files
chris-durandWasabiFan
authored andcommitted
[stm32] Fix initialization of FDCAN message RAM
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.
1 parent 9e7bdf4 commit 3614dc0

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/modm/platform/can/common/fdcan/message_ram.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,15 @@ class MessageRam
270270
{
271271
return messageRamWord(FilterListExtended(), index * ExtendedFilterSize);
272272
}
273+
273274
public:
275+
static void
276+
zeroAllData()
277+
{
278+
for (uint32_t word = 0; word < Config.totalSectionWords(); ++word)
279+
*messageRamWord(RamBase, word) = 0;
280+
}
281+
274282
/// Write TX element headers to TX queue
275283
static void
276284
writeTxHeaders(uint8_t putIndex, CommonFifoHeader_t common, TxFifoHeader_t tx)

src/modm/platform/can/stm32-fdcan/can.cpp.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ modm::platform::Fdcan{{ id }}::initializeWithPrescaler(
216216
static_assert(MessageRam::Config.txFifoSectionOffset() + MessageRam::Config.txFifoSectionWords() == MessageRam::Config.totalSectionWords());
217217

218218
MessageRam::setRamBase(SRAMCAN_BASE + (messageRamBaseWords * MessageRam::RamWordSize));
219+
if (!messageRamInitialized_) {
220+
MessageRam::zeroAllData();
221+
messageRamInitialized_ = true;
222+
}
219223

220224
%% if target["family"] == "h7"
221225
// Configure number of elements in each RAM section

src/modm/platform/can/stm32-fdcan/can.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private:
111111
using MessageRam = fdcan::MessageRam<{{ id - 1 }}, fdcan::Fdcan{{id}}MessageRamConfig>;
112112

113113
static inline volatile ErrorCallback errorCallback_ = nullptr;
114+
static inline bool messageRamInitialized_{false};
114115

115116
static void
116117
initializeWithPrescaler(

0 commit comments

Comments
 (0)