diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/Common/cellular_setup.c b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/Common/cellular_setup.c index ffbd3478f..12fae0a14 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/Common/cellular_setup.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/Common/cellular_setup.c @@ -61,6 +61,8 @@ #define CELLULAR_PDN_CONNECT_WAIT_INTERVAL_MS ( 1000UL ) +#define CELLULAR_PDN_CONTEXT_NUM ( CELLULAR_PDN_CONTEXT_ID_MAX - CELLULAR_PDN_CONTEXT_ID_MIN + 1U ) + /*-----------------------------------------------------------*/ /* the default Cellular comm interface in system. */ @@ -86,17 +88,23 @@ bool setupCellular( void ) CellularCommInterface_t * pCommIntf = &CellularCommInterface; uint8_t tries = 0; CellularPdnConfig_t pdnConfig = { CELLULAR_PDN_CONTEXT_IPV4, CELLULAR_PDN_AUTH_NONE, CELLULAR_APN, "", "" }; - CellularPdnStatus_t PdnStatusBuffers = { 0 }; + CellularPdnStatus_t PdnStatusBuffers[ CELLULAR_PDN_CONTEXT_NUM ] = { 0 }; char localIP[ CELLULAR_IP_ADDRESS_MAX_SIZE ] = { '\0' }; uint32_t timeoutCountLimit = ( CELLULAR_PDN_CONNECT_TIMEOUT / CELLULAR_PDN_CONNECT_WAIT_INTERVAL_MS ) + 1U; uint32_t timeoutCount = 0; - uint8_t NumStatus = 1; + uint8_t NumStatus = 0; CellularPsmSettings_t psmSettings = { 0 }; + bool pdnStatus = false; + uint32_t i = 0U; /* Initialize Cellular Comm Interface. */ cellularStatus = Cellular_Init( &CellularHandle, pCommIntf ); - if( cellularStatus == CELLULAR_SUCCESS ) + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular_Init failure %d <<<\r\n", cellularStatus ) ); + } + else { /* wait until SIM is ready */ for( tries = 0; tries < CELLULAR_MAX_SIM_RETRY; tries++ ) @@ -107,19 +115,7 @@ bool setupCellular( void ) ( ( simStatus.simCardState == CELLULAR_SIM_CARD_INSERTED ) && ( simStatus.simCardLockState == CELLULAR_SIM_CARD_READY ) ) ) { - /* Turn of PSM because this is demo to showcase MQTT instead of PSM mode. */ - psmSettings.mode = 0; - cellularStatus = cellularStatus = Cellular_SetPsmSettings( CellularHandle, &psmSettings ); - - if( cellularStatus != CELLULAR_SUCCESS ) - { - configPRINTF( ( ">>> Cellular_SetPsmSettings failure <<<\r\n" ) ); - } - else - { - configPRINTF( ( ">>> Cellular SIM okay <<<\r\n" ) ); - } - + configPRINTF( ( ">>> Cellular SIM okay <<<\r\n" ) ); break; } else @@ -131,27 +127,55 @@ bool setupCellular( void ) vTaskDelay( pdMS_TO_TICKS( CELLULAR_SIM_CARD_WAIT_INTERVAL_MS ) ); } + + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular SIM failure <<<\r\n" ) ); + } + } + + /* Turn off PSM because this is demo to showcase MQTT instead of PSM mode. */ + if( cellularStatus != CELLULAR_SUCCESS ) + { + psmSettings.mode = 0; + cellularStatus = cellularStatus = Cellular_SetPsmSettings( CellularHandle, &psmSettings ); + + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular_SetPsmSettings failure <<<\r\n" ) ); + } } /* Setup the PDN config. */ if( cellularStatus == CELLULAR_SUCCESS ) { cellularStatus = Cellular_SetPdnConfig( CellularHandle, CellularSocketPdnContextId, &pdnConfig ); - } - else - { - configPRINTF( ( ">>> Cellular SIM failure <<<\r\n" ) ); + + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular_SetPdnConfig failure %d <<<\r\n", cellularStatus ) ); + } } /* Rescan network. */ if( cellularStatus == CELLULAR_SUCCESS ) { cellularStatus = Cellular_RfOff( CellularHandle ); + + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular_RfOff failure %d <<<\r\n", cellularStatus ) ); + } } if( cellularStatus == CELLULAR_SUCCESS ) { cellularStatus = Cellular_RfOn( CellularHandle ); + + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular_RfOn failure %d <<<\r\n", cellularStatus ) ); + } } /* Get service status. */ @@ -178,8 +202,10 @@ bool setupCellular( void ) if( timeoutCount >= timeoutCountLimit ) { - cellularStatus = CELLULAR_INVALID_HANDLE; - configPRINTF( ( ">>> Cellular module can't be registered <<<\r\n" ) ); + /* Return timeout to indicate network is not registered within + * CELLULAR_PDN_CONNECT_TIMEOUT. */ + cellularStatus = CELLULAR_TIMEOUT; + configPRINTF( ( ">>> Cellular module can't be registered within CELLULAR_PDN_CONNECT_TIMEOUT <<<\r\n" ) ); } vTaskDelay( pdMS_TO_TICKS( CELLULAR_PDN_CONNECT_WAIT_INTERVAL_MS ) ); @@ -189,19 +215,51 @@ bool setupCellular( void ) if( cellularStatus == CELLULAR_SUCCESS ) { cellularStatus = Cellular_ActivatePdn( CellularHandle, CellularSocketPdnContextId ); + + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular_ActivatePdn failure %d <<<\r\n", cellularStatus ) ); + } } if( cellularStatus == CELLULAR_SUCCESS ) { cellularStatus = Cellular_GetIPAddress( CellularHandle, CellularSocketPdnContextId, localIP, sizeof( localIP ) ); + + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular_GetIPAddress failure %d <<<\r\n", cellularStatus ) ); + } } if( cellularStatus == CELLULAR_SUCCESS ) { - cellularStatus = Cellular_GetPdnStatus( CellularHandle, &PdnStatusBuffers, CellularSocketPdnContextId, &NumStatus ); + cellularStatus = Cellular_GetPdnStatus( CellularHandle, PdnStatusBuffers, CELLULAR_PDN_CONTEXT_NUM, &NumStatus ); + + if( cellularStatus != CELLULAR_SUCCESS ) + { + configPRINTF( ( ">>> Cellular_GetPdnStatus failure %d <<<\r\n", cellularStatus ) ); + } } - if( ( cellularStatus == CELLULAR_SUCCESS ) && ( PdnStatusBuffers.state == 1 ) ) + if( cellularStatus == CELLULAR_SUCCESS ) + { + for( i = 0U; i < NumStatus; i++ ) + { + if( ( PdnStatusBuffers[ i ].contextId == CellularSocketPdnContextId ) && ( PdnStatusBuffers[ i ].state == 1 ) ) + { + pdnStatus = true; + break; + } + } + + if( pdnStatus == false ) + { + configPRINTF( ( ">>> Cellular PDN is not activated <<<\r\n" ) ); + } + } + + if( ( cellularStatus == CELLULAR_SUCCESS ) && ( pdnStatus == true ) ) { configPRINTF( ( ">>> Cellular module registered, IP address %s <<<\r\n", localIP ) ); cellularRet = true; diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/DemoTasks/MutualAuthMQTTExample.c b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/DemoTasks/MutualAuthMQTTExample.c index d97098c82..6915a1325 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/DemoTasks/MutualAuthMQTTExample.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/DemoTasks/MutualAuthMQTTExample.c @@ -210,7 +210,7 @@ /** * @brief Transport timeout in milliseconds for transport send and receive. */ -#define mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 10000U ) +#define mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 5000U ) /** * @brief ALPN (Application-Layer Protocol Negotiation) protocol name for AWS IoT MQTT. diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/cellular_config.h b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/cellular_config.h index a055cfb69..96cf2ff61 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/cellular_config.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/cellular_config.h @@ -105,4 +105,10 @@ extern void vLoggingPrintf( const char * pcFormatString, */ #define CELLULAR_IP_ADDRESS_MAX_SIZE ( 64U ) +/* + * BG96 supports different URC port. Define this macro if "usbat" port is URC output port. + * Otherwise, "uart1" will be configured to URC output port. + */ +#define CELLULAR_BG96_URC_PORT_USBAT + #endif /* __CELLULAR_CONFIG_H__ */ diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_HL7802/DemoTasks/MutualAuthMQTTExample.c b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_HL7802/DemoTasks/MutualAuthMQTTExample.c index d97098c82..6915a1325 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_HL7802/DemoTasks/MutualAuthMQTTExample.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_HL7802/DemoTasks/MutualAuthMQTTExample.c @@ -210,7 +210,7 @@ /** * @brief Transport timeout in milliseconds for transport send and receive. */ -#define mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 10000U ) +#define mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 5000U ) /** * @brief ALPN (Application-Layer Protocol Negotiation) protocol name for AWS IoT MQTT. diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_SARA_R4/DemoTasks/MutualAuthMQTTExample.c b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_SARA_R4/DemoTasks/MutualAuthMQTTExample.c index d97098c82..6915a1325 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_SARA_R4/DemoTasks/MutualAuthMQTTExample.c +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_SARA_R4/DemoTasks/MutualAuthMQTTExample.c @@ -210,7 +210,7 @@ /** * @brief Transport timeout in milliseconds for transport send and receive. */ -#define mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 10000U ) +#define mqttexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 5000U ) /** * @brief ALPN (Application-Layer Protocol Negotiation) protocol name for AWS IoT MQTT. diff --git a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_SARA_R4/cellular_config.h b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_SARA_R4/cellular_config.h index 136fbab07..73015a8c8 100644 --- a/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_SARA_R4/cellular_config.h +++ b/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_SARA_R4/cellular_config.h @@ -149,4 +149,9 @@ extern void vLoggingPrintf( const char * pcFormatString, * #define CELLULAR_CONFIG_SARA_R4_SET_MNO_PROFILE ( ...insert here... ) */ +/* + * Reboot Sara R4 cellular modem in module init function. + */ +#define CELLULAR_CONFIG_SARA_R4_REBOOT_ON_INIT + #endif /* __CELLULAR_CONFIG_H__ */ diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Cellular-Interface b/FreeRTOS-Plus/Source/FreeRTOS-Cellular-Interface index 0289b787b..2bd3f79b4 160000 --- a/FreeRTOS-Plus/Source/FreeRTOS-Cellular-Interface +++ b/FreeRTOS-Plus/Source/FreeRTOS-Cellular-Interface @@ -1 +1 @@ -Subproject commit 0289b787b745d0c675fb12ef002574d98d4b402e +Subproject commit 2bd3f79b4e5070a3e3ec500980e86b5013fdcc62 diff --git a/lexicon.txt b/lexicon.txt index aba98cc8e..3b39577c1 100644 --- a/lexicon.txt +++ b/lexicon.txt @@ -2848,6 +2848,7 @@ usagefault usart usarts usb +usbat usbbus usbconfiguration usbdevice diff --git a/manifest.yml b/manifest.yml index b075918cf..6347302fe 100644 --- a/manifest.yml +++ b/manifest.yml @@ -130,7 +130,7 @@ dependencies: path: "FreeRTOS/Demo/ThirdParty/Partner-Supported-Demos" - name: "FreeRTOS-Cellular-Interface" - version: "v1.2.0" + version: "2bd3f79" repository: type: "git" url: "https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface.git"