sonoffsc icon indicating copy to clipboard operation
sonoffsc copied to clipboard

Can't flash ATMega328P

Open revdaz opened this issue 7 years ago • 40 comments

Hello,

I really like your work, but I can’t flash the ATMega328P with Arduino and do not know what I’m doing wrong. I flashed a lot of sonoff devices and also the ESP part of the Sonoff SC, but don’t know how to flash the ATMega328P. I have compiled everything without errors, but when I want to upload the code I get everytime this message: avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x1c avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00 avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x1c avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0 avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x8e avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x1c avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x1c avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0 avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xfc avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x70 Beim Hochladen des Sketches ist ein Fehler aufgetreten

Have I press a button to get in flash mode? I have choosen Board: Arduino Nano and processor: ATMega328P. The green LEd is blinking on the Sonoff. In the serial monitor I see AT+STATUS? I have also disconnected the jumpers. I really tried everything and getting crazy….

Thank you very much for help

revdaz avatar Sep 29 '17 18:09 revdaz

I use “Arduino Uno” as board type. Also, you can try flashing it via the serial header using an USB2UART programmer. Check this post about the Sonoff SC.

xoseperez avatar Oct 05 '17 21:10 xoseperez

Hi I have the same error here.

@xoseperez What is the correct commandline-command to do this? Platformio and arduino-IDE should list it. Please post here for reference. To get it please run platformio run --target upload -v in the directory atmega328. Thanks!!

This saves us setting up both systems (with more potential traps) I'd like to rule out that I killed the ATMega328P.

(used your platformio-file to build & upload, pulled both jumper, connected all 5 cables and even switched RX and TX for testing) I use the FTDI USB to TTL. Which voltage do I have to set it to for the atmega? (3.3 or 5V) (3.3V for esp8266 is clear)

kollaesch avatar Oct 07 '17 08:10 kollaesch

Hi Guys,

I received my sonoffsc and flashed ESP in few minutes but struggled 2 days with ATMEGA. Nothing worked! I tested ATMega and saw it was not dead by connecting serial terminal and seeing AT+STATUS? from original firmware being sent over (be aware of the baud rate). I first bet reset pin was not working but multi-meter show everything ok.

Finally I downloaded the original source code to try put some light and read something like "first flash bootloader" in the readme file. Immediately thought "Are they flashing with ISP without arduino bootloader?"; grabbed my ArduinoDUE that was with ArduinoISP firmware, wired everyting (3v3, so do not put sonoffsc on the USB or DUE will fry), burned bootloader and voilá, not it flashes ok but fail reading (fuse issue). Worked!

Maybe you have a sample like mine? Mine is a V2 PCB with DHT11 soldered (I removed it and put headers so I can change sensor every time it fails - DHTxx fails a lot).

BR, Benito

jrbenito avatar Oct 19 '17 02:10 jrbenito

@jrbenito Thanks, I saw your post on comments thread. I'll use my Uno as ISP... I've planned to do it later next week, but now... I want to try! 👍 UPDATE: I had to flash the bootloader too: I used my Uno with "Arduino as ISP" on the soldered header; I used the Arduino Uno bootloader. Now I can flash both chips... So, we can expect in SC v2 with soldered DHT11 a bootloader flash.

ghiglie avatar Oct 21 '17 22:10 ghiglie

I don't have any Uno. What could I use as an alternative for ISP? (esp8266 / esp32) ?

If I access the 'atmega' bypicocom -b 19200 /dev/tty.usbserial-A50285BI I get the following response.

AT+STATUS?t is error
it is error
...

Ideas? Couldn't find anything in the internet. I don't have any DHT** connected. So I'm wondering if this is because of the missing DHT or because something on the atmega is faulty. (hardware or firmware)

kollaesch avatar Oct 27 '17 19:10 kollaesch

Can somebody get me on the way ? i am flashing my SC for the second time de Atmega328p but when i try now i get this error. Who has the solution ?

38588 106 1020 39714 9b22 .pioenvs/sonoffsc/firmware.elf Error: The program size (38694 bytes) is greater than maximum allowed (32256 by tes) *** [.pioenvs/sonoffsc/firmware.elf] Explicit exit, status 1 ========================== [ERROR] Took 14.03 seconds =========================

Wieg avatar Nov 05 '17 01:11 Wieg

Hi,

Your firmware is too big

Em 4 de nov de 2017 23:15, "Wieg" [email protected] escreveu:

