Multiple CAN channel usage issue in MPC5748G GW board using Free RTOS FlexCAN

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

Multiple CAN channel usage issue in MPC5748G GW board using Free RTOS FlexCAN

Jump to solution
2,130 Views
hims8111
Contributor II

Hi,

I am facing issue regarding memory allocation during task creation while using multiple FlexCAN channels in MPC5748G-GW board. I have used example shared on below Knowledge base link  https://community.nxp.com/t5/MPC5xxx-Knowledge-Base/Example-MPC5748G-FlexCAN-TX-RX-FreeRTOS-S32DS2-1...

CAN Tx and Rx task works fine with canCom1:FlexCAN (CAN1) as given in example. However, as per my application requirement, I have added one more CAN channel component with same settings is  canCom2:FlexCAN. (Please find attached image). After adding same initialization for CAN2 in hardware setup function, errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY error encountered during scheduler call.

At First, I was skeptical about freeRtos heap memory allocation (by default it was 16384). I checked by doubling it (32768). After that it has created tasks successfully but during execution it got in to DevAssert block in devassert.h. (So probably, my hardware doesn't have enough RAM to allocate dynamically during SendCANdata function call. please correct me if my understanding is wrong)

Could you please help me to understand is it possible to use multiple CAN channel for Transmission and Reception using Free RTOS? If yes, then what should I do to resolve this issue? Any help will be appreciated.

Thanks in advance.FreeRTOSexample-memoryAllocation-issue.PNG

 

 

 

 

 

0 Kudos
Reply
1 Solution
2,000 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

as far as I know this is due to driver over freertos "eats" a lot of Heap Memory for the semaphores for each MBs.

BR, Petr

View solution in original post

0 Kudos
Reply
6 Replies
2,054 Views
hims8111
Contributor II

Hi, 

Thanks for trying, I have modified your original example for target board MPC5748G-GW-RDB (Gateway board). So after initializing canCOM2 I was facing memory issue during scheduler call. However, I could figure out temporary workaround by increasing the FreeRTOS heap size more than 65000. But I still don't understand the significant memory requirement change after including 2 CAN channels. If you find the reason, please let me know.

Thanks.

0 Kudos
Reply
2,101 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

from which function you got devassert, can you identify the line?
What if beside increasing heap you also increase stack size, when creating task.

BR, Petr

0 Kudos
Reply
2,092 Views
hims8111
Contributor II

Hi, 

Thanks. I just checked by increasing stack depth to 1000 and checked but still the same. It goes to DevAssert section from xPortStartScheduler(). Please find attached image. I want to understand, how adding one more CAN channel impact the memory significantly?

hims8111_0-1630324543582.png

hims8111_1-1630324718016.png

 

 

My Current Configuration:

FreeRTOS Total heap size : Changed from 16384 to 32768

Tx and Rx task stack depth : 1000 (I guess its more than enough for two CAN channels, as one channel communication works with 200<Minimal_stack_size>)

I have also attached modified example with #define ENABLE_FLEXCAN2 in rtos.c file to check the difference in behavior by commenting/uncommenting it. 

Please let me know incase more details required form my side.

Thanks.

 

 

0 Kudos
Reply
2,061 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I tried the example on DEVKIT, but without connecting to bus, and it does not stop on any devassert.
What is your board and connection, in fact?

BR, Petr

0 Kudos
Reply
2,034 Views
hims8111
Contributor II

Hi, Thanks for trying, I have modified your original example for target board MPC5748G-GW-RDB (Gateway board). So after initializing canCOM2 I was facing memory issue during scheduler call. However, I could figure out temporary workaround by increasing the FreeRTOS heap size more than 65000. But I still don't understand the significant memory requirement change after including 2 CAN channels. If you find the reason, please let me know. Thanks.

0 Kudos
Reply
2,001 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

as far as I know this is due to driver over freertos "eats" a lot of Heap Memory for the semaphores for each MBs.

BR, Petr

0 Kudos
Reply