AnalogRead in mbed ticker would cause failure

When I upload the code, the LED starts to blink in 4 fast and 4 slow in regular.
After a while, I lose the connection with the board.

If I delete the line contains analogRead(), it'll work.
But what I need is the analogRead.
Does anybody have a solution.

#include <ArduinoBLE.h>

mbed::Ticker timer;

const int ledPin = LED_BUILTIN; // pin to use for the LED
volatile bool flip = false;
volatile bool update = true;

void setup() {
Serial.begin(115200);
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin, HIGH);
timer.attach(attime,0.1);
}

void attime() {
analogRead(A0);
if (update){
digitalWrite(ledPin, HIGH);
update = false;
}else{
digitalWrite(ledPin, LOW);
update = true;
}
}

void loop() {
BLE.poll();
}

By the way, I had try mbed::AnalogIn. It didn't work either.

Unfortunately, I don't have a solution for you, but I'll provide some additional information that might be helpful to you or others trying to help you.

I was able to reproduce the problem when running your sketch. I notice it even repeatedly disconnects all the other devices plugged into the USB hub!

The 4X long, 4X short blink pattern on the onboard LED is an error indicator. Serial debug information is output on the pin marked "TX1" on the Nano 33 BLE boards at 115200 baud when this happens. You can connect a USB to TTL serial adapter to that pin and then open its port in Serial Monitor to see the output. When I did this while your sketch was running, the output I got was:

++ MbedOS Error Info ++
Error Status: 0x80010133 Code: 307 Module: 1
Error Message: Mutex: 0x200101FC, Not allowed in ISR context
Location: 0x45F4F
Error Value: 0x200101FC
Current Thread: mainĀ  Id: 0x200043D4 Entry: 0x45E7D StackSize: 0x8000 StackMem: 0x200081C8 SP: 0x2003FEEC 
For more info, visit: https://mbed.com/s/error?error=0x80010133&tgt=ARDUINO_NANO33BLE
-- MbedOS Error Info --

You could set a flag in the attime function and do the rest in your main loop or a function called from your main loop.

The analogRead function has been written in a more complicated way than one might think, thats why mbedOS does not like you to run it inside an interrupt service routine.