Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cores/nRF5/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ void loop( void ) ;
#ifdef __cplusplus
#include "Uart.h"
#include "rtos.h"
void check_and_report_fault();
void dump_call_stack();
#endif // __cplusplus

#endif // Arduino_h
4 changes: 4 additions & 0 deletions cores/nRF5/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ size_t Uart::write(const uint8_t data)
return 1;
}

Uart::operator bool() {
return nrfUart->ENABLE == UART_ENABLE_ENABLE_Enabled;
}

#if defined(NRF52_SERIES)
#define NRF_UART0_IRQn UARTE0_UART0_IRQn
#elif defined(NRF51_SERIES)
Expand Down
4 changes: 2 additions & 2 deletions cores/nRF5/Uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class Uart : public HardwareSerial

void IrqHandler();

operator bool() { return true; }
operator bool();

private:
NRF_UART_Type *nrfUart;
NRF_UART_Type *nrfUart{nullptr};
RingBuffer rxBuffer;

IRQn_Type IRQn;
Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/freertos/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@
#endif

#ifndef configRECORD_STACK_HIGH_ADDRESS
#define configRECORD_STACK_HIGH_ADDRESS 0
#define configRECORD_STACK_HIGH_ADDRESS 1
#endif

#ifndef configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H
Expand Down
6 changes: 6 additions & 0 deletions cores/nRF5/freertos/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,12 @@ TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;


/** [N-able ADDED] Backtrace capture code for fault handler **/
#if ( configRECORD_STACK_HIGH_ADDRESS == 1 )
uint32_t ulGetCurrentStackLowAddress(void);
uint32_t ulGetCurrentStackHighAddress(void);
#endif /* configRECORD_STACK_HIGH_ADDRESS */

/* *INDENT-OFF* */
#ifdef __cplusplus
}
Expand Down
21 changes: 21 additions & 0 deletions cores/nRF5/freertos/tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5393,3 +5393,24 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
#endif

#endif /* if ( configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H == 1 ) */

/** [N-able ADDED] Backtrace capture code for fault handler **/
#if ( configRECORD_STACK_HIGH_ADDRESS == 1 )
uint32_t ulGetCurrentStackLowAddress(void)
{
if (pxCurrentTCB != NULL)
{
return (uint32_t)pxCurrentTCB->pxStack;
}
return 0;
}

uint32_t ulGetCurrentStackHighAddress(void)
{
if (pxCurrentTCB != NULL)
{
return (uint32_t)pxCurrentTCB->pxEndOfStack;
}
return 0;
}
#endif /* configRECORD_STACK_HIGH_ADDRESS */
2 changes: 1 addition & 1 deletion cores/nRF5/nordic/linker/nrf52833_s140_v7_adabl.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ MEMORY
FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0x74000 - 0x27000 - 0x4000
USER_STORE (rw) : ORIGIN = 0x74000 - 0x4000, LENGTH = 0x2000
BOND_STORE (rw) : ORIGIN = 0x74000 - 0x2000, LENGTH = 0x2000
RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x20000 - 0x6000
RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x20000 - 0x6000 - 0x100
}
2 changes: 1 addition & 1 deletion cores/nRF5/nordic/linker/nrf52833_serial_adabl.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MEMORY
FLASH (rx) : ORIGIN = 0x00001000, LENGTH = 0x74000 - 0x1000 - 0x4000
USER_STORE (rw) : ORIGIN = 0x70000, LENGTH = 0x2000
BOND_STORE (rw) : ORIGIN = 0x72000, LENGTH = 0x2000
RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x20000 - 0x8
RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x20000 - 0x8 - 0x100
}


Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/nordic/linker/nrf52833_xxaa.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MEMORY
USER_STORE (rw) : ORIGIN = 0x7C000, LENGTH = 0x2000
BOND_STORE (rw) : ORIGIN = 0x7E000, LENGTH = 0x2000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x20000
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x20000
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x20000 - 0x100
}


Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/nordic/linker/nrf52840_dongle.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MEMORY
FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0xDB000
USER_STORE (rw) : ORIGIN = 0xDC000, LENGTH = 0x2000
BOND_STORE (rw) : ORIGIN = 0xDE000, LENGTH = 0x2000
RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x40000 - 0x8
RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x40000 - 0x8 - 0x100
}


Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/nordic/linker/nrf52840_s140_v6_adabl.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MEMORY
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0xF4000 - 0x26000 - 0x4000
USER_STORE (rw) : ORIGIN = 0xF4000 - 0x4000, LENGTH = 0x2000
BOND_STORE (rw) : ORIGIN = 0xF4000 - 0x2000, LENGTH = 0x2000
RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x40000 - 0x6000
RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x40000 - 0x6000 - 0x100
}

INCLUDE "nrf52_common.ld"
2 changes: 1 addition & 1 deletion cores/nRF5/nordic/linker/nrf52840_s140_v7_adabl.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MEMORY
FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0xF4000 - 0x27000 - 0x4000
USER_STORE (rw) : ORIGIN = 0xF4000 - 0x4000, LENGTH = 0x2000
BOND_STORE (rw) : ORIGIN = 0xF4000 - 0x2000, LENGTH = 0x2000
RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x40000 - 0x6000
RAM (rwx) : ORIGIN = 0x20006000, LENGTH = 0x40000 - 0x6000 - 0x100
}

INCLUDE "nrf52_common.ld"
2 changes: 1 addition & 1 deletion cores/nRF5/nordic/linker/nrf52840_serial_adabl.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MEMORY
FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0xF4000 - 0x1000 - 0x4000
USER_STORE (rw) : ORIGIN = 0xF0000, LENGTH = 0x2000
BOND_STORE (rw) : ORIGIN = 0xF2000, LENGTH = 0x2000
RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x3FFF8
RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x3FFF8 - 0x100
}


Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/nordic/linker/nrf52840_xxaa.ld
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MEMORY
BOND_STORE (rw) : ORIGIN = 0xFE000, LENGTH = 0x2000
EXTFLASH (rx) : ORIGIN = 0x12000000, LENGTH = 0x8000000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x40000
CODE_RAM (rwx) : ORIGIN = 0x800000, LENGTH = 0x40000 - 0x100
}


Expand Down
13 changes: 9 additions & 4 deletions cores/nRF5/rtos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@ extern "C" {
void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
{
Serial.printf("Task: %s, stack overflow\n", pcTaskName);
dump_call_stack();
delay(50);
NVIC_SystemReset();
while (1){}
}

void vApplicationMallocFailedHook(void)
{
Serial.println("Malloc failed");
Serial.printf("\n=== MEMORY ALLOCATION FAILED ===\n");
dump_call_stack();
delay(50);
NVIC_SystemReset();
while (1){}
}

void vApplicationIdleHook(void) {
NRF_WDT->RR[0] = WDT_RR_RR_Reload;
#ifdef USE_TINYUSB
extern uint32_t tud_cdc_write_flush (void);
tud_cdc_write_flush();
#ifdef USB_CDC_DEFAULT_SERIAL
Serial.flush();
#endif
}

Expand Down
Loading
Loading