Skip to main content
Associate II
July 20, 2023
Question

STM32U575 - USBPD_CAD_Init error wit Thread-Safe setting

  • July 20, 2023
  • 4 replies
  • 2727 views

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:

  1. _init_alloc() => _mutex_initialize(mutex_t *lock): initializes the mutex and returns 1.
  2. __ccp_initialize_aeabi_() => __armlib_thread_safety_init() : mark all mutexes as uninitialized

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

This topic has been closed for replies.

4 replies

HFISTM
ST Employee
July 21, 2023

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

PepilsAuthor
Associate II
July 21, 2023

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

Piranha
Principal III
July 23, 2023
PepilsAuthor
Associate II
September 14, 2023

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.

Piranha
Principal III
September 14, 2023

Put a breakpoint in _mutex_initialize() function. What happens there? Is it called at all?