element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
FPGA
  • Technologies
  • More
FPGA
Blog 7 Ways to Leave Your Spartan-6 Challenge - add BLE interface
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
FPGA requires membership for participation - click to join
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ralphjy
  • Date Created: 25 Jul 2022 1:27 AM Date Created
  • Views 1539 views
  • Likes 9 likes
  • Comments 4 comments
  • arty-s7
  • 7 Ways to Leave Your Spartan-6
  • spartan-7
  • xilinx fpga
  • Spartan_Migration
Related
Recommended

7 Ways to Leave Your Spartan-6 Challenge - add BLE interface

ralphjy
ralphjy
25 Jul 2022

Since I've been doing a lot of work with BLE this summer, I thought it would be appropriate to add a BLE interface to my Arty S7 project for the challenge.  I initially thought about wiring up a BLE UART board that I had available, either a DSD Tech HM-19 that uses the Ti CC2640 chip or an Adafruit BLE Friend that uses a Nordic nRF51822 chip, but I noticed that the PmodBLE module was available - I just had to wait a week or so to get one.  The PmodBLE uses a Microchip RN4871 chip and I haven't used a Microchip BLE part before, so I thought I'd give it a try.  It would be a lot cleaner interface and worst case I could fall back to one of the other boards.

image

                                                PmodBLE

It turns out that incorporating the PmodBLE has been a lot bigger task than I had anticipated.  The PmodBLE is in Digilent's Vivado Pmod IP library and the previous Pmods were not a problem other than generating "Critical Warnings" in Vivado because the Pmod IP hasn't been updated for Xilinx tools beyond the 2019.1-2 version.

I didn't have any problems adding the PmodBLE in Vivado other than the Critical Warnings.

Here is the Block Diagram with the PmodBLE incorporated:

image

Zoomed in to show the IO:

image
.
And a picture of the new setup:
The PmodBLE is the third one down with the blue LED.
image

I encountered problems when I tried to create an application program in Vitis.  For some reason Vitis could not find the necessary include file "PmodBLE.h", so the application would not compile.  I verified that the driver files were included in the hardware file exported from Vivado.  So, it must be a path or configuration issue.  I'll need to do some hunting to find it.

I decided that I should first verify that the PmodBLE IP would work if I used it on its own without the other Pmods.  So, I went back to Vivado and simplified the design.

image

image

Exported the hardware file to Vitis - and now everything compiled correctly.

The PmodBLE library is fairly sparse.  It implements the following basic functions to configure the interface and implement the UART send/receive:

void BLE_Begin(PmodBLE* InstancePtr, u32 GPIO_Address, u32 UART_Address, u32 AXI_ClockFreq, u32 Uart_Baud);
int BLE_RecvData(PmodBLE* InstancePtr, u8 *Data, int nData);
int BLE_SendData(PmodBLE* InstancePtr, u8 *Data, int nData);
void BLE_ChangeBaud(PmodBLE* InstancePtr, int baud);
void BLE_WriteRTS(PmodBLE* InstancePtr, u8 enable);
int BLE_ReadCTS(PmodBLE* InstancePtr);
void BLE_SetReset(PmodBLE* InstancePtr, u8 Value);
int BLE_IsConnected(PmodBLE* InstancePtr);

I discovered that the RN4871 as a GATT Server hosts the Microchip Transparent UART Service by default. The Transparent UART Service provides a simple bidirectional data transfer service. It defines two characteristics for data communication, one for receiving data with the Write property and the other for sending data with the Notify property.  So, getting it to work seemed like it would be simple since the service properties and UUIDs are preconfigured.

Service Name

UUID

Microchip Transparent UART

49535343-FE7D-4AE5-8FA9-9FAFD205E455

Characteristic Name

UUID

Properties

Microchip Transparent UART TX

49535343-1E4D-4BD9-BA61-23C647249616

Notify, Write, Write without response

Client Characteristic Descriptor

 

Read, Write

Microchip Transparent UART RX

49535343-8841-43F4-A8D4-ECBE34729BB3

Write, Write without response

