mirror of
https://github.com/alexhopeoconnor/firmware.git
synced 2026-10-21 10:42:35 +10:00
Merge branch 'pioarduino' into crowpanel-p4
This commit is contained in:
@@ -239,7 +239,9 @@ void cpuDeepSleep(uint32_t msecToWake)
|
||||
#if SOC_RTCIO_HOLD_SUPPORTED && SOC_PM_SUPPORT_EXT_WAKEUP
|
||||
uint64_t gpioMask = (1ULL << (config.device.button_gpio ? config.device.button_gpio : BUTTON_PIN));
|
||||
#endif
|
||||
|
||||
#ifdef ALT_BUTTON_WAKE
|
||||
gpioMask |= (1ULL << BUTTON_PIN_ALT);
|
||||
#endif
|
||||
#ifdef BUTTON_NEED_PULLUP
|
||||
gpio_pullup_en((gpio_num_t)BUTTON_PIN);
|
||||
#endif
|
||||
|
||||
@@ -23,5 +23,6 @@ void lateInitVariant()
|
||||
cfg.i2s.bits = BIT_LENGTH_16BITS;
|
||||
cfg.i2s.rate = RATE_44K;
|
||||
board.begin(cfg);
|
||||
board.setVolume(75); // 75% volume
|
||||
}
|
||||
#endif
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <nrfx_wdt.h>
|
||||
#include <stdio.h>
|
||||
// #include <Adafruit_USBD_Device.h>
|
||||
#include "HardwareRNG.h"
|
||||
#include "NodeDB.h"
|
||||
#include "PowerMon.h"
|
||||
#include "error.h"
|
||||
@@ -398,15 +399,14 @@ void nrf52Setup()
|
||||
#endif
|
||||
|
||||
// Init random seed
|
||||
union seedParts {
|
||||
uint32_t seed32;
|
||||
uint8_t seed8[4];
|
||||
} seed;
|
||||
nRFCrypto.begin();
|
||||
nRFCrypto.Random.generate(seed.seed8, sizeof(seed.seed8));
|
||||
LOG_DEBUG("Set random seed %u", seed.seed32);
|
||||
randomSeed(seed.seed32);
|
||||
nRFCrypto.end();
|
||||
uint32_t seed = 0;
|
||||
if (!HardwareRNG::seed(seed)) {
|
||||
LOG_WARN("Hardware RNG seed unavailable, using PRNG fallback");
|
||||
// Use a hardware timer value as a fallback seed for better entropy
|
||||
seed = micros();
|
||||
}
|
||||
LOG_DEBUG("Set random seed %u", seed);
|
||||
randomSeed(seed);
|
||||
|
||||
// Set up nrfx watchdog. Do not enable the watchdog yet (we do that
|
||||
// the first time through the main loop), so that other threads can
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "CryptoEngine.h"
|
||||
#include "HardwareRNG.h"
|
||||
#include "PortduinoGPIO.h"
|
||||
#include "SPIChip.h"
|
||||
#include "mesh/RF95Interface.h"
|
||||
@@ -233,7 +234,9 @@ void portduinoSetup()
|
||||
std::cout << "Running in simulated mode." << std::endl;
|
||||
portduino_config.MaxNodes = 200; // Default to 200 nodes
|
||||
// Set the random seed equal to TCPPort to have a different seed per instance
|
||||
randomSeed(TCPPort);
|
||||
uint32_t seed = TCPPort;
|
||||
HardwareRNG::seed(seed);
|
||||
randomSeed(seed);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -512,7 +515,9 @@ void portduinoSetup()
|
||||
#endif
|
||||
printf("MAC ADDRESS: %02X:%02X:%02X:%02X:%02X:%02X\n", dmac[0], dmac[1], dmac[2], dmac[3], dmac[4], dmac[5]);
|
||||
// Rather important to set this, if not running simulated.
|
||||
randomSeed(time(NULL));
|
||||
uint32_t seed = static_cast<uint32_t>(time(NULL));
|
||||
HardwareRNG::seed(seed);
|
||||
randomSeed(seed);
|
||||
|
||||
std::string defaultGpioChipName = gpioChipName + std::to_string(portduino_config.lora_default_gpiochip);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "HardwareRNG.h"
|
||||
#include "configuration.h"
|
||||
#include "hardware/xosc.h"
|
||||
#include <hardware/clocks.h>
|
||||
@@ -98,10 +99,12 @@ void getMacAddr(uint8_t *dmac)
|
||||
|
||||
void rp2040Setup()
|
||||
{
|
||||
/* Sets a random seed to make sure we get different random numbers on each boot.
|
||||
Taken from CPU cycle counter and ROSC oscillator, so should be pretty random.
|
||||
*/
|
||||
randomSeed(rp2040.hwrand32());
|
||||
/* Sets a random seed to make sure we get different random numbers on each boot. */
|
||||
uint32_t seed = 0;
|
||||
if (!HardwareRNG::seed(seed)) {
|
||||
seed = rp2040.hwrand32();
|
||||
}
|
||||
randomSeed(seed);
|
||||
|
||||
#ifdef RP2040_SLOW_CLOCK
|
||||
uint f_pll_sys = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_PLL_SYS_CLKSRC_PRIMARY);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
.globl HardFault_Handler
|
||||
.syntax unified
|
||||
.thumb
|
||||
|
||||
.type HardFault_Handler, %function
|
||||
HardFault_Handler:
|
||||
tst lr, #4
|
||||
ite eq
|
||||
mrseq r0, msp
|
||||
mrsne r0, psp
|
||||
b HardFault_Handler_C
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "RTC.h"
|
||||
#include "configuration.h"
|
||||
#include <stdarg.h>
|
||||
#include <stm32wle5xx.h>
|
||||
#include <stm32wlxx_hal.h>
|
||||
|
||||
@@ -53,4 +54,99 @@ extern "C" void __wrap__tzset_unlocked_r(struct _reent *reent_ptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Taken from https://interrupt.memfault.com/blog/cortex-m-hardfault-debug
|
||||
typedef struct __attribute__((packed)) ContextStateFrame {
|
||||
uint32_t r0;
|
||||
uint32_t r1;
|
||||
uint32_t r2;
|
||||
uint32_t r3;
|
||||
uint32_t r12;
|
||||
uint32_t lr;
|
||||
uint32_t return_address;
|
||||
uint32_t xpsr;
|
||||
} sContextStateFrame;
|
||||
|
||||
// NOTE: If you are using CMSIS, the registers can also be
|
||||
// accessed through CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk
|
||||
#define HALT_IF_DEBUGGING() \
|
||||
do { \
|
||||
if ((*(volatile uint32_t *)0xE000EDF0) & (1 << 0)) { \
|
||||
__asm("bkpt 1"); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static char hardfault_message_buffer[256];
|
||||
|
||||
// printf directly using srcwrapper's debug UART function.
|
||||
static void debug_printf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int length = vsnprintf(hardfault_message_buffer, sizeof(hardfault_message_buffer), format, args);
|
||||
va_end(args);
|
||||
|
||||
if (length < 0)
|
||||
return;
|
||||
uart_debug_write((uint8_t *)hardfault_message_buffer, min((unsigned int)length, sizeof(hardfault_message_buffer) - 1));
|
||||
}
|
||||
|
||||
// N picked by guessing
|
||||
#define DOT_TIME 1200000
|
||||
static void dot()
|
||||
{
|
||||
digitalWrite(LED_POWER, LED_STATE_ON);
|
||||
for (volatile int i = 0; i < DOT_TIME; i++) { /* busy wait */
|
||||
}
|
||||
digitalWrite(LED_POWER, LED_STATE_OFF);
|
||||
for (volatile int i = 0; i < DOT_TIME; i++) { /* busy wait */
|
||||
}
|
||||
}
|
||||
|
||||
static void dash()
|
||||
{
|
||||
digitalWrite(LED_POWER, LED_STATE_ON);
|
||||
for (volatile int i = 0; i < (DOT_TIME * 3); i++) { /* busy wait */
|
||||
}
|
||||
digitalWrite(LED_POWER, LED_STATE_OFF);
|
||||
for (volatile int i = 0; i < DOT_TIME; i++) { /* busy wait */
|
||||
}
|
||||
}
|
||||
|
||||
static void space()
|
||||
{
|
||||
for (volatile int i = 0; i < (DOT_TIME * 3); i++) { /* busy wait */
|
||||
}
|
||||
}
|
||||
|
||||
// Disable optimizations for this function so "frame" argument
|
||||
// does not get optimized away
|
||||
extern "C" __attribute__((optimize("O0"))) void HardFault_Handler_C(sContextStateFrame *frame)
|
||||
{
|
||||
debug_printf("HardFault!\r\n");
|
||||
debug_printf("r0: %08x\r\n", frame->r0);
|
||||
debug_printf("r1: %08x\r\n", frame->r1);
|
||||
debug_printf("r2: %08x\r\n", frame->r2);
|
||||
debug_printf("r3: %08x\r\n", frame->r3);
|
||||
debug_printf("r12: %08x\r\n", frame->r12);
|
||||
debug_printf("lr: %08x\r\n", frame->lr);
|
||||
debug_printf("pc[return address]: %08x\r\n", frame->return_address);
|
||||
debug_printf("xpsr: %08x\r\n", frame->xpsr);
|
||||
|
||||
HALT_IF_DEBUGGING();
|
||||
|
||||
// blink SOS forever
|
||||
while (1) {
|
||||
dot();
|
||||
dot();
|
||||
dot();
|
||||
dash();
|
||||
dash();
|
||||
dash();
|
||||
dot();
|
||||
dot();
|
||||
dot();
|
||||
space();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user