Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pnp sample #28

Merged
merged 14 commits into from
Jul 9, 2021
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"image": "tizho/azurertos-regression",
"runArgs": [ "--cap-add=NET_ADMIN"],
"postStartCommand": ".github/scripts/init_linux_port_vm_network.sh",
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools"
]
}
5 changes: 5 additions & 0 deletions .github/scripts/ci_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,28 @@ function sample_build() {
echo -e "::group::Building sample for linux port"
sample_build "PC" "linux" "build_pc_linux"
exit_if_binary_does_not_exist "build_pc_linux" "iot-middleware-sample"
exit_if_binary_does_not_exist "build_pc_linux" "iot-middleware-sample-pnp"

######################## ST Boards #########################

echo -e "::group::Building sample for ST b-l475e-iot01a port"
sample_build "ST" "b-l475e-iot01a" "build_st_b-l475e-iot01a"
exit_if_binary_does_not_exist "build_st_b-l475e-iot01a" "iot-middleware-sample.elf"
exit_if_binary_does_not_exist "build_st_b-l475e-iot01a" "iot-middleware-sample-pnp.elf"

echo -e "::group::Building sample for ST stm32h745i-disco port"
sample_build "ST" "stm32h745i-disco" "build_st_stm32h745i-disco"
exit_if_binary_does_not_exist "build_st_stm32h745i-disco" "iot-middleware-sample.elf"
exit_if_binary_does_not_exist "build_st_stm32h745i-disco" "iot-middleware-sample-pnp.elf"

echo -e "::group::Building sample for ST b-l4s5i-iot01a port"
sample_build "ST" "b-l4s5i-iot01a" "build_st_b-l4s5i-iot01a"
exit_if_binary_does_not_exist "build_st_b-l4s5i-iot01a" "iot-middleware-sample.elf"
exit_if_binary_does_not_exist "build_st_b-l4s5i-iot01a" "iot-middleware-sample-pnp.elf"

######################## NXP Boards ########################

echo -e "::group::Building sample for NXP mimxrt1060 port"
sample_build "NXP" "mimxrt1060" "build_nxp_mimxrt1060"
exit_if_binary_does_not_exist "build_nxp_mimxrt1060" "iot-middleware-sample.elf"
exit_if_binary_does_not_exist "build_nxp_mimxrt1060" "iot-middleware-sample-pnp.elf"
1 change: 1 addition & 0 deletions .github/scripts/ci_tests_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ git config --system core.longpaths true
Write-Output "::group::Building sample for PC windows port"
sample_build -vendor "PC" -board "windows" -outdir "build_windows" -additionalFlags "-DCMAKE_GENERATOR_PLATFORM=Win32"
exit_if_binary_does_not_exist -search_dir "build_windows" -filename "iot-middleware-sample.exe"
exit_if_binary_does_not_exist -search_dir "build_windows" -filename "iot-middleware-sample-pnp.exe"
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ Below you will find samples for development kits and simulators showing how to u
* PC Simulation:
* [Linux](demos/projects/PC/linux/)
* [Windows](demos/projects/PC/windows/)

## Plug and Play Sample

The easiest way to interact with the Plug and Play sample from the service side is to use Azure IoT Explorer. To use the sample:

- Install [Azure IoT Explorer](https://github.com/Azure/azure-iot-explorer/#plug-and-play).
- Download [the Thermostat model](https://github.com/Azure/opendigitaltwins-dtdl/blob/master/DTDL/v2/samples/Thermostat.json) to a local directory.
- Start Azure IoT Explorer and then:
- [Configure your hub](https://github.com/Azure/azure-iot-explorer/#configure-an-iot-hub-connection). Once you've created your thermostat device, you should see it listed in the UX.
- Go to `IoT Plug and Play Settings` on the home screen, select `Local Folder` for the location of the model definitions, and point to the folder you downloaded the thermostat model.
- Go to the devices list and select your thermostat device. Now select `IoT Plug and Play components` and then `Default Component`.
- You will now be able to interact with the Plug and Play device.

Additional instructions for Azure IoT Explorer, including screenshots, are available [here](https://github.com/Azure/azure-iot-explorer/#plug-and-play).

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down
2 changes: 1 addition & 1 deletion cmake/common/utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FetchContent_Declare(
FetchContent_Declare(
NXP_MCUX_SDK
GIT_REPOSITORY https://github.com/NXPmicro/mcux-sdk.git
GIT_TAG a0764538cb37f65907155b2aa6cd514cee8e3442
GIT_TAG 8e910ea4ecc093943bdfd3afd7e2bf578029f92b
GIT_PROGRESS TRUE
)

Expand Down
11 changes: 10 additions & 1 deletion demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ string(TOUPPER ${BOARD} BOARD_U)
# Target for sample task
if(NOT (TARGET SAMPLE::AZUREIOT))
add_library(SAMPLE::AZUREIOT INTERFACE IMPORTED)

target_sources(SAMPLE::AZUREIOT INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/sample_azure_iot/sample_azure_iot.c)
${CMAKE_CURRENT_SOURCE_DIR}/sample_azure_iot/sample_azure_iot.c)
endif()

# Target for pnp sample task
if(NOT (TARGET SAMPLE::AZUREIOTPNP))
add_library(SAMPLE::AZUREIOTPNP INTERFACE IMPORTED)

target_sources(SAMPLE::AZUREIOTPNP INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/sample_azure_iot_pnp/sample_azure_iot_pnp.c)
endif()

# Target for freertos tcpip socket
Expand Down
51 changes: 43 additions & 8 deletions demos/projects/NXP/mimxrt1060/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: MIT

set(MCUX_SDK_PROJECT_NAME ${PROJECT_NAME})
# set parent scope path
set(BOARD_DEMO_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/config CACHE INTERNAL "Config path")
set(BOARD_DEMO_FREERTOS_PORT_PATH ${FreeRTOS_ARM_CM4F_PATH} CACHE INTERNAL "FreeRTOS Port used ")

set(MCUX_SDK_PROJECT_NAME mcux-sdk-lib)

add_library(${MCUX_SDK_PROJECT_NAME})
target_include_directories(${MCUX_SDK_PROJECT_NAME}
PUBLIC
${BOARD_DEMO_FREERTOS_PORT_PATH}
)
target_link_libraries(${MCUX_SDK_PROJECT_NAME}
PUBLIC
FreeRTOS
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious which part of their sdk require this depenency ?

I was under impression that our final binary requires OS depenency and middleware

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


nxp_mcux_sdk_fetch()
lwip_fetch()

list(APPEND CMAKE_MODULE_PATH ${NXP_MCUX_SDK_PATH})

# set parent scope path
set(BOARD_DEMO_CONFIG_PATH ${CMAKE_CURRENT_SOURCE_DIR}/config CACHE INTERNAL "Config path")
set(BOARD_DEMO_FREERTOS_PORT_PATH ${FreeRTOS_ARM_CM4F_PATH} CACHE INTERNAL "FreeRTOS Port used ")

find_package(LWIP)

include(${CMAKE_CURRENT_SOURCE_DIR}/gcc_flags.cmake)
Expand All @@ -23,8 +33,6 @@ include_directories(nxp_code/lwip)
file(GLOB NXPCODE_SOURCES nxp_code/*.c nxp_code/lwip/*.c)
set(PROJECT_SOURCES ${NXPCODE_SOURCES} main.c)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})

# configure modules
set(CONFIG_USE_driver_lpuart true)
set(MCUX_DEVICE "MIMXRT1062")
Expand Down Expand Up @@ -90,6 +98,7 @@ include(driver_phy-common)

include(driver_dcp)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE
FreeRTOS::Timers
FreeRTOS::Heap::5
Expand All @@ -102,11 +111,37 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
LWIP
SAMPLE::SOCKET::LWIP
SAMPLE::AZUREIOT
SAMPLE::TRANSPORT::MBEDTLS)
SAMPLE::TRANSPORT::MBEDTLS
${MCUX_SDK_PROJECT_NAME}
)

add_custom_command(TARGET ${PROJECT_NAME}
# Run after all other rules within the target have been executed
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}> ${PROJECT_NAME}.bin
COMMENT "Generate Bin file"
VERBATIM)

add_executable(${PROJECT_NAME}-pnp ${PROJECT_SOURCES})
target_link_libraries(${PROJECT_NAME}-pnp PRIVATE
danewalton-msft marked this conversation as resolved.
Show resolved Hide resolved
FreeRTOS::Timers
FreeRTOS::Heap::5
FreeRTOS::ARM_CM4F
FreeRTOS::EventGroups
FreeRTOSPlus::Utilities::backoff_algorithm
FreeRTOSPlus::Utilities::logging
FreeRTOSPlus::ThirdParty::mbedtls
az::iot_middleware::freertos
LWIP
SAMPLE::SOCKET::LWIP
SAMPLE::AZUREIOTPNP
SAMPLE::TRANSPORT::MBEDTLS
${MCUX_SDK_PROJECT_NAME}
)

add_custom_command(TARGET ${PROJECT_NAME}-pnp
# Run after all other rules within the target have been executed
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}-pnp> ${PROJECT_NAME}-pnp.bin
COMMENT "Generate Bin file"
VERBATIM)
19 changes: 19 additions & 0 deletions demos/projects/PC/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,22 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
SAMPLE::AZUREIOT
SAMPLE::TRANSPORT::MBEDTLS
SAMPLE::SOCKET::FREERTOSTCPIP)

# Add demo files and dependencies for PnP Sample
add_executable(${PROJECT_NAME}-pnp main.c)
target_link_libraries(${PROJECT_NAME}-pnp PRIVATE
FreeRTOS::Timers
FreeRTOS::Heap::3
FreeRTOS::EventGroups
FreeRTOS::Posix
FreeRTOSPlus::Utilities::backoff_algorithm
FreeRTOSPlus::Utilities::logging
FreeRTOSPlus::ThirdParty::mbedtls
FreeRTOSPlus::TCPIP
FreeRTOSPlus::TCPIP::PORT
az::iot_middleware::freertos
pthread
pcap
SAMPLE::AZUREIOTPNP
SAMPLE::TRANSPORT::MBEDTLS
SAMPLE::SOCKET::FREERTOSTCPIP)
15 changes: 13 additions & 2 deletions demos/projects/PC/linux/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ static void prvSRand( UBaseType_t ulSeed )
}
/*-----------------------------------------------------------*/

UBaseType_t uxRand( void )
danewalton-msft marked this conversation as resolved.
Show resolved Hide resolved
{
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;

/* Utility function to generate a pseudo random number. */

ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
}
/*-----------------------------------------------------------*/

static void prvMiscInitialisation( void )
{
time_t xTimeNow;
Expand Down Expand Up @@ -319,7 +330,7 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
( void ) ulDestinationAddress;
( void ) usDestinationPort;

return configRAND32();
return (uint32_t) configRAND32();
}
/*-----------------------------------------------------------*/

Expand All @@ -334,7 +345,7 @@ extern uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
*/
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
{
*pulNumber = configRAND32();
*pulNumber = (uint32_t) configRAND32();
return pdTRUE;
}
/*-----------------------------------------------------------*/
Expand Down
20 changes: 20 additions & 0 deletions demos/projects/PC/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,23 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
SAMPLE::AZUREIOT
SAMPLE::TRANSPORT::MBEDTLS
SAMPLE::SOCKET::FREERTOSTCPIP)

# Add demo files and dependencies for PnP sample
add_executable(${PROJECT_NAME}-pnp main.c)
target_include_directories(${PROJECT_NAME}-pnp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/WinPCap)
target_link_libraries(${PROJECT_NAME}-pnp PRIVATE
FreeRTOS::Timers
FreeRTOS::Heap::4
FreeRTOS::EventGroups
FreeRTOS::MSVC-MingW
FreeRTOSPlus::Utilities::backoff_algorithm
FreeRTOSPlus::Utilities::logging
FreeRTOSPlus::ThirdParty::mbedtls
FreeRTOSPlus::TCPIP
FreeRTOSPlus::TCPIP::PORT
az::iot_middleware::freertos
${CMAKE_CURRENT_SOURCE_DIR}/WinPCap/wpcap.lib
Bcrypt.lib
SAMPLE::AZUREIOTPNP
SAMPLE::TRANSPORT::MBEDTLS
SAMPLE::SOCKET::FREERTOSTCPIP)
39 changes: 39 additions & 0 deletions demos/projects/ST/b-l475e-iot01a/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,42 @@ add_custom_command(TARGET ${PROJECT_NAME}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}> ${PROJECT_NAME}.bin
COMMENT "Generate Bin file"
VERBATIM)

# Add PnP Sample
danewalton-msft marked this conversation as resolved.
Show resolved Hide resolved
add_executable(${PROJECT_NAME}-pnp ${PROJECT_SOURCES})
target_include_directories(${PROJECT_NAME}-pnp PUBLIC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently in gcc_flags we set the map file to be output.map, and now we have two target generated. This will cause the later target to override previous map file.

${CMAKE_CURRENT_LIST_DIR}
st_code)
target_link_libraries(${PROJECT_NAME}-pnp PRIVATE
FreeRTOS::Timers
FreeRTOS::Heap::5
FreeRTOS::ARM_CM4F
FreeRTOSPlus::Utilities::backoff_algorithm
FreeRTOSPlus::Utilities::logging
FreeRTOSPlus::ThirdParty::mbedtls
HAL::STM32::L4::RCC
HAL::STM32::L4::RCCEx
HAL::STM32::L4::SPI
HAL::STM32::L4::RTC
HAL::STM32::L4::UART
HAL::STM32::L4::DMA
HAL::STM32::L4::PWR
HAL::STM32::L4::PWREx
HAL::STM32::L4::GPIO
HAL::STM32::L4::CORTEX
HAL::STM32::L4::RNG
HAL::STM32::L4::TIM
HAL::STM32::L4::TIMEx
CMSIS::STM32::L475xx
BSP::STM32::STM32L475E_IOT01
STM32::NoSys
az::iot_middleware::freertos
SAMPLE::AZUREIOTPNP
SAMPLE::TRANSPORT::MBEDTLS)

add_custom_command(TARGET ${PROJECT_NAME}-pnp
# Run after all other rules within the target have been executed
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}-pnp> ${PROJECT_NAME}-pnp.bin
COMMENT "Generate Bin file"
VERBATIM)
39 changes: 39 additions & 0 deletions demos/projects/ST/b-l4s5i-iot01a/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,42 @@ add_custom_command(TARGET ${PROJECT_NAME}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}> ${PROJECT_NAME}.bin
COMMENT "Generate Bin file"
VERBATIM)

# PnP Sample
add_executable(${PROJECT_NAME}-pnp ${PROJECT_SOURCES})
target_include_directories(${PROJECT_NAME}-pnp PUBLIC
${SOURCE_DIR}
${SOURCE_DIR}/st_code)
target_link_libraries(${PROJECT_NAME}-pnp PRIVATE
FreeRTOS::Timers
FreeRTOS::Heap::5
FreeRTOS::ARM_CM4F
FreeRTOSPlus::Utilities::backoff_algorithm
FreeRTOSPlus::Utilities::logging
FreeRTOSPlus::ThirdParty::mbedtls
HAL::STM32::L4::RCC
HAL::STM32::L4::RCCEx
HAL::STM32::L4::SPI
HAL::STM32::L4::RTC
HAL::STM32::L4::UART
HAL::STM32::L4::DMA
HAL::STM32::L4::PWR
HAL::STM32::L4::PWREx
HAL::STM32::L4::GPIO
HAL::STM32::L4::CORTEX
HAL::STM32::L4::RNG
HAL::STM32::L4::TIM
HAL::STM32::L4::TIMEx
CMSIS::STM32::L475xx
BSP::STM32::STM32L475E_IOT01
STM32::NoSys
az::iot_middleware::freertos
SAMPLE::AZUREIOTPNP
SAMPLE::TRANSPORT::MBEDTLS)

add_custom_command(TARGET ${PROJECT_NAME}-pnp
# Run after all other rules within the target have been executed
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}-pnp> ${PROJECT_NAME}-pnp.bin
COMMENT "Generate Bin file"
VERBATIM)
Loading