[活动专区] 【AT-START-F407测评】+ 网口试验

[复制链接]
1148|5
 楼主| 比神乐 发表于 2021-1-31 13:47 | 显示全部楼层 |阅读模式
本帖最后由 比神乐 于 2021-1-31 13:50 编辑

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

  5. /** @addtogroup AT32F407_StdPeriph_Examples
  6.   * @{
  7.   */

  8. /** @addtogroup ETH_TCP_Server
  9.   * @{
  10.   */

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

  14. /* Gloable functions ---------------------------------------------------------*/
  15. /**
  16.   * [url=home.php?mod=space&uid=247401]@brief[/url]  Main Function.
  17.   * @param  None
  18.   * @retval None
  19.   */
  20. int main(void)
  21. {
  22.   unsigned char tcp_data[] = "TCP client experiment!\n";
  23.   struct tcp_pcb *pcb;
  24.   uint32_t Status;
  25.         /* --------BSP Init ------------------------------------------------*/
  26.   AT32_Board_Init();
  27.   UART_Print_Init(115200);
  28.   /* Setup AT32 system (clocks, Ethernet, GPIO, NVIC)*/
  29.   Status = System_Setup();
  30.   while(Status == ETH_DRIVER_FAIL);
  31.   
  32.   /* Initilaize LwIP satck, IP configuration and MAC configuration*/
  33.   LwIP_Init();
  34.   /* Initialize TCP client module */
  35.   TCP_Client_Init(TCP_LOCAL_PORT,TCP_SERVER_PORT,TCP_SERVER_IP);  //Initialize TCP client
  36.   while(1)
  37.   {         
  38.       pcb = Check_TCP_Connect();
  39.       if(pcb != 0)
  40.       {        
  41.         TCP_Client_Send_Data(pcb,tcp_data,sizeof(tcp_data));      //Send data to TCP server actively
  42.       }
  43.       Delay_s(0xfffff);                                                                                                              //necessary delay
  44.       System_Periodic_Handle();                                                                                          //Update TCP timers
  45.   }
  46. }

  47. /**
  48.   * [url=home.php?mod=space&uid=247401]@brief[/url]  Inserts a delay time.
  49.   * @param  nCount: number of 10ms periods to wait for.
  50.   * @retval None
  51.   */
  52. void Delay(uint32_t nCount)
  53. {
  54.   /* Capture the current local time */
  55.   timingdelay = LocalTime + nCount;  

  56.   /* wait until the desired delay finish */  
  57.   while(timingdelay > LocalTime)
  58.   {     
  59.   }
  60. }

  61. /**
  62.   * @brief  Updates the system local time
  63.   * @param  None
  64.   * @retval None
  65.   */
  66. void Time_Update(void)
  67. {
  68.   LocalTime += SYSTEMTICK_PERIOD_MS;
  69. }

  70. /**
  71.   * @brief  Handles the periodic tasks of the system
  72.   * @param  None
  73.   * @retval None
  74.   */
  75. void System_Periodic_Handle(void)
  76. {
  77.   /* LwIP periodic services are done here */
  78.   LwIP_Periodic_Handle(LocalTime);
  79. }
  1. /* TCP server and client configuration*/
  2. #define TCP_LOCAL_PORT                     1030
  3. #define TCP_SERVER_PORT                    1031

  4. #define TCP_SERVER_IP   192,168,1,19        //server IP
  1. static uint8_t G_IP[ADDR_LENGTH]   = {192, 168, 1, 37};
  2. static uint8_t G_GW[ADDR_LENGTH]   = {192, 168, 1, 187};
  3. static uint8_t G_MASK[ADDR_LENGTH] = {255, 255, 255, 0};
效果图:
1.jpg
4.jpg
5.jpg 6.jpg
注意还要关闭防火墙。

caizhiwei 发表于 2021-1-31 21:17 | 显示全部楼层
厉害 小辣椒哥哥~
无所谓随意 发表于 2021-2-2 15:10 | 显示全部楼层
能分享代码吗
 楼主| 比神乐 发表于 2021-2-2 15:50 | 显示全部楼层

例程一点都没改
纪国圣 发表于 2021-2-2 17:07 来自手机 | 显示全部楼层
有空可以试试IPERF例程,测试一下看看网速多少。
里面有晴雨 发表于 2021-2-5 09:13 | 显示全部楼层
可以分享一下代码吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

470

主题

3537

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部