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.
Fork of MoxDes-mbed-os-BLE-USB-passthru by
Revision 3:29543066244b, committed 2018-10-30
- Comitter:
- zaldawid
- Date:
- Tue Oct 30 15:34:35 2018 +0000
- Parent:
- 2:3e203cc2a88f
- Commit message:
- stripped of all the functions.
Changed in this revision
--- a/README.md Sat Apr 29 01:32:11 2017 +0000 +++ b/README.md Tue Oct 30 15:34:35 2018 +0000 @@ -1,65 +0,0 @@ -# Moxon Design mbed OS V5 BLE UartService to USBUART passthru - -This guide reviews the steps required to get BLU UART working on an mbed OS platform. - -Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). - -## Import the example application - -From the command-line, import the example: - -``` -mbed import MoxDes-mbed-os-BLE-USB-passthru -cd MoxDes-mbed-os-BLE-USB-passthru -``` - -### Now compile - -Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: - -``` -mbed compile -m nRF42-DK -t ARM -``` - - -### Program your board - -1. Connect your mbed device to the computer over USB. -1. Copy the binary file to the mbed device. -1. Press the reset button to start the program. - -The BLE device should advertise as "BLART" (BLe-uART) - -## Export the project to Keil MDK, and debug your application - -From the command-line, run the following command: - -``` -mbed export -m nRF42-DK -i uvision -``` - -To debug the application: - -1. Start uVision. -1. Import the uVision project generated earlier. -1. Compile your application, and generate an `.axf` file. -1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger). -1. Set breakpoints, and start a debug session. - - - -## Troubleshooting - -1. Make sure `mbed-cli` is working correctly and its version is `>1.0.0` - - ``` - mbed --version - ``` - - If not, you can update it: - - ``` - pip install mbed-cli --upgrade - ``` - -2. If using Keil MDK, make sure you have a license installed. [MDK-Lite](http://www.keil.com/arm/mdk.asp) has a 32 KB restriction on code size. \ No newline at end of file
--- a/main.cpp Sat Apr 29 01:32:11 2017 +0000 +++ b/main.cpp Tue Oct 30 15:34:35 2018 +0000 @@ -1,179 +1,72 @@ -/* mbed BLE Library - USB/UART Serial Pass-thru Example +/* BLE/UART Cows tracker communication module * - * author : Moxon Design - * date : 4/27/2017 - * platforms : Rigado BLE-350/300, Nordic rRF52-DK, rRF51-DK - * requires : mBed Platform Version 5+ - - * Overview: - * - * Employs the mBed platform ble/services/UARTService for UART emulation, - * as well as exposing the phyical UART device connected to the USB host, - * providing a transparent bridge between the two interfaces. By default, - * Serial dev(USBTX, USBRX); + * author : Dawid Zalewski + * date : 16-10-2018 + * platforms : rRF52-DK * - * Set "UART_LoopBack" to enable local loopback test instead of pass-thru. - * - * Notes : - * 1) Advertises as "BLART" for BLe-usbUART - * 2) ble/services/UARTService is 20 byte max packets or about 4800 Baud (be patient) - * 3) transparent bridge - * - * License : - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ - + /* mbed platform defines */ -#include "mbed.h" -#include "ble/BLE.h" -#include "ble/services/UARTService.h" +#include <events/mbed_events.h> +#include <mbed.h> +#include "Serial.h" + +// Some ugly redefines to get things working +#define RESET_PIN (P0_21) +#define CUSTOM_LED (P0_25) +#define CUSTOM_TX (P0_06) +#define CUSTOM_RX (P0_08) +#define UART_BAUDRATE ( 115200 ) + +static mbed::Serial *serialPtr; + +DigitalOut led1(CUSTOM_LED, 1); -/* got debug? */ -/* Set this if you need debug messages on the console */ -/* Negative impact on code-size and power consumption */ -#define DEBUG_OUTPUT 0 -#if DEBUG_OUTPUT -#define DEBUG(...) { printf(__VA_ARGS__); } -#else -#define DEBUG(...) /* no output mapped */ -#endif +// apparently needed +EventQueue eventQueue(16 * EVENTS_EVENT_SIZE); + + +// UART thingies begin here +#define UART_RX_BUFFER_LEN (256) +static uint8_t uartReceiveBuffer[UART_RX_BUFFER_LEN]; +static uint8_t uartRxLen = 0; + +void onUartDataWritten(); -/* instantiate BLE services and softUART service */ -BLEDevice ble; -UARTService *uartServicePtr; -int UART_LoopBack = 0; - -/* instantiate hardware UART devices */ -/* devicename(TXD, RXD); */ -/* for "JLink CDC UART Port" use the define below : */ -/* Serial dev(USBTX, USBRX); */ -/* otherwise use the hardware UART on 0.12 & 0.11 */ -/* (a.k.a. d1 & D1 in Arduino parlance... */ - //Serial dev(P0_12, P0_11); - Serial dev(USBTX, USBRX); - static uint8_t rx_buf[32]; - static uint8_t rx_len=0; - int tx_buf; - static uint8_t tx_len=0; +void handleUartDataWritten( ){ + + while( serialPtr->readable() ){ + + //read all that is available + serialPtr->putc('<'); -/* define some blinky LED fun */ -DigitalOut led1(LED1); -//DigitalOut led2(LED2); -//DigitalOut led3(LED3); -//DigitalOut led4(LED4); - -void theBLEdisconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) -{ - #if DEBUG_OUTPUT - DEBUG("Disconnected!\n\r"); - DEBUG("Restarting the advertising process\n\r"); - #endif - ble.startAdvertising(); + while( serialPtr->readable() && (uartRxLen < UART_RX_BUFFER_LEN )){ + serialPtr->putc(serialPtr->getc()); + } + + serialPtr->putc('>'); + } + serialPtr->attach(onUartDataWritten, Serial::RxIrq); } -void theBLEonDataWritten(const GattWriteCallbackParams *params) -{ - if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) { - uint16_t bytesRead = params->len; - uint8_t byteCnt; - - #if DEBUG_OUTPUT - DEBUG("BLART BLE received %u bytes\n\r", bytesRead); - #endif - - if (UART_LoopBack == 0) { - /* pass thru BLE UART data to UART1 */ - for (byteCnt = 0; byteCnt < bytesRead; byteCnt++) { - dev.putc(params->data[byteCnt]); - } - } else { - /* otherwise, loopback BLE UART data to itself */ - ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead); - } - } +void onUartDataWritten(){ + serialPtr->attach(NULL, Serial::RxIrq); + eventQueue.call(handleUartDataWritten); } -void theUARTonDataWritten(void) { - while(dev.readable()) - { - rx_buf[rx_len++] = dev.getc(); - #if DEBUG_OUTPUT - DEBUG("BLART BLE received %u \n\r", rx_buf[rx_len]); - #endif - if (UART_LoopBack == 0) { - ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), rx_buf, rx_len); - rx_len = 0; - } else { - for (tx_len = 0; tx_len < rx_len; tx_len++) { - tx_buf = rx_buf[tx_len]; - dev.putc(tx_buf); - } - rx_len = 0; - } - } +void initUart(){ + serialPtr = new Serial(USBTX, USBRX, UART_BAUDRATE); + serialPtr->attach(&onUartDataWritten, Serial::RxIrq); } -void theTickCallback(void) +void blinker(void) { - /* toggle the LED each timer tick (1 sec) */ led1 = !led1; } -int main(void) -{ - /* set up a 1 sec timer to toggle the LED */ - led1 = 1; - Ticker ticker; - ticker.attach(theTickCallback, 1); - - /* attach the hardwate UART1 data received callback */ - dev.attach( &theUARTonDataWritten , dev.RxIrq); - - /* initialze the BLE services */ - #if DEBUG_OUTPUT - DEBUG("Initialising the nRF5x\n\r"); - #endif - ble.init(); - ble.onDisconnection(theBLEdisconnectionCallback); - ble.onDataWritten(theBLEonDataWritten); - - /* setup the BLE advertising */ - ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); - ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - /* my names "BLART", what's yours? */ - #if DEBUG_OUTPUT - DEBUG("Advertising nRF5x as BLART i.e. BLe-uART\n\r"); - #endif - ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, - (const uint8_t *)"BLART", sizeof("BLART") - 1); - ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, - (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed)); - - /* Advertising Rate at 1000ms, a multiple of the 0.625ms base timer */ - ble.setAdvertisingInterval(1000); - ble.startAdvertising(); - - /* start the BLE UARTServices */ - UARTService uartService(ble); - uartServicePtr = &uartService; - - /* start the hardware UART1 */ - //uart1.printf("Hello! My name is BLART, what's yours?\n"); - - /* main loop */ - while (true) { - /* call wait to give other threads a chance to run */ - ble.waitForEvent(); - } +int main(){ + eventQueue.call_every(250, blinker); + initUart(); + eventQueue.dispatch_forever(); + return 0; } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Tue Oct 30 15:34:35 2018 +0000 @@ -0,0 +1,7 @@ +{ + "target_overrides": { + "NRF52_DK": { + "target.uart_hwfc": 0 + } + } +} \ No newline at end of file