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.
Prototype RF Driver for STM Sub-1 GHz RF Expansion Boards based on the SPSGRF-868 and SPSGRF-915 Modules for STM32 Nucleo
Currently supported boards:
Note, in order to use expansion board X-NUCLEO-IDS01A4 in mbed you need to perform the following HW modifications on the board:
- Unmount resistor
R4 - Mount resistor
R7
Furthermore, on some Nucleo development boards (e.g. the NUCLEO_F429ZI), in order to be able to use Ethernet together with these Sub-1 GHz RF expansion boards, you need to compile this driver with macro SPIRIT1_SPI_MOSI=PB_5 defined, while the development board typically requires some HW modification as e.g. described here!
This driver can be used together with the 6LoWPAN stack (a.k.a. Nanostack).
Revision 11:b769d6caad82, committed 2016-10-26
- Comitter:
- Wolfgang Betz
- Date:
- Wed Oct 26 15:08:44 2016 +0200
- Parent:
- 10:dedd44d58c0f
- Child:
- 12:b8056eda4028
- Commit message:
- Extend nanostack interface
Changed in this revision
--- a/.gitignore Tue Oct 25 10:56:52 2016 +0200 +++ b/.gitignore Wed Oct 26 15:08:44 2016 +0200 @@ -3,3 +3,4 @@ projectfiles *.py* RCS +atmel-rf-driver
--- a/SimpleSpirit1.cpp Tue Oct 25 10:56:52 2016 +0200 +++ b/SimpleSpirit1.cpp Wed Oct 26 15:08:44 2016 +0200 @@ -314,7 +314,7 @@ enable_spirit_irq(); BUSYWAIT_UNTIL(SPIRIT1_STATUS() != SPIRIT1_STATE_TX, 50); - MBED_ASSERT(linear_fifo_read_num_elements_tx_fifo() == 0); + // MBED_ASSERT(linear_fifo_read_num_elements_tx_fifo() == 0); return RADIO_TX_OK; }
--- a/SimpleSpirit1.h Tue Oct 25 10:56:52 2016 +0200
+++ b/SimpleSpirit1.h Wed Oct 26 15:08:44 2016 +0200
@@ -401,11 +401,17 @@
/** Get latest value of RSSI **/
float get_last_rssi_dbm(void) {
+ if(last_rssi == 0) {
+ last_rssi = qi_get_rssi();
+ }
return (-120.0+((float)(last_rssi-20))/2);
}
/** Get latest value of LQI **/
uint8_t get_last_lqi(void) {
+ if(last_lqi == 0) {
+ last_lqi = qi_get_lqi();
+ }
return last_lqi;
}
--- a/mbed_driver_api.cpp Tue Oct 25 10:56:52 2016 +0200
+++ b/mbed_driver_api.cpp Wed Oct 26 15:08:44 2016 +0200
@@ -1,6 +1,16 @@
#include "SimpleSpirit1.h"
#include "nanostack/platform/arm_hal_phy.h"
+/*Atmel RF Part Type*/
+// betzw - TODO
+typedef enum
+{
+ ATMEL_UNKNOW_DEV = 0,
+ ATMEL_AT86RF212,
+ ATMEL_AT86RF231,
+ ATMEL_AT86RF233
+}rf_trx_part_e;
+
static uint8_t mac_address[8] = {
MBED_CONF_SPIRIT1_MAC_ADDRESS_0,
MBED_CONF_SPIRIT1_MAC_ADDRESS_1,
@@ -13,6 +23,7 @@
};
static phy_device_driver_s device_driver;
static int8_t rf_radio_driver_id = -1;
+static uint8_t rf_rnd_rssi = 0;
const phy_rf_channel_configuration_s phy_subghz = {868000000, 1000000, 250000, 11, M_GFSK};
@@ -89,31 +100,40 @@
{
/*Control MAC pending bit for Indirect data transmission*/
case PHY_EXTENSION_CTRL_PENDING_BIT:
+ break;
+
/*Return frame pending status*/
case PHY_EXTENSION_READ_LAST_ACK_PENDING_STATUS:
// TODO: *data_ptr = rf_if_last_acked_pending();
+ *data_ptr = 0;
break;
+
/*Set channel, used for setting channel for energy scan*/
case PHY_EXTENSION_SET_CHANNEL:
break;
+
/*Read energy on the channel*/
case PHY_EXTENSION_READ_CHANNEL_ENERGY:
// TODO: *data_ptr = rf_get_channel_energy();
+ *data_ptr = rf_device->get_last_rssi_dbm();
break;
+
/*Read status of the link*/
case PHY_EXTENSION_READ_LINK_STATUS:
// TODO: *data_ptr = rf_get_link_status();
+ *data_ptr = rf_device->get_last_lqi();
break;
+
default:
break;
}
return 0;
}
-#if 0 // TODO - if we really need this - WAS
static int8_t rf_address_write(phy_address_type_e address_type, uint8_t *address_ptr)
{
+#if 0 // TODO - if we really need this - WAS
switch (address_type)
{
/*Set 48-bit address*/
@@ -133,10 +153,10 @@
rf_set_pan_id(address_ptr);
break;
}
+#endif // 0
return 0;
}
-#endif // 0
/* Note: we are in IRQ context */
static void rf_handle_ack(uint8_t seq_number, uint8_t data_pending)
@@ -242,7 +262,7 @@
rf_device->attach_irq_callback(rf_callback_func);
}
-int8_t rf_device_register(void)
+extern "C" int8_t rf_device_register(void)
{
/* Do some initialization */
rf_init();
@@ -258,13 +278,15 @@
/*Maximum size of payload is 255*/
device_driver.phy_MTU = MAX_PACKET_LEN;
+
/*No header in PHY*/
device_driver.phy_header_length = 0;
+
/*No tail in PHY*/
device_driver.phy_tail_length = 0;
/*Set up driver functions*/
- device_driver.address_write = NULL; // betzw - TODO - if we really need this - WAS: &rf_address_write;
+ device_driver.address_write = &rf_address_write;
device_driver.extension = &rf_extension;
device_driver.state_control = &rf_interface_state_control;
device_driver.tx = &rf_start_cca;
@@ -283,3 +305,39 @@
return rf_radio_driver_id;
}
+
+/*
+ * \brief Function reads the MAC address array.
+ *
+ * \param ptr Pointer to read array
+ *
+ * \return none
+ */
+extern "C" void rf_read_mac_address(uint8_t *ptr)
+{
+ memcpy(ptr, mac_address, 8);
+}
+
+/*
+ * \brief Function returns the generated 8-bit random value for seeding Pseudo-random generator. This value was generated by reading noise from RF channel in RF initialisation.
+ *
+ * \param none
+ *
+ * \return random RSSI value
+ */
+extern "C" int8_t rf_read_random(void)
+{
+ return rf_rnd_rssi;
+}
+
+/*
+ * \brief Read connected radio part.
+ *
+ * This function only return valid information when rf_init() is called
+ *
+ * \return
+ */
+extern "C" rf_trx_part_e rf_radio_type_read(void)
+{
+ return ATMEL_UNKNOW_DEV;
+}
X-NUCLEO-IDS01A4 Sub-1GHz RF Expansion Board