比神乐 发表于 2021-1-31 13:47

【AT-START-F407测评】+ 网口试验

本帖最后由 比神乐 于 2021-1-31 13:50 编辑

今天捣鼓了一下网口试验。
TCP客户端。
代码:
/* Includes -----------------------------------------------------------------*/
#include "at32_board.h"
#include "main.h"
#include "eth_config.h"

/** @addtogroup AT32F407_StdPeriph_Examples
* @{
*/

/** @addtogroup ETH_TCP_Server
* @{
*/

/* Gloable variables ---------------------------------------------------------*/
__IO uint32_t LocalTime = 0; /* this variable is used to create a time reference incremented by 10ms */
uint32_t timingdelay;

/* Gloable functions ---------------------------------------------------------*/
/**
* @briefMain Function.
* @paramNone
* @retval None
*/
int main(void)
{
unsigned char tcp_data[] = "TCP client experiment!\n";
struct tcp_pcb *pcb;
uint32_t Status;
      /* --------BSP Init ------------------------------------------------*/
AT32_Board_Init();
UART_Print_Init(115200);
/* Setup AT32 system (clocks, Ethernet, GPIO, NVIC)*/
Status = System_Setup();
while(Status == ETH_DRIVER_FAIL);

/* Initilaize LwIP satck, IP configuration and MAC configuration*/
LwIP_Init();
/* Initialize TCP client module */
TCP_Client_Init(TCP_LOCAL_PORT,TCP_SERVER_PORT,TCP_SERVER_IP);//Initialize TCP client
while(1)
{         
      pcb = Check_TCP_Connect();
      if(pcb != 0)
      {      
      TCP_Client_Send_Data(pcb,tcp_data,sizeof(tcp_data));      //Send data to TCP server actively
      }
      Delay_s(0xfffff);                                                                                                            //necessary delay
      System_Periodic_Handle();                                                                                          //Update TCP timers
}
}

/**
* @briefInserts a delay time.
* @paramnCount: number of 10ms periods to wait for.
* @retval None
*/
void Delay(uint32_t nCount)
{
/* Capture the current local time */
timingdelay = LocalTime + nCount;

/* wait until the desired delay finish */
while(timingdelay > LocalTime)
{   
}
}

/**
* @briefUpdates the system local time
* @paramNone
* @retval None
*/
void Time_Update(void)
{
LocalTime += SYSTEMTICK_PERIOD_MS;
}

/**
* @briefHandles the periodic tasks of the system
* @paramNone
* @retval None
*/
void System_Periodic_Handle(void)
{
/* LwIP periodic services are done here */
LwIP_Periodic_Handle(LocalTime);
}/* TCP server and client configuration*/
#define TCP_LOCAL_PORT                     1030
#define TCP_SERVER_PORT                  1031

#define TCP_SERVER_IP   192,168,1,19      //server IPstatic uint8_t G_IP   = {192, 168, 1, 37};
static uint8_t G_GW   = {192, 168, 1, 187};
static uint8_t G_MASK = {255, 255, 255, 0};效果图:



注意还要关闭防火墙。

caizhiwei 发表于 2021-1-31 21:17

厉害 小辣椒哥哥~

无所谓随意 发表于 2021-2-2 15:10

能分享代码吗

比神乐 发表于 2021-2-2 15:50

无所谓随意 发表于 2021-2-2 15:10
能分享代码吗

例程一点都没改

纪国圣 发表于 2021-2-2 17:07

有空可以试试IPERF例程,测试一下看看网速多少。

里面有晴雨 发表于 2021-2-5 09:13

可以分享一下代码吗?
页: [1]
查看完整版本: 【AT-START-F407测评】+ 网口试验