Keil MDK TCP/IP stack basic configuration

RTX integration

  • According to the MDK Middleware recommendations, these are the changes to make to the RTX configuration file, CMSIS/RTX_Config_CM.c:
    • Increase the Number of concurrent running user threads by 2
    • Increase the Number of threads with user-provided stack size by 2
    • Increase Total stack size [bytes] for threads with user-provided stack size by 1536 bytes
    • Enable User Timers

For RTX5 just use the same config you used without the TCP/IP stack

MDK integration

  • Add the proper libraries to the Run-Time Environment configuration; in the Run-Time Environment management window:

    • for CMSIS Driver, used as Ethernet driver: select CMSIS Driver -> Ethernet MAC (API) -> Ethernet MAC and CMSIS Driver -> Ethernet PHY (API) -> LAN8742A (check the correct PHY for your hardware, this one is the one used on the Nucleo boards)Keil MDK Manage Run-Time Environment
    • for MDK itself:
      • set Network Variant as either MDK-Plus or MDK-Professional, depending on your license
      • set Network -> Interface -> ETH count to 1
      • select Network -> Core and its Variant as IPv4 Release
      • select Network -> Socket -> BSD, Network -> Socket -> TCP, andNetwork -> Socket -> UDPKeil MDK Manage Run-Time Environment
  • Then there are several config files we need to change according to our application. All support using the Configuration Wizard

    • In Network/Net_Config_ETH_0.h:
      • select IPv4, uncheck NetBIOS Name Service and check Dynamic Host Configuration (DHCP); or set your static configuration if not using DHCP
      • Optionally enable IPv6 as you wish
      • we can configure our MAC address here too
    • In Network/Net_Config.c, only if you won't use DHCP, untick Start System Services. You can change your host name here in case you'd like to use NetBIOS
    • In Network/Net_Config_BSD.h set
      • Number of BSD Sockets 10 - Try to serve as many simultaneous connections as possible within our constraints
      • Number of Streaming Server Sockets 2 - the number of listening servers, we just need 1 now but soon we'll be expanding
      • In Network/Net_Config_TCP.h set Number of TCP Sockets 10 (as many as BSD sockets)
      • In Network/Net_Config_UDP.hset Number of UDP Sockets 11 (as many as BSD + one for DHCP)
  • Finally, in the project configuration (Project -> Options for Target 'Target 1'):

    • in the Linker tab we've added Misc Controls: --diag_suppress 6918 to silence a warning due to padding on a RAM region (this belongs to CMSIS-Driver)

We didn't change any other default parameters, this is just an approach; for serious work and performance, a tuning operation might be needed.

Initialization

  • Create an app_main task
    • Initialize the network
    • Wait on a signal/flag that will be set by the netDHCP_Notify() hook when the server assigns us an address.
    • Create the server task to run Mongoose, and terminate.

RTX:

RTX5:

For more information consult the MDK Middleware documentation