Can somebody get me on the way ? i am flashing my SC for the second time de Atmega328p but when i try now i get this error. Who has the solution ? 38588 106 1020 39714 9b22 .pioenvs/sonoffsc/firmware.elf Error: The program size (38694 bytes) is greater than maximum allowed (32256 by tes) *** [.pioenvs/sonoffsc/firmware.elf] Explicit exit, status 1 ========================== [ERROR] Took 14.03 seconds

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xoseperez/sonoffsc/issues/19#issuecomment-341941853, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH6IrVJ3foovsrWcqLoL8YfkC3H6QOgks5szQwVgaJpZM4PpDho .

jrbenito avatar Nov 05 '17 01:11 jrbenito

its the standard download 1.1.1.1 from here .... what to do ? platformio project ... i dont get it ... it worked ....

Wieg avatar Nov 05 '17 01:11 Wieg

Didn't you add nothing? The firmware size you reported is 38k while atmega328 only has 32k (31k if you use arduino bootloader).

Em 4 de nov de 2017 23:21, "Wieg" [email protected] escreveu:

its the standard download 1.1.1.1 from here .... what to do ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xoseperez/sonoffsc/issues/19#issuecomment-341942100, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH6IpNBKNadvh53HFQfOmmsdwKkgyiRks5szQ2tgaJpZM4PpDho .

jrbenito avatar Nov 05 '17 11:11 jrbenito

Yes i know ..... 32k ... strange thing is ... i didn't change anything

I tried, download, unzip open atom/platformio connect the atmega328 and flash - Size to big (flashed the 8266 also with the firmware, no problems at all)

Followed tinkerman and xoseperez .... and get this result ..... Hardware wise i added the DHT22, LED ring, detection sensor .... i am sooooo close in making it all work

i looked at the libaries ... they are all needed, so i am a bit stuck in the final fase of making it work.

i need some tips from guys who did this project .................

Wieg avatar Nov 05 '17 11:11 Wieg

I am far from my computer today to test anything. If you can't solve it later I will try to reproduce.

In my case I discovered I could not flash atmega328 because it was shipped without arduino bootloader. After using isp instead of usb/ttl everything was OK.

Em 5 de nov de 2017 09:39, "Wieg" [email protected] escreveu:

Yes i know ..... 32k ... strange thing is ... i didn't change anything

I tried, download, unzip open atom/platformio connect the atmega328 and flash - Size to big (flashed the 8266 also with the firmware, no problems at all)

Followed tinkerman and xoseperez .... and get this result ..... Hardware wise i added the DHT22, LED ring, detection sensor .... i am sooooo close in making it all work

i looked at the libaries ... they are all needed, so i am a bit stuck in the final fase of making it work.

i need some tips from guys who did this project .................

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xoseperez/sonoffsc/issues/19#issuecomment-341966672, or mute the thread https://github.com/notifications/unsubscribe-auth/AAH6IgASsk7vXed5uieB_wrIAYzqpWwJks5szZ5ggaJpZM4PpDho .

jrbenito avatar Nov 05 '17 11:11 jrbenito

I have Sonoff SC Rev.2.0. I tried to flash ATMega328P for about two months. Tried many options. First I used FTDI USB to TTL with a lot of different drivers. Then I bought another FTDI USB to TTL and again tried different options. Then I bought USBASP and again tried a lot of drivers. Using Platformio and Arduino IDE. Nothing helped. But I was able to reflash ATMega328P only after I updated the firmware on the USBASP, using the following instruction (in Russian): http://xdomus.ru/usbasp-upgrade. After that, everything worked. Hooray!!!

VooDooN1 avatar Nov 05 '17 14:11 VooDooN1

I have exactly the same problem as @Wieg: SonofSC V2.0 w/ DTH11 soldered and no other sensor mounted, freshly downloaded v1.1.1 and getting the error:

Error: The program size (38940 bytes) is greater than maximum allowed (32256 bytes)

I'll try to downgrade

maur8ino avatar Nov 05 '17 16:11 maur8ino

Let me know how it goes @maur8ino .... pulled my hairs out, left it for a moment .... now doing some homeassistant scripts too "clear" my mind

Wieg avatar Nov 05 '17 16:11 Wieg

I was able to compile it and flash it only by commenting out all the references to the Adafruit NeoPixel and WS2812FX which brings down the size to 10176b.

Since I have no led connected, I don't really need them, but other might need them.

@Wieg if you want I can fork the project and just commit the change I've in local 😄

maur8ino avatar Nov 05 '17 16:11 maur8ino

yes please @maur8ino ..... ill start flashing ..... and thinking about my led solution .... i still need some of those function voor my led ring .....

