diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index 8db957221..b40db5455 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -136,6 +136,11 @@ var pinPadMapping = [32]byte{ // found" (indicated by returning ok=false). The pad number is returned to // calculate the DOPO/DIPO bitfields of the various serial peripherals. func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) { + if int(pin)/2 >= len(pinPadMapping) { + // This is probably NoPin, for which no mapping is available. + return + } + nibbles := pinPadMapping[pin/2] upper := nibbles >> 4 lower := nibbles & 0xf diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index 4cb36366a..e2d5124a3 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -322,6 +322,11 @@ var pinPadMapping = [64]uint16{ // (indicated by returning ok=false). The pad number is returned to calculate // the DOPO/DIPO bitfields of the various serial peripherals. func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok bool) { + if int(pin)/2 >= len(pinPadMapping) { + // This is probably NoPin, for which no mapping is available. + return + } + bytes := pinPadMapping[pin/2] upper := byte(bytes >> 8) lower := byte(bytes & 0xff)