suikan4github / murasaki

STM32 HAL class library
MIT License
17 stars 3 forks source link

I2C legacy API of CubeHAL causes compile error on STM32H5 #155

Closed suikan4github closed 1 year ago

suikan4github commented 1 year ago

Describe the bug With STM32H5 target, the following code causes compile error.

https://github.com/suikan4github/murasaki/blob/7effc775287f58489d28ffa343e4ea2ad2827be2/core/i2cmaster.cpp#L222 https://github.com/suikan4github/murasaki/blob/7effc775287f58489d28ffa343e4ea2ad2827be2/core/i2cmaster.cpp#L256

The HAL_I2C_MasterSequentical_IT() is the legacy name. The new API is HAL_I2C_MasterSeq_IT(). Usually, CubeIDE generates code to make compatibility macro in the stm32_hal_legacy.h. But for the H5, the bug of the conditional check prevents making the macro.

#if defined(STM32H7) || defined(STM32WB) || defined(STM32G0) || defined(STM32F0) || defined(STM32F1) || \
    defined(STM32F2) || defined(STM32F3) || defined(STM32F4) || defined(STM32F7) || defined(STM32L0) || \
    defined(STM32L4) || defined(STM32L5) || defined(STM32G4) || defined(STM32L1)
#define HAL_I2C_Master_Sequential_Transmit_IT  HAL_I2C_Master_Seq_Transmit_IT
#define HAL_I2C_Master_Sequential_Receive_IT   HAL_I2C_Master_Seq_Receive_IT
#define HAL_I2C_Slave_Sequential_Transmit_IT   HAL_I2C_Slave_Seq_Transmit_IT
#define HAL_I2C_Slave_Sequential_Receive_IT    HAL_I2C_Slave_Seq_Receive_IT
#endif /* STM32H7 || STM32WB  || STM32G0 || STM32F0 || STM32F1 || STM32F2 || STM32F3 || STM32F4 || STM32F7 || STM32L0 ||
          STM32L4 || STM32L5 || STM32G4 || STM32L1 */

To Reproduce Steps to reproduce the behavior:

  1. Create aa STM32 project for STM32H5.
  2. Enable I2C support.
  3. Install murasaki for this project.

Then, obtain following error :

arm-none-eabi-g++ "../murasaki/core/i2sportadapter.cpp" -mcpu=cortex-m33 -std=gnu++14 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32H503xx -c -I../Core/Inc -I../Drivers/STM32H5xx_HAL_Driver/Inc -I../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32H5xx/Include -I../Drivers/CMSIS/Include -I../Middlewares/Third_Party/FreeRTOS/Source/include/ -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM33_NTZ/non_secure/ -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/ -I../Middlewares/Third_Party/CMSIS/RTOS2/Include/ -I../murasaki/core -O0 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti -fno-use-cxa-atexit -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"murasaki/core/i2sportadapter.d" -MT"murasaki/core/i2sportadapter.o" --specs=nano.specs -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb -o "murasaki/core/i2sportadapter.o"
../murasaki/core/i2cmaster.cpp: In member function 'virtual murasaki::I2cStatus murasaki::I2cMaster::TransmitThenReceive(unsigned int, const uint8_t*, unsigned int, uint8_t*, unsigned int, unsigned int*, unsigned int*, unsigned int)':
../murasaki/core/i2cmaster.cpp:222:18: error: 'HAL_I2C_Master_Sequential_Transmit_IT' was not declared in this scope; did you mean 'HAL_I2C_Master_Seq_Transmit_IT'?
  222 |         status = HAL_I2C_Master_Sequential_Transmit_IT(
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                  HAL_I2C_Master_Seq_Transmit_IT
../murasaki/core/i2cmaster.cpp:256:26: error: 'HAL_I2C_Master_Sequential_Receive_IT' was not declared in this scope; did you mean 'HAL_I2C_Master_Seq_Receive_IT'?
  256 |                 status = HAL_I2C_Master_Sequential_Receive_IT(
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                          HAL_I2C_Master_Seq_Receive_IT
make: *** [murasaki/core/subdir.mk:109: murasaki/core/i2cmaster.o] Error 1
make: *** Waiting for unfinished jobs....
"make -j4 all" terminated with exit code 2. Build might be incomplete.

Expected behavior ST is repeating this problem. See the report in the past .

We should not rely on the compatibility macro by ST. Stop to use the legacy API and use the new API.

suikan4github commented 1 year ago

Merged to develop. Ready to release.