Hi, When i use the can driver, i found that if there's no protect in the creation of semaphore.
When the CAN bus enter busoff state, i use FLEXCAN_DRV_Init to initialize the can controller. But when FLEXCAN_DRV_Init is called, it will call OSIF_SemaCreate((semaphore_t *const)&state->mbs[i].mbSema, 0U) to create the semaphore, no matter the semaphore is created or not.
So what should i do in this case?
Hello, On which platform did you observed this behavior, the release version you used ?
Did you run as baremetal or FreeRTOS, OSIF has different behavior ?
In case of bare metal :
The semaphores space should already be allocated before you call FLEXCAN_DRV_Init in the flexcan_state_t structure that is passed to the init function.
In the driver init function the semaphore is only enabled(initialized) by OSIF_SemaCreate((semaphore_t *const)&state->mbs[i].mbSema, 0U);
Hi, Alexandru, thank you for you reply.
The development enviroment is showed below:
MCU:S32k144
IDE:S32DS v2
SDK:0.8.4
FreeRTOS: Used
Because the rtos is used, the OSIF_SemaCreate() is ported to RTOS API xSemaphoreCreateCounting(). Whenever i call FLEXCAN_DRV_Init, it will call OSIF_SemaCreate((semaphore_t *const)&state->mbs[i].mbSema, 0U) to create the semaphore and it will consume the memory size from the freertos heap.This will cause the memory leak.
Hello,
All semaphores used by FlexCAN are destroyed when calling FLEXCAN_DRV_Deinit. There should not be two subsequent calls of FLEXCAN_DRV_Init without calling FLEXCAN_DRV_Deinit in the mean time. Though, the driver should report an error status if FLEXCAN_DRV_Init is called twice. We will investigate this scenario and thank you for reporting this issue.
Best regards,
Ana
Hi, Ana.
Maybe we can add a judgement when creating the semaphore. If the semaphore is created, we can ignore the following creating process.
For example:
In this case, if the driver fails to initialize, return code FLEXCAN_DRV_Init is different from STATUS_SUCCESS, you can call FLEXCAN_DRV_Deinit that will destroy the already allocated Semaphores. In this case you can avoid excessive allocations.