SDMMC2 on STM32F769NI Discovery

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: SDMMC2 on STM32F769NI Discovery

Postby Giovanni » Wed Jun 06, 2018 9:15 pm

Probably it would be better to add a compile time option for flushing, to be enabled if it is required: device type, default allocation.

Giovanni

dflogeras
Posts: 212
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 7 times
Been thanked: 19 times

Re: SDMMC2 on STM32F769NI Discovery

Postby dflogeras » Wed Jun 06, 2018 10:20 pm

steved wrote:Not sure whether there's any advantage to checking whether the buffer is in cached RAM, but it didn't seem to do any harm.
I've also adjusted my malloc() to assign memory starting on 32-byte boundaries (i.e. cache lines)


I took a different tactic, since:
- For third party stuff like this sqlite VFS layer I'm making, it may hand me pointers that it allocated on its own stack, or using newlib's malloc and I cannot guarantee they are 32 byte
- The FIL data structure's internal buffer may not be 32-byte offset from the start of the structure (now or in the future)


I think my 32byte alignment, married with your check to see if it is in a cacheable RAM segment would be optimal (and of course with better #ifdef logic, but I'll leave that to Giovanni).

sdc_cache_coherency.patch.zip
(672 Bytes) Downloaded 141 times


Dave

dflogeras
Posts: 212
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 7 times
Been thanked: 19 times

Re: SDMMC2 on STM32F769NI Discovery

Postby dflogeras » Thu Jun 07, 2018 4:29 pm

Here's a fixed version of my previous patch. I shouldn't do ptr math after two pots of coffee; just one.

sdc_cache_coherency.patch.zip
(673 Bytes) Downloaded 152 times

tridge
Posts: 141
Joined: Mon Sep 25, 2017 8:27 am
Location: Canberra, Australia
Has thanked: 10 times
Been thanked: 20 times
Contact:

Re: SDMMC2 on STM32F769NI Discovery

Postby tridge » Fri Jun 08, 2018 12:42 pm

we hit something similar in ArduPilot, and ended up solving it using a bouncebuffer API, allowing for an external manager for DMA-capable memory. Patch for SDMMCv1 is here:
https://github.com/ArduPilot/ChibiOS/co ... a984a90803
The bouncebuffer code is here:
https://github.com/ArduPilot/ardupilot/ ... cebuffer.c
https://github.com/ArduPilot/ardupilot/ ... cebuffer.h
We setup the main stack/heap/data in SRAM1/SRAM2, and use DTCM for bouncebuffers and for the heap when the primary heap is full.
We use the same bouncebuffer code for SPI and I2C as well.
Cheers, Tridge

steved
Posts: 825
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: SDMMC2 on STM32F769NI Discovery

Postby steved » Sat Jun 09, 2018 12:30 pm

dflogeras wrote:
steved wrote:Not sure whether there's any advantage to checking whether the buffer is in cached RAM, but it didn't seem to do any harm.
I've also adjusted my malloc() to assign memory starting on 32-byte boundaries (i.e. cache lines)


I took a different tactic, since:
- For third party stuff like this sqlite VFS layer I'm making, it may hand me pointers that it allocated on its own stack, or using newlib's malloc and I cannot guarantee they are 32 byte
- The FIL data structure's internal buffer may not be 32-byte offset from the start of the structure (now or in the future)


I think my 32byte alignment, married with your check to see if it is in a cacheable RAM segment would be optimal (and of course with better #ifdef logic, but I'll leave that to Giovanni).

sdc_cache_coherency.patch.zip

Dave

I created my own malloc() (initially for other reasons), so it was easy to make it call Chibi's heap allocator with 32-byte alignment.

This whole business of managing cached RAM could do with some refinement, although I'm not sure how feasible it is to do things in a totally generic way. It would probably be enough to specify non-cacheable areas in one of the configuration files, which auto-generated MMU code to disable caching if necessary. This then needs a way of keeping track of which MMU banks are in use..... Then a call to determine whether caching is enabled on a particular block - isMemoryCached(start, blockSize), which feeds through to the cache flush and invalidate functions.
Would certainly be better than my very processor-specific check.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: SDMMC2 on STM32F769NI Discovery

Postby Giovanni » Sat Jun 09, 2018 5:04 pm

Using MMU is not that easy because it requires 32 bytes alignment, a general approach is hard.

What could be done is to create a special segment guaranteed to be non-cached (using MMU or other means) but it would still up the application code to put buffers in there, something not easy when using a 3rd part library like FatFS.

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 10 guests