Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

FreeRTOS+TCP for Renesas RX63N

Posted by plek324 on January 22, 2018

Hi,

I made FreeRTOS+TCP work on a RX63N. Perhaps it was already done before, but I could not find it. If anyone is interrested please let me know and I will send it.

Peter


FreeRTOS+TCP for Renesas RX63N

Posted by sbrauss on January 22, 2018

FreeRTOS+TCP for Renesas RX63N

Posted by sbrauss on January 22, 2018

Hi Peter!

Some time ago, I started with a port for RX62N. Together with Hein, it finally also worked, but it consumed too much memory on my system to be used usefully, so I switched back to uIP. How much memory do you reserve for it?

Regards, Stephan


FreeRTOS+TCP for Renesas RX63N

Posted by plek324 on January 22, 2018

Hi Stephan,

Yes, memory consumption is a point of worry for me as well. To give you an idea: I made an application with a very simple CLI, both over uart as well as over TCP. I assigned 64k ram to this application. I use the heap5 scheme, which assigns all free memory to the heap .

at startup the heapsize is 57400 bytes Before ethernet is connected I have 36512 bytes available. After getting a IP address via DHCP I have 31352 available. (minimum ever 26720) After connecting to a simple TCP-CLI server I have 15600 available, (minimum ever 14056) After release from the simple TCP-CLI server I have 27248 available, (minimum ever 12512)

I must say I haven’t invested any time in figuring out where the memory went, nor have I tried other IP-stacks. But judging from your story, I think I should, and probably will.

Peter


FreeRTOS+TCP for Renesas RX63N

Posted by plek324 on January 22, 2018

I just noticed I can attach files on a reply, so here it is.

Attachments

rx63n_tcp.zip (1184460 bytes)

FreeRTOS+TCP for Renesas RX63N

Posted by rtel on January 22, 2018

The memory used by the stack is very configurable. You can run with small MSS and no TCP windowing for low memory consumption, but also slow throughput, or larger MSS and TCP windowing for the opposite. For a CLI I would imagine a minimum memory configuration would suffice.

https://www.freertos.org/FreeRTOS-Plus/FreeRTOSPlusTCP/TCPIPConfiguration_Examples.html


FreeRTOS+TCP for Renesas RX63N

Posted by sbrauss on January 22, 2018

Hi Peter

Thank you for sharing the files! In my application, I need several connections in parallel and I ended up with too much memory usage. The RX62N I used has only 96KB of RAM, and my main application already needs more than 70K. So there is not much RAM remaining for the TCP/IP stack. I have not tried to reduce the MTU, but this is maybe a good approach.

Best regards, Stephan


FreeRTOS+TCP for Renesas RX63N

Posted by heinbali01 on January 22, 2018

Richard wrote:

The memory used by the stack is very configurable. You can run with small MSS and no TCP windowing for low memory consumption

Those are the best methods to reduce memory usage of +TCP.

Adam Dunkels' earlier TCP/IP stack uIP, was indeed using a minimum of RAM. I has a TCP window of 1 packet (MSS). It wants an ACK after each packet sent.

FreeRTOS+TCP also has this "uIP" mode if you define:

~~~ #define ipconfigUSETCPWIN ( 0 ) ~~~

This will save lots of RAM, at the cost of some performance.

You also mentioned decreasing the size of the MTU. That is indeed a very effective and compatible way of decreasing memory usage, for instance:

~~~ #define ipconfigNETWORK_MTU ( 512 ) ~~~

When MTU equals 1500 bytes, the MSS equals 1460. So when you're playing with MTU, use ipconfigTCP_MSS in stead of the constant 1460:

~~~ #define ipconfigTCPRXBUFFERLENGTH ( 3 * ipconfigTCPMSS ) #define ipconfigTCPTXBUFFERLENGTH ( 2 * ipconfigTCPMSS ) ~~~

The above defines the default buffer sizes for reception and transmission. Do not define ipconfigTCP_MSS your self, it is already defined in FreeRTOSIPConfigDefaults.h.

If you are using TCP windows, you may want to reduce :

~~~ #define ipconfigTCPWINSEG_COUNT 64 ~~~

