diff --git a/Projects/Multi/Applications/LoRa/AT_Slave/SW4STM32/B-L072Z-LRWAN1/mlm32l07x01/.settings/language.settings.xml b/Projects/Multi/Applications/LoRa/AT_Slave/SW4STM32/B-L072Z-LRWAN1/mlm32l07x01/.settings/language.settings.xml index 5b9efcdc..af1b4fa0 100644 --- a/Projects/Multi/Applications/LoRa/AT_Slave/SW4STM32/B-L072Z-LRWAN1/mlm32l07x01/.settings/language.settings.xml +++ b/Projects/Multi/Applications/LoRa/AT_Slave/SW4STM32/B-L072Z-LRWAN1/mlm32l07x01/.settings/language.settings.xml @@ -6,7 +6,7 @@ - + diff --git a/Projects/Multi/Applications/LoRa/AT_Slave/SW4STM32/B-L072Z-LRWAN1/mlm32l07x01/mlm32l07x01 Run.cfg b/Projects/Multi/Applications/LoRa/AT_Slave/SW4STM32/B-L072Z-LRWAN1/mlm32l07x01/mlm32l07x01 Run.cfg index e69de29b..50c01c0b 100644 --- a/Projects/Multi/Applications/LoRa/AT_Slave/SW4STM32/B-L072Z-LRWAN1/mlm32l07x01/mlm32l07x01 Run.cfg +++ b/Projects/Multi/Applications/LoRa/AT_Slave/SW4STM32/B-L072Z-LRWAN1/mlm32l07x01/mlm32l07x01 Run.cfg @@ -0,0 +1,28 @@ +# This is an B-L072Z-LRWAN1 board with a single STM32L072CZYx chip +# +# Generated by System Workbench for STM32 +# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s) + +source [find interface/stlink.cfg] + +set WORKAREASIZE 0x5000 + +transport select "hla_swd" + +set CHIPNAME STM32L072CZYx + +# Enable debug when in low power modes +set ENABLE_LOW_POWER 1 + +# Stop Watchdog counters when halt +set STOP_WATCHDOG 1 + +# STlink Debug clock frequency +set CLOCK_FREQ 4000 + +# use hardware reset, connect under reset +# connect_assert_srst needed if low power mode application running (WFI...) +reset_config srst_only srst_nogate connect_assert_srst +set CONNECT_UNDER_RESET 1 + +source [find target/stm32l0x.cfg] diff --git a/Projects/Multi/Applications/LoRa/AT_Slave/inc/at.h b/Projects/Multi/Applications/LoRa/AT_Slave/inc/at.h index 45b911b9..40fbeba5 100644 --- a/Projects/Multi/Applications/LoRa/AT_Slave/inc/at.h +++ b/Projects/Multi/Applications/LoRa/AT_Slave/inc/at.h @@ -100,7 +100,7 @@ typedef enum eATEerror #define AT_JN1DL "+JN1DL" #define AT_JN2DL "+JN2DL" #define AT_NJM "+MODE" -#define AT_NWKID "+NWKID" +#define AT_NWKID "+IDNWK" #define AT_FCU "+FCU" #define AT_FCD "+FCD" #define AT_CLASS "+CLASS" diff --git a/Projects/Multi/Applications/LoRa/AT_Slave/inc/lora.h b/Projects/Multi/Applications/LoRa/AT_Slave/inc/lora.h index 151fb995..fc30cd70 100644 --- a/Projects/Multi/Applications/LoRa/AT_Slave/inc/lora.h +++ b/Projects/Multi/Applications/LoRa/AT_Slave/inc/lora.h @@ -86,6 +86,8 @@ Maintainer: Miguel Luis, Gregory Cristian and Wael Guibene uint8_t DevEui[8]; /*< Device EUI */ uint8_t AppEui[8]; /*< Application EUI */ uint8_t AppKey[16]; /*< Application Key */ + uint32_t NetworkID; /*< Network ID */ + uint32_t DevAddr; /*< Device Address */ uint8_t NwkSKey[16]; /*< Network Session Key */ uint8_t AppSKey[16]; /*< Application Session Key */ int16_t Rssi; /*< Rssi of the received packet */ diff --git a/Projects/Multi/Applications/LoRa/AT_Slave/inc/version.h b/Projects/Multi/Applications/LoRa/AT_Slave/inc/version.h index d594c09a..bdfa2e7a 100644 --- a/Projects/Multi/Applications/LoRa/AT_Slave/inc/version.h +++ b/Projects/Multi/Applications/LoRa/AT_Slave/inc/version.h @@ -72,7 +72,7 @@ extern "C" { #define TEST_VERSION (uint32_t) 0x00000000 /*1 lsb is always 0 in releases */ #define LRWAN_VERSION (uint32_t) 0x00001120 /*3 next hex is i_cube release*/ #define VERSION (uint32_t) (LORA_MAC_VERSION | LRWAN_VERSION | TEST_VERSION) -#define AT_VERSION_STRING "1.1.2" +#define AT_VERSION_STRING "1.1.3" #define AT_DEVICE_STRING "ARD-078" /* Exported types ------------------------------------------------------------*/ diff --git a/Projects/Multi/Applications/LoRa/AT_Slave/src/at.c b/Projects/Multi/Applications/LoRa/AT_Slave/src/at.c index abab3302..dd7da7cd 100644 --- a/Projects/Multi/Applications/LoRa/AT_Slave/src/at.c +++ b/Projects/Multi/Applications/LoRa/AT_Slave/src/at.c @@ -210,29 +210,34 @@ ATEerror_t at_AppEUI_set(const char *param) ATEerror_t at_DevAddr_set(const char *param) { - MibRequestConfirm_t mib; - LoRaMacStatus_t status; + uint32_t DevAddr; + sscanf_uint32_as_hhx(param, &DevAddr); - mib.Type = MIB_DEV_ADDR; - if (sscanf_uint32_as_hhx(param, &mib.Param.DevAddr) != 4) - { - return AT_PARAM_ERROR; - } - status = LoRaMacMibSetRequestConfirm(&mib); - CHECK_STATUS(status); - return AT_OK; + lora_config_devaddr_set(DevAddr); + return AT_OK; } ATEerror_t at_DevAddr_get(const char *param) { - MibRequestConfirm_t mib; - LoRaMacStatus_t status; - mib.Type = MIB_DEV_ADDR; - status = LoRaMacMibGetRequestConfirm(&mib); - CHECK_STATUS(status); AT_PRINTF("+OK="); - print_uint32_as_02x(mib.Param.DevAddr); + print_uint32_as_02x(lora_config_devaddr_get()); + return AT_OK; +} + +ATEerror_t at_NetworkID_get(const char *param) +{ + AT_PRINTF("+OK="); + print_uint32_as_02x(lora_config_networkid_get()); + return AT_OK; +} + +ATEerror_t at_NetworkID_set(const char *param) +{ + uint32_t NetworkID; + sscanf_uint32_as_hhx(param, &NetworkID); + + lora_config_networkid_set(NetworkID); return AT_OK; } @@ -280,67 +285,41 @@ ATEerror_t at_Band_set(const char *param) ATEerror_t at_NwkSKey_get(const char *param) { - MibRequestConfirm_t mib; - LoRaMacStatus_t status; - - mib.Type = MIB_NWK_SKEY; - status = LoRaMacMibGetRequestConfirm(&mib); - CHECK_STATUS(status); AT_PRINTF("+OK="); - print_16_02x(mib.Param.NwkSKey); - + print_16_02x(lora_config_nwkskey_get()); return AT_OK; } ATEerror_t at_NwkSKey_set(const char *param) { - MibRequestConfirm_t mib; - LoRaMacStatus_t status; - uint8_t NwkSKey[16]; - - mib.Type = MIB_NWK_SKEY; - - if (sscanf_16_hhx(param, NwkSKey) != 16) + uint8_t NwkSkey[16]; + int ret = sscanf_16_hhx(param, NwkSkey); + if (ret != 16) { return AT_PARAM_ERROR; } - mib.Param.NwkSKey = NwkSKey; - status = LoRaMacMibSetRequestConfirm(&mib); - CHECK_STATUS(status); - + lora_config_nwkskey_set(NwkSkey); return AT_OK; } ATEerror_t at_AppSKey_get(const char *param) { - MibRequestConfirm_t mib; - LoRaMacStatus_t status; - - mib.Type = MIB_APP_SKEY; - status = LoRaMacMibGetRequestConfirm(&mib); - CHECK_STATUS(status); AT_PRINTF("+OK="); - print_16_02x(mib.Param.AppSKey); - + print_16_02x(lora_config_appskey_get()); return AT_OK; } ATEerror_t at_AppSKey_set(const char *param) { - MibRequestConfirm_t mib; - LoRaMacStatus_t status; uint8_t AppSKey[16]; - - mib.Type = MIB_APP_SKEY; - if (sscanf_16_hhx(param, AppSKey) != 16) + int ret = sscanf_16_hhx(param, AppSKey); + if (ret != 16) { return AT_PARAM_ERROR; } - mib.Param.AppSKey = AppSKey; - status = LoRaMacMibSetRequestConfirm(&mib); - CHECK_STATUS(status); + lora_config_appskey_set(AppSKey); return AT_OK; } @@ -720,36 +699,6 @@ ATEerror_t at_NetworkJoinMode_set(const char *param) return AT_OK; } -ATEerror_t at_NetworkID_get(const char *param) -{ - MibRequestConfirm_t mib; - LoRaMacStatus_t status; - - mib.Type = MIB_NET_ID; - status = LoRaMacMibGetRequestConfirm(&mib); - CHECK_STATUS(status); - AT_PRINTF("+OK="); - print_uint32_as_02x(mib.Param.NetID); - - return AT_OK; -} - -ATEerror_t at_NetworkID_set(const char *param) -{ - MibRequestConfirm_t mib; - LoRaMacStatus_t status; - - mib.Type = MIB_NET_ID; - if (sscanf_uint32_as_hhx(param, &mib.Param.NetID) != 4) - { - return AT_PARAM_ERROR; - } - status = LoRaMacMibSetRequestConfirm(&mib); - CHECK_STATUS(status); - - return AT_OK; -} - ATEerror_t at_UplinkCounter_get(const char *param) { MibRequestConfirm_t mib; @@ -1138,19 +1087,19 @@ static void print_16_02x(uint8_t *pt) static int sscanf_uint32_as_hhx(const char *from, uint32_t *value) { return tiny_sscanf(from, "%02hhx%02hhx%02hhx%02hhx", - &((unsigned char *)(value))[0], - &((unsigned char *)(value))[1], + &((unsigned char *)(value))[3], &((unsigned char *)(value))[2], - &((unsigned char *)(value))[3]); + &((unsigned char *)(value))[1], + &((unsigned char *)(value))[0]); } static void print_uint32_as_02x(uint32_t value) { AT_PRINTF("%02x%02x%02x%02x\r", - (unsigned)((unsigned char *)(&value))[0], - (unsigned)((unsigned char *)(&value))[1], + (unsigned)((unsigned char *)(&value))[3], (unsigned)((unsigned char *)(&value))[2], - (unsigned)((unsigned char *)(&value))[3]); + (unsigned)((unsigned char *)(&value))[1], + (unsigned)((unsigned char *)(&value))[0]); } static void print_8_02x(uint8_t *pt) diff --git a/Projects/Multi/Applications/LoRa/AT_Slave/src/command.c b/Projects/Multi/Applications/LoRa/AT_Slave/src/command.c index 68c449b6..d883d2e7 100644 --- a/Projects/Multi/Applications/LoRa/AT_Slave/src/command.c +++ b/Projects/Multi/Applications/LoRa/AT_Slave/src/command.c @@ -331,7 +331,6 @@ static const struct ATCommand_s ATCommand[] = .run = at_return_error, }, -#ifndef NO_KEY_ADDR_EUI { .string = AT_NWKID, .size_string = sizeof(AT_NWKID) - 1, @@ -342,7 +341,6 @@ static const struct ATCommand_s ATCommand[] = .set = at_NetworkID_set, .run = at_return_error, }, -#endif { .string = AT_FCU, diff --git a/Projects/Multi/Applications/LoRa/AT_Slave/src/lora.c b/Projects/Multi/Applications/LoRa/AT_Slave/src/lora.c index a0ec619e..21fe8dfe 100644 --- a/Projects/Multi/Applications/LoRa/AT_Slave/src/lora.c +++ b/Projects/Multi/Applications/LoRa/AT_Slave/src/lora.c @@ -72,6 +72,8 @@ static lora_configuration_t lora_config = .DevEui = LORAWAN_DEVICE_EUI, .AppEui = LORAWAN_APPLICATION_EUI, .AppKey = LORAWAN_APPLICATION_KEY, + .NetworkID = LORAWAN_NETWORK_ID, + .DevAddr = LORAWAN_DEVICE_ADDRESS, .NwkSKey = LORAWAN_NWKSKEY, .AppSKey = LORAWAN_APPSKEY, .Rssi = 0, @@ -851,11 +853,11 @@ void lora_fsm( LoRaMacRegion_t region ) else { mibReq.Type = MIB_NET_ID; - mibReq.Param.NetID = LORAWAN_NETWORK_ID; + mibReq.Param.NetID = lora_config.NetworkID; LoRaMacMibSetRequestConfirm( &mibReq ); mibReq.Type = MIB_DEV_ADDR; - mibReq.Param.DevAddr = DevAddr; + mibReq.Param.DevAddr = lora_config.DevAddr; LoRaMacMibSetRequestConfirm( &mibReq ); mibReq.Type = MIB_NWK_SKEY; @@ -871,7 +873,7 @@ void lora_fsm( LoRaMacRegion_t region ) LoRaMacMibSetRequestConfirm( &mibReq ); } - DeviceState = DEVICE_STATE_SLEEP; + DeviceState = DEVICE_STATE_JOINED; break; } case DEVICE_STATE_JOINED: @@ -961,6 +963,46 @@ void lora_config_appeui_set(uint8_t appeui[8]) memcpy1(lora_config.AppEui, appeui, sizeof(lora_config.AppEui)); } +uint32_t lora_config_devaddr_get(void) +{ + return lora_config.DevAddr; +} + +void lora_config_devaddr_set(uint32_t devaddr) +{ + lora_config.DevAddr= devaddr; +} + +void lora_config_networkid_set(uint32_t networkid) +{ + lora_config.NetworkID = networkid; +} + +uint32_t lora_config_networkid_get(void) +{ + return lora_config.NetworkID; +} + +uint8_t *lora_config_nwkskey_get(void) +{ + return lora_config.NwkSKey; +} + +void lora_config_nwkskey_set(uint8_t nwkSKey[16]) +{ + memcpy1(lora_config.NwkSKey, nwkSKey, sizeof(lora_config.NwkSKey)); +} + +uint8_t *lora_config_appskey_get(void) +{ + return lora_config.AppSKey; +} + +void lora_config_appskey_set(uint8_t appskey[16]) +{ + memcpy1(lora_config.AppSKey, appskey, sizeof(lora_config.AppSKey)); +} + uint8_t *lora_config_appkey_get(void) { return lora_config.AppKey;