cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H723ZG creating TCP/IP with lwIP but cannot set ethernet RxBuffer location in cubeMx getting hardfault most likely because of memory

GGODA
Associate II

Edit : see this post for answers :

https://www.reddit.com/r/embedded/comments/13rcrqf/stm32h723zg_creating_tcpip_with_lwip_but_cannot/

reddit dot com /r/embedded/comments/13rcrqf/stm32h723zg_creating_tcpip_with_lwip_but_cannot/

Hello

Summary

  • what I want to do
  • what I have done
  • question

##### WHAT I WANT TO DO #####

I want to send protobuf message from my STM32H723ZG (as a client) to a Raspberry using ethernet communication.

So far I am just trying to create an ethernet connection and to ping the adress of the stm.

##### WHAT I HAVE DONE #####

I looked at ressources online.

The most ineteresting seemed to be this set of videos from controllersTech expaining hwo to do a bunch of ethernet thin on stm32H7xxx:

as well as this github repo + video of a polish person doing a HTTPd project ont the exact same card as me stm32h723zg:

this tutoriel from ST on how to use MPU:

honorable mention to user manual lwIP (um1713) but it doesn't talk about cubeMx so not interesting for now.

I tried initializing a simple lwIp project on cubeMx

Following the controllersTech's videos I :

  • enabled ETH (had to force PB0 to ETH_RXD2)


_legacyfs_online_stmicro_images_0693W00000bkmJBQAY.png 

  • checked the size of the descriptors (96B => 0x60)


_legacyfs_online_stmicro_images_0693W00000bkmIEQAY.png 

  • set the right memory address c.f. image 1 (0x3000 0000 for 1st descriptor [beginning of SRAM 1] 0x3000 0060 for second descripto)
  • enabled cortex7 data and instruction cache
  • enable lwIP
  • select LAN8742 in "platform settings"
  • keep the DHCP enabled (I also tried setting a static ip adress and it was inverted so now I keep the DHCP on)
  • set the heap size to 10KB and start it at 0x3000 4000 (SRAM2)


_legacyfs_online_stmicro_images_0693W00000bkmSDQAY.png 

  • enable MPU
  • set base address at 0x3000 000 (SRAM1)
  • set the size to 32KB (SRAM 1 et 2)
  • set memory type to non-shareable device (c.f. youtube.com/watch?v=6IUfxSAFhlw) basicaly put TEX 1 disable everything the most important is that it's not cacheable

From there I can generate the project.

I add "extern struct netif gnetif;" in the main and "ethernetif_input(&gnetif);" and "sys_check_timeouts();" to the super loop (while(1)).

I should now be able to build and run my program and ping the IP address but when debugging it I instantly get a hardfault.

When debugging using "step over", I notice that the programm/thread is stuck during "SCB_EnableDCache();"

I added

 .lwip_sec (NOLOAD) : {

 . = ABSOLUTE(0x30000000);

 *(.RxDescripSection)

  

 . = ABSOLUTE(0x30000060);

 *(.TxDescripSection)

  

 . = ABSOLUTE(0x300000C0);

 *(.RxArraySection)

 } >RAM_D2

In the flash script and i added the lines regarding the RxBuff

__attribute__((at(0x30000000))) ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */

__attribute__((at(0x30000060))) ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */

__attribute__((at(0x300000C0))) uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; /* Ethernet Receive Buffer */

#elif defined ( __GNUC__ ) /* GNU Compiler */

ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */

ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".TxDecripSection")));  /* Ethernet Tx DMA Descriptors */

uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE] __attribute__((section(".RxArraySection"))); /* Ethernet Receive Buffer */

in the ethernetif.c (only the 2 lines regarding RxBuff, the otehr one already existed).

No change in behavior.

I can see that the domaine 2 now have lwip_sec however it is only 192Kb (the descriptors but not the buffer) and I cannot click it in the memory details window to show what is inside (on the controllersTech video he can click on it to show what is inside).


_legacyfs_online_stmicro_images_0693W00000bkmfHQAQ.png 

I tried using the cubeMx files from the github repo mentionned earlier

The github repo seems to have everything working well.

Since I cannot specify the buffer memory address I looked at his cubeMx file.

It uses an older version of cubeMx so I had the choice to continue or to migrate, I tried both and migrate worked.

Indeed his cubeMx file is different than mine: in ETH, he can specify the memory address of the buffer! (at the time I am writting that i cannot reproduce this but I clearly remember it)

The rest of the setup is similar.

However, I added some print on the console through UART to send the ip address (as decimal).

The whole project can be found here : https://drive.google.com/drive/folders/1GFPTB1tn3KoMvoncMS5x6Oi6IVztdZYd?usp=sharing

In that project I am able to run the project for about 2 seconds the first time I launch it before it gets stuck into hardfault.

When i run it after that it run for .5 second.

##### Question #####

If you can answer one of those that would greatly help me:

1) Do you see a problem in my cubeMx setup?

2) Do you see a problem in my code?

3) Do you have an exemple of a working TCP/IP client or server ?

4) Do you know why I cannot set the memory address of the buffer in cubeMx?

5) Do you know why I get hardfaults?

6) Why do I only get 192KB in lwip_sec (no buffer)?

7) Why can't I see what is inside lwip_sec?

Golden question ) How to make it work? 

Thanks in advance for you response.

If something isn't clear, feel free to ask.

Regards

1 REPLY 1
GGODA
Associate II

:)