AnsweredAssumed Answered

STMCube IAR simple GPIO

Question asked by snyder.joe on Apr 20, 2015
Latest reply on Apr 20, 2015 by Clive One
I'm migrating from PIC32s, so bear with me please.  I'm trying to get up to speed on the STM32 using the Cube examples in EWARM.  I'll try to keep this simple (I apologize, I don't know the syntax for code tags in this forum).  When I use the following defines:

#define LCD_GPIO GPIOA
#define LCD_RS GPIO_Pin_0
#define LCD_RW GPIO_Pin_1

The following code compiles fine:

  GPIO_InitStruct.Pin = (GPIO_PIN_0 | GPIO_PIN_1);
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(LCD_GPIO, &GPIO_InitStruct);

But if I try to substitute the GPIO pin names with the more intuitive names by # defining them, I get an error:

  GPIO_InitStruct.Pin = (LCD_RS | LCD_RW);
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_PULLUP;
  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
  HAL_GPIO_Init(LCD_GPIO, &GPIO_InitStruct); 

The error is:  "GPIO_PIN_0 is undefined".  Even more confusing is that it is apparently accepting the #define of "LCD_GPIO", but it is not seeing the define of the individual pins.  Any thoughts would be greatly appreciated.  Thanks.  

Outcomes