Porting to STM32F429, where to increase code size?

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
User avatar
dhylands
Posts: 3247
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Porting to STM32F429, where to increase code size?

Post by dhylands » Thu Dec 31, 2015 9:00 am

I found the problem on master and submitted a PR to fix it.

Jacob_Beningo
Posts: 12
Joined: Thu Jul 07, 2016 8:45 pm

Re: Porting to STM32F429, where to increase code size?

Post by Jacob_Beningo » Thu Jul 07, 2016 8:58 pm

I'm working with the STM32F429 and seem to be running into an issue with the internal flash drive when expanding it beyond the traditional 96kB. My drive size is 664 kB but I can only write 274 kB of data to the drive. Any more and the device locks up, shows up as an unrecognized USB device and requires a power cycle.

I've modified storage.c on line 68 and 69 (within the #elif defined(STM32F429xx) to read:

#define FLASH_MEM_SEG2_START_ADDR(0x08100000) //starting location for Sector 12 in flash Bank 2.
#define FLASH_MEM_SEG2_NUM_BLOCKS(1152) // sectors 12 - 23 4*16kB + 64kB + 7*64kB(of 128)

I compile the code, flash the discovery board and then rebuild the file system. At this point everything seems fine but if I add enough code beyond the 274 kB I get the lock-up. I know that I can use frozen modules but I'm working on a system that requires back-ups and robust operation so I'm planning to have copies of the application code as frozen modules, flash drive files and SD card files (yes a bit paranoid).

Any suggestions or thoughts on what may be happening or where a good starting would be to debug this issue? It would be helpful if someone with a 429Discovery board could verify this problem as well. I wrote a simple (and dirty) test script that writes 1 kB files to the flash system which is below:

import sys

FileNumber = 0

while True:

Part1 = "g:\\test"
Number = str(FileNumber)
FileName = Part1 + Number + ".txt"

f = open(FileName, "w")

for x in range(0, 1000):
f.write("A")

f.close()

FileNumber = FileNumber + 1

if FileNumber == 1000:
print("Made it to 1000!")
sys.exit()

Thanks for insights anyone can provide!

User avatar
dhylands
Posts: 3247
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Porting to STM32F429, where to increase code size?

Post by dhylands » Thu Jul 07, 2016 10:38 pm

Hmm. In order for the flash to work, there has to be enough RAM to store an entire flash block in RAM.

We currently reserve the CCM memory (which is 64K), so you can use 16K and 64K blocks. If you want to use 128K blocks, then you can only use the first 64K of the 128K block (so storage.c would need to take that into consideration).

And you also need to make sure that the linker script doesn't put and code/data (.text and .data sections) in the same place as the filesystem blocks.

Jacob_Beningo
Posts: 12
Joined: Thu Jul 07, 2016 8:45 pm

Re: Porting to STM32F429, where to increase code size?

Post by Jacob_Beningo » Thu Jul 07, 2016 11:09 pm

Thanks! How do I let storage.c know that I want to use the first half 64k of the 128k available? From looking through storage.c I thought it already made this assumption.

As far as the linker goes, I've done the following:

MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x0200000 /* entire flash, 2048 KiB */
FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x0004000 /* sector 0, 16 KiB */
FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x0080000 /* sectors 5,6,7,8, 4*128KiB = 512 KiB (could increase it more) */
// The above line LENGTH was 0x0088000 but this didn't make sense to me as this would be partially within a sector so I set it to a boundry.
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x0030000 /* 192 KiB */
SDRAM(xrw) : ORIGIN = 0xC0000000, LENGTH = 0x0800000 /* 8 MByte */
}

I'm then trying to using sectors 12 - 23 to get additional flash storage space for application code. From the linker I would expect any MP code to be stored in FLASH_TEXT and not interfere with the larger file system.

User avatar
dhylands
Posts: 3247
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Porting to STM32F429, where to increase code size?

Post by dhylands » Sat Jul 09, 2016 10:52 pm

I'm not seeing any code in storage.c to compensate for the fact that only half of the 128K block would be used.

If you set FLASH_MEM_SEG2_NUM_BLOCKS to 224 and FLASH_MEM_SEG2_START_ADDR to 0x8100000 then you'd get double the filesystem size.

Once you go beyond that, you need to start compensating for the fact that only 1/2 of a flash block is used.

I'm assuming that when you say "application code" you're really refering to the filesystem.

Jacob_Beningo
Posts: 12
Joined: Thu Jul 07, 2016 8:45 pm

Re: Porting to STM32F429, where to increase code size?

Post by Jacob_Beningo » Thu Jul 14, 2016 12:17 am

Thanks! I see now what is going on in the code. For now I'm setting the maximum size to 284 kB and then will use frozen modules. As time allows I'm going to go back and make the updates so that the 128 kB sectors can be used.

Thanks for the help!

denisbill
Posts: 1
Joined: Fri Oct 26, 2018 4:20 am

Re: Porting to STM32F429, where to increase code size?

Post by denisbill » Fri Oct 26, 2018 4:24 am

I'm working with the STM32F429 and seem to be running into an issue with the internal flash drive when expanding it beyond the traditional 96kB. My drive size is 664 kB but I can only write 274 kB of data to the drive. Any more and the device locks up, shows up as an unrecognized USB device and requires a power cycle. www.printererrorrepair.com/blog/how-to- ... ine-error/

Post Reply