The example program included with the IP illustrates this simplicity.

PmodBLE_v1_0/examples/main.c

/******************************************************************************/
/*                                                                            */
/* main.c -- Example program using the PmodBLE IP                            */
/*                                                                            */
/******************************************************************************/
/* Author: Arthur Brown                                                       */
/*                                                                            */
/******************************************************************************/
/* File Description:                                                          */
/*                                                                            */
/* This demo continuously polls the Pmod BLE and host development board's     */
/* UART connections and forwards each character from each to the other.       */
/*                                                                            */
/******************************************************************************/
/* Revision History:                                                          */
/*                                                                            */
/*    10/04/2017(artvvb):  Created                                            */
/*	  01/16/2017(Tommyk):  Modified to work for PmodBLE						  */
/*                                                                            */
/******************************************************************************/

#include "xil_cache.h"
#include "xparameters.h"
#include "PmodBLE.h"

//required definitions for sending & receiving data over the host board's UART port
#ifdef __MICROBLAZE__
#include "xuartlite.h"
typedef XUartLite SysUart;
#define SysUart_Send            XUartLite_Send
#define SysUart_Recv            XUartLite_Recv
#define SYS_UART_DEVICE_ID      XPAR_AXI_UARTLITE_0_DEVICE_ID
#define BLE_UART_AXI_CLOCK_FREQ XPAR_CPU_M_AXI_DP_FREQ_HZ
#else
#include "xuartps.h"
typedef XUartPs SysUart;
#define SysUart_Send            XUartPs_Send
#define SysUart_Recv            XUartPs_Recv
#define SYS_UART_DEVICE_ID      XPAR_PS7_UART_1_DEVICE_ID
#define BLE_UART_AXI_CLOCK_FREQ 100000000
#endif

PmodBLE myDevice;
SysUart myUart;

void DemoInitialize();
void DemoRun();
void SysUartInit();
void EnableCaches();
void DisableCaches();

int main()
{
    DemoInitialize();
    DemoRun();
    DisableCaches();
    return XST_SUCCESS;
}

void DemoInitialize()
{
    EnableCaches();
    SysUartInit();
    BLE_Begin (
        &myDevice,
        XPAR_PMODBLE_0_S_AXI_GPIO_BASEADDR,
        XPAR_PMODBLE_0_S_AXI_UART_BASEADDR,
        BLE_UART_AXI_CLOCK_FREQ,
        115200
    );
}

void DemoRun()
{
    u8 buf[1];
    int n;

    xil_printf("Initialized PmodBLE Demo, received data will be echoed here, type to send data\r\n");

    while(1) {
        //echo all characters received from both BLE and terminal to terminal
        //forward all characters received from terminal to BLE
        n = SysUart_Recv(&myUart, buf, 1);
        if (n != 0) {
            SysUart_Send(&myUart, buf, 1);
            BLE_SendData(&myDevice, buf, 1);
        }

        n = BLE_RecvData(&myDevice, buf, 1);
        if (n != 0) {
            SysUart_Send(&myUart, buf, 1);
        }
    }
}

//initialize the system uart device, AXI uartlite for microblaze, uartps for Zynq
void SysUartInit()
{
#ifdef __MICROBLAZE__
    XUartLite_Initialize(&myUart, SYS_UART_DEVICE_ID);
#else
    XUartPs_Config *myUartCfgPtr;
    myUartCfgPtr = XUartPs_LookupConfig(SYS_UART_DEVICE_ID);
    XUartPs_CfgInitialize(&myUart, myUartCfgPtr, myUartCfgPtr->BaseAddress);
#endif
}

void EnableCaches()
{
#ifdef __MICROBLAZE__
#ifdef XPAR_MICROBLAZE_USE_ICACHE
    Xil_ICacheEnable();
#endif
#ifdef XPAR_MICROBLAZE_USE_DCACHE
    Xil_DCacheEnable();
#endif
#endif
}

