Hi,
I’ve being trying to get the mode/BTN/D20 button/pin registering a Falling edge in userspace and I am failing to get anything.
Below is the code I’m trying with bits commented out and in and combinations but nothing seems to work. I’ve got the B5 installed in the stock Eval Board to remove any potential issues with my customer carrier and have swapped out B5’s but still the same results. Is the BTN line available to the userspace? Trying this in version 6.3.5
#include "Particle.h"
STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));
STARTUP(System.enableFeature(FEATURE_RESET_INFO));
STARTUP(System.enableFeature(FEATURE_DISABLE_LISTENING_MODE));
STARTUP(system_thread_set_state(spark::feature::DISABLED, nullptr));
SYSTEM_MODE(MANUAL);
bool printOutDebug;
SystemSleepConfiguration config;
void interu() {
printOutDebug = true;
}
bool pinState=false;
void setup(){
Serial.begin();
waitFor(Serial.isConnected, 10000);
Serial.println("Starting sleep test");
delay(10000);
printOutDebug = false;
pinMode(BTN, INPUT_PULLUP);
//attachInterrupt(BTN, interu,FALLING);
while(1) {
if (pinState!=digitalRead(BTN)) {
pinState=digitalRead(BTN);
Serial.printlnf("Pin state changed to %d", pinState);
}
}
}
void loop(){
/*config.mode(SystemSleepMode::ULTRA_LOW_POWER)
.gpio(BTN, FALLING)
.duration(30s);
SystemSleepResult result = System.sleep(config);*/
//Serial.printlnf("Woke up, reason: %d", result.wakeupReason());
if (printOutDebug) {
Serial.println("BTN Pressed");
printOutDebug = false;
}
if (pinState!=digitalRead(BTN)) {
pinState=digitalRead(BTN);
Serial.printlnf("Pin state changed to %d", pinState);
}
Serial.println("Going back to sleep in 10s");
delay(10000);
Particle.process();
}
Seems it’s a 6.3.5 bug. Code works fine in 6.3.4 and just for giggles tried the 6.3.5 compile on a 6.4.0 install and also works.
You cannot use BTN as a GPIO. Device OS attaches an interrupt and pull-up on the pin for the system button handler and there is no way to turn it off, even if you are not using a button.
I'm not sure why it ever worked, but I'd guess it's because of the order that the interrupt handlers were set up by chance allowed it to work sometimes.
Erm, this is a massive issue. We have developed products that use the Mode Button. And a variety of firmware that also use the Mode button. It works successfully on most OS versions except for 6.3.5. So if this is the intended path, what do we need to do to get a issue raise to stop this path as it will in effect stop support of our current fleet from ever being updated beyond 6.3.4 and we will have to spin new boards that utilise an alternative to the mode button. Which is not cheap.
Sorry, I confused this post and a different one and that code should work because you are only using the button as a wake button, which should work. It's not clear to me why it's not working on 6.3.5.
OK, Phew. Gave me a minor heart attack there.
I’ll wait till 6.4 is available on VSCode and will try and use that, else I’ll re raise the issue.
If you are able to do so easily, putting an external 10K pull-up resistor on the BTN pin with 6.3.5 would be an interesting test. If that works, the cause is that the pull is being lost on sleep, which at least narrows down the problem.
So I put a 6k pull up resistor on the eval board between mode and 3v3. Flashed the app at 6.3.5. It did not work. What is interesting is that that the issue is in the app space.
If I update the B5 OS to 6.3.5 but install the app compiled against 6.3.4 then the mode switch wakes the device correctly. However if I compile the app against 6.3.5 then it does not wake up pressing the mode switch.
I’ve just done a comparison for the deviceOS between 6.3.4 and 6.3.5 and one diff that stands out glaring is in the hal/src/b5som/pinmap_defines.h
The BTN has changed from 24 to 20. If I compile my test app and instead of using BTN (Which macros to 20 in 6.3.5) I put in 24 in the config. It works! So, looks like this pinmap change was made but the s_pin_map in the pinmap_hal.c was not updated to reflect this change.
That is very helpful information; I will have to ask why that was changed. Thank you!
I'm confused where you are seeing this change. If I pull up the latest version of hal/src/b5som/pinmap_defines.h in develop, the definition for BTN is still 24 and hasn't changed in 7 years.
Likewise, if I pull up the tag for 6.3.5, BTN is also 24.