An example project for the Heltec Turtle LoRa board (STM32L4 and SX1276 chips). The projects is only supported for the Nucleo-L432KC board platform in the mbed online and offline compiler environment. Visit www.radioshuttle.de (choose Turtle board) for instructions. Note that most source files and libraries are open source, however some files especially the RadioShuttle core protocol is copyrighted work. Check header for details.

Dependencies:   mbed BufferedSerial SX1276GenericLib NVProperty RadioShuttle-STM32L4 USBDeviceHT

Committer:
Helmut64
Date:
Mon Feb 11 11:12:33 2019 +0000
Revision:
30:8bc655c9b224
Parent:
25:8578fed9087e
Child:
34:d3d60dbb84ea
Moved dump to util.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Helmut64 0:3b6c2ce051a6 1 /*
Helmut Tschemernjak 3:b5052f3fa638 2 * Copyright (c) 2019 Helmut Tschemernjak
Helmut64 0:3b6c2ce051a6 3 * 30826 Garbsen (Hannover) Germany
Helmut64 0:3b6c2ce051a6 4 * Licensed under the Apache License, Version 2.0);
Helmut64 0:3b6c2ce051a6 5 */
Helmut Tschemernjak 3:b5052f3fa638 6
Helmut Tschemernjak 3:b5052f3fa638 7 /*
Helmut Tschemernjak 3:b5052f3fa638 8 * TODO:
Helmut Tschemernjak 3:b5052f3fa638 9 * Compiler Date/Time is not set correctly on startup
Helmut Tschemernjak 3:b5052f3fa638 10 */
Helmut Tschemernjak 3:b5052f3fa638 11 #include "main.h"
Helmut Tschemernjak 3:b5052f3fa638 12 #include "RadioShuttle.h"
Helmut Tschemernjak 3:b5052f3fa638 13 #include "RadioTest.h"
Helmut Tschemernjak 3:b5052f3fa638 14 #include "GenericPingPong.h"
Helmut Tschemernjak 9:a988aa7a4652 15 #ifdef FEATURE_NVPROPERTY
Helmut Tschemernjak 9:a988aa7a4652 16 #include <NVPropertyProviderInterface.h>
Helmut Tschemernjak 9:a988aa7a4652 17 #include "NVProperty.h"
Helmut Tschemernjak 9:a988aa7a4652 18 #endif
Helmut64 0:3b6c2ce051a6 19
Helmut Tschemernjak 3:b5052f3fa638 20 DigitalOut statusLED(LED);
Helmut Tschemernjak 3:b5052f3fa638 21 DigitalOut redLED(LED2);
Helmut Tschemernjak 3:b5052f3fa638 22 InterruptIn buttonIntr(USER_BUTTON);
Helmut Tschemernjak 13:3c7a52b11316 23 volatile int pressedCount;
Helmut64 0:3b6c2ce051a6 24
Helmut Tschemernjak 3:b5052f3fa638 25 void switchInput(void) {
Helmut Tschemernjak 3:b5052f3fa638 26 InterrruptMSG(INT_BUTTON1);
Helmut Tschemernjak 3:b5052f3fa638 27 }
Helmut64 0:3b6c2ce051a6 28
Helmut64 0:3b6c2ce051a6 29
Helmut Tschemernjak 3:b5052f3fa638 30 void timerUpdate(void) {
Helmut Tschemernjak 5:c6a960febe80 31 static LowPowerTimeout timeout;
Helmut Tschemernjak 3:b5052f3fa638 32 if (redLED == 0)
Helmut Tschemernjak 3:b5052f3fa638 33 timeout.attach_us(&timerUpdate, 20000); // setup to call timerUpdate after 20 millis
Helmut Tschemernjak 3:b5052f3fa638 34 else
Helmut Tschemernjak 3:b5052f3fa638 35 timeout.attach_us(&timerUpdate, 2000000); // setup to call timerUpdate after 2 seconds
Helmut Tschemernjak 3:b5052f3fa638 36
Helmut Tschemernjak 3:b5052f3fa638 37 InterrruptMSG(INT_TIMEOUT);
Helmut Tschemernjak 3:b5052f3fa638 38 }
Helmut Tschemernjak 3:b5052f3fa638 39
Helmut Tschemernjak 18:d2f227e0a8bf 40
Helmut64 0:3b6c2ce051a6 41 int main() {
Helmut64 0:3b6c2ce051a6 42 /*
Helmut64 0:3b6c2ce051a6 43 * inits the Serial or USBSerial when available (230400 baud).
Helmut64 0:3b6c2ce051a6 44 * If the serial uart is not is not connected it swiches to USB Serial
Helmut64 0:3b6c2ce051a6 45 * blinking LED means USBSerial detected, waiting for a connect.
Helmut64 0:3b6c2ce051a6 46 * It waits up to 30 seconds for a USB terminal connections
Helmut64 0:3b6c2ce051a6 47 */
Helmut Tschemernjak 3:b5052f3fa638 48 InitSerial(30*1000, &statusLED);
Helmut Tschemernjak 3:b5052f3fa638 49 dprintf("Welcome to RadioShuttle v%d.%d", RS_MAJOR, RS_MINOR);
Helmut Tschemernjak 3:b5052f3fa638 50 dprintf("Voltage: %.2f (%s powered)", BatteryVoltage(), BatterySource());
Helmut Tschemernjak 9:a988aa7a4652 51
Helmut Tschemernjak 22:9cca40fcb25e 52 char buf[32];
Helmut Tschemernjak 22:9cca40fcb25e 53
Helmut Tschemernjak 22:9cca40fcb25e 54 bool cmdLoop = true;
Helmut Tschemernjak 22:9cca40fcb25e 55 while(cmdLoop) {
Helmut Tschemernjak 22:9cca40fcb25e 56 rprintf("\r\nAvailable commands (p = Property Editor, r = Reset, q = Quit)\r\nwaiting 10 secs ...\r\n");
Helmut Tschemernjak 22:9cca40fcb25e 57 rprintf("\r\n$ ");
Helmut Tschemernjak 22:9cca40fcb25e 58 if (ConsoleReadline(buf, sizeof(buf), true, 10000) == NULL) {
Helmut Tschemernjak 22:9cca40fcb25e 59 cmdLoop = false;
Helmut Tschemernjak 22:9cca40fcb25e 60 break;
Helmut Tschemernjak 22:9cca40fcb25e 61 }
Helmut Tschemernjak 22:9cca40fcb25e 62 switch(buf[0]) {
Helmut Tschemernjak 22:9cca40fcb25e 63 case 'p':
Helmut Tschemernjak 22:9cca40fcb25e 64 case 'P':
Helmut Tschemernjak 18:d2f227e0a8bf 65 #ifdef FEATURE_NVPROPERTYEDITOR
Helmut Tschemernjak 22:9cca40fcb25e 66 NVPropertyEditor();
Helmut Tschemernjak 18:d2f227e0a8bf 67 #endif
Helmut Tschemernjak 22:9cca40fcb25e 68 break;
Helmut Tschemernjak 22:9cca40fcb25e 69 case 'q':
Helmut Tschemernjak 22:9cca40fcb25e 70 case 'Q':
Helmut Tschemernjak 22:9cca40fcb25e 71 cmdLoop = false;
Helmut Tschemernjak 22:9cca40fcb25e 72 break;
Helmut Tschemernjak 22:9cca40fcb25e 73 case 'r':
Helmut Tschemernjak 22:9cca40fcb25e 74 case 'R':
Helmut Tschemernjak 22:9cca40fcb25e 75 MCUReset();
Helmut Tschemernjak 22:9cca40fcb25e 76 break;
Helmut Tschemernjak 22:9cca40fcb25e 77 default:
Helmut Tschemernjak 22:9cca40fcb25e 78 break;
Helmut Tschemernjak 22:9cca40fcb25e 79 }
Helmut Tschemernjak 22:9cca40fcb25e 80 }
Helmut Tschemernjak 3:b5052f3fa638 81
Helmut Tschemernjak 3:b5052f3fa638 82 #ifdef FEATURE_LORA
Helmut Tschemernjak 3:b5052f3fa638 83 InitRadio();
Helmut Tschemernjak 3:b5052f3fa638 84 #endif
Helmut Tschemernjak 3:b5052f3fa638 85 #ifdef FEATURE_LORA_PING_PONG
Helmut Tschemernjak 3:b5052f3fa638 86 DeInitRadio();
Helmut Tschemernjak 3:b5052f3fa638 87 SX1276PingPong(); // basic LoRa raw ping/pong without RadioShuttle
Helmut Tschemernjak 3:b5052f3fa638 88 #endif
Helmut Tschemernjak 3:b5052f3fa638 89 dprintf("InitDefaults Done");
Helmut Tschemernjak 3:b5052f3fa638 90 timerUpdate(); // start timer
Helmut Tschemernjak 3:b5052f3fa638 91 #if defined (USER_BUTTON_RISE) // attach switchInput function to the rising or falling edge
Helmut Tschemernjak 3:b5052f3fa638 92 buttonIntr.rise(&switchInput);
Helmut Tschemernjak 3:b5052f3fa638 93 #else
Helmut Tschemernjak 3:b5052f3fa638 94 buttonIntr.fall(&switchInput);
Helmut Tschemernjak 3:b5052f3fa638 95 #endif
Helmut Tschemernjak 3:b5052f3fa638 96
Helmut Tschemernjak 3:b5052f3fa638 97 /*
Helmut Tschemernjak 3:b5052f3fa638 98 * Main event loop, process interrupts and go to sleep
Helmut Tschemernjak 3:b5052f3fa638 99 * the green statusLED indicates CPU activity
Helmut Tschemernjak 5:c6a960febe80 100 * the red redLED indicates that low power timeout function is running.
Helmut Tschemernjak 3:b5052f3fa638 101 */
Helmut Tschemernjak 3:b5052f3fa638 102 while(true) {
Helmut Tschemernjak 3:b5052f3fa638 103 while ((readPendingInterrupts() == 0)) {
Helmut Tschemernjak 3:b5052f3fa638 104 statusLED = 0;
Helmut Tschemernjak 3:b5052f3fa638 105 if (!(usb && usb->connected()))
Helmut Tschemernjak 3:b5052f3fa638 106 sleep();
Helmut Tschemernjak 3:b5052f3fa638 107 statusLED = 1;
Helmut Tschemernjak 3:b5052f3fa638 108 }
Helmut Tschemernjak 3:b5052f3fa638 109
Helmut Tschemernjak 3:b5052f3fa638 110 uint32_t pendirqs = readclrPendingInterrupts();
Helmut Tschemernjak 3:b5052f3fa638 111 if (pendirqs & INT_BUTTON1) {
Helmut Tschemernjak 3:b5052f3fa638 112 #ifdef FEATURE_LORA
Helmut Tschemernjak 3:b5052f3fa638 113 statusLED = !statusLED;
Helmut Tschemernjak 3:b5052f3fa638 114 RadioUpdate(true); // pass the pressed user button to RadioShuttle
Helmut Tschemernjak 3:b5052f3fa638 115 #endif
Helmut Tschemernjak 3:b5052f3fa638 116 }
Helmut Tschemernjak 3:b5052f3fa638 117 if (pendirqs & INT_LORA) {
Helmut Tschemernjak 3:b5052f3fa638 118 #ifdef FEATURE_LORA
Helmut Tschemernjak 3:b5052f3fa638 119 RadioUpdate(false);
Helmut Tschemernjak 3:b5052f3fa638 120 #endif
Helmut Tschemernjak 3:b5052f3fa638 121 }
Helmut Tschemernjak 3:b5052f3fa638 122 if (pendirqs & INT_TIMEOUT) {
Helmut Tschemernjak 3:b5052f3fa638 123 redLED = ! redLED;
Helmut Tschemernjak 3:b5052f3fa638 124 }
Helmut Tschemernjak 3:b5052f3fa638 125 }
Helmut64 0:3b6c2ce051a6 126 }