W5100 Driver for PSoC

details

General Description

The W5100 interface driver provides a simple software driver for using the WIZnet W5100 iEthernet controller with a PSoC (Programmable System-on-Chip) project. The driver can be customized to support many system configurations, and allows for SPI port sharing. Both the SPIM and the SCB interfaces are supported to allow the driver to support many hardware configurations of the application.

 

PSoC_W5100_Driver

 

Features

  • Compatible with PSoC 3, 4, 5, and 5LP
  • SPI port independent (Uses Either SCB or SPIM)
  • Supports TCP, UDP, and ARP
  • 4 simultaneous protocol Sockets
  • 2K off-processor packet buffer per socket

 

Future Plans (Driver version 2)

 

Source code (GitHub) : https://github.com/e2forlife/PSoC-W5100-Driver/tree/Release-1.2

Cypress Community Components

 

Evaluation

Hardware Connection

I mainly use the PSoC Pioneer (PSoC 4) and the FreeSoC Explorer (PSoC 5LP) as test beds for component development, and for the W5100, there happens to be a handy Arduino shield (Ethernet Shield, $38 Digikey) available so no hand wiring today.

For the PSoC 4, just plug the shield in to the Arduino compatible pins on the the Pioneer board (making sure that you’ve soldered in the 6-pin SPI connector), however, the PSoC 5LP setup takes a little more effort since the Explorer does not have the Arduino 6-pin SPI interconnect.  So, we just jumper wire from the MISO, MOSI, and SCK pins on the 6-pin socket of the Ethernet Shield to The P4 connector I/O of the explorer.

SignalPSoC 4PSoC 5LP
CSnP3[4]P5[2]
SCKP0[6]P0[6]
MOSIP3[0]P3[0]
MISOP3[1]P3[1]

Project Setup

libImport

Once the hardware is set up (or your custom board is built), you need to add the e2forlife_W5100.cylib to the project workspace and set it as a dependency for your PSoC Project. This is simply accomplished by selecting File->Add->Existing Project… from the PSoC Creator menus, or by right clicking the work-space and selecting Add->Existing Project...

Select the library to add the components to the catalog.

Once the driver library project has been added to the work-space, right click the application and select “Dependencies…“. When the dialog opens, select Components check-box for the E2ForLife_W5100 user Dependencies.

Firmware

Setting up the firmware using PSoC Creator (currently 3.0) is a snap.  Just switch to the community tab, and expand the Communications/Ethernet tree.  For the PSoC 5LP, drag the “E2ForLife – W5100 (SPIM mode)” macro from the right hand selector and place it on the schematic sheet.

(PSoC 4 Users:) On the PSoC 4, there are two options available. The “E2ForLife – W5100 (SCM Mode)” Macro will utilize the new SCM hardware blocks within the device, and the “E2ForLife – W5100 (SPIM Mode)” Which will utilize UDB SPI Master Mode implementation of the interface.

Configuring Component Options

In order for the PSoC to properly communicate with the W5100 the SPI component needs to be configured to operate in 8-bit mode 0 or 3 SPI.  Depending on the board routing, clock scheme, and environment, the data rate can vary between 8 and 30 MHz.  The default configuration set by the macro initializes the SPI device for an 8 MHz data rate.

W5100 Driver options

The W5100 driver is sectioned in to Driver Configuration, Configuration, and Hardware Configuration. These sections are initialized by the macro to default values and the hardware configuration section is set function with the SPI hardware added.

PSoC 4 Note: Using the PSoC Pioneer board with the Arduino Ethernet Shield will require that the SS_NUM parameter be modified when using the SCM mode.  SS number 1 is tied to the W5100, not 0. Another big note is that you will have to modify the default SCM settings to enable 2 SS outputs from the module, assign the CSn output to SS1 when making pin assignments.

 

ParameterDescription
CMD_TIMEOUTThe number of milliseconds to wait for the W5100 command to execute before declaring a timeout
INCLUDE_TCPFlag used to include the code for the support of TCP/IP. Since TCP is directly handled by the device, only minimal code is required for TCP networking
INCLUDE_UDPInclude the protocol processing for UDP
INIT_DELAYThe number of milliseconds to wait for the device PLL to lock after a reset or power on
TIMEOUTThe number of milliseconds before declaring a generic timeout
GATEWAYThe default gateway IP address for which the W5100 will be configured
IPThe IP Address for the device when operating with fixed IP addressing.
MACThe MAC Hardware Address for which the W5100 will be configured
SUBNET_MASKThe subnet mask to be used for Ethernet communications. Typically 255.255.255.0
SPI_INSTANCEThe instance name of the SPI interface. Configure this to be the name of the interface component for the SPI communications interface.
SS_NUMInteger index of the slave select from the SPI interface. This is used for the SCM component interface for PSoC 4

