-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bootloader burns just fine, uploaded simple program is not working #174
Comments
Can you upload the hex file you're using? When using a bootloader, the program needs to start at address 0x200, because the bootloader uses the first 512 bytes in the flash memory. |
Here it is. |
The problem is that the code isn't compiled for use with a bootloader. If you look at how Intel hex files works, you can see that your program starts at 0x0000 and not 0x0200. You need to compile your program with the bootloader option enabled in Arduino IDE. BTW, are you using Arduino IDE or PlatformIO to compile your code? |
For this one I used Arduino IDE with following settings: So how do I make the program start on 0x200 please? I thought that when I just choose the bootloader it will automatically start here, I can see that the hex file I sent in previous post contains the bootloader in the beginning... |
If I understand it correctly, the first lines are the bootloader and then the code appended starts on :2002000050C0000068C0000066C0000064C0000062C0000060C000005EC000005CC00000E0, which by the link you sent means address 0x200, right? |
Can you post the actual hex file the compiler spits out, not the flash dump? |
test.ino.hex.txt Should be these, one with and one without bootloader. |
Does the sketch that doesn't contain the bootloader run if you upload it using a UPDI programmer? Also, I'd like to see the current fuse settings. Use |
-patmega4809 -cjtag2updi -P/dev/ttyUSB2 -U fuses:r:-:h avrdude: AVR device initialized and ready to accept instructions avrdude done. Thank you. When I switch from board ATmega4809 to Arduino Every and upload it using UPDI (Arduino Nano as jtag2updi), the sketch works and LED blinks. |
Now I did a test. I have tried to compile the code as for Arduino Every, took that one and manually created a .hex file with fuse setting for bootend 0x02. The code alone works, but as soon as the bootloader preceeds it, it does not work. |
I'll have to test on some actual hardware, so you'll have to describe exactly what works and what doesn't.
So you compiled your blink program with the Arduino Nano Every pinout and with a bootloader (UART3)? Was this uploaded using a UPDI programmer? is it the *with_bootloader.hex file that doesn't work? |
Sorry for confusion, by the way, I really appreciate your support, thanks for the immediate replies! I have removed Q1 and Q2 to disconnect UART and UPDI between ATmega4809 and SAMD11. Then, I have added a serial resistor to UPDI with a value of 4k7. After checking the signal with a scope, I found out that UPDI does not work so I tried removing R19 (4k7 PULLUP on UPDI) and it started working. I did this after step 2, but if you have Arduino Nano Every and Arduino Nano to try this, I have summed it in here so it can be done at once.
Board: "Arduino Nano Every" And sketch with options using MegaCoreX with no bootloader: Board: "ATmega4809" will result in two different hex files. So I took the original work
I am using an FT231X as a USB-Serial adapter for ATmega4809, so I might try changing it to CH340 or something like that if it solves the issue. |
Also, I found out that I can not read fuses through the serial3: avrdude -patmega4809 -carduino -P/dev/ttyUSB3 -U fuses:r:-:h avrdude: AVR device initialized and ready to accept instructions avrdude done. Thank you. From the Arduino nano JTAG2UPDI it is possible though: avrdude -patmega4809 -cjtag2updi -P/dev/ttyUSB2 -U fuses:r:-:h avrdude: AVR device initialized and ready to accept instructions avrdude done. Thank you. |
I managed to get it to work. I'm using the built-in jtag2updi programmer on the Nano Every, since I didn't want to modify the board. I'm using I've build the latest Avrdude on my computer, which lets me connect the DTR/RTS line on my USB to serial adapter directly to the Nano Every reset pin without the need for a capacitor. This feature will be available in Avrdude 7.2. (I know this because I'm one of the active Avrdude developers at the moment. Pro tip: Play around with Avrdude terminal mode in Avrdude 7.1 and read the docs. It's an incredible tool that gives you r/w byte access to any memory, and it's also very powerful. Data can also be piped into Avrdude terminal mode)
Burn the bootloader to the Nano Every using the on-board jtag2updi and set the correct fuses:
Test program flashed using the bootloader:
Sketch is compiled in Arduino IDE, with the bootloader option to set the 0x200 offset. The following program blink the LED on pin 13 (PIN_PE2): Flash LED test program usedSource code: // Pro tip: Using PIN_* macros are portable across all pinouts
// PIN_PE2 will always be PB2 regardless of which pinout is used
void setup()
{
pinMode(PIN_PE2, OUTPUT);
}
void loop()
{
static bool toggle;
toggle = !toggle;
digitalWrite(PIN_PE2, toggle);
delay(500);
} Hex file from Arduino IDE
|
Correct. Fuses can only be read/written using a UPDI programmer. |
Unfortunately, when I choose pinout "Nano Every", it throws an error, I was always using "48 pin". `.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.1/avrdude.conf -v -patmega4809 -carduino -P/dev/ttyUSB4 -e -Ufuses:w:0x00,0x54,0x01,0xff,0x00,0b11001001,0x06,0x00,0x02:m -Ulock:w:0xC5:m -Uflash:w:/tmp/arduino_build_518265/spiffs_test.ino.hex:i avrdude: Version 7.1-arduino.1
avrdude: AVR device initialized and ready to accept instructions avrdude done. Thank you. the selected serial port |
I vaguely recall having to add chip erase to the DxCore board defs to make
the bootloader work.
…On Wed, Mar 29, 2023 at 3:53 AM yeayer ***@***.***> wrote:
Unfortunately, when I choose pinout "Nano Every", it throws an error, I
was always using "48 pin".
`.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.1/avrdude.conf -v
-patmega4809 -carduino -P/dev/ttyUSB4 -e
-Ufuses:w:0x00,0x54,0x01,0xff,0x00,0b11001001,0x06,0x00,0x02:m
-Ulock:w:0xC5:m -Uflash:w:/tmp/arduino_build_518265/spiffs_test.ino.hex:i
avrdude: Version 7.1-arduino.1
Copyright the AVRDUDE authors;
see https://github.com/avrdudes/avrdude/blob/main/AUTHORS
System wide configuration file is /home/tlukac/.arduino15/packages/MegaCoreX/hardware/megaavr/1.1.1/avrdude.conf
User configuration file is /home/tlukac/.avrduderc
User configuration file does not exist or is not a regular file, skipping
Using Port : /dev/ttyUSB4
Using Programmer : arduino
AVR Part : ATmega4809
RESET disposition : dedicated
RETRY pulse : SCK
Serial program mode : yes
Parallel program mode : yes
Memory Detail :
Block Poll Page Polled
Memory Type Alias Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
fuse0 wdtcfg 0 0 0 0 no 1 1 0 0 0 0x00 0x00
fuse1 bodcfg 0 0 0 0 no 1 1 0 0 0 0x00 0x00
fuse2 osccfg 0 0 0 0 no 1 1 0 0 0 0x00 0x00
fuse4 tcd0cfg 0 0 0 0 no 1 1 0 0 0 0x00 0x00
fuse5 syscfg0 0 0 0 0 no 1 1 0 0 0 0x00 0x00
fuse6 syscfg1 0 0 0 0 no 1 1 0 0 0 0x00 0x00
fuse7 append 0 0 0 0 no 1 1 0 0 0 0x00 0x00
fuse8 bootend 0 0 0 0 no 1 1 0 0 0 0x00 0x00
fuses 0 0 0 0 no 9 10 0 0 0 0x00 0x00
lock 0 0 0 0 no 1 1 0 0 0 0x00 0x00
tempsense 0 0 0 0 no 2 1 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 1 0 0 0 0x00 0x00
prodsig 0 0 0 0 no 61 61 0 0 0 0x00 0x00
sernum 0 0 0 0 no 10 1 0 0 0 0x00 0x00
osccal16 0 0 0 0 no 2 1 0 0 0 0x00 0x00
osccal20 0 0 0 0 no 2 1 0 0 0 0x00 0x00
osc16err 0 0 0 0 no 2 1 0 0 0 0x00 0x00
osc20err 0 0 0 0 no 2 1 0 0 0 0x00 0x00
data 0 0 0 0 no 0 1 0 0 0 0x00 0x00
userrow usersig 0 0 0 0 no 64 64 0 0 0 0x00 0x00
eeprom 0 0 0 0 no 256 64 0 0 0 0x00 0x00
flash 0 0 0 0 no 49152 128 0 0 0 0x00 0x00
Programmer Type : Arduino
Description : Arduino for bootloader using STK500 v1 protocol
Hardware Version: 3
Firmware Version: 9.0
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e9651 (probably m4809)
avrdude: erasing chip
avrdude stk500_chip_erase() error: chip erase instruction not defined for
part ATmega4809
avrdude done. Thank you.
the selected serial port
does not exist or your board is not connected
`
—
Reply to this email directly, view it on GitHub
<#174 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTXEW4YVK7LJMDIYFXEX6TW6PTBNANCNFSM6AAAAAAWKJJ26A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
____________
Spence Konde
Azzy’S Electronics
New products! Check them out at tindie.com/stores/DrAzzy
GitHub: github.com/SpenceKonde
ATTinyCore <https://github.com/SpenceKonde/ATTinyCore>: Arduino support for
all pre-2016 tinyAVR with >2k flash!
megaTinyCore <https://github.com/SpenceKonde/megaTinyCore>: Arduino support
for all post-2016 tinyAVR parts!
DxCore <https://github.com/SpenceKonde/DxCore>: Arduino support for the AVR
Dx-series parts, the latest and greatest from Microchip!
Contact: ***@***.***
|
I have tried your solution, connected the programmer to UART1 alt pins and it works. So I think there must be something wrong with using UART3 ALT pins for programming for sure. Can you please try to reproduce my steps? You can just remove the two dual transistors and solder RX and TX to the exposed pads. For some reason, it is not working. Also, I would like to ask - how to get the serial communication working now? Serial.begin and Serial.println will dimm the LED when I try using it on pin D7 (PIN_PA1) and Serial1.println() doesnt print anything... |
Hello, so I am currently using it as per your information. For anyone reading this in the future I will add some info: Also I have two last questions for @MCUdude :
In the end, I would like to thank both of you guys responding there in the thread for the information an in the future, if there is a possibility, please try to test the UART3 alt pins for bootloader - I am still not able to get it working. |
As you can see here, I recommend using the Nano Every pinout with an unmodified Nano Every, and for everything else, use one of the "standard" pinouts, as these are much easier to deal with in terms of uploading using UPDI or using a bootloader.
Avrdude 7.2 will let you connect the DTR or RTS pin on the USB to serial adapter directly to the reset pin on the AVR without a capacitor in series. Nobody knows when Avrdude 7.2 will be released, but given how few bugs have been discovered in 7.1, I don't expect a release anytime soon. It will probably happen in 2023 though.
Have a look at the "Minimal setup" schematics: I'm not sure why I haven't added it, but a 10k pullup resistor on the reset pin on the ATmega4809 is also good to add. |
If you want avrdude 7.2 release to be sooner than later, please help to carry out tests aginst the chips/programmers you have. You can check the discussion here. |
``Hello, I am trying to get ATmega4809 on Arduino Nano Every working with serial programmer. Thing I have done:
So my issue is - I can burn bootloader via Arduino Nano to the ATmega4809. When I dump the memory to a file, it is exactly what the bootloader hex from your code looks like. When I try uploading through serial (FT231X connected to mega4809 on Serial3 alt pins), it uploads just fine, reads just fine but the code simply does not run. I checked the fuses, dumped the hex (bootloader is still here, tried to upload also with no bootloader, whatever...). When I tried a sketch as simple as this:
`#include <Arduino.h>
bool test;
void setup()
{
pinMode(5,OUTPUT);
}
void loop()
{
delay(500);
test = !test;
digitalWrite(5,test);
}`
, it simply will not do anything. Tried using serialPrint, SSD1306 display, also nothing. Also I tried uploading with PlatformIO on VScode, it deletes the bootloader but the sketch gets uploaded, also does not work. When I purposefully "messed" the pin operations up in the code, on some versions the LED lit up with a very low current (I guess something got really wrong). Is there anything I forgot? I tried also not using the Arduino pinMode and digitalWrite functions, I just set the registers directly, with also no luck. Is there anything I am forgetting from the HW point? Do I need to add some resistors, etc? It drives me crazy as I have already written a long code that works on Nano Every, but I want to use my own boards and I do not want another chip (SAMD11) here. Thanks in advance!
The text was updated successfully, but these errors were encountered: