Alternate Function and PushPull / Pullup

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
Triest
Posts: 4
Joined: Sat Dec 06, 2014 7:16 pm

Alternate Function and PushPull / Pullup

Post by Triest »

Hello there!
I really like Chibios, but i have some trouble now. I want to use the UART's of my stm32f4 Discovery board. To use them, I have to initialize the corresponding pins with PAL_MODE_ALTERNATE(7 or 8). In Case of UART4, it is

Code: Select all

palSetPadMode(GPIOA, 0, PAL_MODE_ALTERNATE(8));
palSetPadMode(GPIOA, 1, PAL_MODE_ALTERNATE(8));


My problem is, that I cant define these pins as alternate function AND output (Pin 0) as pushpull OR input (pin 1) as Pullup. This is necessary for using higher baudrates in my hardware. I tried

Code: Select all

palSetPadMode(GPIOA, 0, PAL_MODE_ALTERNATE(8) | PAL_MODE_OUTPUT_PUSHPULL);


and

Code: Select all

palSetPadMode(GPIOA, 0, PAL_MODE_ALTERNATE(8) | PAL_MODE_INPUT_PULLUP);


both resulting to absolute no function. Has anybody an idea, how I can manage that?
Tank you!
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Alternate Function and PushPull / Pullup

Post by Giovanni »

Hi,

Those constants/macros are not meant to be ORed, if you need to create a very specific I/O configuration then use the following set (from pal_lld.h), the following constants can be ORed:

Code: Select all

/**
 * @name    STM32-specific I/O mode flags
 * @{
 */
#define PAL_STM32_MODE_MASK             (3 << 0)
#define PAL_STM32_MODE_INPUT            (0 << 0)
#define PAL_STM32_MODE_OUTPUT           (1 << 0)
#define PAL_STM32_MODE_ALTERNATE        (2 << 0)
#define PAL_STM32_MODE_ANALOG           (3 << 0)

#define PAL_STM32_OTYPE_MASK            (1 << 2)
#define PAL_STM32_OTYPE_PUSHPULL        (0 << 2)
#define PAL_STM32_OTYPE_OPENDRAIN       (1 << 2)

#define PAL_STM32_OSPEED_MASK           (3 << 3)
#define PAL_STM32_OSPEED_LOWEST         (0 << 3)
#if defined(STM32F0XX) || defined(STM32F30X) || defined(STM32F37X)
#define PAL_STM32_OSPEED_MID            (1 << 3)
#else
#define PAL_STM32_OSPEED_MID1           (1 << 3)
#define PAL_STM32_OSPEED_MID2           (2 << 3)
#endif
#define PAL_STM32_OSPEED_HIGHEST        (3 << 3)

#define PAL_STM32_PUDR_MASK             (3 << 5)
#define PAL_STM32_PUDR_FLOATING         (0 << 5)
#define PAL_STM32_PUDR_PULLUP           (1 << 5)
#define PAL_STM32_PUDR_PULLDOWN         (2 << 5)

#define PAL_STM32_ALTERNATE_MASK        (15 << 7)
#define PAL_STM32_ALTERNATE(n)          ((n) << 7)


From the above constants are derived the ones you tried to use, please see the file pal_lld.h for details.

Giovanni
Triest
Posts: 4
Joined: Sat Dec 06, 2014 7:16 pm

Re: Alternate Function and PushPull / Pullup

Post by Triest »

Thanks, this did the Job!

Code: Select all

   palSetPadMode(GPIOA, 2,
         PAL_STM32_MODE_ALTERNATE | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST | PAL_STM32_ALTERNATE(7));
   palSetPadMode(GPIOA, 3,
         PAL_STM32_MODE_ALTERNATE | PAL_STM32_PUDR_PULLUP | PAL_STM32_ALTERNATE(7));
Post Reply