cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX generated code doesn't work when mixing use HAL and LL

why_q
Associate II

My project running on STM32G071 uses LL drivers for ADC and USART. The configuration code is generated by STM32CubeMX.  It works fine. However after adding I2C HAL module which connects to a sensor to the project, the I2C function HAL_I2C_IsDeviceReady() always returns HAL_ERROR. 

To investigate it, I created a simple project. It only has I2C. If selecting HAL driver for RCC and GPIO in the CubeMX, the returns from HAL_I2C_IsDeviceReady()  and HAL_I2C_Mem_Read() are correct. 

why_q_0-1696428687162.png

but it selects LL drivers for RCC and GPIO, and I2C stays as HAL, the return from HAL_I2C_IsDeviceReady()  is HAL_ERROR.

why_q_1-1696429012212.png

Any idea what is wrong? Is it possible to mix use HAL and LL like this?

Many thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Foued_KH
ST Employee

Hello @why_q , 

Yes you can mix HAL and LL : 
I couldn't reproduce your issue!

Foued_KH_0-1696586313956.pngFoued_KH_1-1696586328721.png

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

5 REPLIES 5
Foued_KH
ST Employee

Hello @why_q , 

Yes you can mix HAL and LL : 
I couldn't reproduce your issue!

Foued_KH_0-1696586313956.pngFoued_KH_1-1696586328721.png

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Foued,

Thank you for your reply and sorry to hear that you couldn't repeat the issue.

My project was created by Keil uVision, ran CubeMX from there.  The below is the code.  If selecting  LL for RCC and GPIO, the return from HAL_I2C_IsDeviceReady() is HAL_ERROR

why_q_0-1699284615594.png

 

 

Could you take an oscilloscope and check the SDA & SCL behavior.
If you have NACK, you should set the correct address.

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I don't have an oscilloscope. Just wondering why it works correctly if choosing HAL for RCC and GPIO.

Hi Foued,

Just let you know I tried to create a project using CubeIDE.  The issue  didn't happen. It worked on HAL and LL.  Don't understand why using Keil has this problem.