Reduce extra peripherals
Reduce extra peripherals
Hello ,
Can you please suggest the correct way to reduce the extra peripherals which come by default (like I2C, SPI , FS,Timer ) in the current source code so that I can reduce the size of the binary to fit in small microcontroller. Your help is appreciated
Regards
RMQ
Can you please suggest the correct way to reduce the extra peripherals which come by default (like I2C, SPI , FS,Timer ) in the current source code so that I can reduce the size of the binary to fit in small microcontroller. Your help is appreciated
Regards
RMQ
Re: Reduce extra peripherals
Unless you reduce the number of a given peripheral to zero, there won't be any size advantage.
Right now, I don't believe that most of the peripherals are configable.
I think that you'd need to introduce config options for each of the peripherals you want to remove, and find the references to them.
For example, add MICROPY_HW_ENABLE_I2C or perhaps MICROPY_HW_HAS_I2C to be consistent with the other peripherals.
By searching for MICROPY_HW_HAS I was able to see: MICROPY_HW_HAS_SWITCH, MICROPY_HW_HAS_SDCARD, MICROPY_HW_HAS_MMA7660, MICROPY_HW_HAS_LIS3DSH, and MICROPY_HW_HAS_LCD
These can all be turned off in your mpconfigboard.h file for your board.
Which chip are you trying to target? And how much flash/RAM does it have?
Right now, I don't believe that most of the peripherals are configable.
I think that you'd need to introduce config options for each of the peripherals you want to remove, and find the references to them.
For example, add MICROPY_HW_ENABLE_I2C or perhaps MICROPY_HW_HAS_I2C to be consistent with the other peripherals.
By searching for MICROPY_HW_HAS I was able to see: MICROPY_HW_HAS_SWITCH, MICROPY_HW_HAS_SDCARD, MICROPY_HW_HAS_MMA7660, MICROPY_HW_HAS_LIS3DSH, and MICROPY_HW_HAS_LCD
These can all be turned off in your mpconfigboard.h file for your board.
Which chip are you trying to target? And how much flash/RAM does it have?
Re: Reduce extra peripherals
Hello dhylands
Thanks for your reply . I went to STMHAL/boards/STM32F4DISC and change the macros as
#define MICROPY_HW_HAS_SWITCH (1)
#define MICROPY_HW_HAS_SDCARD (0)
#define MICROPY_HW_HAS_MMA7660 (0)
#define MICROPY_HW_HAS_LIS3DSH (0)//1
#define MICROPY_HW_HAS_LCD (0)
#define MICROPY_HW_ENABLE_RNG (0)//1
#define MICROPY_HW_ENABLE_RTC (0)//1
#define MICROPY_HW_ENABLE_TIMER (0)//1
#define MICROPY_HW_ENABLE_SERVO (0)
#define MICROPY_HW_ENABLE_DAC (0)//1
#define MICROPY_HW_ENABLE_SPI1 (0)//1
#define MICROPY_HW_ENABLE_SPI2 (0)//1
#define MICROPY_HW_ENABLE_SPI3 (0)
#define MICROPY_HW_ENABLE_CAN (0)//1
and I saw the difference in size of the firmware1.bin from 252608 bytes to 238960 bytes . Is this the correct way to find the size of the binary.
To answer your question , we would be writing a wrapper layer for a connectivity module so we are evaluating the amount of flash/RAM that will be required by the OS apart from the peripherals (similar to what is done with LIS3DH) . Do you have any data which gives information about the footprint of bare OS and with peripherals so that we can evaluate the correct controller from ST for our job,
Regards
RMQ
Thanks for your reply . I went to STMHAL/boards/STM32F4DISC and change the macros as
#define MICROPY_HW_HAS_SWITCH (1)
#define MICROPY_HW_HAS_SDCARD (0)
#define MICROPY_HW_HAS_MMA7660 (0)
#define MICROPY_HW_HAS_LIS3DSH (0)//1
#define MICROPY_HW_HAS_LCD (0)
#define MICROPY_HW_ENABLE_RNG (0)//1
#define MICROPY_HW_ENABLE_RTC (0)//1
#define MICROPY_HW_ENABLE_TIMER (0)//1
#define MICROPY_HW_ENABLE_SERVO (0)
#define MICROPY_HW_ENABLE_DAC (0)//1
#define MICROPY_HW_ENABLE_SPI1 (0)//1
#define MICROPY_HW_ENABLE_SPI2 (0)//1
#define MICROPY_HW_ENABLE_SPI3 (0)
#define MICROPY_HW_ENABLE_CAN (0)//1
and I saw the difference in size of the firmware1.bin from 252608 bytes to 238960 bytes . Is this the correct way to find the size of the binary.
To answer your question , we would be writing a wrapper layer for a connectivity module so we are evaluating the amount of flash/RAM that will be required by the OS apart from the peripherals (similar to what is done with LIS3DH) . Do you have any data which gives information about the footprint of bare OS and with peripherals so that we can evaluate the correct controller from ST for our job,
Regards
RMQ
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Reduce extra peripherals
A minimal port of MicroPython takes around 70K on a Cortex-M, and that's just the core without any libraries or even a REPL. I would say that absolute min specs to have something useful are like 128K Flash and 32K of RAM. If you want to do serious stuff, then multiply those figures by 2.
Just my 0,02...
Just my 0,02...
Re: Reduce extra peripherals
If you want to see the size of uPy without any peripherals then compile the code in bare-arm/ or minimal/ directories. That will build also with minimal Python features (eg no float, no sets) and give you around 75k binary. If you enable all Python features (float, bignum, line number info, etc) it grows to about 130-150k.
The 250k of stmhal includes a lot of peripheral drivers, maths functions (eg cos, sin) and other things. One big cost is the USB driver.
The 250k of stmhal includes a lot of peripheral drivers, maths functions (eg cos, sin) and other things. One big cost is the USB driver.
Re: Reduce extra peripherals
Thanks for the detailed explanation regarding the size of the stack. I tried to compile the bare-arm by going to the folder bare-arm and command "make BOARD=STM32F4DISC V=1" . I got the output in build with firmware.elf having the size
" -rwxr-xr-x. 1 root root 183788 Jun 11 22:12 firmware.elf".
Is the correct way of doing or there is mistake in my process ? Can you please guide me ?
Regards
RMQ
" -rwxr-xr-x. 1 root root 183788 Jun 11 22:12 firmware.elf".
Is the correct way of doing or there is mistake in my process ? Can you please guide me ?
Regards
RMQ
Re: Reduce extra peripherals
BOARD= is only applicable for stmhal builds (at least currently).
Just running make in bare-arm is correct.
I get a 156,504 byte firmware.elf (using gcc 4.9.3). To determine the code size, run the size command:
Just running make in bare-arm is correct.
I get a 156,504 byte firmware.elf (using gcc 4.9.3). To determine the code size, run the size command:
Code: Select all
size build/firmware.elf
text data bss dec hex filename
71304 0 392 71696 11810 build/firmware.elf
Re: Reduce extra peripherals
I have some more queries on the size . Is it possible to have a break of the memory as follows
1. Stmhal basic (only StdPeriphLibs inside)
2. Stmhal (point 1) + OS (RTOS)
3. Stmhal (point 2) + FS (FAT FS)
4. Stmhal (point 3) + USB (USB Libs, device and host)
I was trying to make some changes in the MakeFile in folder stmhal but I was not successful enough to compile . I see some flags like USBDEV_DIR, FATFS_DIR which I tried to comment to reduce the size but I received compile time error . Can you help me in this ?
I also see an answer to my query "That will build also with minimal Python features (eg no float, no sets) and give you around 75k binary". Can you guide me the changes to get the 75k binary ?
Regards
RMQ
1. Stmhal basic (only StdPeriphLibs inside)
2. Stmhal (point 1) + OS (RTOS)
3. Stmhal (point 2) + FS (FAT FS)
4. Stmhal (point 3) + USB (USB Libs, device and host)
I was trying to make some changes in the MakeFile in folder stmhal but I was not successful enough to compile . I see some flags like USBDEV_DIR, FATFS_DIR which I tried to comment to reduce the size but I received compile time error . Can you help me in this ?
I also see an answer to my query "That will build also with minimal Python features (eg no float, no sets) and give you around 75k binary". Can you guide me the changes to get the 75k binary ?
Regards
RMQ
- danicampora
- Posts: 342
- Joined: Tue Sep 30, 2014 7:20 am
- Contact:
Re: Reduce extra peripherals
Use the bare arm build.I also see an answer to my query "That will build also with minimal Python features (eg no float, no sets) and give you around 75k binary". Can you guide me the changes to get the 75k binary ?
Re: Reduce extra peripherals
Hello,
I compiled the /micropython/bare-arm with the make command and I got the following output . Did not make change in make file. I am not able to get 75K
ls -ls firmware.elf
128 -rwxr-xr-x. 1 root root 183788 Jun 15 19:27 firmware.elf
size firmware.elf
text data bss dec hex filename
71436 0 392 71828 11894 build/firmware.elf
Is it correct ?
I compiled the /micropython/bare-arm with the make command and I got the following output . Did not make change in make file. I am not able to get 75K
ls -ls firmware.elf
128 -rwxr-xr-x. 1 root root 183788 Jun 15 19:27 firmware.elf
size firmware.elf
text data bss dec hex filename
71436 0 392 71828 11894 build/firmware.elf
Is it correct ?