Skip to content

Commit 7a4df09

Browse files
committed
[stm32] Default FDCAN to FIFO mode instead of Queue Mode
Queue Mode will send CAN frames in priority order according to their arbitration ID. This is inconsistent with modm's software-managed queue which is a strict FIFO. To make the behavior of the driver consistent with an end-to-end FIFO order, we disable Queue Mode by default. There is a new lbuild option, "tx_hw_queue_mode", which allows the user to opt back into the old behavior if desired. This is mostly intended for if they also set "buffer.tx" to zero and optionally increase "message_ram.tx_fifo_elements". Note that the fdcan unit test was implicitly assuming FIFO order. This change also fixes that test for larger HW TX buffer sizes.
1 parent a5223aa commit 7a4df09

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ modm::platform::Fdcan{{ id }}::initializeWithPrescaler(
257257
{{ reg }}->RXGFC |= (MessageRam::Config.filterCountStandard << FDCAN_RXGFC_LSS_Pos) | (MessageRam::Config.filterCountExtended << FDCAN_RXGFC_LSE_Pos);
258258
%%endif
259259

260+
%% if options["tx_hw_queue_mode"] == "Priority"
260261
// Tx buffer: queue mode
261262
{{ reg }}->TXBC |= FDCAN_TXBC_TFQM;
263+
%% endif
262264

263265
// Enable bit rate switching and CANFD frame format
264266
if(fdDataTimings) {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ namespace modm::platform
4040
* FDCAN instances.
4141
*
4242
* This driver supports SW-managed/in-memory FIFOs which augment the hardware TX
43-
* and RX FIFOs. Note that the HW TX queue is set to "queue mode" (not "FIFO mode").
44-
* This means CAN messages are popped from the in-memory FIFO in order of addition
45-
* but arbitrated according to ID priority within the HW queue.
43+
* and RX FIFOs. Note that the HW TX queue defaults to FIFO order but can be
44+
* configured to transmit the highest priority (lowest arbitration ID) frames
45+
* first.
4646
*
4747
* ## Filter
4848
%% if target["family"] == "h7"
@@ -59,6 +59,10 @@ namespace modm::platform
5959
* `buffer.rx` parameters. If set to 0, filling a HW FIFO will immediately drop
6060
* frames.
6161
*
62+
* The `tx_hw_queue_mode` configures the order in which frames are transmitted
63+
* from the hardware buffers. "FIFO" transmits in the order frames were enqueued.
64+
* "Priority" transmits the message with the lowest arbitration ID first.
65+
*
6266
%% if target["family"] == "h7"
6367
* You can configure the message RAM space allocation as follows:
6468
* - `message_ram.standard_filter_count`: Maximum number of standard (11-bit ID) acceptance filters

src/modm/platform/can/stm32-fdcan/module.lb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ from collections import defaultdict
1717

1818
global_properties = {}
1919

20+
tx_hw_queue_mode_description = """
21+
Controls the order in which frames are popped from the hardware TX queue (see
22+
message_ram.tx_fifo_elements). Does not affect the optional software buffer
23+
(buffer.tx), which is always popped in FIFO order.
24+
25+
FIFO: transmit frames in the order they were enqueued.
26+
Priority: transmit the frame with the lowest arbitration ID first.
27+
"""
28+
2029
message_ram_option_legacy_values = {
2130
"message_ram.standard_filter_count": 28,
2231
"message_ram.extended_filter_count": 8,
@@ -39,6 +48,13 @@ def load_options(module, options):
3948
minimum=0, maximum="64Ki-2",
4049
default=32))
4150

51+
module.add_option(
52+
EnumerationOption(
53+
name="tx_hw_queue_mode",
54+
description=tx_hw_queue_mode_description,
55+
default="FIFO",
56+
enumeration=["FIFO", "Priority"]))
57+
4258
supports_configurable_message_ram = options[":target"].identifier.family == "h7"
4359

4460
if supports_configurable_message_ram:

0 commit comments

Comments
 (0)