NEWER New Optiboot bootloader

6v6gt: It is not in the data sheet. The most concrete information about shared use of SPI lines, that I can find, is here: http://ww1.microchip.com/downloads/en/appnotes/atmel-2521-avr-hardware-design-considerations_applicationnote_avr042.pdf , although this may not exactly cover your scenario.

However, there is a also lot of anecdotal evidence about the wisdom of keeping clear of the SPI lines when possible to minimise the risk of interference with attempts to program the device, for example: https://www.avrfreaks.net/forum/can-i-reuse-isp-pins-other-taskstarget-atmega164p?skey=reuse%20of%20spi%20lines

As a result of my own experience, I attempt to keep at least 1K away from the SPI lines where possible. I documented some of this here: https://forum.arduino.cc/index.php?topic=673817.0 (post#6 onwards)

If you won't be changing the bootloader, already have one then connecting SD won't stop you from changing your sketch.

With 328pb you have an extra UART capable of full speed master-mode SPI, Nick Gammon has the software to do it. You could have Serial RX/TX, ISCP and still have hardware-SPI. Atmel had really good engineers.

GoForSmoke: The minimal breadboard Duino article has chip ID and Nick's programming software that accepts many ID's.

Here's a page with what you may want directly:

http://www.gammon.com.au/bootloader

Hi,

I went through Nick Gammon's forum (http://www.gammon.com.au/forum/?id=11635) and am so happy to tell you that i could detect the ATmega328PB's signature correctly as well as could upload the bootloader onto the chip. Thank you for guiding me!

I think the issue was with the internal clock as somehow it couldn't detect the chip and i was stuck. On the forum, i found an alternative to it. Using the sketch Atmega_Board_Programmer, i got an alternative of getting a 8MHz clock signal on pin D9 of the programming board. Now, i can move forward to programming my board :)

6v6gt: It is not in the data sheet. The most concrete information about shared use of SPI lines, that I can find, is here: http://ww1.microchip.com/downloads/en/appnotes/atmel-2521-avr-hardware-design-considerations_applicationnote_avr042.pdf , although this may not exactly cover your scenario.

However, there is a also lot of anecdotal evidence about the wisdom of keeping clear of the SPI lines when possible to minimise the risk of interference with attempts to program the device, for example: https://www.avrfreaks.net/forum/can-i-reuse-isp-pins-other-taskstarget-atmega164p?skey=reuse%20of%20spi%20lines

As a result of my own experience, I attempt to keep at least 1K away from the SPI lines where possible. I documented some of this here: https://forum.arduino.cc/index.php?topic=673817.0 (post#6 onwards)

Thank you for sharing the knowledge. I am sure it will help others as well.

Also, i finally could get the bootloader onto the chip!

Hi,

I am doing a thesis which include adding functionality to flash sketches over CAN (using a module). Optiboot should be kept as original as possible since the author of the thesis want to keep possibilities for the original sketch upload.

At the moment I’m trying to flash a sketch (example blink sketch but with external LED connected to pin 7) where the data bytes of the hexfile is put into an uint8 array and then written to flash. This is working as expected, I’ve compared the flash content using my flash method to uploading the sketch using Arduino IDE. The content of flash is exactly the same.

The problem is that the application never starts running. At power on, neither the built in LED or the LED connected to pin 7 flashes. If i but the reset button, the built in LED flashes constantly.

I suspect that my way of end the flash procedure and jump to application doesn’t work. From my understanding, when the watchdog with time 1 second runs out, there should be a jump to 0x0000 since Optiboot only runs after a external reset. However, it seems like I get stuck in a bootloader loop.

Hardware: Arduino nano with ATmega328p, using version 8 of Optiboot.

Can anyone help me to understand what needs to be done to start the application after written a sketch to flash?

Attaching my function that writes to flash, which gets called just before the forever for-loop that reads UART.
Except that, no changes have been done to Optiboot.

Best regards,
Henrik

void write_fixed_page(void).c (1.21 KB)

Check your fuses. Carefully check them again.

From my understanding the fuses doesn't affect execution from flash. Are you referring to the lock bits?

How ever, lock bits are described in the datasheet to protect the memory from software updates, and my data get's stored in memory fine. It's after the flash the problem occurs. The execution of the loaded sketch doesn't start.

