This lab is quite similar to the previous lab. However we will use the IoT Discovery Kit node which is having the onboard secure element. i.e. to remove the constraint mentioned in the previous lab.
This require to use the native tooling from ST. i.e. STM32Cube IDE for the FreeRTOS Cellular HAL Source Code Compilation. Also this lab, shows how to collect the onboard sensor data from the STM32 discovery kit and send to AWS IoT core.
The secure element has a secure bootloader & SBSFU and requires some additional post-processing during the firmware source code compilation. Currently the firmware compilation which has the secure element specific post-processing steps are integrated with the STM32Cube IDE.X-CUBE-AWS-2.0 is pre-integrated with the FreeRTOS Kernel version 202002 and has the middleware for ST-SAFE secure element i.e. security co-processor. However FreeRTOS Cellular HAL is based on FreeRTOS Kernel Version 202007, in this lab we will provide the steps to do a manual migration of the source of FreeRTOS cellular HAL to compile with the STM32Cube IDE
Pre-requisites
1.Install the STM32Cube Ecosystem Tools (Cube IDE, Cube Programmer etc.,). Refer to this lab for more details if you are not familiar with the STM32 IoT Discovery kit with secure element here
2.X-CUBE-AWS V2.0 SDK DOWNLOAD FROM HERE
3.Extract the x-cube-aws v2.0 SDK to a folder. ie. C:\STM32CubeExpansion_Cloud_AWS_V2.0.0
Caveat
There are are couple of conflicts, i) the “HAL_UART_MspInit” & “HAL_UART_MspDeInit” is defined in two files. ie. comm_if_st.c & stm32l4xx_hal_msp.c. This need to be manually resolved. The fix is to disable the duplicate definition from one of the files. ii) The iot_secure_sockets.c file which has changes done by ST specific to the WiFi MCU, need to be overwritten by the iot_secure_sockets.c for cellular. During this testing, this was manually replaced, hence making WiFi/Cellular mutually-exclusive.
3rd party libraries like mBedTLS etc., aren’t upgraded per the latest FreeRTOS package used in cellular HAL. The original version which is available in x-cube-aws-2.0 is retained as-is (This has a dependency with the ST-SAFE middleware)
STM32L4+ Discovery boards works in both the modes. i.e using the on-board secure element generating the device certificates (or) using an external device certificates (Generated by AWS IoT Core).
Adaptation of the FreeRTOS folder structure to suit the X-Cube-AWS-2.0 packaging format. This involves, removing the folders pertaining to other silicon partners from the projects & the vendor folder. The current FreeRTOS packaging is a monolithic format, where the multi-vendor/partner vendor specific projects & source codes resides in a common folder
Replace the FreeRTOS Kernel in the x-cube-aws-2.0 to the version that is used by FreeRTOS Cellular HAL. i.e upgrade from 202002 to 202007
Copy the Cellular HAL specific folders to x-cube-aws-2.0 source code structure.
Update the demo source to ensure the cellular manager is able to initialise.(Impact to the existing Network Manager)
There is a subtle difference in the way the vendor specific folder for ST is organised in the X-Cube-AWS-2.0 and the FreeRTOS AWS Reference Integration Packaging (i.e. FREERTOS_BASEDIR/vendors/st/boards/stm32l475_discovery). This set of files requires special treament. Exploded directory approach used by x-cube-aws-2.0
mkdir /c/src
cd /c/src
git clone https://github.com/chinglee-iot/amazon-freertos.git --recurse-submodules -b feature/cellular
Navigate to the $FreeRTOS_BASEDIR/vendors folder. Remove all the folders except for the these four folders [ aws, pc, quectel, vendor,st ]
Navigate to the $FreeRTOS_BASEDIR/projects folder. Remove all the folders except for the these three folders [ pc , st, vendor ]
Now, let’s copy these to the X-CUBE-AWS-2.0 Cube Expansion Folder. If the x-cube-aws-2.0 source code is extracted to the default directory, it will be extracted to C:\STM32CubeExpansion_Cloud_AWS2.0.0 a.k.a. X-CUBE-AWS-BASEDIR henceforth.
Copy the cellular HAL specific demo files (cherry pick the specific files/folders mentioned here)
Copy the files from $FreeRTOS_BASEDIR/vendors/st/boards/stm32l475_discovery/ports/comm_if to $X-CUBE-AWS-BASEDIR/Projects/B-L4S5I-IOT01A/Applications/Cloud/aws_demos/Src/ports. i.e. the files (comm_if_st.c, iot_fifo.c iot_fifo.h)
Copy the below set of files from $FreeRTOS_BASEDIR/vendors/st/boards/stm32l475_discovery/aws_demos/config_files to $X-CUBE-AWS-BASEDIR/Projects/B-L4S5I-IOT01A/Applications/Cloud/aws_demos/config_files [ aws_demo_config.h, aws_cellular_config.h, FreeRTOSConfig.h, FreeRTOSIPConfig.h aws_iot_network_config.h, aws_secure_sockets_config.h ]
Copy the file iot_secure_sockets.c from $FREERTOS_BASEDIR/libraries/abstractions/secure_sockets/cellular/iot_secure_sockets.c to $X-CUBE-AWS-BASEDIR/Projects//B-L4S5I-IOT01A/Applications/Cloud/aws_demos/Src/ports
In the file $X-CUBE-AWS-BASEDIR/Projects//B-L4S5I-IOT01A/Applications/Cloud/aws_demos/Src/main.c, vApplicationDaemonTaskStartupHook() comment the prvWiFiConnect() & other WiFi specific initialisations. If this step isn’t done, even though Cellular Manager is enabled, the actual user data shall use the WiFi connectivity.
Resolve the duplicate definition of the 2 functions HAL_UART_MspInit & HAL_UART_MspDeInit in the file $X-CUBE-AWS-BASEDIR/Projects/B-L4S5I-IOT01A/Applications/Cloud/aws_demos/Src/stm32l4xx_hal_msp.c
Update the .project & .cproject. To perform this step, download the attachment from the below link