UDP LOOPBACK 기능구현하고 있습니다.
네트웍 정보(IP, GW, SUB) Write/Read는 정상 동작합니다.(CPU<->W5500 SPI 통신 정상)
그런데 상대방 pc에서 ping, arp등 아무것도 안됩니다.
W5500 라이브러리 다운받아서 링크 제대로 걸었는데 왜 안되는지 도움부탁드립니다.
와이어샥으로 캡쳐시 아래 메시지만 표시됩니다.
(374 87.000196 RealtekS_36:01:c2 Broadcast ARP 42 Who has 192.168.0.20? Tell 192.168.0.2)
=>HW 구성: CPU<-SPI 통신->W5500<-트랜스포머->PC
/* Includes ------------------------------------------------------------------*/
#include “spi_w5500.h”
#include “bsp_eep.h”
#include “spi_w5500.h”
#include “main.h”
#define MAIN_DEBUG
#define TICKRATE_HZ1 (1000) /* 1000 ticks per second, for SysTick /
#define TICKRATE_HZ2 (1) / 1 ticks per second, for Timer0 /
volatile uint32_t msTicks; / counts 1ms timeTicks */
//////////////////////////////////////////////////
// Socket & Port number definition for Examples //
//////////////////////////////////////////////////
#define SOCK_TCPS 0
#define SOCK_UDPS 1
#define PORT_TCPS 5000
#define PORT_UDPS 3000
////////////////////////////////////////////////
// Shared Buffer Definition for Loopback test //
////////////////////////////////////////////////
#define BUF_SIZE 2048 // defined in loopback.h
uint8_t gDATABUF[BUF_SIZE];
wiz_NetInfo gWIZNETINFO = { .mac = {0x00, 0x08, 0xDC, 0xAB, 0xCD, 0xEF},
.ip = {192, 168, 0, 20},
.sn = {255, 255, 255, 0},
.gw = {192, 168, 0, 1},
.dns = {0, 0, 0, 0},
.dhcp = NETINFO_STATIC };
uint8_t destip[4]={192, 168, 0, 2};
uint16_t destport=PORT_UDPS;
int32_t RcvLen=0;
int pll_spi_read(uint32_t addr, uint8_t *val_p)
{
return 0;
}
int pll_spi_write(uint32_t addr, const uint8_t val)
{
}
void W5500_LowLevel_DeInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_Cmd(W5500_SPI, DISABLE);
SPI_I2S_DeInit(W5500_SPI);
W5500_SPI_CLK_INIT(W5500_SPI_CLK, DISABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = W5500_SPI_SCK_PIN;
GPIO_Init(W5500_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = W5500_SPI_MISO_PIN;
GPIO_Init(W5500_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = W5500_SPI_MOSI_PIN;
GPIO_Init(W5500_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
}
void W5500_LowLevel_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
W5500_SPI_CLK_INIT(W5500_SPI_CLK, ENABLE);
RCC_AHB1PeriphClockCmd(W5500_SPI_SCK_GPIO_CLK | W5500_SPI_MISO_GPIO_CLK |
W5500_SPI_MOSI_GPIO_CLK, ENABLE);
GPIO_PinAFConfig(W5500_SPI_SCK_GPIO_PORT, W5500_SPI_SCK_SOURCE, W5500_SPI_SCK_AF);
GPIO_PinAFConfig(W5500_SPI_MISO_GPIO_PORT, W5500_SPI_MISO_SOURCE, W5500_SPI_MISO_AF);
GPIO_PinAFConfig(W5500_SPI_MOSI_GPIO_PORT, W5500_SPI_MOSI_SOURCE, W5500_SPI_MOSI_AF);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Pin = W5500_SPI_SCK_PIN;
GPIO_Init(W5500_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = W5500_SPI_MOSI_PIN;
GPIO_Init(W5500_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = W5500_SPI_MISO_PIN;
GPIO_Init(W5500_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
}
void W5500_DeInit(void)
{
W5500_LowLevel_DeInit();
}
void W5500_SPI_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
W5500_LowLevel_Init();
W5500_CS_LOW();
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //low fix
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; // SPI_CPHA_1Edge:rising, SPI_CPHA_2Edge:falling => 1Edig fix
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(W5500_SPI, &SPI_InitStructure);
SPI_Cmd(W5500_SPI, ENABLE);
}
uint8_t W5500_SendByte(uint8_t byte)
{
u32 c_timeout=I2C_TIME;
while (SPI_I2S_GetFlagStatus(W5500_SPI, SPI_I2S_FLAG_TXE) == RESET){
if(c_timeout) --c_timeout;
else return 0;
}
SPI_I2S_SendData(W5500_SPI, byte);
while (SPI_I2S_GetFlagStatus(W5500_SPI, SPI_I2S_FLAG_RXNE) == RESET){
if(c_timeout) --c_timeout;
else return 0;
}
return SPI_I2S_ReceiveData(W5500_SPI);
}
void W5500_WriteBuffer(uint8_t* pBuffer, uint16_t NumByteToWrite)
{
//W5500_CS_LOW();
while (NumByteToWrite–){
W5500_SendByte(*pBuffer);
pBuffer++;
}
//W5500_CS_HIGH();
}
void W5500_ReadBuffer(uint8_t* pBuffer, uint16_t NumByteToRead)
{
//W5500_CS_LOW();
while (NumByteToRead–){
*pBuffer = W5500_SendByte(sFLASH_DUMMY_BYTE);
pBuffer++;
}
//W5500_CS_HIGH();
}
void wizchip_select(void)
{
//Chip_GPIO_SetPinState(LPC_GPIO, 0, 2, false); // SSEL(CS) //nam
W5500_CS_LOW();
}
void wizchip_deselect(void)
{
//Chip_GPIO_SetPinState(LPC_GPIO, 0, 2, true); // SSEL(CS) //nam
W5500_CS_HIGH();
}
uint8_t wizchip_read(void)
{
uint8_t rb;
//Chip_SSP_ReadFrames_Blocking(LPC_SSP0, &rb, 1); //nam
W5500_ReadBuffer(&rb, 1);
return rb;
}
void wizchip_write(uint8_t wb)
{
//Chip_SSP_WriteFrames_Blocking(LPC_SSP0, &wb, 1); //nam
W5500_WriteBuffer(&wb, 1);
}
static void Display_Net_Conf(void)
{
uint8_t tmpstr[6] = {0,};
DisMsg(“\r\n\r\n MAC : %02X:%02X:%02X:”, gWIZNETINFO.mac[0], gWIZNETINFO.mac[1], gWIZNETINFO.mac[2]);
DisMsg(“%02X:%02X:%02X\r\n”, gWIZNETINFO.mac[3], gWIZNETINFO.mac[4], gWIZNETINFO.mac[5]);
DisMsg(" IP : %d.%d.%d.“, gWIZNETINFO.ip[0], gWIZNETINFO.ip[1], gWIZNETINFO.ip[2]);
DisMsg(”%d\r\n",gWIZNETINFO.ip[3],0,0);
DisMsg(" GW : %d.%d.%d.“, gWIZNETINFO.gw[0], gWIZNETINFO.gw[1], gWIZNETINFO.gw[2]);
DisMsg(”%d\r\n",gWIZNETINFO.gw[3],0,0);
DisMsg(" SN : %d.%d.%d.“, gWIZNETINFO.sn[0], gWIZNETINFO.sn[1], gWIZNETINFO.sn[2]);
DisMsg(”%d\r\n",gWIZNETINFO.sn[3],0,0);
}
void W5500_Init(void)
{
uint8_t tmp;
u16 i;
uint8_t tmpstr[6];
uint8_t memsize[2][8] = { { 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 2, 2, 2, 2, 2, 2, 2 } };
//Chip_GPIO_SetPinState(LPC_GPIO, 0, 2, true); // SSEL(CS) //nam
W5500_CS_HIGH();
//Chip_GPIO_SetPinState(LPC_GPIO, 0, 22, false); // N_RESET //nam
W5500_Reset_OnOff(OFF);
delay_ms(500);
//Chip_GPIO_SetPinState(LPC_GPIO, 0, 22, true); // N_RESET //nam
W5500_Reset_OnOff(ON);
delay_ms(500);
reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);
if (ctlwizchip(CW_INIT_WIZCHIP, (void*) memsize) == -1) {
StrMsg(“\r\nWIZCHIP Initialized fail.”);
while (1);
}
do{
if(ctlwizchip(CW_GET_PHYLINK, (void*)&tmp) == -1)
StrMsg(“\r\nUnknown PHY Link stauts.”);
}while(tmp == PHY_LINK_OFF);
ctlnetwork(CN_SET_NETINFO, (void*)&gWIZNETINFO);
ctlnetwork(CN_GET_NETINFO, (void*)&gWIZNETINFO);
ctlwizchip(CW_GET_ID,(void*)tmpstr);
DisMsg(“\r\n>> CW_GET_ID %02x %02x %02x,”,tmpstr[0],tmpstr[1],tmpstr[2]);
DisMsg(" %02x %02x %02x",tmpstr[3],tmpstr[4],tmpstr[5]);
Display_Net_Conf(); // Print out the network information to serial terminal
}
int32_t LoopbackUdps(uint8_t sn, uint8_t* buf, uint16_t port)
{
int32_t ret;
uint16_t size, sentsize;
//uint8_t packinfo = 0;
switch(getSn_SR(sn)){
case SOCK_UDP :
if((size = getSn_RX_RSR(sn)) > 0){
if(size > BUF_SIZE) size = BUF_SIZE;
ret = recvfrom(sn,buf,size,destip,(uint16_t*)&destport);
if(ret <= 0){
DisMsg(“\r\n%d: recvfrom error. %ld”,sn,ret,0);
return ret;
}
size = (uint16_t) ret;
sentsize = 0;
while(sentsize != size){
ret = sendto(sn,buf+sentsize,size-sentsize,destip,destport);
if(ret < 0){
DisMsg(“\r\n%d: sendto error. %ld”,sn,ret,0);
return ret;
}
sentsize += ret; // Don’t care SOCKERR_BUSY, because it is zero.
}
}
break;
case SOCK_CLOSED:
DisMsg(“\r\n%d:LBUStart”,sn,0,0);
if((ret=socket(sn,Sn_MR_UDP,port,0x00)) != sn)
return ret;
DisMsg(“\r\n%d:Opened, port [%d]”,sn, port,0);
break;
default :
break;
}
return 1;
}
void W5500_Task(void)
{
int32_t ret = 0, i;
static u32 UdpSendTime=0;
if(++UdpSendTime>30000){
UdpSendTime=0;
for(i=0; i<128; i++){
gDATABUF[i]=i;
}
//ret = sendto(SOCK_UDPS,gDATABUF,128,destip,3000);
//if(ret < 0){
// DisMsg(“\r\n%d: sendto error. %ld”,SOCK_UDPS,ret,0);
//}
}
if( (ret = LoopbackUdps(SOCK_UDPS, gDATABUF, 3000)) < 0) {
DisMsg(“\r\nSOCKET ERROR : %ld”, ret,0,0);
}
}