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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
3,309 次查看
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 项奖励
回复
1 解答
3,179 次查看
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 项奖励
回复
6 回复数
3,233 次查看
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 项奖励
回复
3,280 次查看
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 项奖励
回复
3,271 次查看
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 项奖励
回复
3,240 次查看
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 项奖励
回复
3,213 次查看
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 项奖励
回复
3,180 次查看
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 项奖励
回复