GPIO_TypeDef unusable from ST lib

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
lilvinz
Posts: 130
Joined: Sat Dec 21, 2013 2:56 pm
Has thanked: 1 time
Been thanked: 6 times

GPIO_TypeDef unusable from ST lib

Post by lilvinz »

Hi,

when refactoring large projects, it is often feasible to do a step by step transition.
I have had the opportunity to replace FreeRTOS / ST lib by ChibiOS and came
across an issue with the ChibiOS modification in ST's chip header file.
e.g. stm32f4xx.h
There the GPIO_TypeDef struct has been removed and thus makes it impossible to use
ST libs gpio functions. This in turn renders legacy drivers unusable and makes a step by step
transition very hard.
I think it is not necessary to completely remove this struct but fix it while preserving compatibility with ST lib:

Code: Select all

typedef struct {

  __IO uint32_t MODER;    /*!< GPIO port mode register,               Address offset: 0x00      */
  __IO uint32_t OTYPER;   /*!< GPIO port output type register,        Address offset: 0x04      */
  __IO uint32_t OSPEEDR;  /*!< GPIO port output speed register,       Address offset: 0x08      */
  __IO uint32_t PUPDR;    /*!< GPIO port pull-up/pull-down register,  Address offset: 0x0C      */
  __IO uint32_t IDR;      /*!< GPIO port input data register,         Address offset: 0x10      */
  __IO uint32_t ODR;      /*!< GPIO port output data register,        Address offset: 0x14      */
  union {
    struct {
      __IO uint16_t BSRRL;/*!< GPIO port bit set/reset low register,  Address offset: 0x18      */
      __IO uint16_t BSRRH;/*!< GPIO port bit set/reset high register, Address offset: 0x1A      */
    };
    volatile union {
        __IO uint32_t W;
      struct {
        __IO uint16_t set;
        __IO uint16_t clear;
      } H;
    } BSRR;
  };
  __IO uint32_t LCKR;     /*!< GPIO port configuration lock register, Address offset: 0x1C      */
  union {
    __IO uint32_t AFR[2]; /*!< GPIO alternate function registers,     Address offset: 0x20-0x24 */
    struct {
      __IO uint32_t AFRL;
      __IO uint32_t AFRH;
    };
  };
} GPIO_TypeDef;


Of course the corresponsing declaration then has to be removed from STM32/GPIOv2/pal_lld.h.
What do you think?

Best regards,

Vinz
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPIO_TypeDef unusable from ST lib

Post by Giovanni »

That would make the PAL driver non functional.

The conflict has been addressed in ChibiOS3.0 but will not be backported officially in 2.6.x. You may start using 3.0 or backport the 3.0 PAL driver in 2.6.

Giovanni
User avatar
lilvinz
Posts: 130
Joined: Sat Dec 21, 2013 2:56 pm
Has thanked: 1 time
Been thanked: 6 times

Re: GPIO_TypeDef unusable from ST lib

Post by lilvinz »

Thanks for the quick response. I will look at the 3.0 implementation.
I would very much appreciate to know why my proposed solution won't work.

Thanks again and cheers,

Vinz
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: GPIO_TypeDef unusable from ST lib

Post by Giovanni »

Hi,

It is because some compilers complain about anonymous structs and unions, those are not standard constructs.

Of course you can use them in your project.

Giovanni
Post Reply