Skip to content

Nucleo F401RE - Serial1 undefined #458

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
iacopo opened this issue Feb 26, 2019 · 7 comments
Closed

Nucleo F401RE - Serial1 undefined #458

iacopo opened this issue Feb 26, 2019 · 7 comments
Labels
answered question ❓ Usually converted as a discussion

Comments

@iacopo
Copy link

iacopo commented Feb 26, 2019

I'm very new to this and I know I should post to the stm32duino.com forum, but there's no way to register there!

I'm working on a nucleo F401RE, trying to use Serial1 in my sketch but the compiler says it's undefined.
I can only use Serial and Serial2, but they are basically the same one and mapped to the usb, I need an alternative serial communication port.

I thought there was some other error in my code, so I made a super simple one, but I confirm this does not work on my setup.

long val = 0;

void setup() {
  // put your setup code here, to run once:
  //Serial.begin(115200); //works over USB
  //Serial2.begin(115200); //works over USB
  Serial1.begin(115200); //doesn't work
}

void loop() {
  // put your main code here, to run repeatedly:
  val++;
  Serial1.write(val); //doesn't work
  //Serial.write(val); //works over USB
  //Serial2.write(val); //works over USB
 
  delay(100);
}

here is a screenshot of my settings in the Arduino IDE

screen shot 2019-02-25 at 16 52 02

@fpistm fpistm transferred this issue from stm32duino/BoardManagerFiles Feb 26, 2019
@fpistm fpistm added the question ❓ Usually converted as a discussion label Feb 26, 2019
@fpistm
Copy link
Member

fpistm commented Feb 26, 2019

The generic instance on the Nucelo-F401RE is on USART2.
That's why Serial2 is defined and mapped on Serial.

If you want another serial, you can add a build_opt.h file with: -DENABLE_HWSERIAL1
This will define the Serial1 using the first USART1 instance found in the PeripheralPins.c.
In this case on PA10/PA9.
https://github.com/stm32duino/Arduino_Core_STM32/blob/master/variants/NUCLEO_F401RE/PeripheralPins.c#L153
https://github.com/stm32duino/Arduino_Core_STM32/blob/master/variants/NUCLEO_F401RE/PeripheralPins.c#L142

One other option is to simply define it:
HardwareSerial Serial1(PA10, PA9);
or
HardwareSerial Serial1(PB7, PB6);
...

So your code can be:

long val = 0;
HardwareSerial Serial1(PA10, PA9);

void setup() {
  Serial1.begin(115200); 
}

void loop() {
  // put your main code here, to run repeatedly:
  val++;
  Serial1.write(val);
 
  delay(100);
}

@fpistm fpistm added the waiting feedback Further information is required label Feb 26, 2019
@iacopo
Copy link
Author

iacopo commented Feb 26, 2019

Thank you so much Frederic for the help, now I see my question was very trivial!

@iacopo iacopo closed this as completed Feb 26, 2019
@romainreignier
Copy link

I think this issue is natural for an Arduino user, I have faced it myself some weeks ago.
Maybe we should document it clearly somewhere.
Maybe here: https://github.com/stm32duino/wiki/wiki/API

@iacopo
Copy link
Author

iacopo commented Feb 26, 2019

Yes, documenting it would help a lot for new unexperienced users just like me

@fpistm
Copy link
Member

fpistm commented Feb 27, 2019

You're right guys, several documentation are missing.
I've planned to use the GitHub page feature to documents the core but time is always the missing ingredients. 😭

Roger has created https://github.com/stm32duino/stm32duino.github.io
This would be fine to use it. Then all will be available thanks http://stm32duino.github.io

@romainreignier
Copy link

Ok nice, I can't promise but I might help a bit to kick start the doc.
So you would advise to use the plain website instead of the wiki?
Because I am not a web developer, I am Ok to write down some markdown, but not much to write plain HTML and CSS...
Or maybe we can find a nice documentation template for a static website generator like jekyll or hugo.

@fpistm
Copy link
Member

fpistm commented Feb 27, 2019

Honestly, I don't know. Maybe a new issue can be opened to discuss about that and maybe some users could share their feedback about GitHub pages usage.

@fpistm fpistm added answered and removed waiting feedback Further information is required labels Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered question ❓ Usually converted as a discussion
Projects
None yet
Development

No branches or pull requests

3 participants