Reduce extra peripherals

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
rmq
Posts: 10
Joined: Thu May 21, 2015 5:21 am

Reduce extra peripherals

Post by rmq » Wed Jun 10, 2015 3:46 pm

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

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

Re: Reduce extra peripherals

Post by dhylands » Wed Jun 10, 2015 3:57 pm

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?

rmq
Posts: 10
Joined: Thu May 21, 2015 5:21 am

Re: Reduce extra peripherals

Post by rmq » Thu Jun 11, 2015 9:47 am

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

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Reduce extra peripherals

Post by danicampora » Thu Jun 11, 2015 9:59 am

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...

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Reduce extra peripherals

Post by Damien » Thu Jun 11, 2015 10:02 am

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.

rmq
Posts: 10
Joined: Thu May 21, 2015 5:21 am

Re: Reduce extra peripherals

Post by rmq » Thu Jun 11, 2015 4:44 pm

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

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

Re: Reduce extra peripherals

Post by dhylands » Thu Jun 11, 2015 5:12 pm

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:

Code: Select all

size build/firmware.elf 
   text	   data	    bss	    dec	    hex	filename
  71304	      0	    392	  71696	  11810	build/firmware.elf

rmq
Posts: 10
Joined: Thu May 21, 2015 5:21 am

Re: Reduce extra peripherals

Post by rmq » Mon Jun 15, 2015 8:24 am

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

User avatar
danicampora
Posts: 342
Joined: Tue Sep 30, 2014 7:20 am
Contact:

Re: Reduce extra peripherals

Post by danicampora » Mon Jun 15, 2015 8:52 am

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 ?
Use the bare arm build.

rmq
Posts: 10
Joined: Thu May 21, 2015 5:21 am

Re: Reduce extra peripherals

Post by rmq » Mon Jun 15, 2015 1:55 pm

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 ?

Post Reply