Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[driver] DW3110 UWB radio #1124

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
479b6dd
WIP: [driver] radio: Add DW3110 UWB phy
rleh Jan 29, 2024
7dd509d
WIP: [examples] nucleo_f411re: DW3110 UWB radio communication
rleh Jan 29, 2024
69fda86
WIP: [examples] nucleo_f411re: fix DW3110 SPI setup
kingelilol Feb 29, 2024
ffed521
WIP: [driver] radio: add dw3110 device ping
kingelilol Feb 29, 2024
cfdd334
WIP: [driver] radio: abstract dw3110 send function (broken)
kingelilol Mar 5, 2024
f34dab5
fix
rleh Mar 5, 2024
92b57cf
WIP: [driver] radio: move cs pin direction to dw3110 initialisation
kingelilol Mar 8, 2024
c47c610
WIP: [examples] nucleo_f411re: add second module
kingelilol Mar 8, 2024
477d112
WIP: [driver] radio: dw3110 - fix missing cs in unused phys
kingelilol Mar 10, 2024
10daf5e
WIP: [driver] radio: dw3110 WIP
kingelilol Mar 22, 2024
ddcde25
[driver] radio: dw3110 Rework interface
Javask Apr 26, 2024
0ef6905
[driver] radio: dw3110 Working ping pong
Javask Aug 14, 2024
3c21503
[driver] radio: dw3110 Fix channel not being set
Javask Aug 14, 2024
1b4ee31
[driver] radio: dw3110 Improve soft reset behaviour
Javask Aug 14, 2024
5d91012
[driver] radio: dw3110 Fix TX/RX states
Javask Aug 14, 2024
01cd60b
[examples] nucleo_f401re: Add explicit parameters
Javask Aug 14, 2024
112e8c2
[driver] radio: dw3110 Cleanup
Javask Aug 14, 2024
046118b
[driver] radio: dw3110 Add wait for reply
Javask Aug 15, 2024
416d676
[driver] radio: dw3110 Remove debug logging
Javask Aug 15, 2024
b4a64d2
[driver] radio: dw3110 Remove useless auto ack function
Javask Aug 15, 2024
6598d3f
[driver] radio: dw3110 Fix the spi lock sometimes desyncing
Javask Aug 15, 2024
5c640af
[driver] radio: dw3110 Simplify transmit interface
Javask Aug 16, 2024
94b6a36
[examples] nucleo_f401re: Use Protothreads for RX and TX
Javask Aug 16, 2024
9b255b0
[driver] radio: dw3110 Add ability to check if currently listening
Javask Aug 16, 2024
d370ead
[examples] radio: dw3110 Add better logging
Javask Aug 19, 2024
06899fd
[driver] radio: dw3110 Use modm registers
Javask Aug 19, 2024
c3eefa3
[driver] radio: dw3110 Expose ranging flag for tx
Javask Aug 19, 2024
fbd60f5
[driver] radio: dw3110 Implement frame filtering functions
Javask Aug 19, 2024
f173cfd
[driver] radio: dw3110 Formatting
Javask Aug 20, 2024
9625d12
[driver] radio: dw3110 Fix rx timeout
Javask Aug 20, 2024
51412d8
[driver] radio: dw3110 Add way to clear status bits
Javask Aug 20, 2024
34b32f2
[driver] radio: dw3110 Use CCA by default
Javask Aug 21, 2024
8d974f8
[driver] radio: dw3110 Add delayed transmissions
Javask Aug 22, 2024
1d5c9ac
[driver] radio: dw3110 Remove old test function
Javask Aug 22, 2024
3a5aa0b
[driver] radio: dw3110 Better propagate tx errors
Javask Aug 22, 2024
123c0d4
[examples] nucleo_f401re DW3110 Update to fix compile errors
Javask Aug 22, 2024
eb86556
[driver] radio: dw3110 Remove outdated TODOs
Javask Aug 22, 2024
63fc406
[driver] radio: dw3110 Improve docs
Javask Aug 23, 2024
bc29e2b
[driver] radio: dw3110 Fix wrong mask in setEnableFastTurnaround
Javask Aug 23, 2024
34f573e
[driver] radio: dw3110 Move some enums to Dw3110Phy
Javask Aug 23, 2024
0a704e6
[driver] radio: dw3110 Enable antenna delay calibration
Javask Aug 25, 2024
db85535
[driver] radio: dw3110 Add interrupt configuration
Javask Aug 27, 2024
303cfc7
[driver] radio: dw3110 Fix wrong module description
Javask Aug 28, 2024
dbda6d2
[driver] radio: dw3110 Add STS capabilities
Javask Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,90 +738,91 @@ your specific needs.
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1631">DS1631</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds18b20">DS18B20</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-dw3110">DW3110</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input">Encoder Input</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input-bitbang">Encoder Input BitBang</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_output-bitbang">Encoder Output BitBang</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft245">FT245</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft6x06">FT6x06</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft6x06">FT6x06</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">Gpio Sampler</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hclax">HCLAx</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hd44780">HD44780</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc58x">HMC58x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc6343">HMC6343</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hx711">HX711</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hx711">HX711</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ili9341">ILI9341</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-is31fl3733">IS31FL3733</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-itg3200">ITG3200</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ixm42xxx">IXM42XXX</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-l3gd20">L3GD20</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-l3gd20">L3GD20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lan8720a">LAN8720A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3dsh">LIS3DSH</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3mdl">LIS3MDL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lm75">LM75</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lm75">LM75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lp503x">LP503x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6dso">LSM6DSO</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ltc2984">LTC2984</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max31855">MAX31855</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max31855">MAX31855</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max31865">MAX31865</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max6966">MAX6966</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23x17</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp3008">MCP3008</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp3008">MCP3008</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp7941x">MCP7941x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp990x">MCP990X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ms5611">MS5611</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ms5837">MS5837</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9535">PCA9535</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-qmc5883l">QMC5883L</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7789">ST7789</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx128x">SX128X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp12x">TMP12x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
</tr>
</table>
<!--/drivertable-->
Expand Down
171 changes: 171 additions & 0 deletions examples/nucleo_f401re/dw3110-communication/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* Copyright (c) 2024, Elias H.
* Copyright (c) 2024, Raphael Lehmann
* Copyright (c) 2024, Michael Jossen
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <modm/board.hpp>
#include <modm/debug/logger.hpp>
#include <modm/driver/radio/dw3110/dw3110_phy.hpp>
#include <modm/processing/protothread.hpp>
#include <modm/processing/timer.hpp>

