Skip to content

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

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

Closed
ABOSTM opened this issue Aug 12, 2022 · 1 comment · Fixed by #1824
Labels
bug 🐛 Something isn't working
Milestone

Comments

@ABOSTM
Copy link
Contributor

ABOSTM commented Aug 12, 2022

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)) 
@ABOSTM ABOSTM added the bug 🐛 Something isn't working label Aug 12, 2022
This was referenced Aug 12, 2022
@fpistm
Copy link
Member

fpistm commented Aug 12, 2022

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

@ABOSTM ABOSTM 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 Aug 22, 2022
@fpistm fpistm added this to the 2.4.0 milestone Sep 1, 2022
fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Sep 1, 2022
@fpistm fpistm closed this as completed in 1a8f87a Sep 2, 2022
cparata pushed a commit to cparata/Arduino_Core_STM32 that referenced this issue Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants