Message Buffer instead of FIFO

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Message Buffer instead of FIFO

708 Views
vigneshv1
Contributor I

Hello NXP community,

I am using S32K3.

I have few question about FLexCAN module.

1)So I can not able to use FIFO for transmit purpose right?

2)I can use Message Buffer for receive purpose instead of FIFO right?

3)If I am using FIFO means, when can I use enhanced FIFO and Legacy FIFO?

4)And these message buffer address are mapped with SRAM right?

Thanks for your time and replies. 

0 Kudos
Reply
5 Replies

685 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

1) correct, as the name "RX FIFO" indicates, it is for receiving CAN messages only.
2) the MB can be set either for RX or TX operation
3) yes, FlexCAN has two FIFO options, Legacy RX FIFO and Enhanced RX FIFO, but both options cannot be enabled at the same time. When CAN FD is enabled the legacy RX FIFO cannot be used. That's why enhanced RX FIFO was introduced and it can store up to 20 CAN FD messages.  Classic CAN messages can be stored in Enhanced RX FIFO as well.
4) Message buffers are mapped in FlexCAN embedded RAM starting at address offset 0080h. See chapter 73.6.5 FlexCAN message buffer memory map

BR, Petr

0 Kudos
Reply

683 Views
vigneshv1
Contributor I

Hi @PetrS ,

Thanks for your reply.

If I am using only 2 message buffers. out of which one for Rx one for Tx.

In this case how can I use unused message buffer area as general purpose RAM.

0 Kudos
Reply

646 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

If for example on FlexCAN0, which has 96 MBs, and you use only 2, without legacy RXFIFO:

  • Set MAXMB = 1 (MB0 and MB1 used).
  • MB2 to MB95 are unused.
  • You can use the RAM starting from MB2’s address (e.g., 0x0080h + 2 * MB_SIZE) as general-purpose RAM.

below is possible implementation

#include "S32K344.h"  

#define FLEXCAN0_BASE      0x40024000UL
#define FLEXCAN_MB_OFFSET  0x80UL       // MBs start at offset 0x80
#define FLEXCAN_MB_SIZE    0x10UL       // Each MB is 16 bytes, assuming 8byte payload

// Calculate address of MB2 (unused)
#define MB2_ADDR (FLEXCAN0_BASE + FLEXCAN_MB_OFFSET + (2 * FLEXCAN_MB_SIZE))

void write_to_unused_mb_ram(void) {
    volatile uint32_t* mb2_ptr = (uint32_t*)MB2_ADDR;

    // Write some data
    mb2_ptr[0] = 0xDEADBEEF;
    mb2_ptr[1] = 0x12345678;
    mb2_ptr[2] = 0xABCDEF01;
    mb2_ptr[3] = 0x0BADF00D;

    // Read back
    uint32_t val0 = mb2_ptr[0];
    uint32_t val1 = mb2_ptr[1];

    // Use val0, val1 as needed

 BR, Petr

0 Kudos
Reply

614 Views
vigneshv1
Contributor I

Hi @PetrS ,

Thanks for continuous reply.

Is it possible if I am specifying  these Message Buffer address in different section linker script, then I can place the variable using compiler attribute like, int a __attribute__(section("message buffer section")) ?

0 Kudos
Reply

599 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

yes, it would be possible.

BR, Petr

0 Kudos
Reply