diff --git a/arch/arm/src/samdl/sam_port.c b/arch/arm/src/samdl/sam_port.c index 4df84495f11..dddc7a1ae9e 100644 --- a/arch/arm/src/samdl/sam_port.c +++ b/arch/arm/src/samdl/sam_port.c @@ -310,11 +310,26 @@ static inline void sam_configperiph(uintptr_t base, port_pinset_t pinset) pin = (pinset & PORT_PIN_MASK) >> PORT_PIN_SHIFT; bit = (1 << pin); + /* If pin is output with readback then set the pin as output */ + + if ((pinset & PORT_OUTREADBACK_MASK) == PORT_OUTREADBACK_ENABLE) + { + putreg32(bit, base + SAM_PORT_DIRSET_OFFSET); + } + /* Set the pin configuration. This will be an peripheral with the * selected function. */ regval = (PORT_WRCONFIG_WRPINCFG | PORT_WRCONFIG_WRPMUX | PORT_WRCONFIG_PMUXEN); + + /* If pin is output with readback then enable the input buffer */ + + if ((pinset & PORT_OUTREADBACK_MASK) == PORT_OUTREADBACK_ENABLE) + { + regval |= PORT_WRCONFIG_INEN; + } + if (pin > 16) { /* Select the upper half word and adjust the bit setting */ diff --git a/arch/arm/src/samdl/sam_port.h b/arch/arm/src/samdl/sam_port.h index 58bd4146c77..d40c9246a41 100644 --- a/arch/arm/src/samdl/sam_port.h +++ b/arch/arm/src/samdl/sam_port.h @@ -76,9 +76,9 @@ * ------------ ----------------------------- * PORT Input: MMRR .... .S.. .... ..PB BBBB * PORT Output: MM.. .... D..V .... ..PB BBBB - * Peripheral: MM.. FFF. .... II.. ..PB BBBB + * Peripheral: MM.. FFFO .... II.. ..PB BBBB * ------------ ----------------------------- - * MMRR FFF. DS.V II.. ..PB BBBB + * MMRR FFFO DS.V II.. ..PB BBBB */ /* Input/output/peripheral mode: @@ -162,6 +162,23 @@ #define PORT_FUNCG (PORT_PERIPHERAL | _PORT_FUNCG) /* Function G */ #define PORT_FUNCH (PORT_PERIPHERAL | _PORT_FUNCH) /* Function H */ +/* Output and Input Buffer both enabled to let readback + * + * MODE BITFIELDS + * ------------ ----------------------------- + * 2222 1111 1111 1100 0000 0000 + * 3210 9876 5432 1098 7654 3210 + * ------------ ----------------------------- + * PORT Input: .... .... .... .... .... .... + * PORT Output: .... .... .... .... .... .... + * Peripheral: .... ...O .... .... .... .... + */ + +#define PORT_OUTREADBACK_SHIFT (16) /* Bit 16: Pin output and input buffer enabled */ +#define PORT_OUTREADBACK_MASK (1 << PORT_OUTREADBACK_SHIFT) +# define PORT_OUTREADBACK_DISABLE (0 << PORT_OUTREADBACK_SHIFT) +# define PORT_OUTREADBACK_ENABLE (1 << PORT_OUTREADBACK_SHIFT) + /* Output drive control * * MODE BITFIELDS