Ethernet is stopped after using global variables in STM32.

huangapple go评论57阅读模式
英文:

Ethernet is stopped after using global variables in STM32

问题

I am using STM32H735ZGTx_ LQFP144.
我正在使用STM32H735ZGTx_ LQFP144。

I have done Ethernet configuration according to this link https://controllerstech.com/stm32-ethernet-1-connection/
我已经根据此链接https://controllerstech.com/stm32-ethernet-1-connection/进行了以太网配置。

If I am not using any global in any of the source file, I am not facing any issue, Ethernet is working fine.
如果我在任何源文件中不使用任何全局变量,我就不会遇到任何问题,以太网正常工作。

Whenever I declare and use global variables or static variables, I am facing some issue and the Ethernet is stopped.
每当我声明并使用全局变量或静态变量时,我就会遇到一些问题,以太网停止工作。

I am getting different errors based on the global variables size, as follows:
根据全局变量的大小,我会收到不同的错误,如下:

Error : Hard Fault error
char buff[5] = "123"; //已初始化
错误:硬件错误

char buff[100]; // uninitialized
Error: ssertion "pc>custom_free_function != NULL" failed at line 767 in../Middlewares/Third_Party/LwIP/sr/core/pbuf.c
char buff[100]; // 未初始化
错误:在../Middlewares/Third_Party/LwIP/sr/core/pbuf.c的第767行处,出现了“断言”pc > custom_free_function != NULL”的错误

char buff[200]: //uninitialized
Error:
Assertion "pbuf_free: p->ref > 0" failed at line 753 in../Middlewares/Third_Party/LwIP/src/core/pbuf.c
Error: Assertion "mem_trim: legal memory" failed at line 721 in ../Middlewares/Third_Party/LwIP/src/core/mem.c
char buff[200]: // 未初始化
错误:
在../Middlewares/Third_Party/LwIP/src/core/pbuf.c的第753行处,出现了“断言”pbuf_free: p->ref > 0”的错误
错误:在../Middlewares/Third_Party/LwIP/src/core/mem.c的第721行处,出现了“断言”mem_trim: legal memory”的错误

Changing the variable size is changing the errors.
更改变量大小会改变错误。

I'm new to STM, please help me with this issue.
我对STM不太了解,请帮我解决这个问题。

I have checked the address of global variables, all are stored in RAM_D1.
我已经检查了全局变量的地址,它们都存储在RAM_D1中。

In the hard fault, I noticed that, it's causing error when it is in pbuf_free() function.
在硬件错误中,我注意到当它在pbuf_free()函数中时,会导致错误。

<details>
<summary>英文:</summary>

I am using STM32H735ZGTx_ LQFP144.
I have done Ethernet configuration according to this link https://controllerstech.com/stm32-ethernet-1-connection/

If I am not using any global in any of the source file, I am not facing any issue, Ethernet is working fine.

Whenever I declare and use global variables or static variables, I am facing some issue and the Ethernet is stopped.

I am getting different errors based on the global variables size, as follows 

char buff[5] = "123"; //initialized
Error : Hard Fault error

char buff[100]; // uninitialized
Error: ssertion "pc>custom_free_function != NULL" failed at line 767 in../Middlewares/Third_Party/LwIP/sr/core/pbuf.c

char buff[200]: //uninitialized
Error:
Assertion "pbuf_free: p->ref > 0" failed at line 753 in../Middlewares/Third_Party/LwIP/src/core/pbuf.c
Error: Assertion "mem_trim: legal memory" failed at line 721 in ../Middlewares/Third_Party/LwIP/src/core/mem.c


Changing the variable size is changing the errors.
I&#39;m new to STM, please help me with this issue.

I have checked the address of global variables, all are stored in RAM_D1.

In the hard fault, I noticed that, it&#39;s causing error when it is in pbuf_free() function.

</details>


# 答案1
**得分**: 0

我发现一些STM32H7x系列的芯片存在以太网问题。尽管我们在CubeMX的ethernetif.c中配置了地址,但我们需要将RX_POOL缓冲区放在特定的RAM位置。

要修改链接脚本(*.ld)以便将ETH描述符和缓冲区放在D2 SRAM中。还建议将所有RAM都放在RAM_D1中。在STM32CubeMX生成的项目中,默认情况下使用带有"_FLASH"后缀的链接脚本(例如:STM32H750XBHx_FLASH.ld),应该进行修改。带有"_RAM"后缀的链接脚本是用于从内部RAM存储器执行代码的模板。

在进行这些修改之后,我的问题得到了解决。Rx_Pool存储pbufs,但由于不正确的对齐,它会覆盖一些pbuf指针。

**注意**:如果您将Rx_Pool存储在其他RAM或地址中,对齐必须正确,否则它会再次覆盖。

<details>
<summary>英文:</summary>

I have found that some of the STM32H7x series have Ethernet issues.
Although we configured the address in CubeMX in ethernetif.c but we need to place RX_POOL buffer at specific RAM.

/* USER CODE BEGIN 2 /
#if defined ( GNUC ) /
GNU Compiler /
attribute((section(".Rx_PoolSection"))) extern u8_t memp_memory_RX_POOL_base[];
#endif
/
USER CODE END 2 */

Modify the linkerscript (*.ld) that the **ETH descriptors and buffers are located in D2 SRAM. Also it is recommended to place all RAM to RAM_D1.** In STM32CubeMX generated project, the &quot;_FLASH&quot; suffix linkerscript should be modified, which is used by default 

(e.g.: STM32H750XBHx_FLASH.ld). The &quot;_RAM&quot; suffix linkerscript is template for executing code from internal RAM memory.

} >RAM_D1

/* Modification start */
.lwip_sec (NOLOAD) :
{
. = ABSOLUTE(0x30040000);
*(.RxDecripSection)

. = ABSOLUTE(0x30040060);
*(.TxDecripSection)
 /* Rx_Pool section must be added in linker */
. = ABSOLUTE(0x30040200);
*(.Rx_PoolSection)  

} >RAM_D2

After these modifications, my issue was resolved.  
Rx_Pool stores the pbufs, but due to improper alignment it was overwriting some of the pbuf pointers. 

**Note**: If you are storing Rx_Pool in some other RAM or address, the alignment must be proper, or else it will overwrite again.

</details>



huangapple
  • 本文由 发表于 2023年2月10日 15:01:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75407860.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定