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

Serial port broken on XIAO ESP32C3 after upgrade from 1.9.1.7 #1480

Open
mikmog opened this issue Apr 25, 2024 · 9 comments
Open

Serial port broken on XIAO ESP32C3 after upgrade from 1.9.1.7 #1480

mikmog opened this issue Apr 25, 2024 · 9 comments

Comments

@mikmog
Copy link

mikmog commented Apr 25, 2024

Target name(s)

XIAO_ESP32C3

Firmware version

1.9.1.21

Was working before? On which version?

1.9.1.7

Device capabilities

System Information
HAL build info: nanoCLR running @ ESP32_C3 built with ESP-IDF 38eeba2
Target: XIAO_ESP32C3
Platform: ESP32

Firmware build Info:
Date: Mar 23 2024
Type: MinSizeRel build, chip rev. >= 3, without support for PSRAM
CLR Version: 1.9.1.21
Compiler: GNU ARM GCC v8.4.0

OEM Product codes (vendor, model, SKU): 0, 0, 0

Serial Numbers (module, system):
00000000000000000000000000000000
0000000000000000

Target capabilities:
Has nanoBooter: NO
IFU capable: NO
Has proprietary bootloader: YES

AppDomains:

Assemblies:

Native Assemblies:
mscorlib v100.5.0.19, checksum 0x445C7AF9
nanoFramework.Runtime.Native v100.0.9.0, checksum 0x109F6F22
nanoFramework.Hardware.Esp32 v100.0.10.0, checksum 0x6A20A689
nanoFramework.Networking.Sntp v100.0.4.4, checksum 0xE2D9BDED
nanoFramework.ResourceManager v100.0.0.1, checksum 0xDCD7DF4D
nanoFramework.System.Collections v100.0.1.0, checksum 0x2DC2B090
nanoFramework.System.Text v100.0.0.1, checksum 0x8E6EB73D
nanoFramework.System.IO.Hashing v100.0.0.1, checksum 0xEBD8ED20
nanoFramework.System.Security.Cryptography v100.0.0.2, checksum 0xF4AEFE6C
nanoFramework.Runtime.Events v100.0.8.0, checksum 0x0EAB00C9
EventSink v1.0.0.0, checksum 0xF32F4C3E
System.IO.FileSystem v1.0.0.2, checksum 0x545A6C79
System.Math v100.0.5.5, checksum 0x9F9E2A7E
System.Net v100.2.0.1, checksum 0xD82C1452
System.Device.Adc v100.0.0.0, checksum 0xE5B80F0B
System.Device.Gpio v100.1.0.6, checksum 0x097E7BC5
System.Device.I2c v100.0.0.2, checksum 0xFA806D33
System.Device.I2c.Slave v1.0.0.0, checksum 0x4238164B
System.Device.I2s v100.0.0.1, checksum 0x478490FE
System.Device.Pwm v100.1.0.4, checksum 0xABF532C3
System.IO.Ports v100.1.6.1, checksum 0xB798CE30
System.Device.Spi v100.1.2.0, checksum 0x3F6E2A7E
System.Runtime.Serialization v100.0.0.0, checksum 0x0A066871
System.Device.Wifi v100.0.6.4, checksum 0x00A058C6
Windows.Storage v100.0.3.0, checksum 0xF0C37E1B

++++++++++++++++++++++++++++++++
++ Memory Map ++
++++++++++++++++++++++++++++++++
Type Start Size
++++++++++++++++++++++++++++++++
RAM 0x3fca6238 0x0001d000
FLASH 0x00000000 0x00400000

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++ Flash Sector Map ++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Region Start Blocks Bytes/Block Usage
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0 0x00010000 1 0x1A0000 nanoCLR
1 0x001B0000 1 0x1F0000 Deployment
2 0x003C0000 1 0x040000 Configuration

+++++++++++++++++++++++++++++++++++++++++++++++++++
++ Storage Usage Map ++
+++++++++++++++++++++++++++++++++++++++++++++++++++
Start Size (kB) Usage
+++++++++++++++++++++++++++++++++++++++++++++++++++
0x003C0000 0x040000 (256kB) Configuration
0x00010000 0x1A0000 (1664kB) nanoCLR
0x001B0000 0x1F0000 (1984kB) Deployment

Deployment Map
Empty

Description

I'm using nanoFramework to read power consumption in real time (every 10 second) from an Aidon power meter. The protocol is plain ASCII

After upgrading the mighty XIAO_ESP32C3 to 1.9.1.21 or later, reading the SerialPort returns jibberish. Downgrading to 1.9.1.7 resolves the issue. Tested on two different XIAO C3's