FreeRTOS+TCP has a fixed amount of packet buffers. Each buffer can hold a complete Ethernet packet. You can choose to have all buffers allocated at start-up, or dynamically ( using pvPortMalloc() ). Please check BufferAllocation_1.c versus BufferAllocation_2.c.

Regards, Hein


FreeRTOS+TCP for Renesas RX63N

Posted by heinbali01 on January 23, 2018

Hi Stephan, Peter,

The RX62N I used has only 96KB of RAM, and my main application already needs more than 70K

Does that mean that 96 - 70 = 26 KB remains for TCP/IP ? That is well possible !

I just created a mini-project that creates a UDP port for logging, and a TCP port in listening mode.

In this case, I prefer to use BufferAllocation_2.c, because it will malloc() just enough bytes and only when needed. The module BufferAllocation_1.c is preferable for high-performance systems, where there is plenty of RAM available.

A few parameters for FreeRTOSIPConfig.h that help reducing the need for RAM:

~~~ /* The maximum number of network buffers: */

define ipconfigNUMNETWORKBUFFER_DESCRIPTORS ( 10 )

/* The Maximum Transmission Unit: */

define ipconfigNETWORK_MTU ( 512 + 40 )

/* Not using DHCP: */

define ipconfigUSE_DHCP 0

/* Each TCP socket has a buffer for RX and one for TX. Make them big enough to hold 1 packet: */

define ipconfigTCPRXBUFFERLENGTH ( 1 * ipconfigTCPMSS )
define ipconfigTCPTXBUFFERLENGTH ( 1 * ipconfigTCPMSS )

~~~

Measuring RAM/heap usage is always difficult. For my test, I was using an STM32F4. The results below are just an estimate and may vary among different compilers and platforms:

Starting up the IP-task, creating lists and buffers: 17 KB Creating a UDP socket: 100 bytes Creating a TCP socket in listen mode: 376 bytes Listening socket gets connected and creates buffers: 1088 bytes( 2 x MSS ) DATA and BSS, i.e. memory claimed at compile time: 900 bytes.

The listening socket was created with the socket option FREERTOS_SO_REUSE_LISTEN_SOCKET. That means that when a connection comes in, the listening socket turns into a connected socket. Normally, the listening stays in the listening state and it will accept() many connections.

The amount of flash used by the +TCP and NetworkInterface.c : 21 KB.


FreeRTOS+TCP for Renesas RX63N

Posted by plek324 on January 23, 2018

Hi Richard and Hein,

Thank you for your input. As a small clarification, the program I have uploaded here with CLI is just a small test to get a working ethernet driver for the RX63N. I am now going to lift the driver over to an existing application that runs UDP at the moment. The RX63N I use has in fact 128kb of RAM, but like in Stephans case, I already use quite a lot of it. In the end I want to get MQTT running, ideally over SSL. I don't need high throughput.

Setting ipconfigUSETCPWIN to 0, and MTU size to 586 already saved 17kb or so of dynamic memory. This is good enough for me now.

Disabling DHCP is not an option for me. (at least not at build time)

I still have a question though: If I reduce the MTU size, whay will happen if the server I connect to wants to send me a message that is 1500 bytes? Will it get chopped into 3 frames in an underlying layer? Or will it get dropped on the floor?


FreeRTOS+TCP for Renesas RX63N

Posted by heinbali01 on January 23, 2018

I still have a question though: If I reduce the MTU size, what will happen if the server I connect to wants to send me a message that is 1500 bytes? Will it get chopped into 3 frames in an underlying layer? Or will it get dropped on the floor?

Good question: For TCP it will work OK. In the SYN packets, there is an option that proposes an MSS for the connection. The peer may come up with 1460, but if your device wants 512, that value will be chosen by both parties.

I think that there will be a problem if you need to respond to large (ICMP) ECHO commands, or if you want to use large UDP commands. The other party doesn't know that your buffers are small (512+40 bytes in the example).

Will it get chopped into 3 frames in an underlying layer?

No, we stopped supporting fragmentation, because it is not often used anymore, and it made the code larger and more complex


FreeRTOS+TCP for Renesas RX63N

Posted by plek324 on January 23, 2018

Ok, thanks for clearing that out. That also explains why DHCP has a minimum requirement for the MTU size(586 bytes).


FreeRTOS+TCP for Renesas RX63N

Posted by sbrauss on January 30, 2018