using namespace Board;
using namespace std::chrono_literals;

using MySpiMaster = modm::platform::SpiMaster1;
using MyDw3110_a = modm::Dw3110Phy<MySpiMaster, GpioB6>;
using MyDw3110_b = modm::Dw3110Phy<MySpiMaster, GpioA10>;

constexpr static size_t PacketLength = 1021;

class TXThread : public modm::pt::Protothread
{
public:
bool
init()
{
auto ret = RF_CALL_BLOCKING(radio.initialize(
modm::Dw3110::Channel::Channel9, modm::Dw3110::PreambleCode::Code_64Mhz_9,
modm::Dw3110::PreambleLength::Preamble_128,
modm::Dw3110::StartFrameDelimiter::Decawave_8));
RF_CALL_BLOCKING(radio.setEnableLongFrames(true));
return ret;
}

bool
run()
{
PT_BEGIN();
while (true)
{

txdata[txdata.size() - 1]++;
timeout.restart(Button::read() ? 500ms : 10ms);
PT_WAIT_UNTIL(timeout.execute());
if (PT_CALL(radio.transmit(txdata, true)) == MyDw3110_b::Error::None)
{
sentCount++;
} else
{
MODM_LOG_DEBUG << "[TX] Failed to trasmit!" << modm::endl;
}
}
PT_END();
}

size_t
getCount()
{
return sentCount;
}

private:
MyDw3110_b radio{};
std::array<uint8_t, PacketLength> txdata = {0xBA, 0xDE, 0xAF, 0xFE, 0x00};
modm::Timeout timeout{10ms};
size_t sentCount{0};
};

