Skip to content

Compilation error with STM32F051R4, STM32_F058R8 and STM32L010C6. Alternate function without AF registers  #1798

Closed

Description

@ABOSTM

Describe the bug
CI compilation failed for several MCU:

/github/home/.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/variants/STM32F0xx/F051R4T/PeripheralPins.c:128:69: error: 'GPIO_AF0_TIM3' undeclared here (not in a function); did you mean 'GPIO_AF1_TIM3'?
  128 |   {PC_8,       TIM3,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM3, 3, 0)}, // TIM3_CH3
      |                                                                     ^~~~~~~~~~~~~
/github/home/.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/cores/arduino/stm32/PinNamesTypes.h:88:26: note: in definition of macro 'STM_PIN_DEFINE_EXT'
   88 |                        ((AFNUM  & STM_PIN_AFNUM_MASK) << STM_PIN_AFNUM_SHIFT) |\
      |                          ^~~~~
/github/home/.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/variants/STM32F0xx/F051R4T/PeripheralPins.c:128:23: note: in expansion of macro 'STM_PIN_DATA_EXT'
  128 |   {PC_8,       TIM3,  STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF0_TIM3, 3, 0)}, // TIM3_CH3
      |                       ^~~~~~~~~~~~~~~~
Error during build: exit status 1
|  76/325  | GENERIC_F051R4TX                           |   failed   | 19.23 s |

Analysis
1st analysis shows that some GPIO specificities are not properly managed:
For example, STM32F051R4 has Port C.
On PC8 we can access to Alternate function TIM3_CH3.
But this GPIO port (PORTC) doesn't have register GPIOx_AFRL/GPIOx_AFRH registers,
there is a unique Alternate capability which is TIM3_CH3, no register to select it, it is default.
This is the reason why define GPIO_AF0_TIM3 doesn't exist, there is no register to enter this value.

This is subtly mentioned in Reference Manual RM0091 Rev 10

8.1 Introduction
Each general-purpose I/O port has four 32-bit configuration registers (GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR and 
GPIOx_PUPDR), two 32-bit data registers (GPIOx_IDR and GPIOx_ODR) and a 32-bit set/reset register (GPIOx_BSRR). 
Ports A and B also have a 32-bit locking register (GPIOx_LCKR) and two 32-bit alternate function selection registers 
(GPIOx_AFRH and GPIOx_AFRL).
On STM32F07x and STM32F09x devices, also ports C, D, E, and F have two 32-bit alternate function selection registers 
(GPIOx_AFRH and GPIOx_AFRL).

Also in CMSIS there is a define which clearly state that only port A and port B support Alternate registers (for stm32f051x8),
it may be useful for a potential fix:

#define IS_GPIO_AF_INSTANCE(INSTANCE) (((INSTANCE) == GPIOA) || \

#define IS_GPIO_AF_INSTANCE(INSTANCE)   (((INSTANCE) == GPIOA) || \
                                         ((INSTANCE) == GPIOB)) 

Activity

  1. added
    bug 🐛
    on Aug 12, 2022
  2. fpistm commented on Aug 12, 2022

    @fpistm
    Member

    As it is generated, I would have a look to the xml description files from stm32 open database

  3. changed the title [-]Compilation error with STM32F051R4, GENERIC_F058R8, STM32L010C6. Alternate function without AF registers [/-] [+]Compilation error with STM32F051R4, STM32_F058R8 and STM32L010C6. Alternate function without AF registers [/+] on Aug 22, 2022
  4. added this to the 2.4.0 milestone on Sep 1, 2022
  5. added a commit that references this issue on Sep 1, 2022
    deca336
  6. added a commit that references this issue on Jan 31, 2023
    f16e74d
  7. added a commit that references this issue on Jun 22, 2024
    1a8f87a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions