Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT
Revision 0:3b6c2ce051a6, committed 2019-01-18
- Comitter:
- Helmut64
- Date:
- Fri Jan 18 15:59:46 2019 +0000
- Child:
- 1:56fdc660a26a
- Commit message:
- inital checkin
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BufferedSerial.lib Fri Jan 18 15:59:46 2019 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/sam_grove/code/BufferedSerial/#a0d37088b405
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinMap.h Fri Jan 18 15:59:46 2019 +0000 @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018 Helmut Tschemernjak + * 30826 Garbsen (Hannover) Germany + * Licensed under the Apache License, Version 2.0); + */ + + + +#ifdef TARGET_NUCLEO_L476RG + #define FEATURE_LORA + +#elif TARGET_DISCO_L072CZ_LRWAN1 + #define FEATURE_LORA + +#elif TARGET_STM32L432KC + #define HELTEC_STM32L4 + #define FEATURE_LORA + #define FEATURE_USBSERIAL +#endif + + + +#if defined(TARGET_DISCO_L072CZ_LRWAN1) +#define LED LED2 + +#define LORA_SPI_MOSI PA_7 +#define LORA_SPI_MISO PA_6 +#define LORA_SPI_SCLK PB_3 +#define LORA_CS PA_15 +#define LORA_RESET PC_0 +#define LORA_DIO0 PB_4 +#define LORA_DIO1 PB_1 +#define LORA_DIO2 PB_0 +#define LORA_DIO3 PC_13 +#define LORA_DIO4 PA_5 +#define LORA_DIO5 PA_4 +#define LORA_ANT_RX PA_1 +#define LORA_ANT_TX PC_2 +#define LORA_ANT_BOOST PC_1 +#define LORA_TCXO PA_12 // 32 MHz + + + +#elif defined(TARGET_NUCLEO_L476RG) // using the RFM95 board + +#define LORA_SPI_MOSI PC_12 +#define LORA_SPI_MISO PC_11 +#define LORA_SPI_SCLK PC_10 +#define LORA_CS PA_0 +#define LORA_RESET PA_1 +#define LORA_DIO0 PD_2 // DIO0=TxDone/RXDone +#define LORA_DIO1 PB_7 // +#define LORA_DIO2 PC_14 // DIO2=FhssChangeChannel +#define LORA_DIO3 PC_15 // DIO3=CADDone +#define LORA_DIO4 PH_0 // ???? +#define LORA_DIO5 NC // unused? + +#elif defined (HELTEC_STM32L4) + +#define USER_BUTTON PH_3 // boot pin +#define LED PB_0 // red +#define LED2 PB_1 // green +#define LED1 LED + +#define POWER_VEXT PA_3 +#define POWER_VEXT_ON 0 +#define POWER_VEXT_OFF 1 + + +#define LORA_SPI_MOSI PA_7 +#define LORA_SPI_MISO PA_6 +#define LORA_SPI_SCLK PA_5 +#define LORA_CS PA_4 +#define LORA_RESET PA_1 +#define LORA_DIO0 PA_0 // DIO0=TxDone/RXDone/CADDone +#define LORA_DIO1 NC // +#define LORA_DIO2 NC // +#define LORA_DIO3 NC // +#define LORA_DIO4 NC // +#define LORA_DIO5 NC // + +#elif defined(TARGET_NUCLEO_L432KC) // using the RFM95 board + +// #define LED PB_3 // green +#define LED PB_5 // green + +#define LORA_SPI_MOSI PA_7 +#define LORA_SPI_MISO PA_6 +#define LORA_SPI_SCLK PB_5 +#define LORA_CS PA_4 +#define LORA_RESET PA_1 +#define LORA_DIO0 PA_0 // DIO0=TxDone/RXDone/CADDone +#define LORA_DIO1 NC // +#define LORA_DIO2 NC // +#define LORA_DIO3 NC // +#define LORA_DIO4 NC // +#define LORA_DIO5 NC // + + +#else + +#error "unknown board" + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RadioShuttle-STM32L4.lib Fri Jan 18 15:59:46 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Helmut64/code/RadioShuttle-STM32L4/#2c3a48b9797e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SX1276GenericLib.lib Fri Jan 18 15:59:46 2019 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/Helmut64/code/SX1276GenericLib/#f2826a8fbff2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDeviceHT.lib Fri Jan 18 15:59:46 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Helmut64/code/USBDeviceHT/#fb690c44c0b1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Jan 18 15:59:46 2019 +0000
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2018 HELIOS Software GmbH
+ * 30826 Garbsen (Hannover) Germany
+ * Licensed under the Apache License, Version 2.0);
+ */
+ #include "main.h"
+
+
+DigitalOut myled(LED);
+
+
+int main() {
+#ifdef HELTEC_STM32L4
+ DigitalOut vext(POWER_VEXT);
+ vext = POWER_VEXT_ON;
+#endif
+ /*
+ * inits the Serial or USBSerial when available (230400 baud).
+ * If the serial uart is not is not connected it swiches to USB Serial
+ * blinking LED means USBSerial detected, waiting for a connect.
+ * It waits up to 30 seconds for a USB terminal connections
+ */
+ InitSerial(30*1000, &myled);
+ dprintf("Welcome to the SX1276GenericLib");
+
+ dprintf("Starting a simple LoRa PingPong");
+ SX1276PingPong();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Fri Jan 18 15:59:46 2019 +0000 @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018 Helmut Tschemernjak + * 30826 Garbsen (Hannover) Germany + * Licensed under the Apache License, Version 2.0); +*/ + +#include "mbed.h" +#include "PinMap.h" +#include "BufferedSerial.h" +#ifdef FEATURE_USBSERIAL +#include "USBSerialBuffered.h" +#endif +#include "GenericPingPong.h" + + +extern BufferedSerial *ser; +#ifdef FEATURE_USBSERIAL +extern USBSerialBuffered *usb; +#endif +extern bool _useDprintf; +extern void InitSerial(int timeout, DigitalOut *led); +extern void dump(const char *title, const void *data, int len, bool dwords = false); + +extern void dprintf(const char *format, ...) __attribute__((format(printf,1,2))); +extern void rprintf(const char *format, ...) __attribute__((format(printf,1,2))); +extern void VAprintf(bool timstamp, bool newline, bool printEnabled, const char *format, va_list arg); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Jan 18 15:59:46 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/utils.cpp Fri Jan 18 15:59:46 2019 +0000
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2018 Helmut Tschemernjak
+ * 30826 Garbsen (Hannover) Germany
+ */
+ #include "main.h"
+
+time_t cvt_date(char const *date, char const *time);
+
+BufferedSerial *ser;
+#ifdef FEATURE_USBSERIAL
+USBSerialBuffered *usb;
+#endif
+bool _useDprintf;
+
+void InitSerial(int timeout, DigitalOut *led)
+{
+ _useDprintf = true;
+ bool uartActive;
+ {
+ {
+ // need to turn rx low to avoid floating signal
+ DigitalOut rx(USBRX);
+ rx = 0;
+ }
+ DigitalIn uartRX(USBRX);
+ uartActive = uartRX.read();
+ }
+#ifdef FEATURE_USBSERIAL
+ if (!uartActive) {
+ usb = new USBSerialBuffered();
+ Timer t;
+ t.start();
+ while(!usb->connected()) {
+ if (led)
+ *led = !*led;
+ wait_ms(100);
+ if (timeout) {
+ if (t.read_ms() >= timeout)
+ return;
+ }
+ }
+ return;
+ } else {
+#else
+ {
+#endif
+ ser = new BufferedSerial(USBTX, USBRX);
+ ser->baud(230400);
+ ser->format(8);
+ }
+ time_t t = cvt_date(__DATE__, __TIME__);
+ if (t > time(NULL)) {
+ set_time(t);
+ }
+
+}
+
+void printTimeStamp()
+{
+ static LowPowerTimer *timer;
+ if (!timer) {
+ timer = new LowPowerTimer();
+ timer->start();
+ }
+ time_t seconds = time(NULL);
+ struct tm *tm = localtime(&seconds);
+ int usecs = timer->read_us();
+ if (usecs < 0) {
+ usecs = 0;
+ timer->stop();
+ timer->reset();
+ timer->start();
+ }
+ int msecs = usecs % 1000000;
+
+ rprintf("%02d:%02d:%02d.%06d ", tm->tm_hour, tm->tm_min, tm->tm_sec, msecs);
+}
+
+void dprintf(const char *format, ...)
+{
+ std::va_list arg;
+
+ va_start(arg, format);
+ VAprintf(true, true, _useDprintf, format, arg);
+ va_end(arg);
+}
+
+void rprintf(const char *format, ...)
+{
+ std::va_list arg;
+
+ va_start(arg, format);
+ VAprintf(false, false, _useDprintf, format, arg);
+ va_end(arg);
+}
+
+void VAprintf(bool timstamp, bool newline, bool printEnabled, const char *format, va_list arg)
+{
+ if (!printEnabled)
+ return;
+
+ if (timstamp)
+ printTimeStamp();
+#ifdef FEATURE_USBSERIAL
+ if (usb) {
+ usb->vprintf_irqsafe(format, arg);
+ if (newline)
+ usb->printf_irqsafe("\r\n");
+#else
+ if (0) {
+#endif
+ } else if (ser) {
+ // serial jas
+ int r = 0;
+ r = vsnprintf(NULL, 0, format, arg);
+ if (r < 82) {
+ char buffer[82+1];
+
+ vsnprintf(buffer, sizeof(buffer), format, arg);
+ r = ser->write(buffer, r);
+ } else {
+ char *buffer = new char[r+1];
+ if (buffer) {
+ vsnprintf(buffer, r+1, format, arg);
+ r = ser->write(buffer, r);
+ delete[] buffer;
+ } else {
+ error("%s %d cannot alloc memory (%d bytes)!\r\n", __FILE__, __LINE__, r+1);
+ r = 0;
+ }
+ }
+ if (newline)
+ ser->write("\r\n", 2);
+ }
+}
+
+
+void dump(const char *title, const void *data, int len, bool dwords)
+{
+ dprintf("dump(\"%s\", 0x%x, %d bytes)", title, data, len);
+
+ int i, j, cnt;
+ unsigned char *u;
+ const int width = 16;
+ const int seppos = 7;
+
+ cnt = 0;
+ u = (unsigned char *)data;
+ while (len > 0) {
+ rprintf("%08x: ", (unsigned int)data + cnt);
+ if (dwords) {
+ unsigned int *ip = ( unsigned int *)u;
+ rprintf(" 0x%08x\r\n", *ip);
+ u+= 4;
+ len -= 4;
+ cnt += 4;
+ continue;
+ }
+ cnt += width;
+ j = len < width ? len : width;
+ for (i = 0; i < j; i++) {
+ rprintf("%2.2x ", *(u + i));
+ if (i == seppos)
+ rprintf(" ");
+ }
+ rprintf(" ");
+ if (j < width) {
+ i = width - j;
+ if (i > seppos + 1)
+ rprintf(" ");
+ while (i--) {
+ rprintf("%s", " ");
+ }
+ }
+ for (i = 0; i < j; i++) {
+ int c = *(u + i);
+ if (c >= ' ' && c <= '~')
+ rprintf("%c", c);
+ else
+ rprintf(".");
+ if (i == seppos)
+ rprintf(" ");
+ }
+ len -= width;
+ u += width;
+ rprintf("\r\n");
+ }
+ rprintf("--\r\n");
+}
+
+/*
+ * Convert compile time to system time
+ */
+time_t
+cvt_date(char const *date, char const *time)
+{
+ char s_month[5];
+ int year;
+ struct tm t;
+ static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
+ sscanf(date, "%s %d %d", s_month, &t.tm_mday, &year);
+ sscanf(time, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec);
+ // Find where is s_month in month_names. Deduce month value.
+ t.tm_mon = (strstr(month_names, s_month) - month_names) / 3;
+ t.tm_year = year - 1900;
+ return (int)mktime(&t);
+}