Go Down

Topic: What sketch size on Arduino Pro Mini 8Mhz with an ISP-programmer? (Read 1 time) previous topic - next topic

gimpo

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?
 :(



Arduino, what else?

pert

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:
https://github.com/MCUdude/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.

gimpo

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?
Arduino, what else?

pert

Boot loader -> No/Yes, if I choose "Yes" then the small 512 bytes will be uploaded, I'm right?
Yes
Variant -> 328P/328PA or 328/328A or 328PB, what version I should select here?
328P/328PA
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.

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

gimpo

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!
Arduino, what else?

pert

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.


gimpo

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

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
Arduino, what else?

DrAzzy

Turn on LTO

It's on by default in standard boards, but disabled by default on minicore to maintain backwards compatibility with old versions
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

gimpo

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

gimpo

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...
Arduino, what else?


gimpo

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.

Arduino, what else?

gimpo

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!  :D
Arduino, what else?

gimpo

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?
Arduino, what else?

Go Up