Best regards

There are also the HIGH fuse bits which determine boot sector size, start address and boot reset vector enabled status. The original Nano fuses settings are designed for a 2KB boot loader. Optiboot is 512B. However, the install bootloader option of the Arduino IDE, if you used that, normally ensures the correct fuse settings are made for the chosen bootloader (board type). Uno is usually a good choice of board type if you want to install Optiboot on a Nano. Maybe this makes it clearer what the Fuse options are: https://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p

Since we are implementing CAN support in the bootloader we have extended the boot sector to 4096 bytes. Highfuse are 0xD0 and I have changed the makefile's linker directives to: atmega328: LDSECTIONS = -Wl,--section-start=.text=0x7000 -Wl,--section-start=.version=0x7ffe.

I have kept the functionality to upload sketches through UART in my version of Optiboot, and when I upload a sketch with Arduino IDE (using my version of Optiboot) the sketch runs fine. So the problem shouldn't be the placement of bootloader code or fuse for reset vector since a external programmer is needed for flashing bootloader?

Did you see https://github.com/Optiboot/optiboot/issues/250 and https://github.com/Optiboot/optiboot/issues/247? Basically, if you're going to try to reset your board via some mechanism other than hardware reset or poweron, you should reset both MCUSR and the watchdog at the beginning of your code.

Curie: Hi,

I went through Nick Gammon's forum (http://www.gammon.com.au/forum/?id=11635) and am so happy to tell you that i could detect the ATmega328PB's signature correctly as well as could upload the bootloader onto the chip. Thank you for guiding me!

I think the issue was with the internal clock as somehow it couldn't detect the chip and i was stuck. On the forum, i found an alternative to it. Using the sketch Atmega_Board_Programmer, i got an alternative of getting a 8MHz clock signal on pin D9 of the programming board. Now, i can move forward to programming my board :)

Nick sez: "If you bought a "raw" chip direct from the manufacturer you should not have this problem, as the chips default to using an internal 8 MHz oscillator. But if you got your chip from a third party who already installed a bootloader, then the "fuse settings" may have been changed to expect the crystal."

Nick's Blog/Tutorial: Solving problems with uploading programs to your Arduino. This gets into fuses, even covers using high-V programmers to unbrick AVRs. http://www.gammon.com.au/forum/?id=11643

@henkees

watchdogConfig(WATCHDOG_16MS); // for a reset of the MCU while (1); // to prevent return to application in the 15MS to reset

Hi All,

I am using an ATTiny3217 with a standard bootloader and everything is working fine. With this being the case would there be a reason to install the Optiboot bootloader? The only reason I installed a boot loader at all was to set the UPDI pin to GPIO as I NEEDED to use that pin for analog in.

That's your call. Application specific, designer's choice.

Are you stalking me??

And thanks.

am using an ATTiny3217 with a standard bootloader

What do you think is the "standard" bootloader? AFAIK, optiboot is the only tiny-1 series bootloader that's been implemented and works with Arduino. (optiboot is what DrAzzy's "core" uses.)

In the board manager you can select 3217 or 3217 (optiboot)

The only reason I installed a boot loader at all was to set the UPDI pin to GPIO…

The new megaTinyCore 2.1.4 allows setting the UPDI pin to GPIO without Optiboot.
Of course, make sure you have a working HV-UPDI programmer available.

Example of how your board settings would look…

With Optiboot

Non-Optiboot

Here, don’t get confused by the wording “burn bootloader” or “Bootload burn req’d”.
This just means that if any changes are made, you need to run “Burn Bootloader” in the Tools menu.
This won’t add Optiboot … it just updates the fuses.

I worked that out. I was just querying if optiboot did anything more in my case. Everything is now working great on Spence's board. Just waiting for my new boards to arrive from China.

windoze_killa: I worked that out. I was just querying if optiboot did anything more in my case. Everything is now working great on Spence's board. Just waiting for my new boards to arrive from China.

Let you write to flash in runtime? ATtiny3217 has 32KB flash.....

GoForSmoke: Let you write to flash in runtime? ATtiny3217 has 32KB flash.....

I know. And I am using nearly all of it.