Seeing the changes that went in to 1.9.1.21 is unfortunately over my head. At least I'll be able to assist testing

Thanks for an awesome library!

How to reproduce

Reproduced by running provided code snippet

Expected behaviour

Expect to receive something in the ASCII range like this:
2F-41-44-4E-39-20-36-35-33-34-0D-0A-0D-0A-30-2D-30-3A-31-2E-30-2E-30-28-32-34-30-34-32-35-31-38-35-36-30-30-57-29-0D-0A-31-2D-30-3A-31-2E-38-2E-30-28-30-30-30-31-30-30-30-30-2E-33-36-37-2A-6B-57-68-29-0D-0A-31-2D-30-3A-32-2E-38-2E-30-28-30-30-30-30-30-30-30-30-2E-30-30-30-2A-6B-57-68-29-0D-0A-31-2D-30-3A-33-2E-38-2E-30-28-30-30-30-30-30-30-30-33-2E-36-37-38-2A-6B-56-41-72-68-29-0D-0A-31-2D-30-3A-34-2E-38-2E-30-28-30-30-30-30-32-34-36-34-2E-39-30-35-2A-6B-56-41-72-68-29-0D-0A-31-2D-30-3A-31-2E-37-2E-30-28-30-30-30-31-2E-31-37-35-2A-6B-57-29-0D-0A-31-2D-30-3A-32-2E-37-2E-30-28-30-30-30-30-2E-30-30-30-2A-6B-57-29-0D-0A-31-2D-30-3A-33-2E-37-2E-30-28-30-30-30-30-2E-30-30-30-2A-6B-56-41-72-29-0D-0A-31-2D-30-3A-34-2E-37-2E-30-28-30-30-30-30-2E-35-32-35-2A-6B-56-41-72-29-0D-0A-31-2D-30-3A-32-31-2E-37-2E-30-28-30-30-30-30-2E-33-36-37-2A-6B-57-29-0D-0A-31-2D-30-3A-32-32-2E-37-2E-30-28-30-30-30-30-2E-30-30-30-2A-6B-57-29-0D-0A-31-2D-30-3A-34-31-2E-37-2E-30-28-30-30-30-30-2E-37-34-32-2A-6B-57-29-0D-0A-31-2D-30-3A-34-32-2E-37-2E-30-28-30-30-30-30-2E-30-30-30-2A-6B-57-29-0D-0A-31-2D-30-3A-36-31-2E-37-2E-30-28-30-30-30-30-2E-31-30-36-2A-6B-57-29-0D-0A-31-2D-30-3A-36-32-2E-37-2E-30-28-30-30-30-30-2E-30-30-30-2A-6B-57-29-0D-0A-31-2D-30-3A-32-33-2E-37-2E-30-28-30-30-30-30-2E-30-30-30-2A-6B-56-41-72-29-0D-0A-31-2D-30-3A-32-34-2E-37-2E-30-28-30-30-30-30-2E-32-36-30-2A-6B-56-41-72-29-0D-0A-31-2D-30-3A-34-33-2E-37-2E-30-28-30-30-30-30-2E-30-30-30-2A-6B-56-41-72-29-0D-0A-31-2D-30-3A-34-34-2E-37-2E-30-28-30-30-30-30-2E-32-30-31-2A-6B-56-41-72-29-0D-0A-31-2D-30-3A-36-33-2E-37-2E-30-28-30-30-30-30-2E-30-30-30-2A-6B-56-41-72-29-0D-0A-31-2D-30-3A-36-34-2E-37-2E-30-28-30-30-30-30-2E-30-36-36-2A-6B-56-41-72-29-0D-0A-31-2D-30-3A-33-32-2E-37-2E-30-28-32-33-31-2E-38-2A-56-29-0D-0A-31-2D-30-3A-35-32-2E-37-2E-30-28-32-33-32-2E-37-2A-56-29-0D-0A-31-2D-30-3A-37-32-2E-37-2E-30-28-32-33-32-2E-39-2A-56-29-0D-0A-31-2D-30-3A-33-31-2E-37-2E-30-28-30-30-31-2E-37-2A-41-29-0D-0A-31-2D-30-3A-35-31-2E-37-2E-30-28-30-30-33-2E-33-2A-41-29-0D-0A-31-2D-30-3A-37-31-2E-37-2E-30-28-30-30-30-2E-35-2A-41-29-0D-0A-21-37-31-37-46-0D-0A

