Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: clock: stm32: stm32c03 fail to build #83543

Closed
nandojve opened this issue Jan 3, 2025 · 2 comments
Closed

drivers: clock: stm32: stm32c03 fail to build #83543

nandojve opened this issue Jan 3, 2025 · 2 comments
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32

Comments

@nandojve
Copy link
Member

nandojve commented Jan 3, 2025

Describe the bug

The stm32c0 fail to build because of missing apb2_prescaler.

Expected behavior
All stm32 SoC should build with a default value for apb to avoid this issue.

Impact
Not possible to build when using timers3.

include/generated/zephyr/devicetree_generated.h:931:36: error: 'DT_N_S_soc_S_rcc_40021000_P_apb2_prescaler' undeclared (first use in this function); did you mean 'DT_N_S_soc_S_rcc_40021000_P_apb1_prescaler'?
  931 | #define DT_N_NODELABEL_rcc         DT_N_S_soc_S_rcc_40021000
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
include/zephyr/devicetree.h:5231:29: note: in definition of macro 'DT_CAT3'
 5231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
include/zephyr/drivers/clock_control/stm32_clock_control.h:73:33: note: in expansion of macro 'DT_PROP'
   73 | #define STM32_APB2_PRESCALER    DT_PROP(DT_NODELABEL(rcc), apb2_prescaler)
      |                                 ^~~~~~~

Environment (please complete the following information):

  • OS: Linux
  • Toolchain Zephyr SDK 0.17
  • Commit mainline
@nandojve nandojve added the bug The issue is a bug, or the PR is fixing a bug label Jan 3, 2025
@nandojve nandojve self-assigned this Jan 3, 2025
nandojve added a commit to nandojve/zephyr that referenced this issue Jan 3, 2025
The stm32c0 fail to build when using timer3 because of missing
apb2_prescaler definition. This add a default value to fix the
issue.

Fixes zephyrproject-rtos#83543

Signed-off-by: Gerson Fernando Budke <[email protected]>
nandojve added a commit to FreedomVeiculosEletricos/zephyr that referenced this issue Jan 3, 2025
The stm32c0 fail to build when using timer3 because of missing
apb2_prescaler definition. This add a default value to fix the
issue.

Fixes zephyrproject-rtos#83543

Signed-off-by: Gerson Fernando Budke <[email protected]>
@henrikbrixandersen henrikbrixandersen added the platform: STM32 ST Micro STM32 label Jan 4, 2025
@mathieuchopstm
Copy link
Collaborator

I have not been able to reproduce this error by building both samples/drivers/counter/alarm/ and tests/drivers/pwm/pwm_api/ for board nucleo_c031c6, and the error message you provided does not indicate in which place the macro is being expanded.

As far as I can tell, there are only three places where STM32_APB2_PRESCALER is used, all of which make sure the property exists before using the macro, so I'm a bit confused as to where it comes from.

Can you please give instructions on how to reproduce the issue?


  1. Should not cause the error: gated behind property existance check

    #if DT_NODE_HAS_PROP(DT_NODELABEL(rcc), apb2_prescaler)
    uint32_t apb2_clock = get_bus_clock(ahb_clock, STM32_APB2_PRESCALER);
    #elif defined(STM32_CLOCK_BUS_APB2)

  2. Should not cause the error: gated behind !CONFIG_SOC_SERIES_STM32C0X

    #if !defined(CONFIG_SOC_SERIES_STM32C0X) && !defined(CONFIG_SOC_SERIES_STM32F0X) && \
    !defined(CONFIG_SOC_SERIES_STM32G0X) && !defined(CONFIG_SOC_SERIES_STM32U0X)
    else {
    #if defined(CONFIG_SOC_SERIES_STM32MP1X)
    apb_psc = (uint32_t)(READ_BIT(RCC->APB2DIVR, RCC_APB2DIVR_APB2DIV));
    #else
    apb_psc = STM32_APB2_PRESCALER;
    #endif
    }
    #endif

  3. Should not cause the error: gated behind !HAS_COMPAT(st,stm32f0-rcc)

    #if !DT_HAS_COMPAT_STATUS_OKAY(st_stm32f0_rcc)
    else {
    #if defined(CONFIG_SOC_SERIES_STM32MP1X)
    apb_psc = (uint32_t)(READ_BIT(RCC->APB2DIVR, RCC_APB2DIVR_APB2DIV));
    #else
    apb_psc = STM32_APB2_PRESCALER;
    #endif /* CONFIG_SOC_SERIES_STM32MP1X */
    }
    #endif /* ! st_stm32f0_rcc */

    which is the compatible used by STM32C0 RCC:
    rcc: rcc@40021000 {
    compatible = "st,stm32f0-rcc";

@nandojve
Copy link
Member Author

nandojve commented Jan 6, 2025

Hi @mathieuchopstm ,

You are right! This was found initially when the #70951 was open. I was searching on mainline about STM32_APB2_PRESCALER, after your report, and found that current PWM driver have a different implementation we have on #70951.

#if !defined(CONFIG_SOC_SERIES_STM32C0X) && !defined(CONFIG_SOC_SERIES_STM32F0X) && \
!defined(CONFIG_SOC_SERIES_STM32G0X) && !defined(CONFIG_SOC_SERIES_STM32U0X)
else {
#if defined(CONFIG_SOC_SERIES_STM32MP1X)
apb_psc = (uint32_t)(READ_BIT(RCC->APB2DIVR, RCC_APB2DIVR_APB2DIV));
#else
apb_psc = STM32_APB2_PRESCALER;
#endif
}
#endif
#endif

With this it is not necessary the #83544 patch since the problem was found inside the freq-meter.

@nandojve nandojve closed this as completed Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants