[En-Nut-Discussion] Unified GPIO implementation

Thiago A. Corrêa thiago.correa at gmail.com
Wed Oct 20 04:46:38 CEST 2010


Hi All,

About the wiki article, in the part it says:

The obsolete definitions:

#define GPIO_CFG_MULTIDRIVE  Enable Open-Drain: This should default as
PushPull can break the chip if enabled by accident.

It is dangerous to have PushPull as default with GPIO_CFG_OUTPUT. If
one uses the examples with a slightly different board it might kill
the hardware. So default should be Open-Drain or Weak Pullup if the
CPU supports that. If PushPull is supported it must be set by reason
and under programmers control.

---

Actually, I think the PushPull is the one that is not available on
most platforms. AVR32 and AVR 8 bits both have weak pull ups refered
as simply pull up, and in the case of AVR32 there is a open-drain
enable register.

I think we should then have a definition where PushPull must always be
explicitly enabled, never default. And output should be open-drain if
the CPU supports that. Therefore remove the "Weak pullup" case from
the specification, as it's simply GPIO_CFG_PULLUP and it's dealt with
as a flag of it's own if the user wants it enabled.

Based on that, I'm making the changes as this:

    if (flags & GPIO_CFG_OUTPUT) {
        gpio_port->oders = mask;
		/* Unless specified, outputs default open-drain in Nut/OS */
		if(flags & ~GPIO_CFG_PULLUP)
			gpio_port->odmers = mask;
		else
			gpio_port->odmerc = mask;
    } else {
        gpio_port->oderc = mask;
    }

ODMER is the register to enable Open Drain mode in AVR32.

Also, if you assume that PushPull is the special case, than this part
should also be modified:

#define GPIO_CFG_PUSHPULL    AVR: Enable Pullup, ARM/Cortex: Enable
strong pull-up.
#define GPIO_CFG_PULLUP      Enable Pullup.


to

#define GPIO_CFG_PULLUP        Enable (weak) Pullup, (AVR, AVR32, ARM/Cortex).
#define GPIO_CFG_PUSHPULL    Enable strong pull-up if available (ex.
ARM/Cortex), otherwise it's just #define GPIO_CFG_PUSHPULL
GPIO_CFG_PULLUP

One other thing, we might need an GPIO_CFG_PULLDOWN as well. Looks
like there are AVR32 parts with this feature judging from the Atmel
Software Framework source code in the repository.

Kind Regards,
     Thiago A. Correa



More information about the En-Nut-Discussion mailing list