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

Add support for FreeRTOS TCP/IP stack #9

Merged
merged 13 commits into from
Oct 13, 2023

Conversation

urutva
Copy link
Contributor

@urutva urutva commented Oct 4, 2023

Add support for FreeRTOS TCP/IP stack

Description

This PR adds support for FreeRTOS TCP/IP stack and makes it the default network stack for the FRI.

Test Steps

Tested AWS IoT core end to end connectivity and OTA job.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

Depends on FreeRTOS/FreeRTOS-Plus-TCP#1009

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -62,7 +62,7 @@ extern uint32_t SystemCoreClock;
#define configTICK_RATE_HZ ( ( uint32_t ) 100 ) /* Scheduler polling rate of 1000 Hz */

#define pdMS_TO_TICKS( xTimeInMs ) ( ( TickType_t ) xTimeInMs )
Copy link
Member

Choose a reason for hiding this comment

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

Why are you defining these? These are already defined in projdefs.h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added description about FVP behaviour and the justification for setting configTICK_RATE_HZ to 100 and the custom definition of pdMS_TO_TICKS.

@@ -62,7 +62,7 @@ extern uint32_t SystemCoreClock;
#define configTICK_RATE_HZ ( ( uint32_t ) 100 ) /* Scheduler polling rate of 1000 Hz */
Copy link
Member

Choose a reason for hiding this comment

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

Comment does not match the actual value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe let's just specify the unit in the comment so we never need to update this again should the value change.
OR just delete the comment since the macro already has the unit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added description about FVP behaviour and the justification for setting configTICK_RATE_HZ to 100 and the custom definition of pdMS_TO_TICKS.

