Skip to main content
Graduate
January 15, 2024
Solved

Why does LwIP need CPU DCache (on STM32H743)?

  • January 15, 2024
  • 5 replies
  • 3951 views

To enable LwIP in CubeMX (inside CubeIDE) it needs the CPU data cache enabled.  Ok, no problems, but it doesn't explain why and I can't find why this is the case. Is anyone able to offer an explaination?

 

    This topic has been closed for replies.
    Best answer by Pavel A.

    @musmuris The D-cache is required because the LwIP code uses "cache maintenance" operations (aka flush & discard). These may crash when the cache is not active - because of bug or "feature" in some low level stuff (CMSIS or whatever). Nucleo-H743ZI2 is a mature well known board, the ready examples should work. So, better start with these examples and *do not touch anything* for now, just let it work as is. If you want to edit the board config in CubeMX/IDE & re-generate the project: please suppress the urge until you get the ETH example working. (yes, these examples have some other issues but deal with them later). 

    If you absolutely have to disable the D cache: a. Skip the enable (rather than enable then disable), b. Remove/comment out the "cache maintenance" stuff.

    Good luck.

     

     

    5 replies

    Technical Moderator
    January 15, 2024

    Dear @musmuris ,

     

    Welcome in STCommunity , I assume the MCU is STM32H5 series ? , we will move the topic to MCU boards for follow up .

    Ciao

    STOne-32.

    musmurisAuthor
    Graduate
    January 15, 2024

    @STOne-32 

    Thanks. I assumed this was more a CubeMX thing, but wasn't sure where to put it.  It's actually the STM32H743  (Nucleo-H743ZI2 board to be even more precise)

    Graduate II
    January 15, 2024

    It does NOT need any cache, that's just some *** CubeMX restriction.

    I have lwip running on F7 and H7 STMs, no cache enabled.

    Technical Moderator
    January 15, 2024

    Hello,

    You need to enable the cache to boost the performance. You can also disable the cache but with less performance.

    musmurisAuthor
    Graduate
    January 15, 2024

    @mƎALLEm wrote:

    Hello,

    You need to enable the cache to boost the performance. You can also disable the cache but with less performance.


    @mƎALLEm  Thanks - I understand that, but that doesn't mean it's mandated but CubeMX makes you do it (rather than just recommend) - And if you then disable it then LwIP gets disabled.   If DCache is not required then this is a bug in CubeMX isn't it?

    I'm obviously happy to enable it and use DCache - but I like to understand reasons for things (or if it's just a bug)

    Thanks,

    Nigel 

    Technical Moderator
    January 15, 2024

    "And if you then disable it then LwIP gets disabled"

    From my point of view it doesn't make sense to force the user to enable the cache for that feature (except there is something I'm not aware of). So we need the help of @Sara BEN HADJ YAHYA 

    Pavel A.Answer
    Super User
    January 15, 2024

    @musmuris The D-cache is required because the LwIP code uses "cache maintenance" operations (aka flush & discard). These may crash when the cache is not active - because of bug or "feature" in some low level stuff (CMSIS or whatever). Nucleo-H743ZI2 is a mature well known board, the ready examples should work. So, better start with these examples and *do not touch anything* for now, just let it work as is. If you want to edit the board config in CubeMX/IDE & re-generate the project: please suppress the urge until you get the ETH example working. (yes, these examples have some other issues but deal with them later). 

    If you absolutely have to disable the D cache: a. Skip the enable (rather than enable then disable), b. Remove/comment out the "cache maintenance" stuff.

    Good luck.

     

     

    musmurisAuthor
    Graduate
    January 15, 2024

    @Pavel A. wrote:

    The D-cache is required because the LwIP code uses "cache maintenance" operations (aka flush & discard). These may crash when the cache is not active 

     

    Thanks - that's a good reason! As I said I have no need to disable the cache, I just like to know why things are needed where possible

     


    Nucleo-H743ZI2 is a mature well known board, the ready examples should work. 

    The examples do - but trying to start from scratch is a nightmare.  I have managed to walk a narrow path and get PING working, but then it only handles 10 UDP packets before crashing.  But diffing that solution with a broken one I made it's really hard to tell what is wrong (i.e. it's in clocks or something).  Also CubeMX has changed and no longer has (for example) the Rx Buffers option on ETH which others show in screenshots
    The best example doesn't use CubeMX so is harder to take and adapt for people new to STM32 (I'm gonna need to add QSPI flash next)

    Super User
    January 15, 2024

    This is why I don't recommend to start from scratch with a cube-generated project. Ethernet examples are hand-tuned. Cube can generate code for some things but not others, have to merge carefully.