piątek, 8 stycznia 2021

STM32H7 - STM32H723ZG - LWIP

Ten post jest rozwinięciem wcześniejszej części. W nim chciałbym przedstawić sposób dostosowania układu STM32H723, który został umieszczony na płycie Nucleo-144, do współpracy z biblioteką LWIP.

[Źródło: https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-mpu-eval-tools/stm32-mcu-mpu-eval-tools/stm32-nucleo-boards/nucleo-h753zi.html#overview]

Skupię się tutaj tylko i wyłącznie na konfiguracji pliku FLASH. Pozostałe elementy pozostają nie zmienione względem wcześniejszego postu dla STM32H7 LWIP.

Poniżej znajduje się opis adresów w pamięci układu.


Podobnie jak wcześniej należy dołożyć definicję buforów RX oraz TX.

  1. .lwip_sec (NOLOAD) : {
  2.     . = ABSOLUTE(0x30000000);
  3.     *(.RxDecripSection)
  4.    
  5.     . = ABSOLUTE(0x30000060);
  6.     *(.TxDecripSection)
  7.    
  8.     . = ABSOLUTE(0x30000200);
  9.     *(.RxArraySection)
  10. } >RAM_D2 AT> ROM

W przypadku generowania projektu przez CubeMx zostaną wygenerowane pliki zawierające opis pamięci RAM oraz FLASH. Z takim zestawem plików nie udało mi się wygenerować działającego projektu LWIP. Zostawiłem tylko plik FLASH wygenerowany z przykładu udostępnionego przez ST. 

Zmodyfikowane wartości pamięci wygląda następująco

  1. /* Memories definition */
  2. MEMORY
  3. {
  4.   ITCMRAM    (xrw)    : ORIGIN = 0x00000000,   LENGTH = 64K
  5.   RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 128K
  6.   ROM    (rx)    : ORIGIN = 0x08000000,   LENGTH = 1024K
  7.   RAM_D2 (xrw)      : ORIGIN = 0x30000000, LENGTH = 288K
  8. }

Plik z ustawieniami biblioteki LWIP został ustawiony w następujący sposób:

  1. /**
  2.   ******************************************************************************
  3.   * File Name          : Target/lwipopts.h
  4.   * Description        : This file overrides LwIP stack default configuration
  5.   *                      done in opt.h file.
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under Ultimate Liberty license
  13.   * SLA0044, the "License"; You may not use this file except in compliance with
  14.   * the License. You may obtain a copy of the License at:
  15.   *                             www.st.com/SLA0044
  16.   *
  17.   ******************************************************************************
  18.   */
  19.  
  20. /* Define to prevent recursive inclusion --------------------------------------*/
  21. #ifndef __LWIPOPTS__H__
  22. #define __LWIPOPTS__H__
  23.  
  24. #include "main.h"
  25.  
  26. /*-----------------------------------------------------------------------------*/
  27. /* Current version of LwIP supported by CubeMx: 2.1.2 -*/
  28. /*-----------------------------------------------------------------------------*/
  29.  
  30. /* Within 'USER CODE' section, code will be kept by default at each generation */
  31. /* USER CODE BEGIN 0 */
  32. /* USER CODE END 0 */
  33.  
  34. #ifdef __cplusplus
  35.  extern "C" {
  36. #endif
  37.  
  38. /* STM32CubeMX Specific Parameters (not defined in opt.h) ---------------------*/
  39. /* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
  40. ///*----- WITH_RTOS disabled (Since FREERTOS is not set) -----*/
  41. #define WITH_RTOS 0
  42. ///*----- CHECKSUM_BY_HARDWARE enabled -----*/
  43. #define CHECKSUM_BY_HARDWARE 1
  44. ///*-----------------------------------------------------------------------------*/
  45. //
  46. ///* LwIP Stack Parameters (modified compared to initialization value in opt.h) -*/
  47. ///* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
  48. /*-----------------------------------------------------------------------------*/
  49. /* USER CODE BEGIN 1 */
  50. #define ETH_RX_BUFFER_SIZE (1536UL)
  51.  /**
  52.   * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
  53.   * critical regions during buffer allocation, deallocation and memory
  54.   * allocation and deallocation.
  55.   */
  56.  #define SYS_LIGHTWEIGHT_PROT    0
  57.  
  58.  /**
  59.   * NO_SYS==1: Provides VERY minimal functionality. Otherwise,
  60.   * use lwIP facilities.
  61.   */
  62.  #define NO_SYS                  1
  63.  
  64.  /* ---------- Memory options ---------- */
  65.  /* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
  66.     lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
  67.     byte alignment -> define MEM_ALIGNMENT to 2. */
  68.  #define MEM_ALIGNMENT           4
  69.  
  70.  /* MEM_SIZE: the size of the heap memory. If the application will send
  71.  a lot of data that needs to be copied, this should be set high. */
  72.  #define MEM_SIZE                (10*1024)
  73.  
  74.  /* Relocate the LwIP RAM heap pointer */
  75.  #define LWIP_RAM_HEAP_POINTER    (0x30004000)
  76.  
  77.  /* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
  78.     sends a lot of data out of ROM (or other static memory), this
  79.     should be set high. */
  80.  #define MEMP_NUM_PBUF           10
  81.  /* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
  82.     per active UDP "connection". */
  83.  #define MEMP_NUM_UDP_PCB        6
  84.  /* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
  85.     connections. */
  86.  #define MEMP_NUM_TCP_PCB        10
  87.  /* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
  88.     connections. */
  89.  #define MEMP_NUM_TCP_PCB_LISTEN 6
  90.  /* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
  91.     segments. */
  92.  #define MEMP_NUM_TCP_SEG        8
  93.  /* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
  94.     timeouts. */
  95.  #define MEMP_NUM_SYS_TIMEOUT    10
  96.  
  97.  /* ---------- Pbuf options ---------- */
  98.  /* PBUF_POOL_SIZE: the number of buffers in the pbuf pool.
  99.     @ note: used to allocate Tx pbufs only */
  100.  #define PBUF_POOL_SIZE          8
  101.  
  102.  /* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool */
  103.  #define PBUF_POOL_BUFSIZE       1528
  104.  
  105.  /* LWIP_SUPPORT_CUSTOM_PBUF == 1: to pass directly MAC Rx buffers to the stack
  106.     no copy is needed */
  107.  #define LWIP_SUPPORT_CUSTOM_PBUF      1
  108.  
  109.  /*
  110.     ------------------------------------------------
  111.     ---------- Network Interfaces options ----------
  112.     ------------------------------------------------
  113.  */
  114.  #define LWIP_NETIF_LINK_CALLBACK        1
  115.  
  116.  /* ---------- TCP options ---------- */
  117.  #define LWIP_TCP                1
  118.  #define TCP_TTL                 255
  119.  
  120.  /* Controls if TCP should queue segments that arrive out of
  121.     order. Define to 0 if your device is low on memory. */
  122.  #define TCP_QUEUE_OOSEQ         1
  123.  
  124.  /* TCP Maximum segment size. */
  125.  #define TCP_MSS                 (1500 - 40)      /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
  126.  
  127.  /* TCP sender buffer space (bytes). */
  128.  #define TCP_SND_BUF             (4*TCP_MSS)
  129.  
  130.  /*  TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
  131.    as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
  132.  #define TCP_SND_QUEUELEN        (2* TCP_SND_BUF/TCP_MSS)
  133.  
  134.  /* TCP receive window. */
  135.  #define TCP_WND                 (2*TCP_MSS)
  136.  
  137.  
  138.  /* ---------- ICMP options ---------- */
  139.  #define LWIP_ICMP                       1
  140.  
  141.  
  142.  /* ---------- DHCP options ---------- */
  143.  #define LWIP_DHCP               0
  144.  
  145.  
  146.  /* ---------- UDP options ---------- */
  147.  #define LWIP_UDP                1
  148.  #define UDP_TTL                 255
  149.  
  150.  
  151.  /* ---------- Statistics options ---------- */
  152.  #define LWIP_STATS 0
  153.  
  154.  /*
  155.     --------------------------------------
  156.     ---------- Checksum options ----------
  157.     --------------------------------------
  158.  */
  159.  
  160.  /*
  161.  The STM32H7xx allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware:
  162.   - To use this feature let the following define uncommented.
  163.   - To disable it and process by CPU comment the  the checksum.
  164.  */
  165.  #define CHECKSUM_BY_HARDWARE
  166.  
  167.  
  168.  #ifdef CHECKSUM_BY_HARDWARE
  169.    /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
  170.    #define CHECKSUM_GEN_IP                 0
  171.    /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
  172.    #define CHECKSUM_GEN_UDP                0
  173.    /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
  174.    #define CHECKSUM_GEN_TCP                0
  175.    /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
  176.    #define CHECKSUM_CHECK_IP               0
  177.    /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
  178.    #define CHECKSUM_CHECK_UDP              0
  179.    /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
  180.    #define CHECKSUM_CHECK_TCP              0
  181.    /* CHECKSUM_GEN_ICMP==1: Check checksums by hardware for outgoing ICMP packets.*/
  182.    /* Hardware TCP/UDP checksum insertion not supported when packet is an IPv4 fragment*/
  183.    #define CHECKSUM_GEN_ICMP               1
  184.    /* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
  185.    #define CHECKSUM_CHECK_ICMP             0
  186.  #else
  187.    /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
  188.    #define CHECKSUM_GEN_IP                 1
  189.    /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
  190.    #define CHECKSUM_GEN_UDP                1
  191.    /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
  192.    #define CHECKSUM_GEN_TCP                1
  193.    /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
  194.    #define CHECKSUM_CHECK_IP               1
  195.    /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
  196.    #define CHECKSUM_CHECK_UDP              1
  197.    /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
  198.    #define CHECKSUM_CHECK_TCP              1
  199.    /* CHECKSUM_GEN_ICMP==1: Check checksums by hardware for outgoing ICMP packets.*/
  200.    #define CHECKSUM_GEN_ICMP               1
  201.    /* CHECKSUM_CHECK_ICMP==1: Check checksums by hardware for incoming ICMP packets.*/
  202.    #define CHECKSUM_CHECK_ICMP             1
  203.  #endif
  204.  
  205.  
  206.  /*
  207.     ----------------------------------------------
  208.     ---------- Sequential layer options ----------
  209.     ----------------------------------------------
  210.  */
  211.  /**
  212.   * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
  213.   */
  214.  #define LWIP_NETCONN                    0
  215.  
  216.  /*
  217.     ------------------------------------
  218.     ---------- Socket options ----------
  219.     ------------------------------------
  220.  */
  221.  /**
  222.   * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
  223.   */
  224.  #define LWIP_SOCKET                     0
  225.  
  226. /* USER CODE END 1 */
  227.  
  228. #ifdef __cplusplus
  229. }
  230. #endif
  231. #endif /*__LWIPOPTS__H__ */
  232.  
  233. /************************* (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  234.  

Pozostałe elementy zostają takie same jak w poprzednim opisywanym przykładzie dla układu STM32H7.