sforkowany z mirror/meshtastic-firmware
Fixed compilation on nrf52 and brownout code
rodzic
b20b21c553
commit
ddcfff3b59
|
@ -64,6 +64,7 @@ debug_tool = jlink
|
||||||
; monitor adapter_khz 10000
|
; monitor adapter_khz 10000
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
https://github.com/meshtastic/esp8266-oled-ssd1306.git#35d796226b853b0c0ff818b2f1aa3d35e7296a96 ; ESP8266_SSD1306
|
||||||
https://github.com/geeksville/OneButton.git ; OneButton library for non-blocking button debounce
|
https://github.com/geeksville/OneButton.git ; OneButton library for non-blocking button debounce
|
||||||
1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
|
1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
|
||||||
https://github.com/meshtastic/arduino-fsm.git#55c47b6cded91645aff05a27b6e5821d8d0f64be
|
https://github.com/meshtastic/arduino-fsm.git#55c47b6cded91645aff05a27b6e5821d8d0f64be
|
||||||
|
@ -102,7 +103,6 @@ build_flags =
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${arduino_base.lib_deps}
|
${arduino_base.lib_deps}
|
||||||
https://github.com/meshtastic/esp32_https_server.git
|
https://github.com/meshtastic/esp32_https_server.git
|
||||||
https://github.com/meshtastic/esp8266-oled-ssd1306.git#35d796226b853b0c0ff818b2f1aa3d35e7296a96 ; ESP8266_SSD1306
|
|
||||||
adafruit/DHT sensor library@^1.4.1
|
adafruit/DHT sensor library@^1.4.1
|
||||||
adafruit/Adafruit Unified Sensor@^1.1.4
|
adafruit/Adafruit Unified Sensor@^1.1.4
|
||||||
# Hmm - this doesn't work yet
|
# Hmm - this doesn't work yet
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "mesh/MeshTypes.h"
|
#include "mesh/MeshTypes.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef NO_SCREEN
|
||||||
#include <OLEDDisplay.h>
|
#include <OLEDDisplay.h>
|
||||||
#include <OLEDDisplayUi.h>
|
#include <OLEDDisplayUi.h>
|
||||||
#include <vector>
|
#endif
|
||||||
|
|
||||||
/** A baseclass for any mesh "plugin".
|
/** A baseclass for any mesh "plugin".
|
||||||
*
|
*
|
||||||
* A plugin allows you to add new features to meshtastic device code, without needing to know messaging details.
|
* A plugin allows you to add new features to meshtastic device code, without needing to know messaging details.
|
||||||
|
@ -31,9 +35,9 @@ class MeshPlugin
|
||||||
static void callPlugins(const MeshPacket &mp);
|
static void callPlugins(const MeshPacket &mp);
|
||||||
|
|
||||||
static std::vector<MeshPlugin *> GetMeshPluginsWithUIFrames();
|
static std::vector<MeshPlugin *> GetMeshPluginsWithUIFrames();
|
||||||
|
#ifndef NO_SCREEN
|
||||||
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { return; }
|
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { return; }
|
||||||
|
#endif
|
||||||
protected:
|
protected:
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#include "NRF52Bluetooth.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "error.h"
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -8,184 +5,182 @@
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef NRF52840_XXAA
|
#include "NRF52Bluetooth.h"
|
||||||
// #include <nrf52840.h>
|
#include "configuration.h"
|
||||||
|
#include "error.h"
|
||||||
|
|
||||||
|
#ifdef BQ25703A_ADDR
|
||||||
|
#include "BQ25713.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// #define USE_SOFTDEVICE
|
|
||||||
|
|
||||||
static inline void debugger_break(void)
|
static inline void debugger_break(void) {
|
||||||
{
|
__asm volatile(
|
||||||
__asm volatile("bkpt #0x01\n\t"
|
"bkpt #0x01\n\t"
|
||||||
"mov pc, lr\n\t");
|
"mov pc, lr\n\t");
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle standard gcc assert failures
|
// handle standard gcc assert failures
|
||||||
void __attribute__((noreturn)) __assert_func(const char *file, int line, const char *func, const char *failedexpr)
|
void __attribute__((noreturn))
|
||||||
{
|
__assert_func(const char *file, int line, const char *func,
|
||||||
DEBUG_MSG("assert failed %s: %d, %s, test=%s\n", file, line, func, failedexpr);
|
const char *failedexpr) {
|
||||||
// debugger_break(); FIXME doesn't work, possibly not for segger
|
DEBUG_MSG("assert failed %s: %d, %s, test=%s\n", file, line, func,
|
||||||
while (1)
|
failedexpr);
|
||||||
; // FIXME, reboot!
|
// debugger_break(); FIXME doesn't work, possibly not for segger
|
||||||
|
while (1)
|
||||||
|
; // FIXME, reboot!
|
||||||
}
|
}
|
||||||
|
|
||||||
void getMacAddr(uint8_t *dmac)
|
void getMacAddr(uint8_t *dmac) {
|
||||||
{
|
ble_gap_addr_t addr;
|
||||||
ble_gap_addr_t addr;
|
if (sd_ble_gap_addr_get(&addr) == NRF_SUCCESS) {
|
||||||
|
|
||||||
#ifdef USE_SOFTDEVICE
|
|
||||||
uint32_t res = sd_ble_gap_addr_get(&addr);
|
|
||||||
assert(res == NRF_SUCCESS);
|
|
||||||
memcpy(dmac, addr.addr, 6);
|
memcpy(dmac, addr.addr, 6);
|
||||||
#else
|
} else {
|
||||||
const uint8_t *src = (const uint8_t *)NRF_FICR->DEVICEADDR;
|
const uint8_t *src = (const uint8_t *)NRF_FICR->DEVICEADDR;
|
||||||
dmac[5] = src[0];
|
dmac[5] = src[0];
|
||||||
dmac[4] = src[1];
|
dmac[4] = src[1];
|
||||||
dmac[3] = src[2];
|
dmac[3] = src[2];
|
||||||
dmac[2] = src[3];
|
dmac[2] = src[3];
|
||||||
dmac[1] = src[4];
|
dmac[1] = src[4];
|
||||||
dmac[0] = src[5] | 0xc0; // MSB high two bits get set elsewhere in the bluetooth stack
|
dmac[0] = src[5] |
|
||||||
#endif
|
0xc0; // MSB high two bits get set elsewhere in the bluetooth stack
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NRF52Bluetooth *nrf52Bluetooth;
|
NRF52Bluetooth *nrf52Bluetooth;
|
||||||
|
|
||||||
static bool bleOn = false;
|
static bool bleOn = false;
|
||||||
static const bool useSoftDevice = false; // Set to false for easier debugging
|
static const bool useSoftDevice = true; // Set to false for easier debugging
|
||||||
|
|
||||||
void setBluetoothEnable(bool on)
|
void setBluetoothEnable(bool on) {
|
||||||
{
|
if (on != bleOn) {
|
||||||
if (on != bleOn) {
|
if (on) {
|
||||||
if (on) {
|
if (!nrf52Bluetooth) {
|
||||||
if (!nrf52Bluetooth) {
|
if (!useSoftDevice)
|
||||||
if (!useSoftDevice)
|
DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
||||||
DEBUG_MSG("DISABLING NRF52 BLUETOOTH WHILE DEBUGGING\n");
|
else {
|
||||||
else {
|
nrf52Bluetooth = new NRF52Bluetooth();
|
||||||
nrf52Bluetooth = new NRF52Bluetooth();
|
nrf52Bluetooth->setup();
|
||||||
nrf52Bluetooth->setup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (nrf52Bluetooth)
|
|
||||||
nrf52Bluetooth->shutdown();
|
|
||||||
}
|
}
|
||||||
bleOn = on;
|
}
|
||||||
|
} else {
|
||||||
|
if (nrf52Bluetooth) nrf52Bluetooth->shutdown();
|
||||||
}
|
}
|
||||||
|
bleOn = on;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override printf to use the SEGGER output library
|
* Override printf to use the SEGGER output library
|
||||||
*/
|
*/
|
||||||
int printf(const char *fmt, ...)
|
int printf(const char *fmt, ...) {
|
||||||
{
|
va_list args;
|
||||||
va_list args;
|
va_start(args, fmt);
|
||||||
va_start(args, fmt);
|
auto res = SEGGER_RTT_vprintf(0, fmt, &args);
|
||||||
auto res = SEGGER_RTT_vprintf(0, fmt, &args);
|
va_end(args);
|
||||||
va_end(args);
|
return res;
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "BQ25713.h"
|
void initBrownout() {
|
||||||
|
auto vccthresh = POWER_POFCON_THRESHOLD_V28;
|
||||||
|
|
||||||
void initBrownout()
|
if (useSoftDevice) {
|
||||||
{
|
auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled);
|
||||||
auto vccthresh = POWER_POFCON_THRESHOLD_V28;
|
assert(err_code == NRF_SUCCESS);
|
||||||
|
|
||||||
|
err_code = sd_power_pof_threshold_set(vccthresh);
|
||||||
|
assert(err_code == NRF_SUCCESS);
|
||||||
|
} else {
|
||||||
|
uint32_t pof_flags = POWER_POFCON_POF_Enabled | (vccthresh << POWER_POFCON_THRESHOLD_Pos);
|
||||||
|
|
||||||
|
#ifdef POWER_POFCON_THRESHOLDVDDH_Msk
|
||||||
auto vcchthresh = POWER_POFCON_THRESHOLDVDDH_V27;
|
auto vcchthresh = POWER_POFCON_THRESHOLDVDDH_V27;
|
||||||
|
pof_flags |= (vcchthresh << POWER_POFCON_THRESHOLDVDDH_Pos);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (useSoftDevice) {
|
NRF_POWER->POFCON = pof_flags;
|
||||||
auto err_code = sd_power_pof_enable(POWER_POFCON_POF_Enabled);
|
}
|
||||||
assert(err_code == NRF_SUCCESS);
|
|
||||||
|
|
||||||
err_code = sd_power_pof_threshold_set(vccthresh);
|
|
||||||
assert(err_code == NRF_SUCCESS);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NRF_POWER->POFCON = POWER_POFCON_POF_Msk | (vccthresh << POWER_POFCON_THRESHOLD_Pos) | (vcchthresh << POWER_POFCON_THRESHOLDVDDH_Pos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkSDEvents()
|
void checkSDEvents() {
|
||||||
{
|
if (useSoftDevice) {
|
||||||
if (useSoftDevice) {
|
uint32_t evt;
|
||||||
uint32_t evt;
|
while (NRF_SUCCESS == sd_evt_get(&evt)) {
|
||||||
while (NRF_ERROR_NOT_FOUND == sd_evt_get(&evt)) {
|
switch (evt) {
|
||||||
switch (evt) {
|
case NRF_EVT_POWER_FAILURE_WARNING:
|
||||||
case NRF_EVT_POWER_FAILURE_WARNING:
|
recordCriticalError(CriticalErrorCode_Brownout);
|
||||||
recordCriticalError(CriticalErrorCode_Brownout);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DEBUG_MSG("Unexpected SDevt %d\n", evt);
|
DEBUG_MSG("Unexpected SDevt %d\n", evt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if(NRF_POWER->EVENTS_POFWARN)
|
|
||||||
recordCriticalError(CriticalErrorCode_Brownout);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (NRF_POWER->EVENTS_POFWARN)
|
||||||
|
recordCriticalError(CriticalErrorCode_Brownout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nrf52Loop()
|
void nrf52Loop() { checkSDEvents(); }
|
||||||
{
|
|
||||||
checkSDEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void nrf52Setup()
|
void nrf52Setup() {
|
||||||
{
|
auto why = NRF_POWER->RESETREAS;
|
||||||
|
// per
|
||||||
|
// https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html
|
||||||
|
DEBUG_MSG("Reset reason: 0x%x\n", why);
|
||||||
|
|
||||||
auto why = NRF_POWER->RESETREAS;
|
// Per
|
||||||
// per https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html
|
// https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/monitor-mode-debugging-with-j-link-and-gdbeclipse
|
||||||
DEBUG_MSG("Reset reason: 0x%x\n", why);
|
// This is the recommended setting for Monitor Mode Debugging
|
||||||
|
NVIC_SetPriority(DebugMonitor_IRQn, 6UL);
|
||||||
// Per https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/monitor-mode-debugging-with-j-link-and-gdbeclipse
|
|
||||||
// This is the recommended setting for Monitor Mode Debugging
|
|
||||||
NVIC_SetPriority(DebugMonitor_IRQn, 6UL);
|
|
||||||
|
|
||||||
#ifdef BQ25703A_ADDR
|
#ifdef BQ25703A_ADDR
|
||||||
auto *bq = new BQ25713();
|
auto *bq = new BQ25713();
|
||||||
if (!bq->setup())
|
if (!bq->setup()) DEBUG_MSG("ERROR! Charge controller init failed\n");
|
||||||
DEBUG_MSG("ERROR! Charge controller init failed\n");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Init random seed
|
// Init random seed
|
||||||
// FIXME - use this to get random numbers
|
// FIXME - use this to get random numbers
|
||||||
// #include "nrf_rng.h"
|
// #include "nrf_rng.h"
|
||||||
// uint32_t r;
|
// uint32_t r;
|
||||||
// ble_controller_rand_vector_get_blocking(&r, sizeof(r));
|
// ble_controller_rand_vector_get_blocking(&r, sizeof(r));
|
||||||
// randomSeed(r);
|
// randomSeed(r);
|
||||||
DEBUG_MSG("FIXME, call randomSeed\n");
|
DEBUG_MSG("FIXME, call randomSeed\n");
|
||||||
// ::printf("TESTING PRINTF\n");
|
// ::printf("TESTING PRINTF\n");
|
||||||
|
|
||||||
initBrownout();
|
initBrownout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cpuDeepSleep(uint64_t msecToWake)
|
void cpuDeepSleep(uint64_t msecToWake) {
|
||||||
{
|
// FIXME, configure RTC or button press to wake us
|
||||||
// FIXME, configure RTC or button press to wake us
|
// FIXME, power down SPI, I2C, RAMs
|
||||||
// FIXME, power down SPI, I2C, RAMs
|
#if WIRE_INTERFACES_COUNT > 0
|
||||||
#if WIRE_INTERFACES_COUNT > 0
|
Wire.end();
|
||||||
Wire.end();
|
#endif
|
||||||
#endif
|
SPI.end();
|
||||||
SPI.end();
|
// This may cause crashes as debug messages continue to flow.
|
||||||
Serial.end();
|
Serial.end();
|
||||||
|
|
||||||
#ifdef PIN_SERIAL_RX1
|
#ifdef PIN_SERIAL_RX1
|
||||||
Serial1.end();
|
Serial1.end();
|
||||||
#endif
|
#endif
|
||||||
|
setBluetoothEnable(false);
|
||||||
|
// FIXME, use system off mode with ram retention for key state?
|
||||||
|
// FIXME, use non-init RAM per
|
||||||
|
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled
|
||||||
|
|
||||||
// FIXME, use system off mode with ram retention for key state?
|
auto ok = sd_power_system_off();
|
||||||
// FIXME, use non-init RAM per
|
if (ok != NRF_SUCCESS) {
|
||||||
// https://devzone.nordicsemi.com/f/nordic-q-a/48919/ram-retention-settings-with-softdevice-enabled
|
DEBUG_MSG(
|
||||||
|
"FIXME: Ignoring soft device (EasyDMA pending?) and forcing "
|
||||||
|
"system-off!\n");
|
||||||
|
NRF_POWER->SYSTEMOFF = 1;
|
||||||
|
}
|
||||||
|
|
||||||
auto ok = sd_power_system_off();
|
// The following code should not be run, because we are off
|
||||||
if (ok != NRF_SUCCESS) {
|
while (1) {
|
||||||
DEBUG_MSG("FIXME: Ignoring soft device (EasyDMA pending?) and forcing system-off!\n");
|
delay(5000);
|
||||||
NRF_POWER->SYSTEMOFF = 1;
|
DEBUG_MSG(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The following code should not be run, because we are off
|
|
||||||
while (1) {
|
|
||||||
delay(5000);
|
|
||||||
DEBUG_MSG(".");
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -19,12 +19,13 @@
|
||||||
#ifndef _VARIANT_LORA_ISP4520_
|
#ifndef _VARIANT_LORA_ISP4520_
|
||||||
#define _VARIANT_LORA_ISP4520_
|
#define _VARIANT_LORA_ISP4520_
|
||||||
|
|
||||||
#define HW_VERSION_US
|
#define HW_VERSION_US 1
|
||||||
#undef HW_VERSION
|
#undef HW_VERSION
|
||||||
#define HW_VERSION "0.1.0"
|
#define HW_VERSION "1.0"
|
||||||
#undef HW_VENDOR
|
#undef HW_VENDOR
|
||||||
#define HW_VENDOR "lora_ISP4520"
|
#define HW_VENDOR "lora_ISP4520"
|
||||||
|
|
||||||
|
#define USE_SEGGER
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Headers
|
* Headers
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
@ -33,7 +34,7 @@
|
||||||
|
|
||||||
#define USE_LFXO
|
#define USE_LFXO
|
||||||
|
|
||||||
#define USE_SEGGER
|
//#define USE_SEGGER
|
||||||
|
|
||||||
// Number of pins defined in PinDescription array
|
// Number of pins defined in PinDescription array
|
||||||
#define PINS_COUNT (16)
|
#define PINS_COUNT (16)
|
||||||
|
|
Ładowanie…
Reference in New Issue