Software

For this post, I’m concentrating on getting up and running using the driver, so the application will start, initialize the board hardware, then open a simple telnet server and wait for a connection.  Once the connection is established, it will print “Hello From E2ForLife.com” and end.

For this we will use 7 functions from the API.  First we will call W5100_Start() to initialize the W5100 device and local driver data.  Next we will create and open a socket using the W5100_TcpOpen(), and start a server using the W5100_TcpStartServerWait().  And lastly use the W5100_TcpPrint() to send the data followed by W5100_TcpDisconnect() and W5100_SocketClose() to terminate the connection

 

The startup and in initialization section of the code mainly performs only 2 functions in this case: Start the hardware, Start the driver amp; initialize the W5100 registers.  The hardware initialization is executed using the Cypress API call for the SPIM component (or the corresponding SCB for PSoC 4). Following thisW5100_Start() is called from the W5100 driver API.  This function initializes the internal RAM used by the driver and configures the hardware registers within the W5100.

 

Within the main loop, the socket is opened, a servers is started, output is transferred, and the the connection is terminated.  First,  the socket is opened through a call to W5100_TcpOpen() with the active port passed as a parameter.  In this case, we used the Tcp port 23, since we are going to start a telnet server.  The next step in this simple application is to start a server and wait for connections.  Since we are not doing anything of value while waiting, I used the simple API call W5100_TcpStartServerWait(), which will start a server on the open socket passed, and wait for a connection to be established.

 

w5100-output

 

Once the connection has been established, the API call will return, allowing the application to send it’s string using theW5100_TcpPrint() call to send a string (ASCII-Z style) to the remote client using TCP.  After that, we just close the connection gracefully by disconnecting (W5100_TcpDisconnect), and then close the socket to free the socket to be opened for another function using theW5100_SocketClose() API call.

So, there you have it… A very simple Telnet server using the W5100 driver.

Check out the source repository here.

 

General Description

The W5100 interface driver provides a simple software driver for using the WIZnet W5100 iEthernet controller with a PSoC (Programmable System-on-Chip) project. The driver can be customized to support many system configurations, and allows for SPI port sharing. Both the SPIM and the SCB interfaces are supported to allow the driver to support many hardware configurations of the application.

 

PSoC_W5100_Driver

 

Features

  • Compatible with PSoC 3, 4, 5, and 5LP
  • SPI port independent (Uses Either SCB or SPIM)
  • Supports TCP, UDP, and ARP
  • 4 simultaneous protocol Sockets
  • 2K off-processor packet buffer per socket

 

Future Plans (Driver version 2)

 

Source code (GitHub) : https://github.com/e2forlife/PSoC-W5100-Driver/tree/Release-1.2

Cypress Community Components

 

Evaluation

Hardware Connection

I mainly use the PSoC Pioneer (PSoC 4) and the FreeSoC Explorer (PSoC 5LP) as test beds for component development, and for the W5100, there happens to be a handy Arduino shield (Ethernet Shield, $38 Digikey) available so no hand wiring today.

For the PSoC 4, just plug the shield in to the Arduino compatible pins on the the Pioneer board (making sure that you’ve soldered in the 6-pin SPI connector), however, the PSoC 5LP setup takes a little more effort since the Explorer does not have the Arduino 6-pin SPI interconnect.  So, we just jumper wire from the MISO, MOSI, and SCK pins on the 6-pin socket of the Ethernet Shield to The P4 connector I/O of the explorer.

SignalPSoC 4PSoC 5LP
CSnP3[4]P5[2]
SCKP0[6]P0[6]
MOSIP3[0]P3[0]
MISOP3[1]P3[1]

Project Setup

libImport

Once the hardware is set up (or your custom board is built), you need to add the e2forlife_W5100.cylib to the project workspace and set it as a dependency for your PSoC Project. This is simply accomplished by selecting File->Add->Existing Project… from the PSoC Creator menus, or by right clicking the work-space and selecting Add->Existing Project...

Select the library to add the components to the catalog.

Once the driver library project has been added to the work-space, right click the application and select “Dependencies…“. When the dialog opens, select Components check-box for the E2ForLife_W5100 user Dependencies.