#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#include <stdio.h>
#define FreeRTOS_debug_printf( X ) \
printf( "%p->%s %d: ", \
Copy link
Member

Choose a reason for hiding this comment

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

Why both prrintf and vLoggingPrintf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was copied from one of the examples. Removed additional printf.

* messages. */
#define ipconfigHAS_PRINTF 1
#if ( ipconfigHAS_PRINTF == 1 )
#include <stdio.h>
Copy link
Member

Choose a reason for hiding this comment

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

Why is this include needed here? Should this not be in the implementation file of vLoggingPrintf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. This is a typo. #include <stdio.h> removed.

*/
#define ipconfigIPv4_BACKWARD_COMPATIBLE 0

#define portINLINE __inline
Copy link
Member

Choose a reason for hiding this comment

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

This should be part of portmacro.h, if not already there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not needed. Removed.

*
* @param[out] pNetworkContext The output parameter to return the created network context.
* @param[in] pServerInfo Server connection info.
* @param[in] pTLSParams socket configs for the connection.
Copy link
Member

Choose a reason for hiding this comment

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

Params sendTimeoutMs and recvTimeoutMs not documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function header updated.

* over the network.
*
* @param[in] pNetworkContext The network context created using Secure Sockets API.
* @param[in] pBuffer Buffer containing the bytes to send over the network stack.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param[in] pBuffer Buffer containing the bytes to send over the network stack.
* @param[in] pMessage Buffer containing the bytes to send over the network stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function header updated.

Comment on lines 152 to 168
/* Set socket receive timeout. */
/* transportTimeout = pdMS_TO_TICKS( recvTimeoutMs ); */
/* / * Setting the receive block time cannot fail. * / */
/* ( void ) FreeRTOS_setsockopt( pNetworkContext->socket, */
/* 0, */
/* FREERTOS_SO_RCVTIMEO, */
/* &transportTimeout, */
/* sizeof( TickType_t ) ); */

/* / * Set socket send timeout. * / */
/* transportTimeout = pdMS_TO_TICKS( sendTimeoutMs ); */
/* / * Setting the send block time cannot fail. * / */
/* ( void ) FreeRTOS_setsockopt( pNetworkContext->socket, */
/* 0, */
/* FREERTOS_SO_SNDTIMEO, */
/* &transportTimeout, */
/* sizeof( TickType_t ) ); */
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove this commented code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. We need this to set the send/receive timeout on the socket. Code retained.

uint32_t ulDestinationAddress,
uint16_t usDestinationPort )
{
psa_status_t xPsaStatus = PSA_ERROR_PROGRAMMER_ERROR;
Copy link
Member

Choose a reason for hiding this comment

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

Consider adding the following to avoid unused variable warning -

( void ) ulSourceAddress;
( void ) usSourcePort;
( void ) ulDestinationAddress;
( void ) usDestinationPort;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

manifest.yml Outdated
version: "3d5ee0e821cab38cb6e6265fcf1ce7552a54519d"
repository:
type: "git"
url: "https://github.com/urutva/FreeRTOS-Plus-TCP.git"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be updated to https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if I am missing something but I cannot see it changed.
It is still pointing to the fork.

Here is my current URL: https://github.com/FreeRTOS/iot-reference-arm-corstone3xx/pull/9/files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please feel free to resolve this. I do not have a resolve button.

@@ -47,6 +47,8 @@ else()
add_compile_options(-O1)
endif()

set(NETWORK_COMPONENT "IOT-VSOCKET")
Copy link
Contributor

Choose a reason for hiding this comment

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

Blinky does not need networking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please feel free to resolve this. I do not have a resolve button.

Comment on lines 83 to 84
# Select the components required by the application
set(NETWORK_COMPONENT "IOT-VSOCKET")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Select the components required by the application
set(NETWORK_COMPONENT "IOT-VSOCKET")
set(CONNECTIVITY_STACK "IOT_VSOCKET" CACHE STRING "Choose the connectivity stack to use")
set_property(CACHE CONNECTIVITY_STACK PROPERTY STRINGS "IOT_VSOCKET")

Copy link
Contributor Author

@urutva urutva Oct 11, 2023

Choose a reason for hiding this comment

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

NETWORK_COMPONENT changed to CONNECTIVITY_STACK .
May be I'm missing something, what is the need to set a property on the variable which isn't used by the build system. If the intention was to describe the possible values, I've added them to the description string in the variable definition.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is so if a UI is used for CMake, the possible values will be selectable.

At the moment the connectivity stack is only selectable by changing the CMakeLists.txt. Perhaps also add an optional argument for the build shell script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently there is no plan to support CMake UI in FRI.

Providing an option to select a network in the build script is useful, however, I cannot think of an use case where developers would like to switch network stack during each build. Hence, hard-coding it in CMake code is a better approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please feel free to resolve this. I do not have a resolve button.

@@ -15,6 +15,8 @@ add_library(iot-vsocket STATIC
transport_tls_iot_socket.c
)

add_library(network-component ALIAS iot-vsocket)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
add_library(network-component ALIAS iot-vsocket)
add_library(connectivity-stack ALIAS iot-vsocket)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please feel free to resolve this. I do not have a resolve button.

Comment on lines 83 to 84
# Select the components required by the application
set(NETWORK_COMPONENT "IOT-VSOCKET")
set(NETWORK_COMPONENT "FREERTOS-TCP-IP")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Select the components required by the application
set(NETWORK_COMPONENT "IOT-VSOCKET")
set(NETWORK_COMPONENT "FREERTOS-TCP-IP")
set(CONNECTIVITY_STACK "FREERTOS_PLUS_TCP" CACHE STRING "Choose the connectivity stack to use")
set_property(CACHE CONNECTIVITY_STACK PROPERTY STRINGS "FREERTOS_PLUS_TCP" "IOT_VSOCKET")

Copy link
Contributor Author

@urutva urutva Oct 11, 2023

Choose a reason for hiding this comment

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

NETWORK_COMPONENT changed to CONNECTIVITY_STACK.
May be I'm missing something, what is the need to set a property on the variable which isn't used by the build system. If the intention was to describe the possible values, I've added them to the description string in the variable definition.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is so if a UI is used for CMake, the possible values will be selectable.

At the moment the connectivity stack is only selectable by changing the CMakeLists.txt. Perhaps also add an optional argument for the build shell script?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as #9 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Please feel free to resolve this. I do not have a resolve button.

@@ -3,3 +3,6 @@
# SPDX-License-Identifier: MIT

add_subdirectory(kernel)
if (${NETWORK_COMPONENT} STREQUAL "FREERTOS-TCP-IP")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (${NETWORK_COMPONENT} STREQUAL "FREERTOS-TCP-IP")
if(CONNECTIVITY_STACK STREQUAL "FREERTOS_PLUS_TCP")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please feel free to resolve this. I do not have a resolve button.

app-config
app-logging
event-helper
PUBLIC
Copy link
Contributor

@hugueskamba hugueskamba Oct 11, 2023

Choose a reason for hiding this comment

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

What is the reason for having this PUBLIC?
Is it worth explaining with a comment or in the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that the dependency on connectivity-stack need not be public. Changed the dependency to PRIVATE.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please feel free to resolve this. I do not have a resolve button.

Instead of directly using malloc, use FreeRTOS provided malloc API.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
FreeRTOS TCP/IP stack recommends `heap_4` and `BufferAllocation_2`.
https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/tree/V4.0.0-appsec#note

Since FreeRTOS manages the heap, set Mbed TLS memory APIs to use
FreeRTOS heap APIs (mbedtls_platform_set_calloc_free).

In addition, reduce allocated heap size from `0x000b0000` to
`0x00000400`, since FreeRTOS manages heap when `heap_4` configuration is
selected. Ideally, heap size should be 0, however, GNU expects linker
symbol `end` to be available. Hence, set it to `0x400`.

Also, set the FreeRTOS config `configAPPLICATION_ALLOCATED_HEAP` to 0,
indicating FreeRTOS allocates the heap based on `configTOTAL_HEAP_SIZE`
(720896 bytes).

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
The socket creation is part of
`Middleware/ARM/IoT_VSocket-lib/AVH/interface/vsocket/iot_socket.c` and
hence `socket_startup.c` is redundant. In addition, `socket_startup()`
always returns 0.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
The system event helper library provides system event management, so
that the tasks can wait on the required system event to happen.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Add a CMake variable `CONNECTIVITY_STACK`, so that the application can
select a network stack from the supported network stacks.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Since we are integrating latest version of FreeRTOS TCP/IP stack which
relies on FreeRTOS kernel, ensure that we are using the latest released
version of FreeRTOS kernel which is `V10.6.1`.

In addtion, fix a typo and remove unused macro from `FreeRTOSConfig.h`.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
@urutva urutva force-pushed the add-freertos-tcp-ip-stack-support branch from 767e6de to b9b82d7 Compare October 11, 2023 16:01
aggarg
aggarg previously approved these changes Oct 12, 2023
Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Added support for FreeRTOS TCP/IP stack and made it the default choice
of network stack.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Added support for choosing either ecosystem FVP or Arm virtual hardware
FVP running in the AMI to the `run.sh` script. The ecosystem FVP is used
by default.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
With the addition of support for FreeRTOS TCP/IP stack, in addition to
Arm Virtual Hardware using Amazon Machine Images, Arm FRI can now run
ecosystem FVPs.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Provide justification for setting `configTICK_RATE_HZ` to `100` to
simulate scheduler polling rate of `1000 Hz` or 1 tick per second.

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
@@ -9,7 +9,7 @@
*/

__STACK_SIZE = 0x00002800;
__HEAP_SIZE = 0x000b0000;
__HEAP_SIZE = 0x00000400;
Copy link
Contributor

@hugueskamba hugueskamba Oct 12, 2023

Choose a reason for hiding this comment

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

As the linker scripts and FreeRTOSConfig.h are used by the two applications, is it also necessary to modify Blinky to use Heap 4 instead of Heap 3?

Can we move the heap selection to https://github.com/FreeRTOS/iot-reference-arm-corstone3xx/blob/main/Middleware/FreeRTOS/CMakeLists.txt so it applies to all applications using the FRI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. Let's handle that as part of another PR to improve blinky example.

@amazonKamath amazonKamath self-requested a review October 13, 2023 09:30
@urutva urutva merged commit 52b13ab into FreeRTOS:main Oct 13, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants