microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
708 stars 588 forks source link

Using the function "pins.pulseIn" will result in error code 914 #5321

Closed LOBOT-ROBOT closed 1 year ago

LOBOT-ROBOT commented 1 year ago

image

let data = pins.pulseIn(DigitalPin.P0, PulseValue.High)
basic.forever(function () {

})

When the above code downloaded to microbit, a 914 error occurs.

elecfreaks1 commented 1 year ago

Yes, I also encountered this problem

elecfreaks1 commented 1 year ago

image

let data = pins.pulseIn(DigitalPin.P0, PulseValue.High)
basic.forever(function () {

})

When the above code downloaded to microbit, a 914 error occurs.

martinwork commented 1 year ago

Related: https://github.com/microsoft/pxt-microbit/issues/4821

The error occurs in current MakeCode with micro:bit V2 and the pulse in block in on start.

The error doesn't occur with any of these variations:

d2i-23 commented 1 year ago

However, I got the exact error by making an ultrasonic sensor read in a forever loop?

basic.forever(function () {
    if (sonar.ping(
    DigitalPin.P0,
    DigitalPin.P1,
    PingUnit.Centimeters
    ) != 0) {
        basic.showString("o")
    } else {
        basic.showString("i")
    }
})

Code that I used to replicate the error

The ultrasonic sensor likely uses the pulse in block somewhere in its code. Thus, basically, this happened in a forever loop.

ichaelm commented 1 year ago

I also have this problem today, and did not have it on friday. Version info:

makecode.microbit.org version: 6.0.16 Microsoft MakeCode version: 9.0.12 microbit runtime version: v2.2.0-rc6 codal-microbit-v2 runtime version: v0.2.56

d2i-23 commented 1 year ago

Same here, my code worked perfectly fine two days ago. It is only up until as of time the OP started this post I started having this specific issue and some of my attached sensors stopped working. It likely isn't a problem with our code but a version change overnight without addressing this issue. (If you check at the repository for MakeCode, many of them are changed 4 days ago) Seeing that quite a few are already facing this a day after post highly suggest something wrong on the software. Plus, many of my peers are troubleshooting this exact issue.

jwunderl commented 1 year ago

Hm, looks like regression from https://github.com/microsoft/pxt-microbit/pull/5316, @JohnVidler any idea here? Looks like it's hitting PANIC_CALLED_FROM_ISR here https://github.com/microsoft/pxt-common-packages/blob/master/libs/base/gc.cpp#L161 or here https://github.com/microsoft/pxt-common-packages/blob/master/libs/base/gc.cpp#L740 when trying to alloc right after calling pins.pulseIn without yielding-- e.g.

let asdf = pins.pulseIn(DigitalPin.P0, PulseValue.High)

and

let asdf = pins.pulseIn(DigitalPin.P0, PulseValue.High)
pause(50)
basic.forever(function () {

})

are fine, but

let asdf = pins.pulseIn(DigitalPin.P0, PulseValue.High)
basic.forever(function () {

})

errors

For reference, here is a link to the previous version (from friday) where it was working: https://makecode.microbit.org/v6.0.15#editor

martinwork commented 1 year ago

When the 914 error is not triggered, it seems to hang. With the C++ example below, I don't see "Hello"

#include "MicroBit.h"

MicroBit uBit;

int period = 0;

void forever()
{
    while (true)
    {
        uBit.display.image.setPixelValue( 0, 0, 255);
        uBit.io.P0.setPolarity(1);
        period = uBit.io.P0.getPulseUs(2000000);
        uBit.display.image.setPixelValue( 4, 4, 255);

        uBit.sleep(1000);
        uBit.display.scroll( "Hello");
    }
}

int main()
{
    uBit.init();
    create_fiber( forever);
    release_fiber();
    return 0;
}
JohnVidler commented 1 year ago

Thanks for the repro @martinwork and everyone on the thread here - currently investigating. I'll report back when I've tracked down the behaviour seen here.

PPPDUD commented 1 year ago

I am also getting a 914 when using my 4Tronics Sonar sensor on my BitBot. Microbit V2.00 and Android 13.

JohnVidler commented 1 year ago

I believe I have found the root cause of this all - I think that it all comes down to an incorrect use of an internal lock.

However, as its currently 00:06 local time, I'll have to push a fix tomorrow.

@jwunderl I'll fire up a PR first thing tomorrow UK time so we can test this via the CI and get it merged if all is well.

Thanks folks.

jwunderl commented 1 year ago

Sounds good, thanks / get some rest! I'll be available to prep a build and push a hotfix tomorrow am PT~

JohnVidler commented 1 year ago

Currently building this as a test PR over in https://github.com/microsoft/pxt-microbit/pull/5324 - I'll post a link to the CI build for this if folks want to test things as well once its built.

JohnVidler commented 1 year ago

CI build of Makecode URL: https://makecode.microbit.org/app/9a10ab6b7fb776c05981ce9814171e8e0da1871a-842ac95e33

JohnVidler commented 1 year ago

Ok, so we're looking good here with the fix.

I've tested this with this in MakeCode:

image

... and this, just for extra:

image

Along with the CODAL test case posted by @martinwork and all seem to be behaving now.

@LOBOT-ROBOT @elecfreaks1 @d2i-23 @ichaelm - if any of you want to test your code against this PR before we go live, the link is here: https://makecode.microbit.org/app/9a10ab6b7fb776c05981ce9814171e8e0da1871a-842ac95e33 but unless anyone finds any issues we should go ahead and take https://github.com/microsoft/pxt-microbit/pull/5324 to live if we can please @jwunderl . I'll remove the DO NOT MERGE tags.

martinwork commented 1 year ago

All my examples behave as expected in the new build.

kimlabtoy commented 1 year ago

But I still can't run sonar program V2 in new build. The same code can work on V1.5 board, but on V2, it can only detect <10cm and unstable.

A1 363023312_1714468798974788_4826183488006116484_n

martinwork commented 1 year ago

@kimlabtoy Please check the echo pin. Pin 11 is shared with button B, so is not a good choice. https://tech.microbit.org/hardware/edgeconnector/

kimlabtoy commented 1 year ago

@kimlabtoy Please check the echo pin. Pin 11 is shared with button B, so is not a good choice. https://tech.microbit.org/hardware/edgeconnector/

Thanks for your advice, I change pin to P0 and P1, but it still doesn't work on V2.

jwunderl commented 1 year ago

@kimlabtoy could you please check if your program works on https://makecode.microbit.org/v6.0.15#editor ? It'd be good to know if this is from the same cause, or if it's another bug that's potentially unrelated

kimlabtoy commented 1 year ago

@jwunderl I run my program use V1 in v6.0.15 build, its work well, and run the same program use V2 in v6.0.15 build, it can only detect <10cm and quickly show error 030. By the way, run this program use V2 in v6.0.16 build will show error 914.

jwunderl commented 1 year ago

@kimlabtoy Thank you for checking; this would indicate it's a separate issue at it's root, and just happened to use this code path / hit a more obvious error. Could you file a separate issue for that and we can investigate? This issue will be closed in a few minutes when I release the new payload fixing the 914 error

kimlabtoy commented 1 year ago

@jwunderl Thank you, I will write this issue in new post.

jwunderl commented 1 year ago

I have released the fix for this as of v6.0.17, if anyone is still seeing 914's in that version feel free to ping me here