cancel
Showing results for 
Search instead for 
Did you mean: 

STMCube IAR simple GPIO

joe2399
Associate II
Posted on April 20, 2015 at 19:36

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.  
3 REPLIES 3
Posted on April 20, 2015 at 20:32

Case sensitive?

#define LCD_RS GPIO_Pin_0 // Looks like SPL syntax

#define LCD_RW GPIO_Pin_1

GPIO_InitStruct.Pin = (LCD_RS | LCD_RW);

vs

GPIO_InitStruct.Pin = (GPIO_PIN_0 | GPIO_PIN_1); // HAL/Cube

Format code block is the ''Paintbrush [<>]'' icon.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
joe2399
Associate II
Posted on April 20, 2015 at 22:01

Clive,

Wow.  Ok.  You have no idea how much time I have wasted on this, and it was that.  Sorry for wasting your time.  Thanks a bunch!

Joe

Posted on April 20, 2015 at 22:14

No problem, we've all had those days when we stare into the cupboard looking for the thing that's right in front of us.

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