Firmware

Setting up the firmware using PSoC Creator (currently 3.0) is a snap.  Just switch to the community tab, and expand the Communications/Ethernet tree.  For the PSoC 5LP, drag the “E2ForLife – W5100 (SPIM mode)” macro from the right hand selector and place it on the schematic sheet.

(PSoC 4 Users:) On the PSoC 4, there are two options available. The “E2ForLife – W5100 (SCM Mode)” Macro will utilize the new SCM hardware blocks within the device, and the “E2ForLife – W5100 (SPIM Mode)” Which will utilize UDB SPI Master Mode implementation of the interface.

Configuring Component Options

In order for the PSoC to properly communicate with the W5100 the SPI component needs to be configured to operate in 8-bit mode 0 or 3 SPI.  Depending on the board routing, clock scheme, and environment, the data rate can vary between 8 and 30 MHz.  The default configuration set by the macro initializes the SPI device for an 8 MHz data rate.

W5100 Driver options

The W5100 driver is sectioned in to Driver Configuration, Configuration, and Hardware Configuration. These sections are initialized by the macro to default values and the hardware configuration section is set function with the SPI hardware added.

PSoC 4 Note: Using the PSoC Pioneer board with the Arduino Ethernet Shield will require that the SS_NUM parameter be modified when using the SCM mode.  SS number 1 is tied to the W5100, not 0. Another big note is that you will have to modify the default SCM settings to enable 2 SS outputs from the module, assign the CSn output to SS1 when making pin assignments.

 

ParameterDescription
CMD_TIMEOUTThe number of milliseconds to wait for the W5100 command to execute before declaring a timeout
INCLUDE_TCPFlag used to include the code for the support of TCP/IP. Since TCP is directly handled by the device, only minimal code is required for TCP networking
INCLUDE_UDPInclude the protocol processing for UDP
INIT_DELAYThe number of milliseconds to wait for the device PLL to lock after a reset or power on
TIMEOUTThe number of milliseconds before declaring a generic timeout
GATEWAYThe default gateway IP address for which the W5100 will be configured
IPThe IP Address for the device when operating with fixed IP addressing.
MACThe MAC Hardware Address for which the W5100 will be configured
SUBNET_MASKThe subnet mask to be used for Ethernet communications. Typically 255.255.255.0
SPI_INSTANCEThe instance name of the SPI interface. Configure this to be the name of the interface component for the SPI communications interface.
SS_NUMInteger index of the slave select from the SPI interface. This is used for the SCM component interface for PSoC 4

Software

For this post, I’m concentrating on getting up and running using the driver, so the application will start, initialize the board hardware, then open a simple telnet server and wait for a connection.  Once the connection is established, it will print “Hello From E2ForLife.com” and end.

For this we will use 7 functions from the API.  First we will call W5100_Start() to initialize the W5100 device and local driver data.  Next we will create and open a socket using the W5100_TcpOpen(), and start a server using the W5100_TcpStartServerWait().  And lastly use the W5100_TcpPrint() to send the data followed by W5100_TcpDisconnect() and W5100_SocketClose() to terminate the connection

 

The startup and in initialization section of the code mainly performs only 2 functions in this case: Start the hardware, Start the driver amp; initialize the W5100 registers.  The hardware initialization is executed using the Cypress API call for the SPIM component (or the corresponding SCB for PSoC 4). Following thisW5100_Start() is called from the W5100 driver API.  This function initializes the internal RAM used by the driver and configures the hardware registers within the W5100.

 

Within the main loop, the socket is opened, a servers is started, output is transferred, and the the connection is terminated.  First,  the socket is opened through a call to W5100_TcpOpen() with the active port passed as a parameter.  In this case, we used the Tcp port 23, since we are going to start a telnet server.  The next step in this simple application is to start a server and wait for connections.  Since we are not doing anything of value while waiting, I used the simple API call W5100_TcpStartServerWait(), which will start a server on the open socket passed, and wait for a connection to be established.

 

w5100-output

 

Once the connection has been established, the API call will return, allowing the application to send it’s string using theW5100_TcpPrint() call to send a string (ASCII-Z style) to the remote client using TCP.  After that, we just close the connection gracefully by disconnecting (W5100_TcpDisconnect), and then close the socket to free the socket to be opened for another function using theW5100_SocketClose() API call.

So, there you have it… A very simple Telnet server using the W5100 driver.

Check out the source repository here.

 

COMMENTS

Please Login to comment
  Subscribe  
Notify of