FreeRTOS HTTPS on LPC1788

Hi,

I’m trying use https with FreeRTOS on MCUXpresso for LPC1788. But i’m having many problems with dependencies, and i can’t build the project.

Which project are you trying to build?

My own project, follow project demo LPC54018, but in my case for LPC1788.

My currently project works with FreeRTOS+TCP with HTTP (this manually), but i need to use HTTPS. So i start importing the examplo aws_demo of LPC54018. Firstly i remove mqtt, because i won’t use mqtt protocol, but this cause an error. So i start again using all dependencies used on project aws_demo. Now this compile, but whitout any code in my application for https or tcp, only FreeRTOS.

Now i put the lib FreeRTOS+TCP for use my ethernet driver startup, using DHCP and static IP. But this is causing a error on call xApplicationGetRandomNumber, so i included the file iot_secure_sockets.c from freertos_plus_tcp, but now is causing another error in this file about the function xSemaphoreCreateMutexStatic and many other erros on file iot_pkcs11_mbedtls.c.

So i’m not getting use the https lib.

Could you let us know the exact compiler errors you are seeing with your project?

Thanks.

Hi Gordon,

First the error what occour, is the use only of static memory, in all my project we use dynamic memory.

A stranger thing that hapens when i add the freertos_plus_tcp, the file FreeRTOS_DCHP.h don’t find the definition of type Socket_t, so i add the FreeRTOS_Sockets.h on config file.

After this, return a definition error of xApplicationGetRandomNumber, this is called from file iot_secure_sockets.c so i add this file.

After this steps above, return all this errors below:

Description Resource Path Location Type
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `C_FindObjects’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `C_GenerateKeyPair’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `C_GetAttributeValue’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `C_SignInit’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `C_VerifyInit’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `PKCS11_PAL_DestroyObject’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `prvCreateCertificate’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `prvCreatePrivateKey’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `prvCreatePublicKey’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o: in function `prvGetExistingKeyComponent’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.o:(.data.prvP11FunctionList+0x4): undefined reference to `C_Initialize’ HTTPS_TCP C/C++ Problem
./libraries/abstractions/platform/freertos/iot_threads_freertos.o: in function `IotMutex_Create’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/platform/freertos/iot_threads_freertos.o: in function `IotSemaphore_Create’: HTTPS_TCP C/C++ Problem
./libraries/abstractions/secure_sockets/freertos_plus_tcp/iot_secure_sockets.o: in function `prvSocketsGetCryptoSession’: HTTPS_TCP C/C++ Problem
make: *** [makefile:79: HTTPS_TCP_.axf] Error 1 HTTPS_TCP C/C++ Problem
undefined reference to `PKCS11_PAL_FindObject’ HTTPS_TCP line 1298, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_FindObject’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 1294 C/C++ Problem
undefined reference to `PKCS11_PAL_FindObject’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 2582 C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValue’ HTTPS_TCP line 1303, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValue’ HTTPS_TCP line 2587, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValue’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 513 C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValue’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 2173 C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValue’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 2922 C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValue’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 3229 C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValueCleanup’ HTTPS_TCP line 1330, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValueCleanup’ HTTPS_TCP line 2377, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValueCleanup’ HTTPS_TCP line 2606, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValueCleanup’ HTTPS_TCP line 2983, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValueCleanup’ HTTPS_TCP line 3288, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_GetObjectValueCleanup’ HTTPS_TCP line 572, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_SaveObject’ HTTPS_TCP line 3825, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_SaveObject’ HTTPS_TCP line 530, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\pkcs11\mbedtls\iot_pkcs11_mbedtls.c C/C++ Problem
undefined reference to `PKCS11_PAL_SaveObject’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 1212 C/C++ Problem
undefined reference to `PKCS11_PAL_SaveObject’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 1725 C/C++ Problem
undefined reference to `PKCS11_PAL_SaveObject’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 1948 C/C++ Problem
undefined reference to `PKCS11_PAL_SaveObject’ iot_pkcs11_mbedtls.c /HTTPS_TCP/libraries/abstractions/pkcs11/mbedtls line 3811 C/C++ Problem
undefined reference to `xSemaphoreCreateCountingStatic’ iot_threads_freertos.c /HTTPS_TCP/libraries/abstractions/platform/freertos line 253 C/C++ Problem
undefined reference to `xSemaphoreCreateMutexStatic’ HTTPS_TCP line 153, external location: c:\nxp\mcuxpressoide_11.0.1_2563\ide\plugins\com.nxp.mcuxpresso.tools.win32_11.0.1.201907311258\tools\arm-none-eabi\bin\ld.exe: E:\PROJETOS\CLIENTES\TESTE\HTTPS_TCP\libraries\abstractions\platform\freertos\iot_threads_freertos.c C/C++ Problem
undefined reference to `xSemaphoreCreateMutexStatic’ iot_secure_sockets.c /HTTPS_TCP/libraries/abstractions/secure_sockets/freertos_plus_tcp line 559 C/C++ Problem
undefined reference to `xSemaphoreCreateRecursiveMutexStatic’ iot_threads_freertos.c /HTTPS_TCP/libraries/abstractions/platform/freertos line 148 C/C++ Problem

