Skip to main content
Visitor II
March 2, 2020
Solved

Can we test if GPIO PC3 is present on STM32F412CE with HAL_Driver Library ?

  • March 2, 2020
  • 3 replies
  • 1359 views

Hi,

I've two kind of STM32CubeMX project : one for a STM32F401RE MCU and one for STM32F412CE. The fact is there is no, for example, PC3 pin on STM32F412CE MCU unlike on STM32F401RE MCU. (but STM32F412CE MCU has got a PC15 pin)

it looks like that there is no macro that takes into account that PC3 is not present on STM32F412CE.

Here is some code to illustrate my question :

void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
 /* Check the parameters */
 assert_param(IS_GPIO_PIN(GPIO_Pin)); // 1 --> See comments below
 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); // 2 --> See comments below
 
// do some stuff (here it's the core of HAL_GPIO_TogglePin)
 if ((GPIOx->ODR & GPIO_Pin) == GPIO_Pin)
 {
 GPIOx->BSRR = (uint32_t)GPIO_Pin << GPIO_NUMBER;
 }
 else
 {
 GPIOx->BSRR = GPIO_Pin;
 }
}

1 :

IS_GPIO_PIN should be ok because GPIO_PIN_MASK == 0x0000FFFFU so 

(((((uint32_t)PIN) & GPIO_PIN_MASK ) != 0x00U) && ((((uint32_t)PIN) & ~GPIO_PIN_MASK) == 0x00U))

returns true value.

2 : Should be ok because PORT C is defined in stm32f4xx_hal_gpio_ex.h

#if defined(STM32F412Cx)
#define GPIO_GET_INDEX(__GPIOx__) (uint8_t)(((__GPIOx__) == (GPIOA))? 0U :\
 ((__GPIOx__) == (GPIOB))? 1U :\
 ((__GPIOx__) == (GPIOC))? 2U : 7U)
#endif /* STM32F412Cx */

Conclusion :

It seems that i can't catch some particular cases, for example when not all pins are present on MCU for one port.

    This topic has been closed for replies.
    Best answer by waclawek.jan

    There are no distinct headers per package, so they inevitably cover the largest package in the given subfamily.

    JW

    3 replies

    Super User
    March 2, 2020

    Can't your code simply check DBGMCU_IDCODE ?

    JW

    Graduate II
    March 2, 2020

    You could tell the die apart, but packaging likely isn't. Could try the UNIQUE ID

    https://www.st.com/resource/en/datasheet/stm32f412ce.pdf

    Graduate II
    March 2, 2020

    Could get chronically burdensome to maintain, a lot of these parts share a common die.

    Normally the Idiot Proofing is applied at the CubeMX level.

    AJTAuthor
    Visitor II
    March 3, 2020

    Well, it seems that we can't completely trust IS_GPIO_PIN or IS_GPIO_ALL_INSTANCE; see :

    Here is my .ioc for the STM32F401RE project, as you can see there is no E or D port :

    0690X00000DYWQkQAP.png

    but if we check the stm32f401xe.h file where GPIO are defined, we see that PORTS E and D are defined :

    0690X00000DYWYPQA5.png

    and here is IS_GPIO_ALL_INSTANCE macro definition :

    0690X00000DYWYyQAP.png

    Did i miss something ? or does it just suck ?

    Regards,

    AJT

    Super User
    March 3, 2020

    There are no distinct headers per package, so they inevitably cover the largest package in the given subfamily.

    JW

    AJTAuthor
    Visitor II
    March 3, 2020

    Ok, that what i was thinking. Thank you !