void DisableCaches()
{
#ifdef __MICROBLAZE__
#ifdef XPAR_MICROBLAZE_USE_DCACHE
    Xil_DCacheDisable();
#endif
#ifdef XPAR_MICROBLAZE_USE_ICACHE
    Xil_ICacheDisable();
#endif
#endif
}

Building and uploading the program was simple.  Verifying that it was operating correctly took a bit longer.

My normal method of verifying a BLE UART involves using one of the Nordic apps.  I've successfully used nRF Connect for Desktop on my PC plus nRF Connect and nRF UART on my Android and iOS tablets.  This time I had difficulty getting them to work.  nRF Connect would connect on both the PC and tablet, but I couldn't get the send and receive services to work.  When testing, I also monitor the debug UART output in a GtkTerm on my Ubuntu Virtual Machine.

nRF Connect for Desktop Bluetooth Low Energy app - connects but cannot send/receive data

image

image

nRF Connect on Android - connects but cannot send/receive data

image

image

Then I tried the nRF UART app on Android and it would not recognize the PmodBLE as a UART and would disconnect immediately after connecting.

image

image

I noticed in the Microchip documentation that there was an MHCP Transparent UART Android app, but that was a few years ago and it has apparently been replaced by the Microchip Bluetooth Data app.  This app almost worked, but it only recognized the Receive(Write) service on the Arty.

Microchip Bluetooth Data - has functions in addition to the BLE UART

image

BLE UART supports multiple chipsets

image

Only the receive service for the Transparent UART is shown

image

But it works, Arty receives the data

image

image

So, at this point I'm confused.  Are all these various apps not working or is there something wrong with the program I'm running on the Arty?  I decide to try another program that I've seen mentioned as working with the Microchip Transparent UART -  

Serial Bluetooth Terminal by Kai Morich.

Surprise.  It works! Relaxed  I can send to and receive from the Arty.

image

image

I don't have the access to look under the hood of these apps or modify them, but it could just be an issue recognizing service UUIDs.  Why would Microchip's app have a problem?  Wish I could have tried the original MHCP Transparent UART app.

So, I have evidence that BLE is working.  Now I need to go back and figure out the issue with running with the other Pmods so that I can finish this challenge.

  • Sign in to reply
  • ralphjy
    ralphjy over 2 years ago in reply to javagoza

    Appreciate the info.  I'm using 2020.2 in an Ubuntu 18.04 VM on WIn10.  Generally a clean and build has worked for me when files get lost.  I've read that restarting Vitis fixes issues that clean and build don't.  Unfortunately, I've been through multiple restarts of the VM and reboots of the Win10 host (I shutdown every night because of the summer heat). I've started to notice behavior change on restarts and I just found that the IDE.log file had invalid characters in it and there are error messages about parsing errors in the .xfpm file.  Not sure what corrupted the files. Hope I'm not having drive problems.  I'm going to try starting a new project.  The BLE only project seems like it's still doing okay.

    BTW, I did miss the BLE_uart_interrupt connection.  Thanks for catching that.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • javagoza
    javagoza over 2 years ago in reply to ralphjy

    I am using Vitis version 2021.1 with Windows 10.

    Sometimes, when I refactor and move or rename a file, a clean and build is not enough and I have to close Vitis and reopen it.

    It has also happened to me that sometimes the .lock file of the workspace gets caught by an Eclipse process and does not allow that workspace to be opened again. Windows won't let me kill the Eclipse process even with administrator permissions and then I have no choice but to restart the machine.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 2 years ago in reply to javagoza

    javagoza Thanks.  Good catch.  I need to go back and check it.  I may have snapped an early version (I've iterated a couple of times).  If not, I'll fix it.

    Not sure what my Vitis problem is.  I'm starting to suspect I have a hard drive problem because the issue with missing files has gotten worse - Vitis will no longer start in that workspace.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • javagoza
    javagoza over 2 years ago

    Hi ralphjy I noticed in your first block design that the BLE_uart_interrupt is unconnected.

    image

    Open the the Concat block, microblazeblaze_0_xlconcat, used to concatenate the interrupt signals and change the number of ports to 4 then connect the BLE_uart_interrupt port to the new In3[0:0]

    image

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube