Skip to content

Commit 148f1f2

Browse files
[sam] GPIO setOutput overrides peripheral control
Calling setOutput now overrides peripheral control of the pin. This behavior is consistent with the STM32 GPIO implementation, this commit also ensures output value is set before the output drive is enabled to prevent glitch. Co-authored-by: Christopher Durand <[email protected]>
1 parent 845840e commit 148f1f2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/modm/platform/gpio/sam/pin.hpp.in

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,26 @@ public:
183183
inline static void
184184
setOutput()
185185
{
186+
// Enable PIO control of the pin (disables peripheral control)
187+
setPortReg(PIO_PER_OFFSET);
188+
// Enable output driver
186189
setPortReg(PIO_OER_OFFSET);
187190
}
188191

189192
inline static void
190193
setOutput(bool status)
191194
{
192-
setOutput();
193195
set(status);
196+
setOutput();
194197
}
195198

196199
static void
197200
setInput()
198201
{
199-
setPortReg(PIO_ODR_OFFSET); // Disable output driver
202+
// Enable PIO control of the pin (disables peripheral control)
203+
setPortReg(PIO_PER_OFFSET);
204+
// Disable output driver
205+
setPortReg(PIO_ODR_OFFSET);
200206
}
201207

202208
static void
@@ -336,19 +342,22 @@ public:
336342
setOutput()
337343
{
338344
setPortReg(PORT_DIRSET_OFFSET);
345+
// Disable peripheral multiplexer
346+
PinCfg::set(0);
339347
}
340348

341349
inline static void
342350
setOutput(bool status)
343351
{
344-
setOutput();
345352
set(status);
353+
setOutput();
346354
}
347355

348356
static void
349357
setInput()
350358
{
351359
setPortReg(PORT_DIRCLR_OFFSET);
360+
PinCfg::set(PORT_PINCFG_INEN);
352361
}
353362

354363
static void

0 commit comments

Comments
 (0)