2023-07-20 07:58 AM
Hello,
I am building an application using ThreadX, FileX, USBX and USBPD. Everyting runs perfectly until I bring USBPD in the game. Whatever I do, I always get an error when the library calls USBPD_CAD_Init().
More precisely, the function fails at a call to malloc when calling _mutex_aquire(mutex_t *lock). The error comes from the fact that the mutex is not initialized. This gives me a hardfault.
After some digging, I found out the mutex is well initialized at startup, but then uninitialized right away. The two related functions are called in this exact order:
It this expected?
I am using the "multi-threaded support" option and tried with different strategies (default, #2 and #3), always get the same result.
Environment
STM32CubeMX: v6.8.1
FW Package: STM32Cube FW_U5 V1.2.0
MCU: STM32U575VGTx
IDE: MDK-ARM v5.37
Board: custom
Many thanks in advance for anyone that can help
2023-07-21 07:30 AM
Hello @Pepils ,
The USBPD_CAD_Init functions calls some part of the USBPD lib which performs a dynamic allocation (malloc).
What is the return code of USBPD_CAD_Init ? Could it be USBPD_CAD_MALLOCERROR ?
You may want to try to increase the Heap in your linker settings.
Regards
2023-07-21 02:37 PM
Hello @HFISTM , thank you for your answer.
The USBPD_CAD_Init does not return anything as it is blocked in this code sample from armlib_lock_glue.c
/**
* @brief Acquire lock mutex
* @param lock The lock
*/
__attribute__((used)) void _mutex_acquire(mutex_t *lock)
{
STM32_LOCK_BLOCK_IF_NULL_ARGUMENT(lock);
stm32_lock_acquire(&static_list_lock);
if (STM32_LOCK_INITIALIZED(STM32_GET_LOCK_PTR(lock)) == 1)
{
stm32_lock_acquire(STM32_LOCK_PARAMETER(STM32_GET_LOCK_PTR(lock)));
}
else
{
STM32_LOCK_BLOCK(); ==> Blocking here
}
stm32_lock_release(&static_list_lock);
}
STM32_LOCK_BLOCK() doing the following:
#define STM32_LOCK_BLOCK() \
do \
{ \
__disable_irq(); \
Error_Handler(); \
while (1); \
} while (0)
The heap is currently set to 0x8000 which should be way more than needed.
Any idea?
KR
2023-07-23 11:37 AM
Probably not the issue here, but be warned:
2023-09-14 12:47 AM
Hello again,
I still haven't got it to work. Tried lots of configurations, nothing works. Can it be a problem with Keil? Because I see that everything happends in precompiled libraries dedicated to keil. And all example codes that are published in GitHub have an IOC file setup for EWARM.
I bought the STM32U575I-EV eval board so I can try flashing the example code without changing anything. Will see if this works.
PS: I moved to CubeMX V6.9.1 by the time, no differences.
2023-09-14 01:27 PM
Put a breakpoint in _mutex_initialize() function. What happens there? Is it called at all?