Skip to content

Pin name PXn should match Arduino pin numberin Dx #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gus-ghielec opened this issue Aug 15, 2017 · 17 comments
Closed

Pin name PXn should match Arduino pin numberin Dx #81

gus-ghielec opened this issue Aug 15, 2017 · 17 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@gus-ghielec
Copy link

gus-ghielec commented Aug 15, 2017

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.

I am using the blink LED code example.

@fpistm
Copy link
Member

fpistm commented 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); and digitalWrite(pinNametoDigitalPin(PC6), HIGH); are the same.
but digitalWrite(PC6, HIGH); not

@rogerclarkmelbourne
Copy link

@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
Copy link
Member

fpistm commented Aug 16, 2017

Thanks @rogerclarkmelbourne
Yes, not the same pinmapping. It is based on mbed pinmap.

@rogerclarkmelbourne
Copy link

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
Copy link
Contributor

it would be great if we can use Pxy names without pinNametoDigitalPin

@fpistm
Copy link
Member

fpistm commented 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
Copy link

Yikes

This is going to be a rather confusing for anyone using the Discovery series boards, which are labelled with Pxn format names

@RickKimball
Copy link
Contributor

The pinname issue is kind of embedded deeply in these cores at this point.

@fpistm
Copy link
Member

fpistm commented Aug 16, 2017

@RickKimball The pinname issue is kind of embedded deeply in these cores at this point.

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
Copy link

I presume the problem is all associated with the Analog pin numbers needing to be Arduino compatible :-(

@fpistm
Copy link
Member

fpistm commented Aug 17, 2017

Yes, always the same problem... to be or not to be Arduino compatible. 😅

@rogerclarkmelbourne
Copy link

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
Copy link
Contributor

Pxy/Dx and Ax, deal? :)

@fpistm fpistm changed the title Nucleo F401RE pin mapping issue Pin name PXn should match Arduino pin numberin Dx Aug 17, 2017
@fpistm fpistm self-assigned this Aug 17, 2017
@fpistm fpistm added the enhancement New feature or request label Aug 17, 2017
@fpistm
Copy link
Member

fpistm commented 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

fpistm added a commit to fpistm/Arduino_Core_STM32 that referenced this issue Aug 17, 2017
@fpistm
Copy link
Member

fpistm commented Aug 17, 2017

Example for Nucleo F429ZI, equivalent calls are:

Digital:

digitalWrite(33, HIGH); 
digitalWrite(D33, HIGH);
digitalWrite(PB0, HIGH);
digitalWrite(pinNametoDigitalPin(PB_0), HIGH);

AnalogRead:

analogRead(A0);
analogRead(0);
analogRead(PA3);
analogRead(pinNametoDigitalPin(PA_3));
analogRead(D78);
analogRead(78);

AnalogWrite:

analogWrite(A0);
analogWrite(PA3);
analogWrite(pinNametoDigitalPin(PA_3));
analogWrite(D78);
analogWrite(78);

Warning: analogWrite(0); write on D0 (PG9)

fpistm added a commit to fpistm/Arduino_Tools that referenced this issue Aug 17, 2017
@fpistm fpistm added this to the next release milestone Aug 17, 2017
@rogerclarkmelbourne
Copy link

Excellent.

@fpistm
Copy link
Member

fpistm commented Aug 18, 2017

PR #83 merged

@fpistm fpistm closed this as completed Aug 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants