안녕하세요 wiz550io board 를 구매해서 tcp client 로 구현하려 진행중입니다.
사용 mcu 는 stm32f103 이구요…
컴파일러는 KEIL(uVision 4) 을 사용중입니다.
SPI2 를 사용하며 VCC ,GND 및 MOSI,MISO,CLK,SS pin 만 연결되어있습니다.
포럼 내용을 참고하여
sample code 를 구현하여 동작시켜 보니 ip address 는 원하는대로 설정되는것 같으나
AX1 프로그램을 이용하여 TCP Loopback connect 를
시도하니 connect fail 이 나타나고 있습니다.
무엇이 잘못설정되어졌는지 문의드리며 추가적으로 궁금한사항을 몇게 문의드립니다.
아래 참고 1 코드를 활용하여 mcu 구동시
Test PC IP : 192.168.1.3
WIZ550io board : 192.168.1.13 : 5000
PC 와 Wiz550Io board 는 cross cable 로 1:1 연결되어있으며
pc 에서 WIZ550Io 쪽으로 ping 시도시 정상적으로 진행이 됩니다.(응답ok)
wiz_NetInfo gWIZNETINFO 의 내용을 변경하여 board 의 IP 를 변경하고 ping test 를 진행해 보아도 해당 ip로 정상적으로 수정되어
ping test ok 가 되고있습니다.
문 1.
AX1 에서 TCP connect fail 원인이 무엇인가요 코드에 설정하지 않은 잘못되어진 부분이 있나요?
문2.
Wiz550io 는 내부 MAC 을 자체적으로 보유하고 있다고하는데
wiz_NetInfo gWIZNETINFO 를 통해 설정해주는 이유가 무엇인가요? 내부 MAC 을 사용하려면 어떻게 하나요?
문3. DHCP 를 활용하려면 추가적으로 호출해야하는 함수가 무엇인가요?(lib DHCP.C 는 include 완료되어짐)(활용방법문의)
참고 1(이하 code)
/* Includes ------------------------------------------------------------------/
#include “stm32f10x.h”
#include <string.h>
#include <stdio.h>
#include <Ethernet/socket.h>
#include <Ethernet/wizchip_conf.h>
#include <Application\loopback\loopback.h>
#include <Internet/DHCP/dhcp.h>
#ifdef GNUC
/ With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to ‘Yes’) calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE f)
#endif / GNUC */
/* Private function prototypes -----------------------------------------------*/
void GPIO_Configuration(void);
void USART_Configuration(void);
/*******************************************************************************
- Function Name : Delay
- Description : Delay Time
- Input : - nCount: Delay Time
- Output : None
- Return : None
- Attention : None
*******************************************************************************/
void Delay (uint32_t nCount)
{
for(; nCount != 0; nCount–);
}
void W5500_select(void)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_12); // Chip Select (Low)
}
void W5500_deselect(void)
{
GPIO_SetBits(GPIOB,GPIO_Pin_12); // CS high
}
uint8_t W5500_read(void)
{
//Is FullDuplex
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); // TXE reset → Send data(DR register)
SPI_I2S_SendData(SPI2, 0xff);
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET); // RXNE reset → Data receive
return SPI_I2S_ReceiveData(SPI2);
}
void W5500_write(uint8_t byte)
{
//Is FullDuplex
SPI_I2S_SendData(SPI2, byte);
}
// H/W Reset
void W5500HARDWARDRESET(void)
{
int i,j;
GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_SET);
GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_RESET);
for(i = 0; i < 10000 ; i++){j++;}
GPIO_WriteBit(GPIOA,GPIO_Pin_8,Bit_SET);
}
void W5500HardwardInitilize(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
SPI_InitTypeDef SPI_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);/*SPI2*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; /*SPI2*/
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);/*SPI2*/
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12; /*SP2*/
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct); /*SP2*/
SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // SPI is Fullduplex communication
SPI_InitStruct.SPI_Mode = SPI_Mode_Master; // Cortex-M3
SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b; // DFF bit / SPI is 1byte Transmission
SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low; // First Start clock is 1(high) CPOL = 1
SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge; // CPHA = 1
SPI_InitStruct.SPI_NSS = SPI_NSS_Soft; // Software Slave Select
//BaudRate - 1sec = 1,000,000,000nsec , Frequency = 36Mhz --> 1/F=T --> 27.77nsec
SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; // fpclk/2 -> W5500 chip is possible 80Mhz SPI communication. So,36Mhz communication.
SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB; // Out of MSB trans
SPI_InitStruct.SPI_CRCPolynomial = 7;
SPI_Init(SPI2, &SPI_InitStruct);
SPI_Cmd(SPI2, ENABLE);
//H/WReset
//W5500HARDWARDRESET();
}
void Network_Config()
{
wiz_NetInfo gWIZNETINFO =
{
{0x00,0x08,0xdc,0x1f,0x17,0xcc},
{192,168,1,13},
{255,255,255,0},
{192,168,1,1},
{8,8,8,0},
//NETINFO_DHCP,
};
setSHAR(gWIZNETINFO.mac);
ctlnetwork(CN_SET_NETINFO, (void*) &gWIZNETINFO);
}
void WIZnet_init(void)
{
uint8_t tmp;
uint8_t memsize[2][8] = {{2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}};
//////////
// TODO //
////////////////////////////////////////////////////////////////////////////////////////////////
// First of all, Should register SPI callback functions implemented by user for accessing WIZCHIP //
////////////////////////////////////////////////////////////////////////////////////////////////
/* Critical section callback ? No use in this example */
//reg_wizchip_cris_cbfunc(0, 0);
/* Chip selection call back */
#if WIZCHIP_IO_MODE == WIZCHIP_IO_MODE_SPI_VDM
reg_wizchip_cs_cbfunc(W5500_select, W5500_deselect);
#elif WIZCHIP_IO_MODE == WIZCHIP_IO_MODE_SPI_FDM
reg_wizchip_cs_cbfunc(W5500_select, W5500_deselect); // CS must be tried with LOW.
#else
#if (WIZCHIP_IO_MODE & WIZCHIP_IO_MODE_SPI) != WIZCHIP_IO_MODE_SPI
#error “Unknown WIZCHIP_IO_MODE”
#else
reg_wizchip_cs_cbfunc(W5500_select, W5500_deselect);
#endif
#endif
/* SPI Read & Write callback function */
reg_wizchip_spi_cbfunc(W5500_read, W5500_write);
//============================================================
// WIZCHIP SOCKET Buffer initialize
//============================================================
if(ctlwizchip(CW_INIT_WIZCHIP,(void*)memsize) == -1)
{
printf("WIZCHIP Initialized fail.\r\n");
while(1);
}
//============================================================
// PHY link status check
//============================================================
do
{
if(ctlwizchip(CW_GET_PHYLINK, (void*)&tmp) == -1)
printf(“Unknown PHY Link stauts.\r\n”);
}while(tmp == PHY_LINK_OFF);
//============================================================
//Default test Network initialization
//============================================================
Network_Config();
}
/*******************************************************************************
- Function Name : main
- Description : Main program
- Input : None
- Output : None
- Return : None
- Attention : None
*******************************************************************************/
#define SOCK_TCPS 0
#define SOCK_UDPS 1
#define SOCK_WEBS 2
#define DATA_BUF_SIZE 2048
uint8_t gDATABUF[DATA_BUF_SIZE];
int main(void)
{
int32_t ret = 0;
GPIO_Configuration();
USART_Configuration();
W5500HardwardInitilize();
WIZnet_init();
printf("\r\n********Ethernet init ok\r\n");
/ Infinite loop */
while (1)
{
if( (ret = loopback_tcps(SOCK_TCPS, gDATABUF, 5000)) < 0) {
printf("SOCKET ERROR : %ld\r\n", ret);
}
}
}
/*******************************************************************************
-
Function Name : GPIO_Configuration
-
Description : Configure GPIO Pin
-
Input : None
-
Output : None
-
Return : None
-
Attention : None
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC , ENABLE);
/** -
LED1 → PF6 , LED2 → PF7 , LED3 → PF8 , LED4 → PF9
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
#ifdef USE_FULL_ASSERT
/**
- @brief Reports the name of the source file and the source line number
- where the assert_param error has occurred.
- @param file: pointer to the source file name
- @param line: assert_param error line source number
-
@retval None
/
void assert_failed(uint8_t file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(“Wrong parameters value: file %s on line %d\r\n”, file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif