Large flash size on STM32 port for PyBoard 1.1

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
User avatar
saiftyfirst
Posts: 10
Joined: Wed Mar 04, 2020 4:58 pm

Large flash size on STM32 port for PyBoard 1.1

Post by saiftyfirst » Tue Mar 24, 2020 10:42 pm

I added a bunch of user modules and ended up with a large build package. Resulted in the following error:
arm-none-eabi-ld: region `FLASH_TEXT' overflowed by 523020 bytes
Fix: by allocating more space for FLASH_TEXT in the linker script for STM32F405 (<>/micropython/ports/stm32/boards/stm32f405.ld)

However, when I try to deploy I get a different exception:
Exception: DFU: set address failed
Trace:
File "../../tools/pydfu.py", line 597, in <module>
main()
File "../../tools/pydfu.py", line 587, in main
write_elements(elements, args.mass_erase, progress=cli_progress)
File "../../tools/pydfu.py", line 525, in write_elements
write_memory(addr, data[:write_size], progress, elem_addr, elem_size)
File "../../tools/pydfu.py", line 222, in write_memory
set_address(xfer_base + xfer_bytes)
File "../../tools/pydfu.py", line 199, in set_address
raise Exception("DFU: set address failed")

For the space for FLASH_TEXT, I doubled every space block and doubled the starting address for each block as shown in the ATTACHMENT. Anything I am doing wrong or missing ?
Attachments
Screenshot from 2020-03-24 23-37-40.png
Screenshot from 2020-03-24 23-37-40.png (48.8 KiB) Viewed 158 times

User avatar
jimmo
Posts: 1459
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Large flash size on STM32 port for PyBoard 1.1

Post by jimmo » Wed Mar 25, 2020 1:47 am

I don't quite understand what you changed? The STM32F405 in the Pyboard 1.1 has 1kiB of flash. You can't just tell it that it now has 2kiB. Or am I misunderstanding what you changed?

If you want to make more room for user modules, you'll need to decrease the space reserved for the filesystem. So tradeoff between FLASH_FS and FLASH_TEXT.

User avatar
saiftyfirst
Posts: 10
Joined: Wed Mar 04, 2020 4:58 pm

Re: Large flash size on STM32 port for PyBoard 1.1

Post by saiftyfirst » Wed Mar 25, 2020 7:12 am

I have a C++ user module that uses a libstdc++, libm etc. and when I add the module, the entire flash just becomes super large.

I'll double check if I'm doing anything off, just in case

User avatar
jimmo
Posts: 1459
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Large flash size on STM32 port for PyBoard 1.1

Post by jimmo » Wed Mar 25, 2020 7:39 am

While it is possible to write embedded stuff in C++, a lot of care must be taken. In particular, you're basically going to end up duplicating a lot of the code already provided in the firmware (e.g. string handling, lists, maps, math, etc).

i.e. if your C++ code uses anything from the STL (vector, map, unordered_map, string) then thats a lot of code that already exists. Also on stm32 we don't use the compiler's libm, instead a minimal subset.

User avatar
jimmo
Posts: 1459
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Large flash size on STM32 port for PyBoard 1.1

Post by jimmo » Wed Mar 25, 2020 7:40 am

But also, does what I said about the linker script and flash size make sense?

User avatar
saiftyfirst
Posts: 10
Joined: Wed Mar 04, 2020 4:58 pm

Re: Large flash size on STM32 port for PyBoard 1.1

Post by saiftyfirst » Wed Mar 25, 2020 10:29 am

I understand. Basically, I've only added the libraries that helped me remove linker errors when I compiled the user module into the firmware. I'd have to investigate more thoroughly to determine what would've been duplicated.

About the flash, I interpreted it as flexible and since I am flashing to an SD card I could resize it and point to new starting addresses. I understand that you are saying that is not allowed.

User avatar
saiftyfirst
Posts: 10
Joined: Wed Mar 04, 2020 4:58 pm

Re: Large flash size on STM32 port for PyBoard 1.1

Post by saiftyfirst » Wed Mar 25, 2020 10:31 am

Previously, I had reallocated more space for flash from the file system as you mentioned but now the size is just too big. Possibly due to the duplication.

User avatar
saiftyfirst
Posts: 10
Joined: Wed Mar 04, 2020 4:58 pm

Re: Large flash size on STM32 port for PyBoard 1.1

Post by saiftyfirst » Wed Mar 25, 2020 12:19 pm

I understand better what you mean by the minimal libraries used for stm32. And yes, there is a lot of duplication that I do not need.

I suppose, I could add the additional functionality manually to the upy source code. Would that be a good idea ? If so, where could I potentially find the source code for the functions I need since implementing them myself is too much work for the moment.

As an example, I need the "pow" function form the math library but the stm32 version does not have the implementation for it

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

Re: Large flash size on STM32 port for PyBoard 1.1

Post by dhylands » Wed Mar 25, 2020 4:52 pm

The firmware runs from the internal flash, and the FLASH_TEXT region in the linker map refers to the size of that internal flash storage area.

The sdcard is only used for storing files. If the sdcard contains python code or .mpy files then these still get loaded into RAM and have nothing to do with FLASH.

User avatar
jimmo
Posts: 1459
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Large flash size on STM32 port for PyBoard 1.1

Post by jimmo » Thu Mar 26, 2020 12:55 am

saiftyfirst wrote:
Wed Mar 25, 2020 12:19 pm
As an example, I need the "pow" function form the math library but the stm32 version does not have the implementation for it
Do you want pow or powf?

Sounds like you may be using doubles, which will lead to a large increase in code size due to no hardware double-precision floating point support.

Remember on pybv1.1 you should probably be using single-precision floating point to match the rest of the MicroPython firmware (on PYBV1.1 the default is single, but you can optionally set double). powf will be available in single, pow in double.

The best advice is to use mp_float_t and MICROPY_FLOAT_C_FUN which will use the correct version depending on the build settings.

Post Reply