The static memory issues can be resolved by setting configSUPPORT_STATIC_ALLOCATION to 1 in FreeRTOSConfig.h. You will then also need to define vApplicationGetIdleTaskMemory()
and vApplicationGetTimerTaskMemory() - you will find examples of these functions below, on the FreeRTOS.org site and by grepping the distribution for that text. I would normally post a direct link but am offline while writing this.

/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
used by the Idle task. */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
/* If the buffers to be provided to the Idle task are declared inside this
function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */
static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];

	/* Pass out a pointer to the StaticTask_t structure in which the Idle task's
	state will be stored. */
	*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;

	/* Pass out the array that will be used as the Idle task's stack. */
	*ppxIdleTaskStackBuffer = uxIdleTaskStack;

	/* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
	Note that, as the array is necessarily of type StackType_t,
	configMINIMAL_STACK_SIZE is specified in words, not bytes. */
	*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
/*-----------------------------------------------------------*/

/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
application must provide an implementation of vApplicationGetTimerTaskMemory()
to provide the memory that is used by the Timer service task. */
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
{
/* If the buffers to be provided to the Timer task are declared inside this
function then they must be declared static - otherwise they will be allocated on
the stack and so not exists after this function exits. */
static StaticTask_t xTimerTaskTCB;
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];

	/* Pass out a pointer to the StaticTask_t structure in which the Timer
	task's state will be stored. */
	*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;

	/* Pass out the array that will be used as the Timer task's stack. */
	*ppxTimerTaskStackBuffer = uxTimerTaskStack;

	/* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
	Note that, as the array is necessarily of type StackType_t,
	configMINIMAL_STACK_SIZE is specified in words, not bytes. */
	*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}

I would also suggest using the Console to configure your project. Please see the documentation here:

https://docs.aws.amazon.com/freertos/latest/userguide/freertos-ocw.html

The Console will allow you to select a platform with only the HTTPS library without having to configure your own project.

Hi @rtel
Use the allocation static memory isn’t possible, because we use heap_5 for use external memory, the internal memory of LPC1788 is only 64KB, and our project is big using a lot of libraries, so FreeRTOS use heap on an external memory. I tried use the static allocation but had problem.

Hi @wanggord,
I done like you said on Amazon FreeRTOS console, and seeing the project, and most of things i done, the only change.
I put the freertos_plus_tcp, for create connection ethernet, and this lib was working on my hardware yet.

I will create a lean project and share with you.

This is the repo of my project.
https://bitbucket.org/ulyssesfonseca/https_freertos

You would need to configure your linker script to allow it.
[edit for clarity] place part of the .bss section in the external memory so the compiler allocates variables in external memory as well as internal[/edit]

@rtel

I use my external memory on settings of my project

This generate the follow code on linker script:

/* BSS section for SDRAM32 */
.bss_RAM3 :
{
   . = ALIGN(4) ;
   PROVIDE(__start_bss_RAM3 = .) ;
   *(.bss.$RAM3)
   *(.bss.$SDRAM32)
   *(.bss.$RAM3.*)
   *(.bss.$SDRAM32.*)
   . = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */
   PROVIDE(__end_bss_RAM3 = .) ;
} > SDRAM32

But this is only recognized with heap_5.
If have another way, could show me? because this is the only way i know.

So will the linker place variables in RAM3? When you say it is only recognized with heap_5, do you mean you have configured heap_5 to cover all of RAM3? If so, you could just reduce the size of the heap.

@rtel

Not, for use the FreeRTOS on an external memory, i need to use the heap_5. I use this RAM3 for other things too, like fonts for UI, images.

From the section of the linker script it looks like it would - unless you have already filled RAM3 with other things.

Hi @rtel,

I read the definition of static, and i saw that i can put the stack of each task at memory where i want. So i will continue my implemantation with static allocation on FreeRTOS, for use HTTPS.

Hi,

Now i have a problem, i’m using static allocation for my tasks, but when i try init de FreeRTOS_IPInit, on step where try get the xQueueCreate return null. So, don’t start the task prvIPTask for FreeRTOS+TCP. This was working when using dynamic allocation.

We already have a feature request to make the stack work with static allocation too, but have not got around to it yet I’m afraid. For now you could edit your copy of the code to change the xQueueCreate to an xQueueCreateStatic - you will also need to change the xTaskCreate that creates the IP task to an xTaskCreateStatic.

Hi,

I done like you said, change the xQueueCreate for xQueueCreateStatic and xTaskCreate for xTaskCreateStatic on FreeRTOS_IP.c file. But now when i try connect on network by DHCP, return all fields with one:

IP Address: 1.1.1.1
Subnet Mask: 1.1.1.1
Gateway IP Address: 1.1.1.1
DNS server IP Address: 1.1.1.1

I think is a problem with my router, because now is working this part.