2020-03-02 01:59 AM
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.
Solved! Go to Solution.
2020-03-03 01:31 AM
There are no distinct headers per package, so they inevitably cover the largest package in the given subfamily.
JW
2020-03-02 02:05 PM
Can't your code simply check DBGMCU_IDCODE ?
JW
2020-03-02 02:22 PM
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.
2020-03-02 02:24 PM
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
2020-03-03 01:11 AM
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 :
but if we check the stm32f401xe.h file where GPIO are defined, we see that PORTS E and D are defined :
and here is IS_GPIO_ALL_INSTANCE macro definition :
Did i miss something ? or does it just suck ?
Regards,
AJT
2020-03-03 01:31 AM
There are no distinct headers per package, so they inevitably cover the largest package in the given subfamily.
JW
2020-03-03 01:34 AM
Ok, that what i was thinking. Thank you !