Skip to content

M5Stack LED doesn't initialize GPIO leading to errors #1109

@jacobguilbeau

Description

@jacobguilbeau

Library/API/IoT binding

M5StickCPlus

Visual Studio version

VS2019 (16.11.16)

.NET nanoFramework extension version

2019.11.0.23

Target name(s)

M5StickCPlus.led.Toggle()

Firmware version

1.8.0.458

Device capabilities

No response

Description

Trying to run a simple one line statement to toggle the LED fails with CLR_E_NULL_REFERENCE

Code trying to run:
M5StickCPlus.Led.Toggle();

Produces this output:
The thread '<No Name>' (0x2) has exited with code 0 (0x0). ++++ Exception System.NullReferenceException - CLR_E_NULL_REFERENCE (1) ++++ ++++ Message: ++++ nanoFramework.M5Stack.M5StickCPlus::get_Led [IP: 000e] ++++ ++++ NFApp2.Program::Main [IP: 0004] ++++ Exception thrown: 'System.NullReferenceException' in nanoFramework.M5StickCPlus.dll An unhandled exception of type 'System.NullReferenceException' occurred in nanoFramework.M5StickCPlus.dll

This is due to the led object depending on a gpio internal object that has not been created. Getting the GPIOController forces the internal object to be created leading to the led object now working correctly.

How to reproduce

  1. Start new nanoframework project
  2. Try and do anything with M5StickCPlus.Led

Expected behaviour

I expect the led to toggle without exception

Screenshots

No response

Sample project or code

No response

Aditional information

Problem is here:
https://github.com/nanoframework/nanoFramework.M5Stack/blob/31c8cf98ba5b458485d41235fe7f0ce50681b955/nanoFramework.M5StickCommon/M5StickCBase.cs#L28

led get just returns _gpio. and doesn't check for null or create a new gpio.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions