Skip to content

Pin name PXn should match Arduino pin numberin Dx #81

@gus-ghielec

Description

@gus-ghielec

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.

Activity

fpistm

fpistm commented on Aug 16, 2017

@fpistm
Member

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

rogerclarkmelbourne commented on Aug 16, 2017

@rogerclarkmelbourne

@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

fpistm commented on Aug 16, 2017

@fpistm
Member

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

rogerclarkmelbourne

rogerclarkmelbourne commented on Aug 16, 2017

@rogerclarkmelbourne

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

Adminius commented on Aug 16, 2017

@Adminius
Contributor

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

fpistm

fpistm commented on Aug 16, 2017

@fpistm
Member

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

rogerclarkmelbourne commented on Aug 16, 2017

@rogerclarkmelbourne

Yikes

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

RickKimball

RickKimball commented on Aug 16, 2017

@RickKimball
Contributor

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

fpistm

fpistm commented on Aug 16, 2017

@fpistm
Member

@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

rogerclarkmelbourne commented on Aug 17, 2017

@rogerclarkmelbourne

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

fpistm

fpistm commented on Aug 17, 2017

@fpistm
Member

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

rogerclarkmelbourne

rogerclarkmelbourne commented on Aug 17, 2017

@rogerclarkmelbourne

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

Adminius commented on Aug 17, 2017

@Adminius
Contributor

Pxy/Dx and Ax, deal? :)

changed the title [-]Nucleo F401RE pin mapping issue[/-] [+]Pin name PXn should match Arduino pin numberin Dx[/+] on Aug 17, 2017
self-assigned this
on Aug 17, 2017
fpistm

fpistm commented on Aug 17, 2017

@fpistm
Member

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

fpistm commented on Aug 17, 2017

@fpistm
Member

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)

added a commit that references this issue on Aug 17, 2017
added this to the next release milestone on Aug 17, 2017
rogerclarkmelbourne

rogerclarkmelbourne commented on Aug 17, 2017

@rogerclarkmelbourne

Excellent.

fpistm

fpistm commented on Aug 18, 2017

@fpistm
Member

PR #83 merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @RickKimball@gus-ghielec@rogerclarkmelbourne@Adminius@fpistm

      Issue actions

        Pin name PXn should match Arduino pin numberin Dx · Issue #81 · stm32duino/Arduino_Core_STM32