
This is an example program that shows how to use the RadioHeadLite library, and does it using threads.
Dependencies: RadioHeadLite
Revision 2:57fefd8ae87c, committed 2019-05-16
- Comitter:
- rlanders73
- Date:
- Thu May 16 15:21:41 2019 +0000
- Parent:
- 1:75d533f15c95
- Child:
- 3:fd3a7f10eed3
- Commit message:
- This program allows you to test the GPS in your system over the USB interface on the Geneva module
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Geneva.h Thu May 16 15:21:41 2019 +0000 @@ -0,0 +1,129 @@ +/* mbed Microcontroller Library + ******************************************************************************* + * Copyright (c) 2018, Point Labs, LLC. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + ******************************************************************************* + */ + +#ifndef GENEVA_PINS_H +#define GENEVA_PINS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define TX PA_9 +#define RX PA_10 + +#define A7 PA_0 +#define A6 PA_4 +#define A5 PA_7 +#define A4 PA_6 +#define A3 PA_5 +#define A2 PC_2 +#define A1 PC_3 +#define A0 PA_3 + +#define B5 PC_1 +#define B4 PC_0 +#define B3 PB_1 +#define B2 PB_0 +#define B1 PC_6 +#define B0 PC_8 + +#define D7 PA_13 +#define D6 PA_14 +#define D5 PA_15 +#define D4 PB_3 +#define D3 PB_4 +#define D2 PB_5 +#define D1 PB_6 +#define D0 PB_7 + +#define C5 PB_8 +#define C4 PB_9 +#define C3 PC_10 +#define C2 PC_11 +#define C1 PC_12 +#define C0 PD_2 + + +// UARTS +#define S1_TX PA_9 +#define S1_RX PA_10 +#define S1_CTS PB_4 +#define S1_RTS PB_3 + +#define S4_TX PC_10_ALT0 +#define S4_RX PC_11_ALT0 +#define S4_CTS PB_7 +#define S4_RTS PA_15 + +#define S5_TX PC_12 +#define S5_RX PD_2 + +#define LP_TX PC_1 +#define LP_RX PC_0 + +// LEDs +#define LED_RED PB_15 +#define LED_GREEN PC_7 +#define LED_BLUE PC_9 + +// SPI +#define SPI_MOSI PA_7 +#define SPI_MISO PA_6 +#define SPI_SCK PA_5 +#define SPI_CS PA_2 + +// User Button +#define USER_BUTTON PA_1 + +// Cellular interface +#define MDM_PIN_POLARITY (1) +#define MODEM_ON_BOARD (1) +#define MBED_CONF_UBLOX_CELL_BAUD_RATE (115200) +// Modem pins +#define MDMTXD PC_4 // Transmit Data +#define MDMRXD PC_5 // Receive Data +#define MDMCTS PB_13 // Clear to Send +#define MDMDSR NC // Data Set Ready +#define MDMDTR PB_15 // Data Terminal Ready +#define MDMRI NC // Ring Indicator +#define MDMRTS PB_14 // Request to Send +#define MDMPWRON PB_2 +#define MDMRST PA_8 +#define MDMVCC PB_12 + +#define BL_MAGIC_NUMBER (0xA87B1234) +#define BL_MAGIC_LOCATION ((unsigned long *) 0x20001000) + +#ifdef __cplusplus +} +#endif + +#endif +
--- a/USBDevice.lib Mon Nov 26 21:01:04 2018 +0000 +++ b/USBDevice.lib Thu May 16 15:21:41 2019 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/teams/PointLabs/code/USBDeviceSTM32L476/#772335cfca9a +https://os.mbed.com/teams/PointLabs/code/USBDevice/#584b0afbd742
--- a/USBSerial_copy.cpp Mon Nov 26 21:01:04 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* Copyright (c) 2010-2011 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#include "stdint.h" -#include "USBSerial.h" - -int USBSerial::_putc(int c) { - if (!terminal_connected) - return 0; - send((uint8_t *)&c, 1); - return 1; -} - -int USBSerial::_getc() { - uint8_t c = 0; - while (buf.isEmpty()); - buf.dequeue(&c); - return c; -} - -int USBSerial::_read(void* buffer, int length) -{ - int data_read = 0; - - uint8_t *ptr = static_cast<uint8_t *>(buffer); - - if (length == 0) { - return 0; - } - - if (buf.isEmpty()) { - return -EAGAIN; - } - - while (data_read < length && !buf.isEmpty()) { - buf.dequeue(ptr++); - data_read++; - } - - return data_read; -} - -int USBSerial::_write(uint8_t * buf, uint16_t size) { - uint16_t sent = size; - - // This handles the case where we have more to send than one bulk frame - while(size > MAX_PACKET_SIZE_EPBULK && send(buf, MAX_PACKET_SIZE_EPBULK)) { - size -= MAX_PACKET_SIZE_EPBULK; - } - if(!send(buf, size)) { - return -EAGAIN; - } - return sent; -} - -bool USBSerial::writeBlock(uint8_t * buf, uint16_t size) { - if(size > MAX_PACKET_SIZE_EPBULK) { - return false; - } - if(!send(buf, size)) { - return false; - } - return true; -} - - - -bool USBSerial::EPBULK_OUT_callback() { - uint8_t c[65]; - uint32_t size = 0; - - //we read the packet received and put it on the circular buffer - readEP(c, &size); - for (uint32_t i = 0; i < size; i++) { - buf.queue(c[i]); - } - - //call a potential handlenr - if (rx) - rx.call(); - - return true; -} - -uint8_t USBSerial::available() { - return buf.available(); -} - -bool USBSerial::connected() { - return terminal_connected; -}
--- a/USBSerial_copy.h Mon Nov 26 21:01:04 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/* Copyright (c) 2010-2011 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef USBSERIAL_H -#define USBSERIAL_H - -#include "USBCDC.h" -#include "Stream.h" -#include "CircBuffer.h" -#include "Callback.h" - -/** -* USBSerial example -* -* @code -* #include "mbed.h" -* #include "USBSerial.h" -* -* //Virtual serial port over USB -* USBSerial serial; -* -* int main(void) { -* -* while(1) -* { -* serial.printf("I am a virtual serial port\n"); -* wait(1); -* } -* } -* @endcode -*/ -class USBSerial: public USBCDC, public Stream { -public: - - /** - * Constructor - * - * @param vendor_id Your vendor_id (default: 0x1f00) - * @param product_id Your product_id (default: 0x2012) - * @param product_release Your preoduct_release (default: 0x0001) - * @param connect_blocking define if the connection must be blocked if USB not plugged in - * - */ - USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true): USBCDC(vendor_id, product_id, product_release, connect_blocking){ - settingsChangedCallback = 0; - }; - - - /** - * Send a character. You can use puts, printf. - * - * @param c character to be sent - * @returns true if there is no error, false otherwise - */ - virtual int _putc(int c); - - /** - * Read a character: blocking - * - * @returns character read - */ - virtual int _getc(); - - /** - * Read a string of characters - * - * @returns character read - */ - virtual int _read(void* buffer, int length); - virtual int _write(uint8_t * buf, uint16_t size); - /** - * Check the number of bytes available. - * - * @returns the number of bytes available - */ - uint8_t available(); - - /** - * Check if the terminal is connected. - * - * @returns connection status - */ - bool connected(); - - /** Determine if there is a character available to read - * - * @returns - * 1 if there is a character available to read, - * 0 otherwise - */ - int readable() { return available() ? 1 : 0; } - - /** Determine if there is space available to write a character - * - * @returns - * 1 if there is space to write a character, - * 0 otherwise - */ - int writeable() { return 1; } // always return 1, for write operation is blocking - - /** - * Write a block of data. - * - * For more efficiency, a block of size 64 (maximum size of a bulk endpoint) has to be written. - * - * @param buf pointer on data which will be written - * @param size size of the buffer. The maximum size of a block is limited by the size of the endpoint (64 bytes) - * - * @returns true if successfull - */ - bool writeBlock(uint8_t * buf, uint16_t size); - - /** - * Attach a member function to call when a packet is received. - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - */ - template<typename T> - void attach(T* tptr, void (T::*mptr)(void)) { - if((mptr != NULL) && (tptr != NULL)) { - rx.attach(tptr, mptr); - } - } - - /** - * Attach a callback called when a packet is received - * - * @param fptr function pointer - */ - void attach(void (*fptr)(void)) { - if(fptr != NULL) { - rx.attach(fptr); - } - } - - /** - * Attach a callback to call when serial's settings are changed. - * - * @param fptr function pointer - */ - void attach(void (*fptr)(int baud, int bits, int parity, int stop)) { - settingsChangedCallback = fptr; - } - -protected: - virtual bool EPBULK_OUT_callback(); - virtual void lineCodingChanged(int baud, int bits, int parity, int stop){ - if (settingsChangedCallback) { - settingsChangedCallback(baud, bits, parity, stop); - } - } - -private: - Callback<void()> rx; - CircBuffer<uint8_t,128> buf; - void (*settingsChangedCallback)(int baud, int bits, int parity, int stop); -}; - -#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/board.h Thu May 16 15:21:41 2019 +0000 @@ -0,0 +1,44 @@ +// +// SkyShepherd Firmware +// +// Copyright © 2018 GPSip, Inc. All rights reserved. +// + +#pragma once +#ifndef BOARD_H +#define BOARD_H + +// ---- Includes --------------------------------------------------------------- +//#include "PinNames.h" +#include "Geneva.h" +// ---- Defines ---------------------------------------------------------------- + +#define DEBUG_UART_TX STDIO_UART_TX // defined by mbed_app.json +#define DEBUG_UART_RX STDIO_UART_RX // defined by mbed_app.json + + +#define nvm_mosi A5 // SPI Data Out +#define nvm_miso A4 // SPI Data IN +#define nvm_sclk A3 // SPI Clock output +#define nvm_cs A2 // CS output + +#define UBLOX_M8N_GPS +#define GPS_EN A1 // GPS power enable. 1 = GPS on, 0 = GPS off +#define GPS_tx TX // gps tx +#define GPS_rx RX // gps rx + +#define BLE_DTR B5 // Module pin function controlled by AT commands, see reference +#define BLE_DSR B4 // led by AT commands Module pin function contro, see reference +#define BLE_TX S4_TX // bluetooth TX +#define BLE_RX S4_RX // bluetooth RX +#define BLE_RTS C1 // HW flow control. Not required to support +#define BLE_CTS C0 // HW flow control. Not required to support +#define nRESET D2 // Bluetooth Reset: Low = Reset, High = Normal mode + +#define TONE_PWM B2 // PWM output for the alert signal. High = buzzer on +#define STIM_PWM B1 // PWM output for the STIM signal. Active High = PWM on +#define VIBE_PWM B1 // PWM output for the vibrator motor. High = motor on. + + +#endif // BOARD_H +
--- a/geneva-lib.lib Mon Nov 26 21:01:04 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://os.mbed.com/teams/PointLabs/code/geneva-lib/#72798cdc8d57
--- a/main.cpp Mon Nov 26 21:01:04 2018 +0000 +++ b/main.cpp Thu May 16 15:21:41 2019 +0000 @@ -1,209 +1,81 @@ #include "mbed.h" #include "USBSerial.h" -#include "Geneva.h" -#define PASSTHROUGH 0 +#define GNSSEN PC_3 +#define GNSSTXD PA_9 +#define GNSSRXD PA_10 +#define GNSSBAUD 9600 /******************** Comms *********************/ -USBSerial pc; // moved the pc interface to the USB serial device -UARTSerial modemUartSerial(MDMTXD, MDMRXD, 115200); +USBSerial pc; +//FileHandle* mbed::mbed_override_console(int) +//{ +// return &pc; +//} + +UARTSerial radio(GNSSTXD, GNSSRXD, 9600); -DigitalInOut cellRst(MDMRST); -DigitalInOut cellPwrKey(MDMPWRON); -DigitalOut cellVcc(MDMVCC, 0); -DigitalOut cellRts(MDMRTS, 0); // Flow control not supported by 410, but RTS must be low -DigitalOut cellCts(MDMCTS, 0); - -DigitalOut gpsEn(PC_3, 0); -DigitalOut bleRst(PB_5, 0); +DigitalOut gpsEn(GNSSEN, 1); -DigitalOut greenLed(LED_GREEN, 1); -DigitalOut blueLed(LED_BLUE, 1); -DigitalOut redLed(LED_RED, 1); - -InterruptIn buttonInt(USER_BUTTON); - -InterruptIn *rxPin; -DigitalOut samplePin(PA_0); Thread myThread; -static char scanBuffer[512]; -static bool buttonWasPushed = false; + -typedef struct +void sendToModem(void) { - DigitalOut *resetPin; - DigitalOut *enablePin; - DigitalOut *dtrPin; - FileHandle *fileHandle; - ATCmdParser *rawParser; - UARTSerial *serial; -} cellContext_t; - -cellContext_t cell; - -char buffer[64]; - -static void buttonPushed(void) -{ - buttonWasPushed = true; + char c; + c = pc.getc(); + radio.write(&c, 1);// push the charcter to the modem } -#if PASSTHROUGH +void sendToPC(void) +{ + char c; + radio.read(&c, 1); + pc.putc(c); +} + + static void passthroughThread(void) { - char c; - pc.printf("Passthrough mode\r\n"); - blueLed = 0; +// pc.attach(&sendToModem); while (1) { // Housekeeping - check button if (pc.readable()) { - c = pc.getc(); - modemUartSerial.write(&c, 1);// push the charcter to the modem + sendToModem(); } - if (modemUartSerial.readable()) + if (radio.readable()) { - modemUartSerial.read(&c, 1); - pc.putc(c); + sendToPC(); } } } -#else -static void autoModeThread(void) -{ - pc.printf("Auto mode\r\n", 11); - - cell.fileHandle = &modemUartSerial; - cell.rawParser = new ATCmdParser(cell.fileHandle); - cell.rawParser->flush(); - cell.rawParser->debug_on(1); - cell.rawParser->set_timeout(2000); - - while (1) - { - cell.rawParser->send("AT"); - if (cell.rawParser->recv("OK")) - break; - wait(1.5); - } - - redLed = 1; - blueLed = 0; - pc.printf("Modem OK\r\n"); - wait(5); - - cell.rawParser->set_timeout(15000); - - while (1) - { - cell.rawParser->send("AT+CCID"); - if (cell.rawParser->recv("OK")) - { - break; - } - wait(4.5); - } - blueLed = 1; - greenLed = 0; - pc.printf("SIM OK\r\n"); - wait(2); - int act; - char plmn[8]; - bool result; - - cell.rawParser->set_timeout(20000); - cell.rawParser->send("AT+CMEE=2") && cell.rawParser->recv("OK"); - - while (1) - { - cell.rawParser->send("AT+COPS?"); - result = cell.rawParser->recv("+COPS: %[^\n]\nOK\n", scanBuffer); - if (true == result) - { - // Parse the registration status - if (sscanf(scanBuffer, "%*d, %*d, \"%[^\"]\", %d", plmn, &act) == 2) - { - if (act == 8) - break; - } - } - wait(3); - } - - pc.printf("Network OK\r\n"); - - while (1) - { - greenLed = 1; - wait(0.75); - greenLed = 0; - wait(0.75); - if (buttonWasPushed) - break; - } - - cell.rawParser->send("AT+COPS=2") && cell.rawParser->recv("OK"); -} -#endif void setup(void) { - // Enable flow control on MDM uart - //modemUartSerial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS); - - buttonInt.mode(PullUp); - buttonInt.fall(buttonPushed); - - cellRst.mode(OpenDrainNoPull); - cellRst.output(); - cellRst = 1; - - cellPwrKey.mode(OpenDrainNoPull); - cellPwrKey.output(); - cellPwrKey = 1; - wait(1); // wait just a bit for the USB to enumerate - pc.printf("Modem Test\r\n", 12); pc.set_blocking(false); - modemUartSerial.set_blocking(false); - - // Power up the modem! - cellVcc = 1; - pc.printf("Modem VCC UP\r\n", 14); - wait(3); + radio.set_blocking(false); - cellPwrKey = 0; - wait(0.9); - cellPwrKey = 1; - pc.printf("Modem Power\r\n", 13); - - redLed = 0; - - wait(5); -} + wait(1); +} int main(void) { setup(); -#if PASSTHROUGH myThread.start(passthroughThread); -#else - myThread.start(autoModeThread); -#endif - - Thread::wait(osWaitForever); return 1; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Thu May 16 15:21:41 2019 +0000 @@ -0,0 +1,20 @@ +{ + "config": { + "trace-level": { + "help": "Options are TRACE_LEVEL_ERROR,TRACE_LEVEL_WARN,TRACE_LEVEL_INFO,TRACE_LEVEL_DEBUG", + "macro_name": "MBED_TRACE_MAX_LEVEL", + "value": "TRACE_LEVEL_DEBUG" + } + }, + "target_overrides": { + "*": { + "target.features_add": ["COMMON_PAL"], + "platform.stdio-baud-rate": 115200, + "platform.stdio-convert-newlines": true, + "platform.default-serial-baud-rate": 115200, + "platform.stdio-buffered-serial": true, + "mbed-trace.enable": true, + "target.network-default-interface-type" : "CELLULAR" + } + } +} \ No newline at end of file