Skip to content
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

Serial1 does not work on Artemis Nano #474

Open
paulvha opened this issue Nov 23, 2022 · 0 comments
Open

Serial1 does not work on Artemis Nano #474

paulvha opened this issue Nov 23, 2022 · 0 comments

Comments

@paulvha
Copy link
Contributor

paulvha commented Nov 23, 2022

Problem description
On an Artemis Nano the Serial1 and Serial do not work independent. They are ONE and the same.

  • Changing the speed on Serial1 also changes the speed on Serial. Also the other way round.
  • Data that is mended for Serial, is also send to Serial1.
  • Data that is mended for Serial1 is also send to Serial.

As A result the SERIAL1 CAN NOT BE USED ON AN ARTEMIS NANO
Also see topic https://forum.sparkfun.com/viewtopic.php?f=169&t=58621

Root cause
An Apollo3 chip has 2 uarts : UART0 and UART1. When a Serial instance is created ( in serial_api.c/ serial_init() ) based on the provided TX and RX pads, a lookup is performed to decide which UART to use. The lookup table is in PeripheralPins.c, part of the Mbed TARGET_Ambiq_Micro.

First, the Serial-instance is created (TX = 48 / RX= 49) and based on the lookup UART0 is assigned. Then the Serial1-instance is created (TX=39, RX =40), but now DUE TO AN ERROR IN THE LOOKUP TABLE, it is ALSO assigned to UART0. As a result BOTH Serial and Serial1 are assigned to UART0.

This ONLY happens on an Artemis Nano as that is using (TX=39, RX =40). The other boards with a Serial1 are using (TX=24, RX =25), which in the table can only be assigned to UART1

Solution

In the same lookup table (PeripheralPins.c) there are already entries to assign (TX=39, RX =40) to UART1. So by commenting out the lines in the TX and RX table for UART0.

	//{AP3_PER_UART0_TX_39, UART_0, (uint32_t)&g_AP3_PER_UART0_TX_39},
        //{AP3_PER_UART0_RX_40, UART_0, (uint32_t)&g_AP3_PER_UART0_RX_40},

Serial1 is now assigned to UART1 and then works as expected. Tested with a simple sketch, where I connected Putty on 9600 to Serial1 and used the Arduino IDE monitor on 115200.


void setup() {
  Serial.begin(115200);
  Serial1.begin(9600);
  delay(1000); // wait for UART to settle
}

void loop() {
  while(Serial.available()){
    Serial1.write(Serial.read());
  }

  while(Serial1.available()){
    Serial.write(Serial1.read());
  }
}

The challenge
As the lookup table in PeripheralPins.c as part of the mbed pre-compiled archive a new archive needs to be created for the Artemis NANO. I have done that (based on 2.2.1) and have added that as a zip-file +instructions in the forum (https://forum.sparkfun.com/viewtopic.php?f=169&t=58621)

Edit: this is NOT a problem in V1.2.3 as there the UART to use is provided with the first parameter : Uart Serial1(1, 10, 9);

regards,
Paulvha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant