QT Py RP2040 philhower core pin definitions: Incorrect?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Kealper
 
Posts: 7
Joined: Thu Dec 06, 2018 11:11 pm

QT Py RP2040 philhower core pin definitions: Incorrect?

Post by Kealper »

Hello! It looks like the pin definitions for the earlephilhower/arduino-pico Arduino core might be incorrect and incomplete for the QT Py RP2040.

In the pin mapping (from here) it has A0 - A3 mapped as follows:
A0 - GPIO26
A1 - GPIO27
A2 - GPIO28
A3 - GPIO29

But looking at the schematic (from here) it shows that the pins that are broken out for what the silkscreen calls A0-A3 are actually wired in reverse of what the above definitions have, like so:
A0 - GPIO29
A1 - GPIO28
A2 - GPIO27
A3 - GPIO26

Everything else looks correctly mapped, though pins like the BOOT button (D21), NeoPixel power (D11), and NeoPixel data (D12) don't have any aliases to make them easier to remember. Having aliases that match the CircuitPython pin names from the pinout image (from here) would be handy for people picking up this board for use with Arduino. It's a really nice board that has just the right amount of IO for most of my projects while still being super-adorably-tiny, and I think it makes a great board for Arduino in addition to being a great board for CircuitPython.

User avatar
danhalbert
 
Posts: 4655
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by danhalbert »

Your observations make sense to me. I brought it to the attention of the right people. If you would like to submit a PR to the philhower core to fix those errors and add more pin names, that would be great. Thank you!

Kealper
 
Posts: 7
Joined: Thu Dec 06, 2018 11:11 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by Kealper »

Awesome, thank you. I'll get a PR whipped up and submitted tonight.

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by adafruit2 »

hmm not actually sure if its easily fixable because those are 'common' definitions - i think we'd have to figure out a way to override them if the board definition has different wiring (the qt py could not route the pins so A0 is ADC0)!

Kealper
 
Posts: 7
Joined: Thu Dec 06, 2018 11:11 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by Kealper »

So once you mentioned that, I went to check it out again and I see what you're saying, as the definitions in common.h are not created using a #define but are actually declared constants. On a whim, I put a #define in the board's pins_arduino.h file below the point that it includes common.h, and the compiler does actually seem to let those consts be overridden by a #define.

This below is what I've just tested and makes the A0-A3 pins match what their silkscreen says (and also makes it consistent with the SAMD21 QT Py):

Code: Select all

#include "../generic/common.h"

#define A0 (29u)
#define A1 (28u)
#define A2 (27u)
#define A3 (26u)
The only thing I haven't checked yet is whether this override is actually an undefined behavior of GCC that happens to work out favorably for now, or if that's something that's intentional and here to stay. Given how I understand those to work, I think that it being able to override defined constants/variables is likely to stay but it would still be a good thing to know how dirty of a hack that is or isn't before pushing it out into the wild. The other option would just be to not include common.h at all for this board and just have all of common.h's contents inside the board's pins_arduino.h except modified to make it compatible with the board. Down side of doing away with including common.h for this board and having all pins defined in one file is that it's not how all the other boards are set up so it would be the odd-one-out, but it also wouldn't be relying on the compiler's preprocessor to override code from common.h.

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by adafruit2 »

could be ok, do you want to do the PR or i can? then we could discuss it with philhower

Kealper
 
Posts: 7
Joined: Thu Dec 06, 2018 11:11 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by Kealper »

I can submit it but I can't do it until much later tonight... Working second shift can be inconvenient like that!

Thinking about it more, I'm not sure those defines even have to be below the common.h include since that's all just preprocessed stuff anyways as opposed to the way the declarations are being done in common.h. But yeah I would be interested in knowing whether philhower would prefer it just all be declared in one single file for the one board or if they'd prefer to keep everything as similar as possible between the way all the board pin definitions are set up. It might even be the case that they did the declarations in common.h that specific way to allow for overrides of specific pin aliases within each board's own pins_arduino.h.

Kealper
 
Posts: 7
Joined: Thu Dec 06, 2018 11:11 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by Kealper »

Okay, I've got a PR open at https://github.com/earlephilhower/arduino-pico/pull/397, I decided against adding other aliases in that commit, perhaps after some more thought on what the aliases should be, I'll do another PR down the road.

Kealper
 
Posts: 7
Joined: Thu Dec 06, 2018 11:11 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by Kealper »

Alright, that PR has been merged in, arduino-pico 1.9.11+ now makes the pins printed on the board match the pin names in the Arduino IDE. As for the other pin aliases, in getting this fixed I noticed that the "GPIOXX" labels on the QT Py RP2040's fancy pinout image match up number-for-number with arduino-pico's "DXX" definitions. So, for example, in CircuitPython the boot button can be accessed with "GPIO21" and in the philhower Arduino core the boot button can be accessed with "D21". "MOSI", "MISO", and "SCK" are also already available and mapped to SPI0 so that's good enough for me for now at least.

User avatar
danhalbert
 
Posts: 4655
Joined: Tue Aug 08, 2017 12:37 pm

Re: QT Py RP2040 philhower core pin definitions: Incorrect?

Post by danhalbert »

Thanks for the PR and for figuring out a clever solution to the remapping problem!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”