What sketch size on Arduino Pro Mini 8Mhz with an ISP-programmer?

I have super-optimized my code for a Pro Mini 8Mhz 3.3V and it is working well.
Now I need 1-1.5K of flash RAM more, so I'm investigating about ISP-programming via a cheap USBasp programmer.

As noticed elsewhere, when I compile a sketch for the Pro Mini the max allowed size prompted by the Arduino IDE is 30720 bytes, because the Pro Mini uses a big and old bootloader.

In this post by the user Pert I read:

"You could also do a Sketch > Upload Using Programmer with your ISP programmer
to flash the board without the use of a bootloader to free up 2 kB but the IDE still
erroneously maintains the maximum size with the boot section."

What does it exactly means? I would not able to upload sketches greater than 30720 byte, even by using and ISP-programmer?
:frowning:

gimpo:
What does it exactly means? I would not able to upload sketches greater than 30720 byte, even by using and ISP-programmer?

That's correct but luckily there's an easy solution. If you install MiniCore:

After selecting the MiniCore's ATmega328 board from the Tools > Board menu, you'll find a new "Bootloader" menu added to the Tools menu where you can select the "No" option. There is also a Tools > Clock menu where you can set the correct clock configuration for your hardware. After that you should do a Tools > Burn Bootloader to set the fuses accordingly.

You might also be interested to know that MiniCore comes with the excellent Optiboot bootloader, which is only 0.5 kB so if you still wanted to use a bootloader that will free up 1.5 kB compared to the standard Pro Mini bootloader.

Hello pert,
thanks for your answer.

By following the instructions on github I have installed the MiniCore boards without problems in a minute (Arduino IDE 1.8.1).

What are now the right options for the Arduino Pro Mini 8Mhz 3.3V?

Boot loader -> No/Yes, if I choose "Yes" then the small 512 bytes will be uploaded, I'm right?
Variant -> 328P/328PA or 328/328A or 328PB, what version I should select here?
BOD -> 2.7/4.3/1.8/Disabled, what I should select here? 2.7?
Clock -> 16/20/18.432/12/8 external/8 internal/ 1 internal, what I should select here?

gimpo:
Boot loader -> No/Yes, if I choose "Yes" then the small 512 bytes will be uploaded, I'm right?

Yes

gimpo:
Variant -> 328P/328PA or 328/328A or 328PB, what version I should select here?

328P/328PA

gimpo:
BOD -> 2.7/4.3/1.8/Disabled, what I should select here? 2.7?

2.7 is the setting used by Arduino's definition for the Pro Mini 3.3V. Figure 32-1 of the datasheet shows that the maximum safe clock speed at 1.8 V is 4 MHz. 10 MHz is the maximum safe clock speed at 2.7 V so a BOD setting of 2.7 V is possibly a bit limiting if you wanted to allow for running at lower voltages (such as when operating on battery power). The microcontroller will automatically reset when the voltage goes below the BOD setting. So really it's your choice how you want to set that option, though of course setting it to 4.3 when your chip is running at 3.3 V will be no good.

gimpo:
Clock -> 16/20/18.432/12/8 external/8 internal/ 1 internal, what I should select here?

8 MHz External

Ok, now it is clear.
The Mini Pro will be connected to the battery of a motorcycle (12V) via a voltage converter, so the voltage should never go under 3.3V. BOD = 2.7V seems a quite reasonable choice in my case.

Now I have to wait for the USBasp programmer I ordered few minutes ago. I should receive it in a couple of days.
I will report my results here.

Thanks a lot for the info pert, you saved my life!

If you have an extra Arduino you could use it as an "Arduino as ISP" programmer so you don't need to wait. But I think the USBasp will be a good tool to have in the long run since you're interested in bootloaders and uploading using the programmer. I use mine all the time.

:wink:

Below two tests made with Arduino IDE 1.8.1
It could be funny, but not in my case... :frowning:

Board = ATMega320:
Compiler output = Sketch uses 32194 bytes (99%) of program storage space. Maximum is 32256 bytes.

Board = Arduino Pro or Pro Mini
Compiler output = Sketch uses 30194 bytes (98%) of program storage space. Maximum is 30720 bytes.

So by using an ISP-programmer I get additional 2K of free space for my program, but the compiler produce a larger program... :o

Turn on LTO

It's on by default in standard boards, but disabled by default on minicore to maintain backwards compatibility with old versions