Wieg avatar Nov 05 '17 16:11 Wieg

@Wieg here's the temporary fix https://github.com/maur8ino/sonoffsc!

@xoseperez is this normal? Thanks! 😄

maur8ino avatar Nov 05 '17 19:11 maur8ino

great ... have a beer on me !

Wieg avatar Nov 05 '17 19:11 Wieg

@maur8ino @Wieg your timing is awesome, I just went to reflash 1.1.1 to my SC after months of doing nothing with it - hit the "too big" issue, and your patch saves me. Thanks!

GregSutcliffe avatar Nov 05 '17 23:11 GregSutcliffe

hahaha i am still thinking ... i built in the presence sensor, dht22 and the LED .... stiil don't get how tinkerman and XO did the firmware for that.

Wieg avatar Nov 06 '17 10:11 Wieg

Maybe some library upgraded recently?

I just cloned project did a "pio run"; since the computer I am using never compiled this project it downloaded all libraries and did compile resulting same 38694 bytes binary. As soon as I get back home tonight I will recompile the firmware there since it worked about a month ago. Than I will try upgrade source code (I don´t believe it changed since I cloned) and after, upgrade libraries. Let´s see.

jrbenito avatar Nov 06 '17 11:11 jrbenito

@jrbenito mmm I just did a fresh clone and I'm still getting the error

Device: atmega328p

Program:   38694 bytes (118.1% Full)
(.text + .data + .bootloader)

Data:       1126 bytes (55.0% Full)
(.data + .bss + .noinit)

the size is 118.1% 😢

maur8ino avatar Nov 06 '17 11:11 maur8ino

@maur8ino ,

It is what I just said, I cloned fresh new code and downloaded libraries (platformio does it for you) and got oversized firmware. However, I do believe that code at my home computer compiles so the only thing I can think about is some library update that made code size exploded.

Checking here with fresh cloned code, I checked out later version of @xoseperez code and give me exact same code size as you got. So, the issue is not in sonoffsc code but in some library. I opened platformio.ini and checked library dependency and:

  • Arduino library for DHT11DHT22 last updated two years ago - seems not guilty

-Adafruit_NeoPixel last update 15 days ago - maybe guilty

-WS2812FX it was not released but had updated 5 days ago, however, if you download fresh new library it will dowload latest commit from git, hence, even not released as new version for platformio, the library code will be download from latest code - maybe guilty (my bet goes to this one)

-Ticker last update 6 months ago, so not guilty

So, I clone WS2812FX but checkouted it to a later version (SHA 069139b9340e14cd46d8fafe14972b6c056273ec) and compiled with code size 29948 bytes. Checked out at sha b31c3fbcffa510afe46897cb2261bbcd6c892249 and code size compiled 38694 bytes. Every sha between those above gave me compilation error.

Hence, the guilty is WS2812FX library, if you want to correct it by hand (workaound) do:

cd .piolibdeps/WS2812FX_ID1647
rm *  
mv .libray.json ../
git clone https://github.com/kitesurfer1404/WS2812FX.git .
git checkout  069139b9340e14cd46d8fafe14972b6c056273ec
mv ../.library.json .

Now your code will, hopefully, compile with manageable size.

BRs, JrBenito.

jrbenito avatar Nov 06 '17 11:11 jrbenito

Filed an issue to the library owner: https://github.com/kitesurfer1404/WS2812FX/issues/50

jrbenito avatar Nov 06 '17 12:11 jrbenito

@jrbenito awsome ........ ill be checking in to this in a few hours ........ can't wait :) great community here .... thank you very much

Wieg avatar Nov 06 '17 12:11 Wieg

@jrbenito thanks for the explanation! 😄

maur8ino avatar Nov 06 '17 12:11 maur8ino

@jrbenito even better you can pin a library to a specific git hash in your platformio.ini file like this 😄

lib_deps =
    DHT sensor library
    Adafruit NeoPixel
-    WS2812FX
+    https://github.com/kitesurfer1404/WS2812FX#069139b
    Ticker
    https://github.com/xoseperez/seriallink#0.1.0

I updated my fork pinning the WS2812FX library to the latest working hash.

maur8ino avatar Nov 06 '17 13:11 maur8ino

Perfect!!!

jrbenito avatar Nov 06 '17 13:11 jrbenito

it worked great .... now to play with it in homeassistant ;)

Wieg avatar Nov 07 '17 15:11 Wieg

Hi, I've the same problem :/

lorenzo-deluca avatar Mar 14 '18 18:03 lorenzo-deluca