Skip to content

Commit b0311d1

Browse files
authored
Merge branch 'master' into fix-micros
2 parents ccd2fe3 + 6c66cd1 commit b0311d1

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

cores/nRF5/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ void setup( void ) ;
3636
void loop( void ) ;
3737

3838
void suspendLoop(void);
39+
void resumeLoop(void);
3940

4041
#include "WVariant.h"
4142

cores/nRF5/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,13 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
182182
configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
183183
if ( xModifiableIdleTime > 0 )
184184
{
185-
#if 0 // With FreeRTOS sd_app_evt_wait increases power consumption with FreeRTOS compared to _WFE (NRFFOSDK-11174)
185+
#if (__FPU_USED == 1)
186+
// nRF52832 errata 87: prevent FPU from keeping CPU on
187+
// https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev2/ERR/nRF52832/Rev2/latest/anomaly_832_87.html?cp=4_2_1_0_1_24
188+
__set_FPSCR(__get_FPSCR() & ~(0x0000009F));
189+
(void) __get_FPSCR();
190+
NVIC_ClearPendingIRQ(FPU_IRQn);
191+
#endif
186192
#ifdef SOFTDEVICE_PRESENT // TODO
187193
uint8_t sd_en = 0;
188194
(void) sd_softdevice_is_enabled(&sd_en);
@@ -193,7 +199,6 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
193199
}
194200
else
195201
#endif
196-
#endif // (NRFFOSDK-11174)
197202
{
198203
/* No SD - we would just block interrupts globally.
199204
* BASEPRI cannot be used for that because it would prevent WFE from wake up.
@@ -227,15 +232,34 @@ void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
227232
diff = xExpectedIdleTime;
228233
}
229234

230-
if (diff > 0)
231-
{
232-
vTaskStepTick(diff);
235+
// nRF-provided fix for delay() wakeup 1ms spin-loop power waste
236+
// See https://devzone.nordicsemi.com/f/nordic-q-a/63828/vtaskdelay-on-nrf52-freertos-port-wastes-cpu-power
237+
BaseType_t switch_req = pdFALSE;
233238

239+
if (diff > 1)
240+
{
241+
vTaskStepTick(diff - 1);
242+
234243
// If dwt cycle count is enable, adjust it as welll
235244
if ( (CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) && (DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk) )
236245
{
237246
DWT->CYCCNT += ((diff * 1000000) / configTICK_RATE_HZ) * 64;
238247
}
248+
249+
switch_req = xTaskIncrementTick();
250+
}
251+
else if (diff == 1)
252+
{
253+
switch_req = xTaskIncrementTick();
254+
}
255+
256+
/* Increment the RTOS tick as usual which checks if there is a need for rescheduling */
257+
if ( switch_req != pdFALSE )
258+
{
259+
/* A context switch is required. Context switching is performed in
260+
the PendSV interrupt. Pend the PendSV interrupt. */
261+
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
262+
__SEV();
239263
}
240264
}
241265
}

cores/nRF5/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ void suspendLoop(void)
100100
vTaskSuspend(_loopHandle);
101101
}
102102

103+
void resumeLoop(void)
104+
{
105+
if ( isInISR() )
106+
{
107+
xTaskResumeFromISR(_loopHandle);
108+
}
109+
else
110+
{
111+
vTaskResume(_loopHandle);
112+
}
113+
}
114+
103115
extern "C"
104116
{
105117

libraries/Adafruit_LittleFS/src/littlefs/lfs_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ void lfs_crc(uint32_t *crc, const void *buffer, size_t size);
168168
// Allocate memory, only used if buffers are not provided to littlefs
169169
static inline void *lfs_malloc(size_t size) {
170170
#ifndef LFS_NO_MALLOC
171+
extern void *pvPortMalloc( size_t xWantedSize );
171172
return pvPortMalloc(size);
172173
#else
173174
(void)size;
@@ -178,6 +179,7 @@ static inline void *lfs_malloc(size_t size) {
178179
// Deallocate memory, only used if buffers are not provided to littlefs
179180
static inline void lfs_free(void *p) {
180181
#ifndef LFS_NO_MALLOC
182+
extern void vPortFree( void *pv );
181183
vPortFree(p);
182184
#else
183185
(void)p;

libraries/Wire/Wire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class TwoWire : public Stream
3939
void begin(uint8_t);
4040
void end();
4141
void setClock(uint32_t);
42+
void setPins(uint8_t pinSDA, uint8_t pinSCL);
4243

4344
void beginTransmission(uint8_t);
4445
uint8_t endTransmission(bool stopBit);

libraries/Wire/Wire_nRF52.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ void TwoWire::setClock(uint32_t baudrate) {
127127
}
128128
}
129129

130+
void TwoWire::setPins(uint8_t pinSDA, uint8_t pinSCL)
131+
{
132+
this->_uc_pinSDA = g_ADigitalPinMap[pinSDA];
133+
this->_uc_pinSCL = g_ADigitalPinMap[pinSCL];
134+
}
135+
130136
void TwoWire::end() {
131137
if (master)
132138
{

0 commit comments

Comments
 (0)