From 4ee9fa33b3fa1fbaee6e04714f84f5b2ee155849 Mon Sep 17 00:00:00 2001 From: AloyseTech Date: Tue, 11 Apr 2017 17:51:01 +0200 Subject: [PATCH 1/2] [core] Fix PIO clocking --- module/cores/arduino/port_sam/core_digital.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/cores/arduino/port_sam/core_digital.c b/module/cores/arduino/port_sam/core_digital.c index 0b931ee..048ec27 100644 --- a/module/cores/arduino/port_sam/core_digital.c +++ b/module/cores/arduino/port_sam/core_digital.c @@ -32,8 +32,8 @@ void pinMode( uint32_t ulPin, PinMode ulMode ) if ( (ulMode == INPUT) || (ulMode == INPUT_PULLUP) || (ulMode == INPUT_PULLDOWN) ) { - /* if all pins are OUTPUT, enable PIO Controller clocking */ - if ( Ports[g_aPinMap[ulPin].iPort].pGPIO->PIO_OSR == 0xffffffff ) + /* if all pins are INPUT, enable PIO Controller clocking (Datasheet Table 16-4. PIO_OSR reset state) */ + if ( Ports[g_aPinMap[ulPin].iPort].pGPIO->PIO_OSR == 0x00000000 ) { // if (Ports[g_aPinMap[ulPin].iPort].ulId < 32) { From 39b7196a2a5c5ac667c304751df399a221309c41 Mon Sep 17 00:00:00 2001 From: AloyseTech Date: Wed, 12 Apr 2017 20:28:10 +0200 Subject: [PATCH 2/2] [core][digital] Change PIO clocking in pinMode --- module/cores/arduino/port_sam/core_digital.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/cores/arduino/port_sam/core_digital.c b/module/cores/arduino/port_sam/core_digital.c index 048ec27..771e618 100644 --- a/module/cores/arduino/port_sam/core_digital.c +++ b/module/cores/arduino/port_sam/core_digital.c @@ -32,9 +32,9 @@ void pinMode( uint32_t ulPin, PinMode ulMode ) if ( (ulMode == INPUT) || (ulMode == INPUT_PULLUP) || (ulMode == INPUT_PULLDOWN) ) { - /* if all pins are INPUT, enable PIO Controller clocking (Datasheet Table 16-4. PIO_OSR reset state) */ - if ( Ports[g_aPinMap[ulPin].iPort].pGPIO->PIO_OSR == 0x00000000 ) - { + /* check if PIO is already clocked */ + if (!(PMC->PMC_PCSR0 & (1 << Ports[g_aPinMap[ulPin].iPort].ulId))) + { // if (Ports[g_aPinMap[ulPin].iPort].ulId < 32) { PMC->PMC_PCER0 = 1 << Ports[g_aPinMap[ulPin].iPort].ulId;