Hello Peter!

Here are the files of my implementation for RX62N, at the state when I stopped. May it is interesting for you. In my application, I have various tasks sending and receiving network packets. For example, I have a DHCP and an NTP client, a HTTP server, an interface to the HMI, and a remote control interface. When I started the project, FreeRTOS+TCP was no available and I took uIP, but if you succeed with the small memory footprint of the RX, I maybe will give it a try, too.

Best regards, Stephan

Attachments

rx62n_tcp.zip (25286 bytes)

FreeRTOS+TCP for Renesas RX63N

Posted by heinbali01 on January 30, 2018

Here are the files of my implementation for RX62N

Thanks a lot!

but if you succeed with the small memory footprint of the RX I maybe will give it a try, too.

uIP is using a minimum of RAM: it is using the same 1.5K buffer over and again. If your application runs well with "just enough memory", you'd better stick to uIP.

FreeRTOS+TCP is very configurable as I showed here above, but when it comes to saving bytes, uIP will win. I think that +TCP will feel more comfortable though, it is easier to understand its logic and the API's are BSD compatible. And most of all, FreeRTOS+TCP is very well integrated into the FreeRTOS kernel.

Regards.


FreeRTOS+TCP for Renesas RX63N

Posted by sbrauss on January 30, 2018

Hi Hein!

Yes, you are right, uIP is not easy to program. Having real sockets it much better than using the PT_THREADS...

Best regards, Stephan


FreeRTOS+TCP for Renesas RX63N

Posted by plek324 on February 5, 2018

Hi,

Just a quick update about the code I posted on 2018-01-22. I found an error in it, in that it didn't handle fragmented packets properly. In fact these packets weren't cleared from the low level driver, resulting in clogged up buffers.

These problems started to show after reducing the MTU size. Some devices on our network were sending broadcasts every once in a while with packets greater than my MTU. And these packets are delivered to the software in fragments.

Since these broadcast are not of interest to my device I can just ignore them, but I do have to make shure the buffers are cleared, which can be done by a small change in the function prvNetworkInterfaceInput( void ), in the file "FreeRTOS-Plus-TCPportableNetworkInterfaceRX63NNetworkInterface.c":

Change the first if- statement to: ~~~ if( ( pxDMARxDescriptor->status & ACT )==0 ) { /* Get the Frame Length of the received packet */ xReceivedLength = pxDMARxDescriptor->RFL;

	pucTemp = (uint8_t *) pxDMARxDescriptor->buf_p;

	if( xReceivedLength==0 )
	{
		//When small buffers are used, segmented packets can be expected.
		//These are usually broadcasts which can be ignored.
		//if a packet is not marked with an end bit, these will have zero length
		//So we consume all zero-length packets here.
		EMAC_UpdateRxConsumeIndex();
	}
}
else
{
	xReceivedLength = 0;
}

~~~ With this change I now have been running this driver for a couple of days now without a single problem, and the amount of RAM used is nothing to complain about.

So thanks Stephan for sharing the uip driver, but I will proceed with the FreeRTOS+TCP driver, as I highly appriciate the BSD style too.

regards, Peter


FreeRTOS+TCP for Renesas RX63N

Posted by sbrauss on February 5, 2018

Hi Peter!

The code I have shared is also for FreeRTOS+TCP. I thought it maybe can be helpfull to have another implementation for you to compare.

BTW, something off-topic: Do you use the USB ports of the RX63N with FreeRTOS?

Best regards, Stephan


FreeRTOS+TCP for Renesas RX63N

Posted by plek324 on February 5, 2018

Hi Stephan, oops, based on your comments I made a bad assumtion (note to self(again): Never Assume!)

I will have a look at your code then. Event though I am pretty happy with how my driver works right now I do admit that the code is a bit messy.

About the USB port: Unfortunately I do not use it. I do have the connector on board, but in our case it's not really needed, so I never came around to start using it. I tried once but that was years ago, I don't even know anymore how far I got.


FreeRTOS+TCP for Renesas RX63N

Posted by sbrauss on February 5, 2018

Hello Peter!

I do admit that the code is a bit messy. Mine does also not win a prize...

Regarding the USB: I used the code supplied by Renesas, but it does not work very well. Tha't s why I asked.

Thanks & best regards, Stephan


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner