MQX Software Solutions Knowledge Base

cancel
Showing results for 
Search instead for 
Did you mean: 

MQX Software Solutions Knowledge Base

Labels

Discussions

Sort by:
TWR-K70F120M running MQX and RTCS can work with the Dual Phy on TWR-SER2. Below I list the modifications I did to the default BSP: 1) I add phy_dp83xxx.c and phy_dp83xxx.h to the bsp_twrk70f120m build project. These files are with MQX in /mqx/source/io/enet/Phy 2) I modify the BSP to use DP83xxx PHY for the Ethernet MACNET: in the /mqx/source/bsp/twrk70f120m/init_enet.c: #include "phy_dp83xxx.h" const ENET_IF_STRUCT ENET_0 = {      &MACNET_IF,      //&phy_ksz8041_IF,      &phy_dp83xxx_IF,      MACNET_DEVICE_0,      MACNET_DEVICE_0,      BSP_ENET0_PHY_ADDR,      BSP_ENET0_PHY_MII_SPEED }; 3) MDIO line requires an external pull up resistor, per DP83849I Data sheet. As I didn't have one at the moment, I enable internal pull up on MCU pin PTB0. in the /mqx/source/bsp/twrk70f120m/init_gpio.c: //pctl->PCR[0] = PORT_PCR_MUX(4) | PORT_PCR_ODE_MASK; /* PTB0, RMII0_MDIO/MII0_MDIO   */ /* PTB0, RMII0_MDIO/MII0_MDIO   */ /* internal pull up enabled on MDIO */ pctl->PCR[0] = PORT_PCR_MUX(4) | PORT_PCR_ODE_MASK | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK; With these changes, the RTCS applications work over TWR-SER2 Dual PHY channel A. On TWR-SER2, J8 and J9 are un-shunted, SW1 = 11000000, SW2 = 10100000 on TWR-K70F120M, J18 is configured to disable 50 MHz OSC, as I use 50 MHz clock source from TWR-SER2 U504 50 MHz output. This clock is used to provide reference clock for the MCU (EXTAL), as well as for the Dual PHY X1 input (RMII reference clock).
View full article
A pair of TCP server & client and a pair UDP server & client are implemented to demo socket API in RTCS. It supports K60N512 and K70F120M on IAR EWARM 6.50 at this moment. You can port it to other boards and IDE easily. 1) Copy Freescale_MQX_4_0 folder and override the default MQX folder 2) RTCS Socket Example Guide.doc can be found in ..\Freescale_MQX_4_0\rtcs\examples\socket
View full article
Hello All,   I want to share a client-server project. In this example the server can accept more than one client (Daemon server implementation). This example was created and tested using MQX4.2, CodeWarrior 10.6 and FRDM-K64F boards.     In general, the client-server model is the most common communication model used by the applications such as HTTP, Telnet, FTP, SSH, and others. In a client-server model, the server listens to client requests and waits for new connections. When a client needs to connect to a server, it sends a request. The server acknowledges the request, and if the client is supported by the server, the connection is established.   A TCP client-server communication can be implemented as in the following figure.         SETTING THE RTCS Below are presented the steps required to set the RTCS with the default settings: Create the RTCS. This step reserves memory for different RTCS parameters and initializes the TCP/IP task. Each project (server and client) contains an RTCS.c file which contains the initialize networking function with the RTCS configuration.     Set the RTCS IP address to the device after initialization. The main.h files have the macros and variables that store the IP parameters. You can change the IP address according your needs. In RTCS.c files,  the following code sets the address, mask, gateway and server IP addresses. ip_addr = IPADDR(A,B,C,D); phy_addr = BSP_DEFAULT_ENET_DEVICE; . . . ip_data. ip = ip_addr; ip_data. mask = ENET_IPMASK; ip_data. gateway = 0;     Calculate the MAC address for the device using the variables. Use the ENET_get_mac_address() function to build a valid MAC address for the application. MAC address calculation takes the device number and IP address as parameters, and returns a valid MAC address in the IPCFG_default_enet_address variable.   Initialize the Ethernet device available in the board with the calculated MAC address. Use the ipcfg_init_device() function to tell the RTCS task what Ethernet device should be used and to set the calculated MAC address to that device. Once the MAC address is set and the device is initialized, it is possible to bind the device to the IP address. error = ipcfg_init_device (phy_addr, serverAddress);     After Ethernet device initialization, bind the device to the IP address and it is ready to communicate. /* If DHCP Enabled, get IP address from DHCP server */              if (dhcp) {                     printf( "\nDHCP bind ... " );                     error = ipcfg_bind_dhcp_wait (phy_addr, 1, &ip_data);                     if (error != IPCFG_ERROR_OK) {                            printf( "Error %08x!\n" , error);                     }                     else {                            printf( "Successful!\n" );                     }              } else {        /* Else bind with static IP */                     printf ( "\nStatic IP bind ... " );                     error = ipcfg_bind_staticip (phy_addr, &ip_data);                       if (error != IPCFG_ERROR_OK) {                            printf( "Error %08x!\n" ,error);                     }                     else {                            printf( "Successful!\n" );                     }              }     SERVER IMPLEMENTATION              For the server implementation, MQX uses a socket structure that is created and filled in this way: laddr. sin_family       = AF_INET; laddr. sin_port         = CONNECT_PORT; laddr. sin_addr . s_addr = INADDR_ANY;   The socket() function creates an unbound socket in a communications domain. This function also returns a handler used in later function calls that operate on sockets. /* Listen on TCP port */ listensock = socket(PF_INET, SOCK_STREAM, 0); if (listensock == RTCS_SOCKET_ERROR) { error = RTCSERR_OUT_OF_SOCKETS; }   The bind() function assigns a local socket address to a socket and the listen() function marks a socket as accepting connections. error = bind (listensock, &laddr, sizeof (laddr)); if (!error) {        error = listen (listensock, 0); }   The accept() function extracts the first connection on the queue of pending connections, creates a new socket with the same socket type protocol and address family as the specified socket, and allocates a new file descriptor for that socket. child_sock = accept (listensock, NULL, NULL);   The recv() function receives a message from a socket. error = recv (sock, ( void *)cRecvBuff, sizeof (cRecvBuff), MSG_WAITALL);                     The send() function initiates transmission of a message from the specified socket to its peer. The send() function sends a message only when the socket is connected. error= send (sock, ( void *)cRecvBuff, sizeof (cRecvBuff), 0);     The messages received are checked in order to toggle a LED or shutdown the connection. while (1)        {              error = recv (sock, ( void *)cRecvBuff, sizeof (cRecvBuff), MSG_WAITALL);              printf( "Received: %s\n" , cRecvBuff);              if (error == RTCS_ERROR)              {                     printf( "There was an error code % lx \n" , RTCS_geterror (sock));                     shutdown(sock, FLAG_CLOSE_TX);                     return ;              }              if (cRecvBuff[0]== 'T' )              {                     printf( "Received: %s\n" , cRecvBuff);                     printf( "LED was toggled from child\r\n" );                     lwgpio_toggle_value (&led1);              }              if (cRecvBuff[0]== 'G' )              {                                              printf( "Received: %s\n" , cRecvBuff);                     printf( "Shutting down connection\n" );                     shutdown(sock,FLAG_CLOSE_TX);                     _time_delay (2000);                      _task_abort (MQX_NULL_TASK_ID);              }            }             CLIENT IMPLEMENTATION   For the client implementation, it uses a socket structure that is created and filled in this way: addr. sin_family       = AF_INET; addr. sin_port         = DESTPORT; addr. sin_addr . s_addr = IPADDR(192,168,1,200); //Server address   The socket() function creates an unbound socket. sock = socket(PF_INET, SOCK_STREAM, 0);     The connect() function attempts to make a connection on a socket. error = connect (sock, &addr, sizeof (addr));        The recv() function receives a message from a socket. error= recv (sock, ( void *)cReadBuff, sizeof (cReadBuff), 0);          The send() function sends a message only when the socket is connected (including when the peer of a connectionless socket has been set via connect() function). error = send (sock, ( void *)cReadBuff, sizeof (cReadBuff), 0);          In addition the client example can toggle a LED in the server board or destroy the socket. /*****Infinite loop waiting for user to push a button***/ while (1){        if ( lwgpio_get_value (&btn1) == LWGPIO_VALUE_LOW )        {              _time_delay (150);              sprintf(( char *)cReadBuff, "Toggle from client2\n" );              printf( "Sending: %s" , cReadBuff);              error = send (sock, ( void *)cReadBuff, sizeof (cReadBuff), 0);              if (error == RTCS_ERROR)              {                     printf( "There was an error trying to send to the server\n" );                     return ;              }        }        if ( lwgpio_get_value (&btn2) == LWGPIO_VALUE_LOW )        {              _time_delay (150);              sprintf(( char *)cReadBuff, "GoodBye\n" );              printf( "Sending: %s" , cReadBuff);              error = send (sock, ( void *)cReadBuff, sizeof (cReadBuff), 0);              if (error == RTCS_ERROR)              {                     printf( "There was an error trying to send to the server\n" );                     return ;              }              printf( "Shutting down connection\n" );              shutdown(sock,FLAG_CLOSE_TX);              _task_abort (MQX_NULL_TASK_ID);        }       I hope this helps, Soledad Original Attachment has been moved to: ClientD_FRDM-K64_MQX4_2_CW10_6.zip Original Attachment has been moved to: ServerDeamon_FRDM-K64_MQX4_2_CW10_6.zip
View full article
Store web pages externally step by step Web pages can be stored on any media accessible via MFS, such as USB memory stick, SD card. It is also possible to use FFS and store web pages on NAND flash. The following example is a step by step guide on how MQX can use nandflash on TWR-K70F120M, we start with the httpsrv demo. 1. Add FTP server  and nandflash flush support This demo starts with default HTTPSRV example, Shell console is enabled in the default httpdsrv.c. Ping, ipconfig and help commands are enabled by default. We add ftpsrv application to support FTP protocol , and nandflash support. 2. Allow RTCS for more sockets We will use two TCP servers. There is one socket need for HTTPSRV listening socket, second listening socket for FTP server. One socket for each connected client. 3 .Add MFS library to the HTTPSRV build project By default, MFS library is not enabled in the HTTPSRV project. It uses only TFS for web pages storage. We add path to MFS library into HTTPSRV build project   4. Add FFS support to the HTTPSRV build project Ffs library is not enabled by default. We need to add path into HTTPSRV build library. Install FFS driver and open it. 5. Resolve build errors When we try to build now the HTTPSRV example, we have compile errors. This is because by default the HTTPSRV example does not include MFS and FFS library head files. We need to add a path for MFS and FFS 6. Configure HTTPSRV root directory Web pages of this demo are to be stored in nandflash within web_pages folder. We need to set rootdir and index Before we can view the web page in browser, we need to copy web pages to nand flash. This is the purpose of FTP server, as one example how to copy files. If you wish to be sure the web pages survive power cycle, make sure you flush the FFS file system after “web_pages” are copied. 7. Build, Download, Execute As hardware we use TWR-K70F120M and TWR-SER. After you download the executable and run, start FTP server by issuing command “ftpsrv  start” on serial console; start FTP client; copy over files from PC host to TWR nandflash. Keep the folder structure of the copied files; now open your web browser (support for HTML5 is required); open Url http://192.168.1.202
View full article
MQX RTCS Memory Configuration Parameters Introduction         RTCS uses some global variables when an application creates it. All the variables have default values. If you want to change the values, the application must do so before it creates RTCS. There are various configuration parameters that allow to fine tune RTCS memory usage. Next I will introduce the parameters, and I hope it will help beginners in configuration the RTCS correctly 1    _RTCSPCB / _RTCS_msgpool / _RTCS_socket_part RTCSPCB represents the pool of Packet Control Blocks - the number of packets you want RTCS to handle at any given time. RTCSPCB has influence on losing packets. RTCS_msgpool represents the pool of RTCS messages, used to encapsulate application requests to RTCS – the number of simultaneous application requests to RTCS. RTCS_Sockets represents the pool of sockets – the number of sockets in existence at any point in time. “_init” is pre-allocated count, allocation happens when RTCS starts. During runtime, when RTCS needs more of these resources, it allocates more by "_grow" chunks until the "_max" is consumed, which is the effective limit for RTCS resources. These parameters must be called before _RTCS_start By default these parameters are defined as RTCSCFG_PCBS_INIT, RTCSCFG_PCBS_GROW, RTCS_PCBS_MAX, RTCSCFG_MSGPOOL_INIT, RTCSCFG_MSGPOOL_GROW, RTCSCFG_PCBS_MAX, RTCSCFG_SOCKET_PART_INIT, RTCSCFG_SOCKET_PART_GROW,  RTCSCFG_SOCKET_PART_MAX. In application we can override these defaults by _init, _grow, _max. We also can override these in user_config.h. How to configure these parameters?   We don’t have a formal method how to configure these for a specific application. We can start with the defaults and then spent some time increasing these parameters, then we can use RTCS TAD window to see, what RTCS resources are out. Then increase the one a bit. Example:  the configuration in web_hvac demo _RTCSPCB_init = 4; _RTCSPCB_grow = 2; _RTCSPCB_max = 20; _RTCS_msgpool_init = 4; _RTCS_msgpool_grow = 2; _RTCS_msgpool_max  = 20; _RTCS_socket_part_init = 4; _RTCS_socket_part_grow = 2; _RTCS_socket_part_max  = 20; RTCS_Create(); 2  Tx Window Size and Rx Window Size Each socket requires to allocation Tx and Rx window size for a listening socket and then for each connected client.  The default tx window size and rx window size are 4380 bytes. With TAD, we can see that every new TCP socket connection needs extra 500+4392x2+148=9432B   as follows: MQX -> Lightweight Memory Block Summary Size (Decimal) Owner    Type 500      0x10001 TCP Control Block;RTCS/TCP 4392 0x10001  TCP Tx Window;RTCS/TCP 4392 0x10001  TCP Rx Window;RTCS/TCP 148 0x10001  TCP Send Clock;RTCS/TCP (TCP/IP Task id is 0x10001) If we call setsockopt() to reduce these two buffers, for example,            uint_32 value; … value = 1024; setsockopt(sock, SOL_TCP,OPT_TBSIZE,&value,sizeof(value)); setsockopt(sock, SOL_TCP,OPT_RBSIZE,&value,sizeof(value)); The memory usage to open a new TCP socket will drop as follows: MQX -> Lightweight Memory Block Summary Size (Decimal) Owner    Type 500  -> 500   0x10001  TCP Control Block;RTCS/TCP 4392 -> 1108   0x10001 TCP Tx Window;RTCS/TCP 4392 -> 1108   0x10001  TCP Rx Window;RTCS/TCP 148  -> 84   0x10001  TCP Send Clock;RTCS/TCP So we can see that, every new socket connection needs extra 500+1108*2+84=2800
View full article
If you have noticed many TCP Retransmission, Out Of Order or Duplicate Acknowledge packets while running a TCP/IP application based on MQX RTCS then you may be interested in this article. After some investigation it comes to be that the default value of global variable _TCP_rto_min may cause this congestion depending on your application. Finally this problem was solved by setting a new value to this variable after calling function RTCS_create(). This article explains what is behind this behavior and how _TCP_rto_min affects the performance in an application using RTCS.
View full article
Hi All, The new Freescale MQX™ 4.1.1 GA release is now available on www.freescale.com/mqxrtos ·          Files available           # Name Description 1 FSL_MQX_RELEASE_NOTES_4_1_1 Freescale   MQX™ RTOS 4.1.1 Release Notes 2 Freescale   MQX RTOS 4.1.1 for Linux This   release has the same basic code as the 4.1.1 version, with just the changes   needed to build and debug on Linux systems. 3 Freescale   MQX RTOS 4.1.1 MQX™    Source code. Includes an RTOS, File System, TCP/IP and USB host/device   software stacks. ·          What is New? ·          New Board Support Package o    FRDM-K64F o    TWR-K64F120M ·          New Features and Updates o    MQX RTOS 4.1.1 enables development on Linux machines o    MQX RTOS 4.1.1 supports the new Freescale IDE, Kinetis Design Studio o    Example ISR and related documentation is updated to give guidance on setting up a Kernel ISR (a.k.a Gorilla ISR) - extremely high priority ISR o    Power PC (PX) family support has been dropped o    Readme files are added to examples without a description o    Register definition header files for Kinetis MCUs are added for convenience when porting to an MCU sub-family device o    Both interrupt driven I2C master and slave mode drivers are changed to support synchronous blocking mode and share the same API with the polling driver variant.  Improves performance by eliminating the need to poll for data availability. ·          Known issues o    For known issues and limitations please consult the release notes
View full article
Atheros WiFi Tower Module (TWR-WIFI-AR4100P) support patch for Freescale MQX™ 4.0.2  is available at MQX Downloads. Files available # Name Description 1 FSL_MQX_ATHEROS_RELEASE_NOTES_4_0_2  Freescale   MQX™ Atheros Wifi package 4.0.2 Release Notes 2 Freescale   MQX RTOS 4.0.2 Atheros Wifi package Atheros   Wifi solution for MQX™ 4.0.2
View full article