diff --git a/Middlewares/Third_Party/LoRaWAN/Mac/LoRaMac.h b/Middlewares/Third_Party/LoRaWAN/Mac/LoRaMac.h
index 06d26bad..c5d0455b 100644
--- a/Middlewares/Third_Party/LoRaWAN/Mac/LoRaMac.h
+++ b/Middlewares/Third_Party/LoRaWAN/Mac/LoRaMac.h
@@ -172,6 +172,53 @@
*/
#define LORAMAC_CRYPTO_MULTICAST_KEYS 127
+/*!
+ * LoRaMAC region enumeration
+ */
+typedef enum eLoRaMacRegion_t
+{
+ /*!
+ * AS band on 923MHz
+ */
+ LORAMAC_REGION_AS923,
+ /*!
+ * Australian band on 915MHz
+ */
+ LORAMAC_REGION_AU915,
+ /*!
+ * Chinese band on 470MHz
+ */
+ LORAMAC_REGION_CN470,
+ /*!
+ * Chinese band on 779MHz
+ */
+ LORAMAC_REGION_CN779,
+ /*!
+ * European band on 433MHz
+ */
+ LORAMAC_REGION_EU433,
+ /*!
+ * European band on 868MHz
+ */
+ LORAMAC_REGION_EU868,
+ /*!
+ * South korean band on 920MHz
+ */
+ LORAMAC_REGION_KR920,
+ /*!
+ * India band on 865MHz
+ */
+ LORAMAC_REGION_IN865,
+ /*!
+ * North american band on 915MHz
+ */
+ LORAMAC_REGION_US915,
+ /*!
+ * Russia band on 864MHz
+ */
+ LORAMAC_REGION_RU864,
+}LoRaMacRegion_t;
+
/*!
* End-Device activation type
*/
@@ -915,6 +962,10 @@ typedef struct sMcpsIndication
* Set if a DeviceTimeAns MAC command was received.
*/
bool DeviceTimeAnsReceived;
+ /*!
+ * Set the region currently in use
+ */
+ LoRaMacRegion_t Region;
}McpsIndication_t;
/*!
@@ -2244,52 +2295,6 @@ typedef enum eLoRaMacStatus
LORAMAC_STATUS_ERROR
}LoRaMacStatus_t;
-/*!
- * LoRaMAC region enumeration
- */
-typedef enum eLoRaMacRegion_t
-{
- /*!
- * AS band on 923MHz
- */
- LORAMAC_REGION_AS923,
- /*!
- * Australian band on 915MHz
- */
- LORAMAC_REGION_AU915,
- /*!
- * Chinese band on 470MHz
- */
- LORAMAC_REGION_CN470,
- /*!
- * Chinese band on 779MHz
- */
- LORAMAC_REGION_CN779,
- /*!
- * European band on 433MHz
- */
- LORAMAC_REGION_EU433,
- /*!
- * European band on 868MHz
- */
- LORAMAC_REGION_EU868,
- /*!
- * South korean band on 920MHz
- */
- LORAMAC_REGION_KR920,
- /*!
- * India band on 865MHz
- */
- LORAMAC_REGION_IN865,
- /*!
- * North american band on 915MHz
- */
- LORAMAC_REGION_US915,
- /*!
- * Russia band on 864MHz
- */
- LORAMAC_REGION_RU864,
-}LoRaMacRegion_t;
/*!
* Enumeration of modules which have a context
diff --git a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/Core/inc/mlm32l0xx_hw_conf.h b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/Core/inc/mlm32l0xx_hw_conf.h
index f5d278a6..2f22a952 100644
--- a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/Core/inc/mlm32l0xx_hw_conf.h
+++ b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/Core/inc/mlm32l0xx_hw_conf.h
@@ -78,8 +78,8 @@ extern "C" {
#define RADIO_DIO_5_PORT GPIOA
#define RADIO_DIO_5_PIN GPIO_PIN_4
-#define RADIO_TCXO_VCC_PORT GPIOA
-#define RADIO_TCXO_VCC_PIN GPIO_PIN_12
+#define RADIO_TCXO_VCC_PORT GPIOB
+#define RADIO_TCXO_VCC_PIN GPIO_PIN_6
#define RADIO_ANT_SWITCH_PORT_RX GPIOA //CRF1
#define RADIO_ANT_SWITCH_PIN_RX GPIO_PIN_1
diff --git a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/inc/at.h b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/inc/at.h
index 40b15a98..c0bfc77d 100644
--- a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/inc/at.h
+++ b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/inc/at.h
@@ -55,6 +55,7 @@ typedef enum eATEerror
/* AT Command strings. Commands start with AT */
#define AT_RESET "Z"
+#define AT_BAND "+BAND"
#define AT_DEUI "+DEUI"
#define AT_DADDR "+DADDR"
#define AT_APPKEY "+APPKEY"
@@ -131,6 +132,20 @@ ATEerror_t at_return_error(const char *param);
*/
ATEerror_t at_reset(const char *param);
+/**
+ * @brief Print RF Band in use
+ * @param Param string of the AT command
+ * @retval AT_OK if OK, or an appropriate AT_xxx error code
+ */
+ATEerror_t at_Band_get(const char *param);
+
+/**
+ * @brief Set RF Band in use
+ * @param Param string of the AT command
+ * @retval AT_OK if OK, or an appropriate AT_xxx error code
+ */
+ATEerror_t at_Band_set(const char *param);
+
/**
* @brief Print Device EUI
* @param Param string of the AT command - unused
diff --git a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/inc/lora.h b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/inc/lora.h
index d1252483..61b3b091 100644
--- a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/inc/lora.h
+++ b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/inc/lora.h
@@ -222,7 +222,7 @@ typedef struct sLoRaMainCallback
* @param [IN] application parmaters
* @retval none
*/
-void LORA_Init(LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam);
+void LORA_Init(LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam, LoRaMacRegion_t region);
/**
* @brief run Lora classA state Machine
@@ -388,6 +388,13 @@ int8_t lora_config_tx_datarate_get(void);
*/
LoRaMacRegion_t lora_region_get(void);
+/**
+ * @brief triggers a reinit when band gets changed
+ * @param none
+ * @retval none
+ */
+void TriggerReinit( LoRaMacRegion_t region );
+
#ifdef __cplusplus
}
#endif
diff --git a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/at.c b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/at.c
index 0d49f139..9affd3a4 100644
--- a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/at.c
+++ b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/at.c
@@ -361,7 +361,13 @@ ATEerror_t at_JoinEUI_set(const char *param)
return AT_PARAM_ERROR;
}
+ MibRequestConfirm_t mib;
+ LoRaMacStatus_t status;
lora_config_joineui_set(JoinEui);
+ mib.Type = MIB_JOIN_EUI;
+ mib.Param.JoinEui = JoinEui;
+ status = LoRaMacMibSetRequestConfirm(&mib);
+ CHECK_STATUS(status);
return AT_OK;
}
@@ -410,6 +416,27 @@ ATEerror_t at_AppKey_set(const char *param)
return AT_OK;
}
+extern LoRaMacRegion_t globalRegion;
+ATEerror_t at_Band_get(const char *param)
+{
+ print_d(globalRegion);
+ return AT_OK;
+}
+
+ATEerror_t at_Band_set(const char *param)
+{
+ LoRaMacRegion_t region;
+ if (tiny_sscanf(param, "%hhu", ®ion) != 1)
+ {
+ return AT_PARAM_ERROR;
+ }
+ if (region != globalRegion) {
+ globalRegion = region;
+ TriggerReinit(globalRegion);
+ }
+ return AT_OK;
+}
+
ATEerror_t at_NwkSKey_get(const char *param)
{
MibRequestConfirm_t mib;
diff --git a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/command.c b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/command.c
index 365fd65e..c3e3b438 100644
--- a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/command.c
+++ b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/command.c
@@ -109,6 +109,19 @@ static const struct ATCommand_s ATCommand[] =
},
#endif
+#ifndef NO_BAND_RUNTIME_SWITCH
+ {
+ .string = AT_BAND,
+ .size_string = sizeof(AT_BAND) - 1,
+#ifndef NO_HELP
+ .help_string = "AT"AT_BAND ": Get or Set the Regional Band\r\n",
+#endif
+ .get = at_Band_get,
+ .set = at_Band_set,
+ .run = at_return_error,
+ },
+#endif
+
#ifndef NO_KEY_ADDR_EUI
{
.string = AT_APPKEY,
diff --git a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/lora.c b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/lora.c
index c8784465..9a2fadbc 100644
--- a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/lora.c
+++ b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/lora.c
@@ -53,11 +53,7 @@ typedef struct
static lora_configuration_t lora_config =
{
.otaa = LORA_ENABLE,
-#if defined( REGION_EU868 )
- .duty_cycle = LORA_ENABLE,
-#else
.duty_cycle = LORA_DISABLE,
-#endif
.DevEui = LORAWAN_DEVICE_EUI,
.JoinEui = LORAWAN_JOIN_EUI,
.AppKey = LORAWAN_APP_KEY,
@@ -87,7 +83,6 @@ static lora_configuration_t lora_config =
#include "LoRaMacTest.h"
-#if defined( REGION_EU868 ) || defined( REGION_RU864 ) || defined( REGION_CN779 ) || defined( REGION_EU433 )
/*!
* LoRaWAN ETSI duty cycle control enable/disable
*
@@ -95,7 +90,6 @@ static lora_configuration_t lora_config =
*/
#define LORAWAN_DUTYCYCLE_ON true
-#endif
#ifdef LORAMAC_CLASSB_ENABLED
/*!
@@ -331,11 +325,11 @@ static void MlmeConfirm(MlmeConfirm_t *mlmeConfirm)
mibReq.Param.Class = CLASS_B;
LoRaMacMibSetRequestConfirm(&mibReq);
-#if defined( REGION_AU915 ) || defined( REGION_US915 )
- mibReq.Type = MIB_PING_SLOT_DATARATE;
- mibReq.Param.PingSlotDatarate = DR_8;
- LoRaMacMibSetRequestConfirm(&mibReq);
-#endif
+ if ((LoRaRegion == LORAMAC_REGION_AU915) || (LoRaRegion == LORAMAC_REGION_US915)) {
+ mibReq.Type = MIB_PING_SLOT_DATARATE;
+ mibReq.Param.PingSlotDatarate = DR_8;
+ LoRaMacMibSetRequestConfirm(&mibReq);
+ }
/*notify upper layer*/
LoRaMainCallbacks->LORA_ConfirmClass(CLASS_B);
@@ -413,7 +407,7 @@ static void MlmeIndication(MlmeIndication_t *MlmeIndication)
/**
* lora Init
*/
-void LORA_Init(LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam)
+void LORA_Init(LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam, LoRaMacRegion_t region)
{
/* init the Tx Duty Cycle*/
LoRaParamInit = LoRaParam;
@@ -439,59 +433,28 @@ void LORA_Init(LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam)
LoRaMacCallbacks.GetBatteryLevel = LoRaMainCallbacks->BoardGetBatteryLevel;
LoRaMacCallbacks.GetTemperatureLevel = LoRaMainCallbacks->BoardGetTemperatureLevel;
LoRaMacCallbacks.MacProcessNotify = LoRaMainCallbacks->MacProcessNotify;
-#if defined( REGION_AS923 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_AS923);
- LoRaRegion = LORAMAC_REGION_AS923;
-#elif defined( REGION_AU915 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_AU915);
- LoRaRegion = LORAMAC_REGION_AU915;
-#elif defined( REGION_CN470 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_CN470);
- LoRaRegion = LORAMAC_REGION_CN470;
-#elif defined( REGION_CN779 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_CN779);
- LoRaRegion = LORAMAC_REGION_CN779;
-#elif defined( REGION_EU433 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_EU433);
- LoRaRegion = LORAMAC_REGION_EU433;
-#elif defined( REGION_IN865 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_IN865);
- LoRaRegion = LORAMAC_REGION_IN865;
-#elif defined( REGION_EU868 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_EU868);
- LoRaRegion = LORAMAC_REGION_EU868;
-#elif defined( REGION_KR920 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_KR920);
- LoRaRegion = LORAMAC_REGION_KR920;
-#elif defined( REGION_US915 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_US915);
- LoRaRegion = LORAMAC_REGION_US915;
-#elif defined( REGION_RU864 )
- LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, LORAMAC_REGION_RU864);
- LoRaRegion = LORAMAC_REGION_RU864;
-#else
-#error "Please define a region in the compiler options."
-#endif
+ LoRaMacInitialization(&LoRaMacPrimitives, &LoRaMacCallbacks, region);
+ LoRaRegion = region;
#if defined( HYBRID )
-#if defined( REGION_US915 ) || defined( REGION_AU915 )
- uint16_t channelMask[] = { 0x00FF, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000};
- mibReq.Type = MIB_CHANNELS_MASK;
- mibReq.Param.ChannelsMask = channelMask;
- LoRaMacMibSetRequestConfirm(&mibReq);
- mibReq.Type = MIB_CHANNELS_DEFAULT_MASK;
- mibReq.Param.ChannelsDefaultMask = channelMask;
- LoRaMacMibSetRequestConfirm(&mibReq);
-#endif
-#if defined( REGION_CN470 )
- uint16_t channelMask[] = { 0x00FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
- mibReq.Type = MIB_CHANNELS_MASK;
- mibReq.Param.ChannelsMask = channelMask;
- LoRaMacMibSetRequestConfirm(&mibReq);
- mibReq.Type = MIB_CHANNELS_DEFAULT_MASK;
- mibReq.Param.ChannelsDefaultMask = channelMask;
- LoRaMacMibSetRequestConfirm(&mibReq);
-#endif
+ if ((LoRaRegion == LORAMAC_REGION_US915) || (LoRaRegion == LORAMAC_REGION_AU915)) {
+ uint16_t channelMask[] = { 0x00FF, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000};
+ mibReq.Type = MIB_CHANNELS_MASK;
+ mibReq.Param.ChannelsMask = channelMask;
+ LoRaMacMibSetRequestConfirm(&mibReq);
+ mibReq.Type = MIB_CHANNELS_DEFAULT_MASK;
+ mibReq.Param.ChannelsDefaultMask = channelMask;
+ LoRaMacMibSetRequestConfirm(&mibReq);
+ }
+ if (LoRaRegion == LORAMAC_REGION_CN470) {
+ uint16_t channelMask[] = { 0x00FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
+ mibReq.Type = MIB_CHANNELS_MASK;
+ mibReq.Param.ChannelsMask = channelMask;
+ LoRaMacMibSetRequestConfirm(&mibReq);
+ mibReq.Type = MIB_CHANNELS_DEFAULT_MASK;
+ mibReq.Param.ChannelsDefaultMask = channelMask;
+ LoRaMacMibSetRequestConfirm(&mibReq);
+ }
#endif
lora_config_otaa_set(LORA_ENABLE);
@@ -524,13 +487,14 @@ void LORA_Init(LoRaMainCallback_t *callbacks, LoRaParam_t *LoRaParam)
mibReq.Param.Class = CLASS_A;
LoRaMacMibSetRequestConfirm(&mibReq);
-#if defined( REGION_EU868 ) || defined( REGION_RU864 ) || defined( REGION_CN779 ) || defined( REGION_EU433 )
- LoRaMacTestSetDutyCycleOn(LORAWAN_DUTYCYCLE_ON);
+ if ((LoRaRegion == LORAMAC_REGION_EU868) || (LoRaRegion == LORAMAC_REGION_RU864) || (LoRaRegion == LORAMAC_REGION_CN779) || (LoRaRegion == LORAMAC_REGION_EU433)) {
+ LoRaMacTestSetDutyCycleOn(LORAWAN_DUTYCYCLE_ON);
- lora_config.duty_cycle = LORA_ENABLE;
-#else
- lora_config.duty_cycle = LORA_DISABLE;
-#endif
+ lora_config.duty_cycle = LORA_ENABLE;
+ }
+ else {
+ lora_config.duty_cycle = LORA_DISABLE;
+ }
mibReq.Type = MIB_SYSTEM_MAX_RX_ERROR;
mibReq.Param.SystemMaxRxError = 20;
@@ -970,6 +934,10 @@ void lora_wan_certif(void)
}
+void TriggerReinit( LoRaMacRegion_t region ) {
+ LORA_Init(LoRaMainCallbacks, LoRaParamInit, region);
+}
+
LoRaMacRegion_t lora_region_get(void)
{
return LoRaRegion;
diff --git a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/main.c b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/main.c
index b51ea1cc..c4c13cf5 100644
--- a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/main.c
+++ b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/LoRaWAN/App/src/main.c
@@ -102,7 +102,7 @@ static LoRaParam_t LoRaParamInit = {LORAWAN_ADR_ON,
LORAWAN_PUBLIC_NETWORK
};
-
+LoRaMacRegion_t globalRegion = LORAMAC_REGION_EU868;
/* Private functions ---------------------------------------------------------*/
@@ -134,7 +134,7 @@ int main(void)
/* USER CODE END 1 */
/* Configure the Lora Stack*/
- LORA_Init(&LoRaMainCallbacks, &LoRaParamInit);
+ LORA_Init(&LoRaMainCallbacks, &LoRaParamInit, globalRegion);
/* main loop*/
while (1)
diff --git a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/SW4STM32/mlm32l07x01/.cproject b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/SW4STM32/mlm32l07x01/.cproject
index 458316b2..270bcc13 100644
--- a/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/SW4STM32/mlm32l07x01/.cproject
+++ b/Projects/B-L072Z-LRWAN1/Applications/LoRa/AT_Slave/SW4STM32/mlm32l07x01/.cproject
@@ -58,6 +58,15 @@
+
+
+
+
+
+
+
+
+