Enabling MCAN in Peripherals tool breaks SRAM calculation

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

Enabling MCAN in Peripherals tool breaks SRAM calculation

Jump to solution
1,081 Views
wilkinsw
Contributor III

LPC5516
MCUXpresso version 11.7.1
SDK version 2.13.0

When I enabled "Allocate messages RAM" for MCAN in the peripherals tool my SRAM usage goes from...

Memory region Used Size Region Size %age Used
PROGRAM_FLASH: 17660 B 244 KB 7.07%
SRAM: 8496 B 64 KB 12.96%
USB_RAM: 0 GB 16 KB 0.00%
SRAMX: 0 GB 16 KB 0.00%

to

Memory region Used Size Region Size %age Used
PROGRAM_FLASH: 20268 B 244 KB 8.11%
SRAM: 73964 B 64 KB 112.86%
USB_RAM: 0 GB 16 KB 0.00%
SRAMX: 0 GB 16 KB 0.00%

I have almost everything in the MCAN initialization set to zero, so it's only allocating 10 bytes. I assume it's something to do with the alignment.  What am I doing wrong?

0 Kudos
Reply
1 Solution
1,028 Views
MartinHo
Contributor IV

Hi the MCAN in the LPC55xx series needs to be alligned to 0x10000! 

see https://community.nxp.com/t5/LPC-Microcontrollers/CAN-base-address-align-restriction-in-LPC55/m-p/13...

for a solution.

What I did in my lates project is:

- define a memory section in the linker settings:

MartinHo_0-1688813009203.png

then define the MCAN Buffer area like this (for example in main.c):

uint32_t __attribute__((section (".CanBuffer")))CAN0_RAM_BASE_ADDRESS[CAN0_MESSAGE_RAM_SIZE] __attribute__ ((aligned (0x10000)));

Martin

View solution in original post

3 Replies
1,029 Views
MartinHo
Contributor IV

Hi the MCAN in the LPC55xx series needs to be alligned to 0x10000! 

see https://community.nxp.com/t5/LPC-Microcontrollers/CAN-base-address-align-restriction-in-LPC55/m-p/13...

for a solution.

What I did in my lates project is:

- define a memory section in the linker settings:

MartinHo_0-1688813009203.png

then define the MCAN Buffer area like this (for example in main.c):

uint32_t __attribute__((section (".CanBuffer")))CAN0_RAM_BASE_ADDRESS[CAN0_MESSAGE_RAM_SIZE] __attribute__ ((aligned (0x10000)));

Martin

970 Views
wilkinsw
Contributor III

Thanks, that helped quite a bit.

I understand now that the reason for the error is that the LPC5516 chip only has 0x10000 (64k) of SRAM.  So the only place the CAN buffer can go is right at the start. When the peripheral tool tries to align the buffer, the linker tries to place it at address 0x10000 after the start SRAM, i.e., at the very end of (and outside of) SRAM.

I'm not sure if there's a more elegant way of doing this, but I seem to have solved the problem by splitting the SRAM and adding a new 1k section in the Memory details.

wilkinsw_0-1689007546429.png

And then adding it in the extra linker script inputs as you suggested:

wilkinsw_1-1689007587190.png

And now the linker is happy:

wilkinsw_2-1689007612090.png

For anyone else that runs into this make sure you also disable "Allocate messages RAM" in the peripherals tool.  I expect it won't work properly on any chip with exactly 64k of SRAM

wilkinsw_3-1689007700717.png

 

0 Kudos
Reply
1,043 Views
frank_m
Senior Contributor III

In absence of any further information, I would say check the map file.
If necessary, compare the map files for both cases.

0 Kudos
Reply