@@ -248,6 +248,15 @@ static s4_t delta_time(u4_t time) {
248
248
return (s4_t )(time - hal_ticks ());
249
249
}
250
250
251
+ // deal with boards that are stressed by no-interrupt delays #529, etc.
252
+ #if defined(ARDUINO_DISCO_L072CZ_LRWAN1)
253
+ # define HAL_WAITUNTIL_DOWNCOUNT_MS 16 // on this board, 16 ms works better
254
+ # define HAL_WAITUNTIL_DOWNCOUNT_THRESH ms2osticks (16 ) // as does this threashold.
255
+ #else
256
+ # define HAL_WAITUNTIL_DOWNCOUNT_MS 8 // on most boards, delay for 8 ms
257
+ # define HAL_WAITUNTIL_DOWNCOUNT_THRESH ms2osticks (9 ) // but try to leave a little slack for final timing.
258
+ #endif
259
+
251
260
u4_t hal_waitUntil (u4_t time) {
252
261
s4_t delta = delta_time (time);
253
262
// check for already too late.
@@ -258,12 +267,12 @@ u4_t hal_waitUntil (u4_t time) {
258
267
// will produce an accurate delay is 16383. Also, STM32 does a better
259
268
// job with delay is less than 10,000 us; so reduce in steps.
260
269
// It's nice to use delay() for the longer times.
261
- while (delta > ( 9000 / US_PER_OSTICK) ) {
270
+ while (delta > HAL_WAITUNTIL_DOWNCOUNT_THRESH ) {
262
271
// deliberately delay 8ms rather than 9ms, so we
263
272
// will exit loop with delta typically positive.
264
273
// Depends on BSP keeping time accurately even if interrupts
265
274
// are disabled.
266
- delay (8 );
275
+ delay (HAL_WAITUNTIL_DOWNCOUNT_MS );
267
276
// re-synchronize.
268
277
delta = delta_time (time);
269
278
}
0 commit comments