-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support for nRF52 Watchdog #11684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@manchoz, thank you for your changes. |
017c8d2
to
c9370f3
Compare
@manchoz Thanks for the contribution. I edited the comment above. There is no need for release notes (as this is just a target update). I'll review the code shortly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questions:
- how was this tested
- why watchdog is not enabled for any current supported targets
/* | ||
* Copyright (c) 2019 Trampoline SRL | ||
* Copyright (c) 2019 Giampaolo Mancini <[email protected]> | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPDX identifiers please to new files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added SPDX for Apache-2.0.
Please, note that this patch fixes upstream bug. See: https://devzone.nordicsemi.com/f/nordic-q-a/51674/maximum-reload-time-for-wdt
c851a06
to
c30ca66
Compare
Remaining questions:
|
Implementation has been tested on several Arduino Nano33Ble boards adapting the Watchdog example for the Arduino platform. The following sketch was used: #include "mbed.h"
#include "drivers/Watchdog.h"
using namespace mbed;
REDIRECT_STDOUT_TO(Serial)
// Connect momentary button beetwen Pin 2 and GND
const byte interruptPin = 2;
// Maximum Watchdog timoute in seconds for nRF52840
// const int INIT_COUNTDOWN = 131071;
const int INIT_COUNTDOWN = 10;
int countdown = INIT_COUNTDOWN;
const uint32_t TIMEOUT_MS = countdown * 1000;
uint32_t now = millis();
const uint32_t interval = 1000;
uint32_t nowLed = millis();
uint32_t ledInterval = 1000;
void trigger()
{
Watchdog::get_instance().kick();
countdown = INIT_COUNTDOWN;
ledInterval = 1000;
}
void setup()
{
Serial.begin(115200);
// Wait for connection on serial port
while (!Serial)
;
Serial.println();
Serial.println("Target started ");
Serial.println();
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), trigger, FALLING);
Watchdog &watchdog = Watchdog::get_instance();
Serial.print("Enabling Watchdog. (");
Serial.print((uint32_t)TIMEOUT_MS);
Serial.println(" ms).");
bool enabled = watchdog.start(TIMEOUT_MS);
Serial.print("Status: ");
Serial.println(enabled ? "Enabled": "Not Enabled");
if (!enabled) {
Serial.println("Timer not enabled. Invalid timeout parameter.");
delay(2000);
while (true);
}
uint32_t watchdog_timeout = watchdog.get_timeout();
Serial.print("Watchdog initialized to ");
Serial.print(watchdog_timeout);
Serial.println(" ms.");
Serial.print("Press BUTTON at least once every ");
Serial.print(watchdog_timeout);
Serial.println(" ms to kick the watchdog and prevent system reset");
nowLed = millis();
now = millis();
}
void loop()
{
if (millis() - now > interval - (float)ledInterval / INIT_COUNTDOWN) {
printf("\r%3i", countdown--);
fflush(stdout);
now = millis();
}
if (millis() - nowLed > ledInterval) {
// Blink LED faster and faster as timout approaches
digitalWrite(LED_BUILTIN, HIGH);
delay(50);
digitalWrite(LED_BUILTIN, LOW);
ledInterval -= (float)ledInterval / INIT_COUNTDOWN;
nowLed = millis();
}
} I really don't know why the watchdog for nRF52x have not been implemented yet on Mbed: it's implemented on almost any other RTOS. |
I see, on Arduino Nano33Ble that does not support daplink (cant be tested with our infrastructure, correct?). Looks fine to me and even better if we can enable this for a common nrf target that can be tested? |
I have run a few tests with a Makerdiary nRF52850-MDK board (which supports DAPlink) in a standard Mbed OS scenario and everything seems ok. Test code and instructions are at https://github.com/manchoz/mbed-os-example-watchdog-nrf52840. (Please note that the repo contains also the support for the nRF52850-MDK board). |
CI started |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
@0xc0170 @ARMmbed/mbed-os-maintainers Thank you so much! |
Description
Add the Watchdog driver implementation for the nRF52 targets using the nRF5 SDK WDT API.
To enable the Watchdog driver for the nRF2 targets, you need to activate it adding the macro
NRFX_WDT_ENABLED=1
in themacro
section ofmbed_app.json
configuration file and adding the"WATCHDOG"
key to the list of the device's drivers. Example file:Pull request type