nanoframework / Home

:house: The landing page for .NET nanoFramework repositories.
https://www.nanoframework.net
MIT License
858 stars 78 forks source link

SpiDevice is not disposing on ESP32-C3 and blocks the execution #1438

Closed Ellerbach closed 2 months ago

Ellerbach commented 7 months ago

Library/API/IoT binding

System.Device.Spi

Visual Studio version

No response

.NET nanoFramework extension version

No response

Target name(s)

XIAO_ESP32C3

Firmware version

latest

Device capabilities

No response

Description

SpiDevice dispose blocks the execution and is never disposing

How to reproduce

        // Frequency is 38KHz in the protocol
        float t_carrier = 1 / 38.0f;
        // Reality is that there is a 2us difference in the output as there is always a 2us bit on on SPI using MOSI
        float t_ushort = t_carrier - 2e-3f;
        // Calulate the outpout frenquency. Here = 16/(1/38 -2^-3) = 658KHz
        int freq = (int)(16.0f * 1000 / t_ushort);

        Configuration.SetPinFunction(4, DeviceFunction.SPI1_CLOCK);
        Configuration.SetPinFunction(5, DeviceFunction.SPI1_MISO);
        Configuration.SetPinFunction(6, DeviceFunction.SPI1_MOSI);

        var settings = new SpiConnectionSettings(1, -1)
        {
            ClockFrequency = freq,
            Mode = SpiMode.Mode3,
            ChipSelectLineActiveState = PinValue.High,
        };

        _spi = new SpiDevice(settings);

        Thread.Sleep(1000);
        _spi.Dispose();

// This is then never ever executed! _spi = new SpiDevice(settings);

Thread.Sleep(1000);

_spi.Dispose();

Thread.Sleep(Timeout.Infinite);

Expected behaviour

SpiDevice should properly dispose

Screenshots

No response

Sample project or code

No response

Aditional information

No response

Ellerbach commented 7 months ago

I've been trying on different ESP32-C3 models and they all have the same issue. There is no problem for a normal ESP32. So it seems related specifically to ESP32-C3.

gwnpeter commented 6 months ago

i have some test code,may be the same problem ,on xiao_esp32_c3

josesimoes commented 4 months ago

This is fixed with nanoframework/nf-interpreter#2915. Can you please confirm?

josesimoes commented 3 months ago

Pinging to the followers of this issue. Appreciate if anyone can retest this and confirm that is indeed fixed. Thanks! 😃

mikmog commented 2 months ago

Ran the provided code snippet in debug mode. The second instantiation of the SpiDeviceand dispose() executed just fine

System.Device.Spi, 1.3.52.0 Target: XIAO_ESP32C3 CLR Version: 1.9.1.265

josesimoes commented 2 months ago

Thanks for testing this. Closing it as fixed. Can be reopened if needed.