This project is a minimal Lightweight IP implementation.
If you follow the steps, you'll have a LaunchPad that will connect to your network, request an IP address, and log that address to your terminal.That's it. The real bare minimal point that you can use as a start for your own IP related projects.
Based on HALCoGen Ethernet Driver and lwIP Integration Demonstrationhttp://processors.wiki.ti.com/index.php/HALCoGen_Ethernet_Driver_and_lwIP_Integration_Demonstrationand on the LaunchPad specific settings as documented in http://processors.wiki.ti.com/index.php/LAUNCHXL2_570LC43:_lwIP_Demo.
Install Demo Software with lwIP LibraryThe software is available from the TI wiki. Look for the latest version that supports TMS570LC43x / RM57x. http://processors.wiki.ti.com/index.php/HALCoGen_Ethernet_Driver_and_lwIP_Integration_DemonstrationDownload and install it. I'm using version 00.03.00 in this document
Configure the microcontroller in HALCoGenCreate new projectFile -> New -> Project
Select Device TMS570LC4357ZWT or RM57L843ZWT. When naming the project, take care to use the same name later in CCS, and check that the location is your CCS working directory.
Short route: import the attached DIL file into your HALCoGen project and skip to 'Generate Code'.
Enable DriversIn the Driver Enable tab, select GIO, SCI1 and EMACSCI1 will be used to do serial communication over the USB COM port.GIO is needed to drive a few LAN lines.EMAC is the Ethernet driver.
Configure TIMER
On the ECLK tab, enable ECLK Pin mode, set the divider to 3 (we need an ECLK of 25 MHz),check Continue on suspend.
I'm quoting the instructions that TI has written for that on http://processors.wiki.ti.com/index.php/LAUNCHXL2_570LC43:_lwIP_Demo :
PIN Muxing tab:
Select MII to enable that peripheral.
This is needed to put the EMAC in the right mode. But this has as side effect that a number of pins get MUXed that should keep their default value. So, we have to reset these pins.
Uncheck the MII and MDIO signals on Balls A14, B4, B11, D19, E18, F3, G3, G19, H18, H19, J18, J19, K19, N19, P1, R2, and V5.These rows should now be blank, although you can select non-ethernet functions if desired instead.
Example:
Change the selection on balls T4, U7 to the default functions (from MII_RX_AVCLK4 to MII_RXCLK, and from MII_TX_AVCLK4 to MII_TX_CLK).The PHY will provide these clocks to the MAC on the launchpad.
Input Pin Muxing tab:
Set all input MII and MDIO signals to default. In the project that we're creating here, that should already be the case. Just do a verification.
MDIO=F4, MII_COL=W4, MII_CRS=V4, MII_RX_DV=U6, MII_RX_ER=U5, MII_RXCLK=T4, MII_RXD[0]=U4, MII_RXD[1]=T3, MII_RXD[2]=U3, MII_RXD[3]=V3, MII_TX_CLK=U7
Example:
In the SCI1 - SCI Data Format tab, validate that the baud rate is 9600, with 8 bits length and 2 stop bits
Use the same settings later in your terminal program to monitor the output.
Configure GIOIn the GIO - Port A tab, mark bit 3 and 4 as output, and set them high.
They are connected to DP83630 Precision PHYTER. Setting them high releases the PHY from reset and power down.
Configure EMACThe EMAC address and Physical address will be available in your main c source file.
On the VIM RAM tab, set the following interrupt handlers:
77: EMACCore0TxIsr79: EMACCore0RxIsr
On the VIM Channel 64-95 tab, enable channel 77 and 79.
This is the biggest chunk of work. Take care that the memory settings match the screen captures below.On the R5-MPU-PMU tab, replicate these settings:
All configuration is complete. Save the project and generate the code.File -> Save ProjectFile -> Generate Code
Write your Program in Code Composer Studio
Create new projectFile -> New -> CCS Project
Select TMS570LC43xx or RM57L8xx as target.Use the XDS110 debugger.
Check that the location is the same directory that was used in HALCoGen above.Choose Empty Project. HALCoGen has already created all source files we need.
for HALCoGen Versions older than June 2015 only, replace the source/HL_sys_link.cmd file generated by HALCoGen by the one from this url:http://processors.wiki.ti.com/index.php/LAUNCHXL2-570LC43-RM57L:_LinkerECCRecommendation
Right click on your project, and select Properies
Add the HALCoGen generated include files to the project include path.
Set the Debug Flash options as documented on the url above.
Create a new Source file lwip_functions.c
This file will hold our lwIP related code
Right-click on the source folder, and select New -> Source File
Enter lwip_functions.c as filename, and select the default c template.
Add these lines
/*
** Interrupt Handler for Core 0 Receive interrupt
*/
/*
** lwIP Compile Time Options for HDK.
*/
#include "lwiplib.h"
#include "HL_sci.h"
#include "lwip\inet.h"
#include "locator.h"
#define sciREGx sciREG1
uint8_t txtCRLF[] = {'\r', '\n'};
uint8_t txtErrorInit[] = {"-------- ERROR INITIALIZING HARDWARE --------"};
uint8_t txtIPAddrTxt[] = {"Device IP Address: "};
uint8_t * txtIPAddrItoA;
volatile int countEMACCore0RxIsr = 0;
#pragma INTERRUPT(EMACCore0RxIsr, IRQ)
void EMACCore0RxIsr(void)
{
countEMACCore0RxIsr++;
lwIPRxIntHandler(0);
}
/*
** Interrupt Handler for Core 0 Transmit interrupt
*/
volatile int countEMACCore0TxIsr = 0;
#pragma INTERRUPT(EMACCore0TxIsr, IRQ)
void EMACCore0TxIsr(void)
{
countEMACCore0TxIsr++;
lwIPTxIntHandler(0);
}
void IntMasterIRQEnable(void)
{
_enable_IRQ();
return;
}
void IntMasterIRQDisable(void)
{
_disable_IRQ();
return;
}
unsigned int IntMasterStatusGet(void)
{
return (0xC0 & _get_CPSR());
}
void sciDisplayText(sciBASE_t *sci, uint8_t *text,uint32_t length)
{
while(length--)
{
while ((sci->FLR & 0x4) == 4); /* wait until busy */
sciSendByte(sci,*text++); /* send out text */
};
}
void EMAC_LwIP_Main (uint8_t * macAddress)
{
unsigned int ipAddr;
struct in_addr devIPAddress;
sciInit();
/* Enable the interrupt generation in CPSR register */
IntMasterIRQEnable();
_enable_FIQ();
/* Initialze the lwIP library, using DHCP.*/
ipAddr = lwIPInit(0, macAddress, 0, 0, 0, IPADDR_USE_DHCP);
if (0 == ipAddr) {
sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
sciDisplayText(sciREGx, txtErrorInit, sizeof(txtErrorInit));
sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
} else {
/* Convert IP Address to string */
devIPAddress.s_addr = ipAddr;
txtIPAddrItoA = (uint8_t *)inet_ntoa(devIPAddress);
LocatorConfig(macAddress, "LaunchPad enet_lwip");
sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
sciDisplayText(sciREGx, txtIPAddrTxt, sizeof(txtIPAddrTxt));
sciDisplayText(sciREGx, txtIPAddrItoA, 16);
sciDisplayText(sciREGx, txtCRLF, sizeof(txtCRLF));
/* Loop forever. All the work is done in interrupt handlers. */
while(1)
{
}
}
}
Edit HL_phy_dp83640.h
Edit the HL_phy_dp83640.h file.We'll have to change the content of that file to make it work with the on-board DP83630.We're actually fooling the system a little bit here. The step may not be neccessary later when this PHYTER ship gets HALCoGen support.
/* USER CODE BEGIN (2) */
#undef DP83640_PHY_ID
#define DP83640_PHY_ID (0x20005CE1u)
/* USER CODE END */
Add the Logic to the Main File
Edit the HL_sys_main.c file.
Add these lines
/* USER CODE BEGIN (1) */
#include "HL_gio.h"
#include "HL_emac.h"
extern void EMAC_LwIP_Main (uint8_t * emacAddress);
/* USER CODE END */
Add these lines
/* USER CODE BEGIN (3) */
gioInit();
EMAC_LwIP_Main(emacAddress);
/* USER CODE END */
Include lwIP librariesWe'll have to add the lwIP sources, add the includes to tproject, and exclude some files from the build.
As a first step, we'll list the location of our installation as a variable. This can later be used to add includes, etc.
On the project property page, add the location of the lwIP install as a Path variable lwIP_INSTALL_ROOT.
My install path is C:\ti\Hercules\HALCoGen EMAC Driver with lwIP Demonstration\v00.03.00\lwip-1.4.1 .
Then we add the lwIP as a source folder.
- Right click on the project, and select New -> Folder
- Select Advanced
- Select Link to alternate location
- Select Variables - > lwIP_INSTALL_ROOT
- Add the neccessary include locations in the properties dialog
"${lwIP_INSTALL_ROOT}/src/include/ipv4"
"${lwIP_INSTALL_ROOT}/ports/hdk/include"
"${lwIP_INSTALL_ROOT}/src/include"
"${lwIP_INSTALL_ROOT}"
Exlude the following files and folders from compilation, by right-clicking on them and selecting Exclude from build. You can select multiple entries at once with the CTRL key down. That speeds up the exercise a bit.
Example:
ports/hdk/netif/hdkif.c
ports/hdk/locator.c
ports/hdk/perf.c
ports/hdk/sys_arch.c
src/core/ip4
src/core/snmp
src/core/dhcp.c
src/core/dns.c
src/core/init.c
src/core/mem.c
src/core/memp.c
src/core/netif.c
src/core/pbuf.c
src/core/raw.c
src/core/stats.c
src/core/sys.c
src/core/tcp_in.c
src/core/tcp_out.c
src/core/tcp.c
src/core/udp.c
src/netif/ppp/auth.c
src/netif/ppp/chap.c
src/netif/ppp/chpms.c
src/netif/ppp/fsm.c
src/netif/ppp/ipcp.c
src/netif/ppp/lcp.c
src/netif/ppp/magic.c
src/netif/ppp/md5.c
src/netif/ppp/pap.c
src/netif/ppp/ppp_oe.c
src/netif/ppp/ppp.c
src/netif/ppp/randm.c
src/netif/ppp/vj.c
src/netif/etharp.c
src/netif/loopif.c
src/netif/slipif.c
src/api
/apps
/doc
/test
Define the processor used as a Predefined SymbolIn the project properties dialog, add _TMS570LC43x_ or _RM57Lx_
Add the lwipopts.h File to your include/ folder
With a file explorer, navigate to your example install dir (for me C:\ti\Hercules\HALCoGen EMAC Driver with lwIP Demonstration\v00.03.00\) and copy the file lwipopts.h from example\hdk\incIn CCS, right click on your include folder, and paste the file.
Build and Debug your Project
You can do this in a single step by pushing the Debug icon. If you prefer, you can first use the Build icon next to it.Your LaunchPad has to be connected via USB, and a network cable plugged in, before you click Debug. You can now Resume the program and connect a Serial Terminal program to the LaunchPad's COM port. The terminal will show the IP address that you acquired from the DHCP service of your network.
Comments