Skip to content

MillerTechnologyPeru/swift-zephyr-rfid

 
 

Repository files navigation

Swift Zephyr RFID Example

This is a simple example project that shows off how Swift can interop with Zephyr using CMake. This example shows off integration with the following features:

  • GPIO LED / Output
  • Bluetooth (Advertising)
  • SPI

Note

Much of the code in this example is based off the work of Eric Bariaux. He was kind enough to share his Swift -> Zephyr examples for the nRF52, which helped significantly with getting started and building this example as well. Check out the nelcea repo on GitHub for more awesome examples from Eric!

Hardware Requirements

This example is coded to work with the Adafruit Feather nRF52840 Express, but can also work with other BLE-enabled boards with an additional overlay file in the boards/ directory.

Other required/recommended hardware:

Something like this can be constructed:

Sample Hardware Setup for the Swift Zephyr RFID Example

When the RFID tag is scanned, the BLE manufacturer data is set to the 5-bytes scanned from the (Mifare) tag. In the LightBlue app (recommended), the RFID tag appears like this in the scanning list:

RFID in manufacturer data of SwiftRFID peripheral

Software Requirements

In order to build this example, you'll need to install the following components:

Building

Start by sourcing Zephyr to get into the venv:

$ source ~/zephyrproject/.venv/bin/activate

A handy build script has been provided that will compile the firmware for the adafruit_feature_nrf52840 for you:

$ ./build.sh
...
[216/216] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      129456 B         1 MB     12.35%
             RAM:       18880 B       256 KB      7.20%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from ~/swift-zephyr-rfid/build/zephyr/zephyr.elf for board: adafruit_feather_nrf52840

Or, the same can be done using west if ZEPHYR_BASE is set to point to your local Zephyr installation:

$ ZEPHYR_BASE=~/zephyrproject/zephyr
$ west build -p always -b adafruit_feather_nrf52840 .
...
[216/216] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:      129456 B         1 MB     12.35%
             RAM:       18880 B       256 KB      7.20%
        IDT_LIST:          0 GB        32 KB      0.00%
Generating files from ~/swift-zephyr-rfid/build/zephyr/zephyr.elf for board: adafruit_feather_nrf52840

Programming

Another handy-dandy script is provided to program the device, verify the firmware, and reset it using nrfutil:

$ ./program.sh
[00:00:02] ###### 100% [2/2 802001236] Programmed
✔️ Firmware was verified on 802001236
✔️ Reset was applied to 802001236

Or, if using west, use the flash command:

$ west flash
-- west flash: rebuilding
ninja: no work to do.
-- west flash: using runner jlink
-- runners.jlink: reset after flashing requested
-- runners.jlink: JLink version: 8.26
-- runners.jlink: Flashing file: ~/swift-zephyr-rfid/build/zephyr/zephyr.hex

About

Swift -> Zephyr sample project for scanning an RFID tag and showing the result over Bluetooth

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 57.6%
  • Swift 28.3%
  • CMake 12.7%
  • Shell 1.1%
  • Linker Script 0.3%