Closed rkompass closed 8 months ago
O.k., I get it. It's the 64K cache for the flash. Somewhere defined, but not reported in the pyb.info().
And the additional 64K RAM is CCM RAM. One may use it though: https://forum.micropython.org/viewtopic.php?f=3&t=3702.
Jimmo stated in Feb 2021 there:
The heap is limited by the available RAM. The default configuration uses all available RAM (left over after .bss and .data).
The only exception is that the CCM is reserved for the block cache. Making that available to the heap would require supporting multiple non-contiguous regions, but isn't currently available.
That should have changed recently, iirc. So in principle there would be away now to have more Heap.
Hi! You are right, that is used as flash cache.
This ugh.. is kinda awkward for the current state of the micropython.
The problem is that the F405's RAM is split into 2 sections. One SRAM (1 and 2, 112K+16K) and one CCM (64K), as you can check in the manual:
But the gc
in micropython requres the memory (RAM) to be continous. Which means, the 64K CCMRAM can not be utilized otherwise. (Maybe as a RAM-disk, but I haven't tried it out yet).
If you were looking for a device with more RAM, I suggest you to checkout the STM32F412RE also made by WeAct Studio. I have a definition for that board as well. It does not have a SPI-Flash but you can get yourself a SD-card, configure it to be mounted on boot and use that to store all your codes and data. It's basically a F411 with more RAM.
I edited: Jimmo stated in Feb 2021 there:
The heap is limited by the available RAM. The default configuration uses all available RAM (left over after .bss and .data).
The only exception is that the CCM is reserved for the block cache. Making that available to the heap would require supporting multiple non-contiguous regions, but isn't currently available.
That should have changed recently, iirc. So in principle there would be away now to have more Heap.
After hearing your comment/opinion I should ask Jimmo in discussions??
That should have changed recently, iirc. So in principle there would be away now to have more Heap.
Are they officially moving stack into the CMMRAM? That's some really exciting news! Thanks for the information!
No. I just noted that there is now a way to have the heap using 2 different RAM regions.
But for the CMMRAM that would probably still be problematic, as there are operations like timed ADC or DAC, that use the DMA under the hood. I should ask Jimmo if it's possible now.
Oh, ok.
But for the CMMRAM that would probably still be problematic, as there are operations like timed ADC or DAC, that use the DMA under the hood. I should ask Jimmo if it's possible now.
As Damien said in that thread, it's probably safe to do so.
So it should be OK to put the stack into CPU-only RAM, ie not accessible by DMA.
I guess you just have to modify these lines.
Are they officially moving stack into the CMMRAM?
Not officially. But chrismas9 did it in the above linked MP forum post:
By reducing the cache size and moving the stack into the second RAM block I can increase the heap by 16k.
And there was no problem. However then that was only the 16K stack. Freeing 16K for the Heap
Those are the lines !
I should search for the secondary heap: Found heap autosplit. What do you think: Could that be applied to CCM RAM?
That is a great feature!
Tho, after a very brief look into it, I believe that is designed towards the esp32
port and recently been replaced/reorganized into the new MICROPY_GC_SPLIT_HEAP
. And this tag seems only to be relevant for the esp32
port.
So the 16K stack relocation is realistic, the heap split not. Also not for this:
The DMA on the STM32 is currently used for the following: SD card, DAC, SPI, I2C. The DAC, SPI and I2C are pretty much exclusively called by Python code with buffers allocated on the heap. SD card read/write can be called from Python with a buffer on the heap, or the USB MSC driver which has a statically allocated buffer in the BSS segment.
So it should be OK to put the stack into CPU-only RAM, ie not accessible by DMA.
I will try to compile this in, once I do a compilation session :-)
Hello @nspsck,
because we were at it: I just wanted to ask you a question, we may close this issue immediately afterwards. But perhaps you decide this belongs to the MP discussons...
With the Blackpill I now have, due to your efforts, in comparison to Pyboard 1.1
But the pyboard has a STM32F405RG with 192K RAM !!! I would expect at least +40-50K more RAM, but there is only +3K more available. Do you have an explanation for this? Is there something grossly misconfigured? Both show _ram_end=20020000, shouldn't it be another value for the Pyboard?