STMicroelectronics / STM32CubeL4

STM32Cube MCU Full Package for the STM32L4 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
262 stars 153 forks source link

stm32l4xx_hal_rcc embedding a directive within macro arguments is not portable #37

Closed lsuchocki closed 2 years ago

lsuchocki commented 3 years ago

Describe the set-up

Describe the bug When compiling with "-Wpedantic", throws the following warning (error with -Werror):

Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c: In function 'HAL_RCC_OscConfig':
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c:946:1: error: embedding a directive within macro arguments is not portable [-Werror]
  946 | #if defined(RCC_PLLP_SUPPORT)
      | ^
Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c:948:1: error: embedding a directive within macro arguments is not portable [-Werror]
  948 | #endif

How To Reproduce Compile with additional compiler flags be adding "CFLAGS += -Wpedantic -Werror" to Makefile

Additional context From the C standard, 6.10.3 Macro replacement: 11 [...] If there are sequences of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives, the behavior is undefined.

I believe the following patch could fix the issue (note line numbers are specific to v1.13.0):

--- a/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c       2021-06-30 17:51:13.772490643 -0500
+++ b/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c   2021-06-30 17:53:55.007765933 -0500
@@ -917,14 +917,20 @@
         }

         /* Configure the main PLL clock source, multiplication and division factors. */
+#if defined(RCC_PLLP_SUPPORT)
         __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
                              RCC_OscInitStruct->PLL.PLLM,
                              RCC_OscInitStruct->PLL.PLLN,
-#if defined(RCC_PLLP_SUPPORT)
                              RCC_OscInitStruct->PLL.PLLP,
-#endif
                              RCC_OscInitStruct->PLL.PLLQ,
                              RCC_OscInitStruct->PLL.PLLR);
+#else
+       __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
+                             RCC_OscInitStruct->PLL.PLLM,
+                             RCC_OscInitStruct->PLL.PLLN,
+                             RCC_OscInitStruct->PLL.PLLQ,
+                             RCC_OscInitStruct->PLL.PLLR);
+#endif

         /* Enable the main PLL. */
         __HAL_RCC_PLL_ENABLE();
RKOUSTM commented 3 years ago

Hi @lsuchocki,

Thank you for your reports.

According to the Development toolchains and compilers section of this release note, the STM32CubeIDE v1.5.1 - gcc version 7_2018_q2 and the STM32 System Workbench (SW4STM32) V2.7 toolchain are recommended for the STM32CubeL4 v1.17.0.

Your report regarding the C standard requirements for the RCC driver, will be forwarded to our development team. We will get back to you as soon as we have more details.

Thank you again for your reports.

With regards,

RKOUSTM commented 3 years ago

Hi @lsuchocki,

First we would like to thank you for your contribution.

The issue you pointed out is confirmed. An internal tracker has been logged and a fix will be implemented and made available in the frame of a future release to enhance the readability of the code. Also, this update is required by the gcc compiler.

Thank you once again for your contribution.

With regards,

RKOUSTM commented 3 years ago

ST Internal Reference: 110117

ALABSTM commented 2 years ago

Hi @lsuchocki,

I hope you are fine. The issue you reported has been fixed in the frame of version v1.17.1 of the STM32CubeL4 published recently on GitHub. Thank you again for having reported.

With regards,