Hi!
Give me just one minute to discover what LTO is/means... :smiley:
(I'm using Ubuntu 16.04)

With verbose output enabled, the first two rows of the compiler output contains

/home/giulio/arduino-1.8.1/arduino-builder -compile....... ,LTO=Os ,.......

is that option? It seems enabled...

Do this:
Tools > Compiler LTO > Enabled

Sketch uses 30214 bytes (93%) of program storage space. Maximum is 32256 bytes.

It works!
Hooray!
Only 20 bytes greater than the one for the standard Pro Mini board. I'm an happy man now.

UPDATE: how to fix troubles/problems if the USBasp won't upload the sketch.

Check 1 - wrong programmer?

After the selection and configurating of the right Minicore board (see posts above), be sure that the right

tools -> Programmer -> USBasp

My selection was still on "AVRISP mkII" :-[

Check 2: connector plugged wrongly?

Be sure that the wiring from the IDC-10 connector to the Arduino pins is correct. Double check it, after that check it again.

Please note that a lot of wiring diagrams on internet are wrong just because the guy didn't plugged the IDC-10 into the USBasp board correctly. So the pin 1 of the board do not correspond to the wire with the red color on the connector-stripe.

If you bought (like me) an USBasp with the connector pointing upward, then the right way to plug the IDC-10 is the one shown in the photo below, i.e. with the red wire connected to the pin 1 (pin 1 is always VCC).

Also, the right wiring of the connector at the other end is the one shown here.
Please carefully look at the second (unfocused) photo, that is the key. Note also the position of the red wire on the stripe relatively to the flat surface of the IDC-10 connector.

Trouble 1: no permissions on the USB?

After issuing the command Sketch -> Upload using Programmer, the upload fails because the IDE states that cannot find any device attached to usb/tty0 (or whatever), even if you can select that usb in the Tools -> Port menu:

avrdude: Warning: cannot open USB device: Permission denied
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor='www.fischl.de' product='USBasp'

This is a problem of permissions in Linux. The solution is available here.

Trouble 2: no answer from the programmer?

Again, the IDE won't upload because this error message:

avrdude: error: program enable: target doesn't answer. 1

If you're using a "slow" Pro Mini at 8Mhz (like me), then Thomas Fischl (the creator of the USBasp) suggest here to bridge the jumper J3. This will slow the clock of the USBasp too.

Trouble 3: avrdude: verification error, first mismatch at byte ......

Try to plug the GND cable to a different ground pin of the IDC-10 connector.

There are four position labeled as ground pins on the connector, they should be all the same but seems they are not. I just switched the GND cable from pin #10 to #8 and the uploading of the sketches has started to work again.
When/if I plug back the cable to the previous position the verification error comes out again.

Now my USBasp uploads sketches like a tornado! Ciaoooo! :smiley:

Question.

I've burned the bootloader by using the Minicore board, all was fine. after that I've uploaded a sketch by using the serial line with success.
Nevertheless, I saw this message during compilation:

Sketch uses 30218 bytes (93%) of program storage space. Maximum is 32256 bytes.

Is this normal?
The bootloader should occupy 512 bytes, so the free space should be less than 32K. I'm missing something?

Without bootloader.

Sketch uses 1032 bytes (3%) of program storage space. Maximum is 32768 bytes.

You're right: 32K = 32768 bytes. So 32768-512 = 32256 bytes...
Ok, I need to sleep more than 3 hours per day...

Today I'm facing a new problem.

I wrote a short test-sketch blinking the default LED with some fancy timing.
First time I've uploaded it without problems. The second time I've got the diabolic message

avrdude: verification error, first mismatch at byte 0x0000

  • 0x00 != 0x0c*

(See details below.)

I tried again and again, by re-starting the IDE, the entire PC, disconnecting and re-connecting the USB cable, etc. Nothing has worked. I'm going crazy.

Here my settings:

The "problem" is that the sketch seems working correctly despite of the avrdude error.
I mean, every modification in the code of the sketch (i.e. the LED blinking sequence) is correctly actuated by the uploaded sketch. In other words, it seems uploaded with success.

I strongly suspect that there is a communication problem between the PC and the USB, more than a bug in the IDE and/or the AVR code.... This problem arises when reading back the sketch for verification.
It can be?

Sketch uses 1098 bytes (3%) of program storage space. Maximum is 32768 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
/home/giulio/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9/bin/avrdude -C/home/giulio/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9/etc/avrdude.conf -v -patmega328p -cusbasp -Pusb -Uflash:w:/tmp/arduino_build_651417/USBasp_test_01.ino.hex:i 

avrdude: Version 6.3, compiled on Jan 17 2017 at 11:00:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/giulio/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9/etc/avrdude.conf"
         User configuration file is "/home/giulio/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: auto set sck period (because given equals null)
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "/tmp/arduino_build_651417/USBasp_test_01.ino.hex"
avrdude: writing flash (1098 bytes):

Writing | ################################################## | 100% 1.34s

avrdude: 1098 bytes of flash written
avrdude: verifying flash memory against /tmp/arduino_build_651417/USBasp_test_01.ino.hex:
avrdude: load data flash data from input file /tmp/arduino_build_651417/USBasp_test_01.ino.hex:
avrdude: input file /tmp/arduino_build_651417/USBasp_test_01.ino.hex contains 1098 bytes
avrdude: reading on-chip flash data:

Reading | ######################################An error occurred while uploading the sketch
############ | 100% 0.61s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x00 != 0x0c
avrdude: verification error; content mismatch

avrdude done.  Thank you.

Try burn bootloader with bootloader yes.
Then burn bootloader with bootloader no.
Then upload sketch using programmer.

Tried, it doesn't work... :slightly_frowning_face:

I receive the "verification error" message after all three steps.

FYI:

  1. I'm using a new Pro Mini board. It was "burned" max 6 or 7 times before (i.e. just for the tests in this thread).
  2. the board is original from Sparkfun, no chinese clone.