cancel
Showing results for 
Search instead for 
Did you mean: 

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

AJT
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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

JW

View solution in original post

6 REPLIES 6

Can't your code simply check DBGMCU_IDCODE ?

JW

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

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

JW

Ok, that what i was thinking. Thank you !