class RXThread : public modm::pt::Protothread
{
public:
bool
init()
{
auto ret = RF_CALL_BLOCKING(radio.initialize(
modm::Dw3110::Channel::Channel9, modm::Dw3110::PreambleCode::Code_64Mhz_9,
modm::Dw3110::PreambleLength::Preamble_128,
modm::Dw3110::StartFrameDelimiter::Decawave_8));
RF_CALL_BLOCKING(radio.setEnableLongFrames(true));
return ret;
}

bool
run()
{
PT_BEGIN();
while (true)
{
while (!PT_CALL(radio.packetReady()))
{
if (!PT_CALL(radio.isReceiving()))
{
// KEEP ON SEPERATE LINE
PT_CALL(radio.startReceive());
}
PT_YIELD();
}

if (PT_CALL(radio.fetchPacket(rxdata, rxlen))) { recvCount++; }
}
PT_END();
}

size_t
getCount()
{
return recvCount;
}

private:
MyDw3110_a radio{};
size_t rxlen{0}, recvCount{0};
std::array<uint8_t, PacketLength> rxdata = {};
};

int
main()
{
Board::initialize();
LedD13::setOutput();

MySpiMaster::initialize<Board::SystemClock, 21_MHz>();
MySpiMaster::connect<GpioA6::Miso, GpioA7::Mosi, GpioA5::Sck>();

// Use the logging streams to print some messages.
// Change MODM_LOG_LEVEL above to enable or disable these messages
MODM_LOG_DEBUG << "debug" << modm::endl;
MODM_LOG_INFO << "info" << modm::endl;
MODM_LOG_WARNING << "warning" << modm::endl;
MODM_LOG_ERROR << "error" << modm::endl;

MODM_LOG_INFO << "Initializing Devices..." << modm::endl;
bool success = true;
TXThread tx;
if (!tx.init())
{
MODM_LOG_ERROR << "Failed to initialize TX Device!" << modm::endl;
success = false;
}

RXThread rx;
if (!rx.init())
{
MODM_LOG_ERROR << "Failed to initialize TR Device!" << modm::endl;
success = false;
}
if (!success)
while (true) {}

modm::PeriodicTimer timer{1000ms};
MODM_LOG_INFO << "Starting ping pong..." << modm::endl;
while (true)
{
rx.run();
tx.run();
if (timer.execute())
{
MODM_LOG_DEBUG << "Sent " << tx.getCount() << ", received " << rx.getCount()
<< ". Diff:" << tx.getCount() - rx.getCount() << modm::endl;
}
}

return 0;
}
12 changes: 12 additions & 0 deletions examples/nucleo_f401re/dw3110-communication/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<library>
<extends>modm:nucleo-f401re</extends>
<options>
<option name="modm:build:build.path">../../../build/nucleo_f401re/dw3110-communication</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:driver:dw3110</module>
<module>modm:platform:spi:1</module>
<module>modm:processing:protothread</module>
</modules>
</library>
33 changes: 33 additions & 0 deletions src/modm/driver/radio/dw3110/dw3110.lb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2024, Elias H.
# Copyright (c) 2024, Raphael Lehmann
# Copyright (c) 2024, Michael Jossen
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------


def init(module):
module.name = ":driver:dw3110"
module.description = "DW3110 Drivers"

def prepare(module, options):
module.depends(
":architecture:register",
":architecture:spi.device",
":debug",
":processing:timer",
":processing:resumable")
return True

def build(env):
env.outbasepath = "modm/src/modm/driver/radio/dw3110"
env.copy("dw3110_phy.hpp")
env.copy("dw3110_phy_impl.hpp")
env.copy("dw3110_definitions.hpp")
Loading
Loading