You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an LED connected to D34(PC6). My code works when I use D34 just fine but then it doesn't work if I use PC6 instead of D34. Both of these should be the same thing. There seem to be an issue when using the processor pin names.
This is necessary for those building products based on the nucleo board and want to use the processor pin name instead of the "Arduino" Dxx pin names.
Hi @gus-ghielec,
PinName and pin numbering are different. Arduino API uses the pin numbering (Dx). When using the PinName (Pxy) its value is not equal to the pin number.
To use the PinName instead of pin numbering use: uint32_t pinNametoDigitalPin(PinName p);
So, digitalWrite(D34, HIGH); and digitalWrite(pinNametoDigitalPin(PC6), HIGH); are the same.
but digitalWrite(PC6, HIGH); not
But given the choice of either being able to use the real Port / Pin name or supporting the Arduino analogue pin number system, I would use Port / Pin
There are so many other things which are not going to be AVR compatible, that trying to make the Analog pin names compatible will be a minor change compared with the Harvard vs Von Neumann architecture and the size of int and float etc, that people will have to get used to, if migrating from AVR.
Activity
fpistm commentedon Aug 16, 2017
Hi @gus-ghielec,
PinName and pin numbering are different. Arduino API uses the pin numbering (Dx). When using the PinName (Pxy) its value is not equal to the pin number.
To use the PinName instead of pin numbering use:
uint32_t pinNametoDigitalPin(PinName p);
So,
digitalWrite(D34, HIGH);
anddigitalWrite(pinNametoDigitalPin(PC6), HIGH);
are the same.but
digitalWrite(PC6, HIGH);
notrogerclarkmelbourne commentedon Aug 16, 2017
@fpistm
I think you mean
digitalWrite(PC6, HIGH); not
BTW. I was not aware that the direct mapping does not work using the pin names like it does in libmaple and STM32Generic
fpistm commentedon Aug 16, 2017
Thanks @rogerclarkmelbourne
Yes, not the same pinmapping. It is based on mbed pinmap.
rogerclarkmelbourne commentedon Aug 16, 2017
If someone made their own variant file, do you think they could map as 1:1 ?
i.e I know @gus-ghielec sells a custom board, and I think it may have pin names rather than pin numbers
Adminius commentedon Aug 16, 2017
it would be great if we can use Pxy names without pinNametoDigitalPin
fpistm commentedon Aug 16, 2017
No @rogerclarkmelbourne as PinName is not an index.
PinNames.h#L33
It encodes the GPIO port and pin number on 8bits
Edit: I've got an idea, need to check if it could be applied
rogerclarkmelbourne commentedon Aug 16, 2017
Yikes
This is going to be a rather confusing for anyone using the Discovery series boards, which are labelled with Pxn format names
RickKimball commentedon Aug 16, 2017
The pinname issue is kind of embedded deeply in these cores at this point.
fpistm commentedon Aug 16, 2017
I will not change the pinmap management but I could grant this request. I will do a PR before the end of the week. I hope ;)
rogerclarkmelbourne commentedon Aug 17, 2017
I presume the problem is all associated with the Analog pin numbers needing to be Arduino compatible :-(
fpistm commentedon Aug 17, 2017
Yes, always the same problem... to be or not to be Arduino compatible. 😅
rogerclarkmelbourne commentedon Aug 17, 2017
Frederic
I'm not sure if its something you can decide...
But given the choice of either being able to use the real Port / Pin name or supporting the Arduino analogue pin number system, I would use Port / Pin
There are so many other things which are not going to be AVR compatible, that trying to make the Analog pin names compatible will be a minor change compared with the Harvard vs Von Neumann architecture and the size of int and float etc, that people will have to get used to, if migrating from AVR.
Adminius commentedon Aug 17, 2017
Pxy/Dx and Ax, deal? :)
[-]Nucleo F401RE pin mapping issue[/-][+]Pin name PXn should match Arduino pin numberin Dx[/+]fpistm commentedon Aug 17, 2017
I will only add possibility to use pin name as an index matching the Dx. (no loop ;))
So Analog will be the same.
PYn == Dx == x for digital
PYn == Ax == x == Dy for analogRead
PYn == Ax == Dy for analogWrite
Pin name PXn should match Arduino pin numberin Dx
fpistm commentedon Aug 17, 2017
Example for Nucleo F429ZI, equivalent calls are:
Digital:
AnalogRead:
AnalogWrite:
Warning:
analogWrite(0);
write on D0 (PG9)Update pin name formatting. PXn -> PX_n
rogerclarkmelbourne commentedon Aug 17, 2017
Excellent.
fpistm commentedon Aug 18, 2017
PR #83 merged