본문 바로가기

WCH/CH32V035

CH32X035 SSM - W5500 을 이용한 Iperf TCP Throughput 측정 테스트

CH32X035는 저렴(2$대)하고 작은크기(3mm x 3mm)의 RISC-V 코어로 소형의 TCP/IP 솔루션으로 사용하기 좋을것 같아 W5500을 이용하여 TCP/IP 전송률 테스트를 해 보았다.

 

우선 Wizet사에서 제공하는 ioLibrary Driver를 다운 받아 프로젝트 폴더에 복사 한다.

 

 

SPI 초기화 함수를 작성한다.

void SPI_FullDuplex_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure = {0};
    SPI_InitTypeDef  SPI_InitStructure = {0};

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    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;
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
    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(SPI1, &SPI_InitStructure);

    SPI_Cmd(SPI1, ENABLE);
}

 

 

 

W5500의 초기화 함수를 작성한다. W5500 CS핀을 제어 하는 wizchip_select 함수, W5500 Read, Write 함수 wizchip_read, wizchip_write, 고속전송을 위한 buffer Read, Write 함수 SPI_WriteReadByte, SPI_WriteBuf, SPI_ReadBuf 를 등록 한다.

void W5500_Init(void)
{
	/*!< Deselect the FLASH: Chip Select high */
	wizchip_deselect();

	// Wiznet
	reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
	reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);
	reg_wizchip_spiburst_cbfunc(SPI_ReadBuf, SPI_WriteBuf);

	/* wizchip initialize*/
	uint8_t tmp;
	uint8_t memsize[2][8] = { {2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}};

	if(ctlwizchip(CW_INIT_WIZCHIP,(void*)memsize) == -1)
	{
		return;
	}

    Net_Conf();
}

 

 

 

등록한 함수를 CH32X035 SSM 보드에 맞도록 수정 해 준다.

unsigned char SPI_WriteReadByte(unsigned char Data)
{
    SPI_wait_TX_complete();
    SPI1->DATAR = Data;

    SPI_wait_RX_available();
    return SPI1->DATAR;
}

unsigned char SPI_WriteBuf(unsigned char *pDataBuf, unsigned int Size)
{
#if _USE_SPI_DMA
  //HAL_SPI_Transmit_DMA(&hSPIHandle, pDataBuf, Size);
  //while(HAL_SPI_GetState(&hSPIHandle) != HAL_SPI_STATE_READY);
#else
  for(int i=0;i<Size;i++)
  {
      SPI_wait_TX_complete();
      SPI1->DATAR = pDataBuf[i];

      SPI_wait_RX_available();
      receivedbyte = SPI1->DATAR;
  }
#endif

return receivedbyte;
}

unsigned char SPI_ReadBuf(unsigned char *pDataBuf, unsigned int Size)
{
  uint8_t receivedbyte = 0;

#if _USE_SPI_DMA
  HAL_SPI_Receive_DMA(&hSPIHandle, pDataBuf, Size);
  while(HAL_SPI_GetState(&hSPIHandle) != HAL_SPI_STATE_READY);
#else
  for(int i=0;i<Size;i++)
  {
      SPI_wait_TX_complete();
      SPI1->DATAR = 0x00;

      SPI_wait_RX_available();
      pDataBuf[i] = SPI1->DATAR;
  }

#endif
  return receivedbyte;
}

 

 

 

W5500으로 TCP루프백 테스트를 할수 있는 main 함수를 작성 한다.

int main(void)
{
	SystemCoreClockUpdate();
	Delay_Init();
	USART_Printf_Init(115200);

	printf("SystemClk:%d\r\n",SystemCoreClock);
	printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );

    GPIO_INIT();
    SPI_FullDuplex_Init();
    printf( "W5500 iperf Test\r\n");

    W5500_Init();
    Display_Net_Info();

    while (1)
    {
      /* USER CODE END WHILE */

      /* USER CODE BEGIN 3 */
      loopback_tcps(SOCK_TCPS0, gDATABUF, 5001);
    }
}

 

 

 Iperf TCP Throughput 측정 테스트 결과 6Mbps 정도로 측정된다.

 

반응형