Instead receiving something like this:
AB-53-AD-E5-EB-9D-A5-9F-8B-99-9D-A3-91-A3-9F-AF-9F-9F-9D-A3-91-AB-7D-AD-E5-EB-9D-A5-9F-8B-95-9D-A3-91-A3-9F-AF-9F-9F-9B-A3-8D-AB-7D-AD-E5-EB-9D-A5-9F-8B-91-9D-A3-91-A3-9F-AF-9F-9F-9F-A3-95-AB-7D-AD-E5-EB-BD-97-79-8F-97-E5-EB-00-68-5F-D7-35-BF-93-95-99-97-E5-EB-E5-EB-9F-A5-9F-8B-9D-A3-9F-A3-9F-AF-9B-97-9F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93-9B-A3-91-A3-9F-AF-9F-9F-9F-9F-A3-9F-9F-9F-AB-29-51-AD-E5-EB-9D-A5-9F-8B-9B-99-A3-91-A3-9F-AF-9F-9F-9F-9F-A3-9F-9F-9F-AB-29-53-7D-1B-AD-E5-EB-9D-A5-9F-8B-9B-97-A3-91-A3-9F-AF-9F-9F-9F-9F-A3-9B-95-91-AB-29-53-7D-1B-AD-E5-EB-9D-A5-9F-8B-97-99-A3-91-A3-9F-AF-9F-9F-9F-9F-A3-9F-9F-9F-AB-29-53-7D-1B-AD-E5-EB-9D-A5-9F-8B-97-97-A3-91-A3-9F-AF-9F-9F-9F-9F-A3-9D-8D-9F-AB-29-53-7D-1B-AD-E5-EB-9D-A5-9F-8B-93-99-A3-91-A3-9F-AF-9F-9F-9F-9F-A3-9F-9F-9F-AB-29-53-7D-1B-AD-E5-EB-9D-A5-9F-8B-93-97-A3-91-A3-9F-AF-9F-9F-9F-9F-A3-9F-93-93-AB-29-53-7D-1B-AD-E5-EB-9D-A5-9F-8B-99-9B-A3-91-A3-9F-AF-9B-99-9D-A3-8D-AB-53-AD-E5-EB-9D-A5-9F-8B-95-9B-A3-91-A3-9F-AF-9B-99-99-A3-99-AB-53-AD-E5-EB-9D-A5-9F-8B-91-9B-A3-91-A3-9F-AF-9B-99-99-A3-99-AB-53-AD-E5-EB-9D-A5-9F-8B-99-9D-A3-91-A3-9F

Screenshots

No response

Aditional information

Code snippet

`
using nanoFramework.Hardware.Esp32;
using System.Diagnostics;
using System.IO.Ports;
using System.Threading;

namespace SerialDemo
{
public class Program
{
private static SerialPort _serialPort;

    public static void Main()
    {
        _serialPort = new P1SerialPort().Create();
        _serialPort.DataReceived += Serial_DataReceived;
    }


    private static void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        var port = (SerialPort)sender;
        if (port.BytesToRead <= 0)
        {
            return;
        }

        Thread.Sleep(100);
        var message = port.ReadExisting();

        //var buffer = new byte[port.BytesToRead];
        //port.Read(buffer, 0, buffer.Length);
        //var message = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

        Debug.WriteLine(message);
    }
}

public class P1SerialPort
{
    public SerialPort Create()
    {
        // XIAO_ESP32C3
        Configuration.SetPinFunction(20, DeviceFunction.COM2_RX);
        Configuration.SetPinFunction(21, DeviceFunction.COM2_TX);

        return new SerialPort("COM2")
        {
            StopBits = StopBits.One,
            BaudRate = 115200,
            DataBits = 8,
            Parity = Parity.None,
            ReadBufferSize = 900,
            InvertSignalLevels = true,
            ReceivedBytesThreshold = 500,
            Handshake = Handshake.None
        };
    }
}

}
`

@josesimoes
Copy link
Member

Possibly related with nanoframework/nf-interpreter#2906

@mikmog
Copy link
Author

mikmog commented Apr 30, 2024

Seeing a lot of new line handling in pull request #2906.
Maybe worth mentioning. I'm receiving CR+LF as line feed terminator. Hex 0D-0A.

@josesimoes
Copy link
Member

@mikmog care to test again. Serial port should be working fine now.

@AdrianSoundy
Copy link
Member

AdrianSoundy commented Jun 19, 2024

The problem here is the InverseSignalsLevels is not being actioned.
The native driver sets the inverse then clears setting when port is opened.

@mikmog
Copy link
Author

mikmog commented Jun 20, 2024

Midsummer eve festivities coming up here. I’ll give it a try anyway in the next couple of days

@mikmog
Copy link
Author

mikmog commented Jun 22, 2024

Sorry. The problem still exist in 1.9.1.265. Based on Adrian's comment I also tried setting inverse signals after the port was opened. But that was not allowed 😕


`System Information
HAL build info: nanoCLR running @ ESP32_C3 built with ESP-IDF e7771c7
Target: XIAO_ESP32C3
Platform: ESP32

Firmware build Info:
Date: Jun 22 2024
Type: MinSizeRel build, chip rev. >= 3, without support for PSRAM
CLR Version: 1.9.1.265
Compiler: GNU ARM GCC v12.2.0

OEM Product codes (vendor, model, SKU): 0, 0, 0

Serial Numbers (module, system):
00000000000000000000000000000000
0000000000000000

Target capabilities:
Has nanoBooter: NO
IFU capable: NO
Has proprietary bootloader: YES

AppDomains:

Assemblies:

Native Assemblies:
mscorlib v100.5.0.19, checksum 0x445C7AF9
nanoFramework.Runtime.Native v100.0.9.0, checksum 0x109F6F22
nanoFramework.Hardware.Esp32 v100.0.10.0, checksum 0x6A20A689
nanoFramework.Hardware.Esp32.Rmt v100.0.4.0, checksum 0x608C5658
nanoFramework.Networking.Sntp v100.0.4.4, checksum 0xE2D9BDED
nanoFramework.ResourceManager v100.0.0.1, checksum 0xDCD7DF4D
nanoFramework.System.Collections v100.0.1.0, checksum 0x2DC2B090
nanoFramework.System.Text v100.0.0.1, checksum 0x8E6EB73D
nanoFramework.System.IO.Hashing v100.0.0.1, checksum 0xEBD8ED20
nanoFramework.System.Security.Cryptography v100.0.0.2, checksum 0xF4AEFE6C
nanoFramework.Runtime.Events v100.0.8.0, checksum 0x0EAB00C9
EventSink v1.0.0.0, checksum 0xF32F4C3E
System.IO.FileSystem v1.1.0.0, checksum 0xCC556D24
System.Math v100.0.5.5, checksum 0x9F9E2A7E
System.Net v100.2.0.1, checksum 0xD82C1452
System.Device.Adc v100.0.0.0, checksum 0xE5B80F0B
System.Device.Gpio v100.1.0.6, checksum 0x097E7BC5
System.Device.I2c v100.0.0.2, checksum 0xFA806D33
System.Device.I2c.Slave v1.0.0.0, checksum 0x4238164B
System.Device.I2s v100.0.0.1, checksum 0x478490FE
System.Device.Pwm v100.1.0.4, checksum 0xABF532C3
System.IO.Ports v100.1.6.1, checksum 0xB798CE30
System.Device.Spi v100.1.2.0, checksum 0x3F6E2A7E
System.Runtime.Serialization v100.0.0.0, checksum 0x0A066871
System.Device.Wifi v100.0.6.4, checksum 0x00A058C6
Windows.Storage v100.0.3.0, checksum 0xF0C37E1B

++++++++++++++++++++++++++++++++
++ Memory Map ++
++++++++++++++++++++++++++++++++
Type Start Size
++++++++++++++++++++++++++++++++
RAM 0x3fcc036c 0x0001c000
FLASH 0x00000000 0x00400000

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++ Flash Sector Map ++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Region Start Blocks Bytes/Block Usage
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0 0x00010000 1 0x1A0000 nanoCLR
1 0x001B0000 1 0x1F0000 Deployment
2 0x003C0000 1 0x040000 Configuration

+++++++++++++++++++++++++++++++++++++++++++++++++++
++ Storage Usage Map ++
+++++++++++++++++++++++++++++++++++++++++++++++++++
Start Size (kB) Usage
+++++++++++++++++++++++++++++++++++++++++++++++++++
0x003C0000 0x040000 (256kB) Configuration
0x00010000 0x1A0000 (1664kB) nanoCLR
0x001B0000 0x1F0000 (1984kB) Deployment`

@AdrianSoundy
Copy link
Member

Thanks for the feedback. I have looked at version 1.9.1.21 and can't see how it would have changed the behavior.
I'll do some further testing and get back to you.

@mikmog
Copy link
Author

mikmog commented Jun 22, 2024

Probably way off. But newer firmware might require a different value on the pull up. I'll do some tinkering and see if anything changes

@mikmog
Copy link
Author

mikmog commented Jun 22, 2024

The value of the pull up or which pin (3.3/5v) is not the cause.

From my point of view as a consumer at C# -level it feels like the assignment of InvertSignalLevels = true is not respected

Just to be sure, I tripled check and
1.9.1.7 => works,
1.9.1.21 => gibberish

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

No branches or pull requests

3 participants