-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add support for Standard Serial Programming #6
Comments
Ok, I think i may have bitten off more then i can chew here. I'm not sure where to start. Here is my outline to get things rolling; (any suggestions are appreciated)
After I figure how to implement these things I can start porting things over and testing. another concern is cross platform compatibility. I need to verify if the 1284p can be loaded the same as the 328p and others on the same boot loader. I personally use the 1284p with the maniac bug port of optiboot so the first thing i wanna do is look there for code. but if we load the same boot loader on several devices and make sure it still loads from serial and the SD as planned, will the boot loader be too big? should i maybe look for another route? |
I don't know much about how to do this but am willing to help with testing and documentation. About ATmega1284P serial upload support: Optiboot already supports ATmega1284P as is. See: https://github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/optiboot/Makefile.1284 I don't know if you're referring to the original maniacbug Mighty 1284P repository(way out of date) or the JChristensen fork but I know that the bootloader source of the JChristensen fork is not the actual source that was used to make the current bootloader files. So I don't think anything in Mighty 1284P will be useful to your project. Instead just use the Optiboot source as a reference. Of course then ATmega2560 support may be another issue as it doesn't look like Optiboot currently supports this(I seem to remember that one of the Optiboot forks has added support) but avr_boot SD upload on ATmega2560 doesn't work right either so maybe that isn't a concern. |
Also you might find this source: https://github.com/thseiler/embedded/tree/master/avr/2boots a useful reference as it already fits SD and serial uploads in 2KB. If nothing else it's proof that this is possible. |
I wasn't aware of the optiboot support for 1284, I'll have to do some more research in to that. does IDE 1.5.x still require the JChristensen"maniacbug" core files to support the 1284? that's what I'm using right now. At any rate, I will look at the source files for 2boots and see if i can pull anything useful. last i heard they were having issues with SD loading which is why i chose to start using AVR_boot, which works great. I'm even working on a way to export .BIN files directly from Arduino. but that's a project for a different day. |
Arduino IDE 1.5+ doesn't support ATmega1284P out of the box but now the only things that need to be added are the bootloader file and the pins_arduino.h as opposed to the original maniacbug Mighty 1284P core which also needed to add patched core libs. The Optiboot boards.txt even uses the arduino:standard variant for ATmega1284P but after looking at that file I don't understand how it could work. |
I'll have to look at the current code to see if maybe I can implement out of the box support. That would be wonderful. However if i remember correctly there were a couple built in libraries that they had to patch for it to work. I know that they added a couple of libraries that have "(1284 supported)" suffix added to the name. not sure what the issue is but they still have them as open in the repository. |
Yes that's correct, some libraries have to be patched to support ATmega1284P. The Ethernet library needed the W5100 CS pin defined, Firmata sets some board specific defines, SD defines the SPI pins, GSM defines the software serial pins. I don't know what the patch is on Servo because that one still compiled when I updated Mighty 1284P to support Arduino 1.5+ so I just kept the previous patched version of that library. |
I wonder if that's something that can be easily merged with the current master for 1.5+ I may fork my own arduino and implement some of the changes, Thats another project for another time though. Thanks for your suggestions. I was able to add the needed STK500 protocol support files from 2boots but I'm still not sure where in avr_boot to implement the code. is it in main.c? |
I've added some code and borrowed some stuff from 2boots in the hopes that i know what the heck I'm doing, I don't. Anyone wanna try and compile this and see if there are any errors? I added a variable to stk500v1.c that is either 0 if the UART loading is successful or 1 if it fails. in main.c the stk500v1 function sits before checkFile, check file is wrapped in an if statement that checks to see if stkFail is true. I haven't tested any of this yet as I don't have access to the right tools right at this moment. |
|
looks like I'm on track to cargo cult engineering this. How would I pass that variable through to main.c from stk500v1.c ? EDIT: nevermind, I've got it. I'll fix that in a second. I'm a n00b. Added the missing extern bool stkFail to stk500v1.h should clear that error. |
Thanks for the pull requests per. I have merged those changes in to my master. I had read through online and found online the C did have built in bool. that's why i had used it. Apparently as of C99 standard bool is actually represented as _Bool and stdbool.h just translates bool to this standard as well as the macros true and false (to 1 or 0 respectively) so either way works. would using '_Bool' rather then loading the macros for 'bool' have any space benefits? |
Sure, I'm just trying to work through the compile errors but am not 100% sure what I'm doing. Feel free to squash any of these eventually if you want to clean up the commit history. I don't know about the bool thing. I've always used C++ so I was surprised when using bool caused the compile error. I just got the information from: http://stackoverflow.com/questions/1921539/using-boolean-values-in-c So now the compile error is:
I'll check back tomorrow to see if you've made any progress and try compiling again. |
Those are all calls to functions in the prog_flash.c file. I think it just needs to be included. I may have forgot to add it to the list. I'm doing this all from my tablet while waiting on family away from home. thanks for putting up with me. I'm just muddling through this myself at the moment. FWIW I think the prog_flash and boards files may need some code cleanup to remove any unneeded code from 2boots. but I'm not sure on exactly whats connected to what. guess we just keep fixing compile errors until it works then break it again. |
I just tried it with prog_flash.c added to CSRC in Makefile and it compiled. |
I added the necessary changes to my master. Try it with the _Bool instead of the bool macro, I'm not sure what C standard is being used. but I assume it will compile just fine. |
_Bool works |
ATmega328P compiles to 4434 bytes, larger than the max bootloader section size. Compiling for ATmega1284P gives the following errors:
|
It appears (as i had noticed previously) there is no definitions for 1284p in 2boots code, I'll have to dig up the datasheets and add it in. as for the size, its close enough, if we trim all the unused code out of the files i borrowed we should be just within the max boot size. we are getting closer. |
Also my compile sizes for avr_boot were larger than zevero's so maybe a different build system will also make it smaller. I'm using the tools included with Arduino 1.6.6 and make from WinAVR. |
Thank you for your efforts!
|
At least you will find the definitions for Atmega1284p which I was primarily using |
I agree, the stk500v1 file could use some optimization and clean up. instead of doing something twice we can reuse your definitions for UART debugging. I'll start looking at how to do that. that should reduce a bit of space. as for returning a bool instead of void, thats probably the best way to do it, i may want to implement wiping any FIRMWARE.BIN files from the SD after a successful UART flash. not sure if after optimizations we will have enough headroom to work this in. One step at a time i guess. This is a steep learning curve for me. thanks for the suggestions! |
The Bootloader, hence our code runs in the last 4kif the Rom. If flash was successful we tell the CPU to start at 0 with this code ((void(*)(void))0)(); |
I am sure stk500 will jump to 0 anyway starting the code it has flashed ;) |
I was looking for the bootloader shipping with arduino. Is it stk500v2?https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/bootloaders/stk500v2/stk500boot.c |
It looks like stk500 from 2 boot doesn't start the code itself. I've added it the end of the function after it sends the quit commands to avrdude. |
Also, does AVR_BOOT not have watchdog timers? |
? No just a rather useless 5s loop. It just jumps to 0 if the first byte is
|
Looks like STK500v2 is only for the mega2560, which is why we can not support it here. they use two different bootloaders. stk500v1 optiboot for uno and others. then the STK500v2 bootloader for the mega2560. |
Ok, i've tried but i think its a little above my abilities and I'm not getting much help anywhere else. I was able to get things to compile without error but I have no idea where to start on the board definitions for the UART. I'm sure once we clean that all up and merge it in to AVR_Boots Debug_Uart we can squeeze the total package in to the 328p. Also need to add the definitions for the 1284 in there to get that working, then we should be golden. I can try to help in any way i can. I have the whole 4 day weekend off from my day job. |
Took some time to look at the code a bit harder. I removed the old UART baud settings and definitions from stk500v1.c and commented out the parts of the code that used the UART functions that were there. I made a backup of the file and added .old as the extension for reference. I think what we need is to add receive routines to uart/uart.c and then use those in place of the stk500v1.c functions such as getch(); and putch(); should be easy for someone to look at the old functions and determine what in uart.c we can make use of or if we need to write new routines. i wasn't sure what those routines were doing exactly. also, the receive pins on all board need to be pulled high to prevent noise from preventing the boot loader from timing out. so we will need to define that for each chip i guess. to reduce code I think we can optimize stk500v1.c by removing some version checking and response commands that aren't fully needed. kind of like a bare minimum stk500v1 protocol. |
Did you get this (serial upload) sorted out? |
I am sorry no. |
Just a suggestion, I'm considering using this bootloader to deliver updates to micros running remotely, and for that purpose, there really is no need for a file system on the SD card at all. We could just write directly to the sectors, and get the code size down considerably. Possibly enough to get Serial back in comfortably? |
Interesting idea ... and indeed much simpler .... but I prefer to be able 2016-07-27 10:50 GMT+02:00 Jadin Roste Andrews [email protected]:
|
I just managed to get optiboot compiled in with avr_boot at 3720 bytes, I used the compiler optimisations from 2boots, and disabled uart and led. Also, I disabled FAT32 in pff.conf. I think these are acceptable tradeoffs considering how nice it would be to have normal serial again. I still need to add some logic to main.c to get it working properly. For now, I just dropped the stk500 serial function before the checkfile function in main.c, which probably breaks mmc flashing, but it's a start. |
Ok, so I got stk500 in there, as mentioned earlier, I just got it to compile. Today I tested it, and I couldn't get serial to work, the tx/rx leds flashed briefly when I tried to load a sketch from the Arduino IDE. So after spending a bit of time trying to make sure I had all the defines and includes right for the stk500 stuff, and trying different things. I eventually realised it was a baud-rate mismatch error. I looked through the stk500 source and saw it was set to 57600 for a 328p, so instead of recompiling and burning a new boot-loader, I just edited the boards.txt and set the upload rate to 57600, and VOILA! Serial worked after that! But, for some reason the mmc flashing is now not working. I think I'm getting pretty close though. I will look at this again when I get more time in the week. The micro hangs after a watch dog reset, even though it's disabled first thing in the boot-loader, so it never gets to the checkfile call. Serial uploads fine, and the program starts fine after a hard reset, there's just some funny business going on that doesn't give the mmc code a chance to execute. I'm thinking, maybe serial should be disabled after a watch dog reset, and just the mmc stuff should run? |
@JadinAndrews any news on this? If fitting it in 4kB is giving you trouble I think it would still be useful to have the option(enabled via preprocessor conditionals) available for the boards with 8kB boot size. |
Any success on this? If not I think I can help optimizing the code to add serial and fit on 4kB. I just don't have experience compiling the bootloader itself. |
@alexsartin I can't give an update because I haven't heard anything since my last comment but you can look at the work @JadinAndrews did here:
Do you need instructions for how to compile? If so, which OS are you using? As I said before, I think just getting serial programming working at all would be a huge step forward, even if it requires a larger boot section. This option can be turned on or off in the makefile so it will have no effect on people who don't need it and I can add a custom Tools menu option in the Arduino IDE for people using it that way. Once it's actually working it would be great to optimize it down to fit in the smaller boot section. I'm sure any help you can provide to reaching these goals would be much appreciated by everyone. |
@per1234 Sorry it's been a while since I worked on this, I got busy with studies and work. As per my previous comment, I got everything compiled in at 3720 bytes, but it wasn't working properly. I actually have some free time for the next month or so, so I'll put in some time to see if I can get it working, I'm certain I can get serial working alongside mmc flashing. By the way, we don't need 8kb, I don't think that is necessary. |
Great! I know how it goes. I have more plans for the Arduino IDE support aspects of avr_boot on my "to do" list but it's taking me a while to get the free time for it. |
Tell me about it, I can't believe it has been 8 months since my last comment. I have a renewed vigor to get this working, maybe then we can work on trimming it to 2kb MMC + Serial.. That's the holy grail. |
Yes @per1234 , I would most appreciate instructions on Makefile, compiling and programming fuse bits. I'm currently using the latest Mac OS (Sierra). Once I have those things figured out I will be able to start testing on Arduino Uno. Have you guys tried out 2boots from Thseiler? He claims to produced a 2kB bootloader with serial and FAT16 sd card reading. I haven't the chance to test it yet, but as far as I know, people are having problems on the FAT16 library to recognize the SD card. |
Unfortunately I can't provide Mac OS specific instructions because I'm using Windows so hopefully someone else can help with that. Here's a general overview: To compile avr_boot you need to have AVR-GCC and make installed. AVR-GCC is included with the Arduino IDE at hardware/tools/avr/bin. You could also install a newer version if you wanted and use that instead. It would be nice if we could set a standard version to use for development and releases to make sure we're all on the same page. Maybe the version included with the current release of the Arduino IDE at the time? The last time I compiled all the bootloader files to use for Arduino IDE support I used AVR-GCC 6.1.0, I think that was the newest version available at that time. Make is not included with recent versions of the Arduino IDE. If you don't have it installed you can download it or get it from an old version of the Arduino IDE (~1.0.6). You need to be able to run those applications from the avr_boot folder. On Windows I do this by adding the folders containing the AVR-GCC executables and make to my path, I don't know what the equivalent is on Mac. You need to configure the build for your target. You can do that by editing lines 6-13 of Makefile. After that you just need to run the command Editing Makefile all the time can be inconvenient, especially if you are building for many targets so it is also possible to set the configuration parameters via command line options, which will override the options set in Makefile. For example:
Will build for ATmega328P at 16 MHz with the SD CS pin set to PD4 (Arduino pin 4) with debug output off and output a file named As for programming fuse bits and flashing the bootloader to your microcontroller, that will require AVRDUDE, which is included with the Arduino IDE at hardware/tools/avr/bin/avrdude.exe or can be downloaded from http://download.savannah.gnu.org/releases/avrdude/. The exact command required will depend on the target and programmer. If you're using the Arduino IDE you can very easily determine the correct command format:
I haven't tried any of the other SD bootloader options. To be honest I've never used avr_boot in a project, though I have used it extensively in testing my contributions, but I do believe that it's valuable to have this option available to the community. I think the big advantages of avr_boot are:
If we could also provide the same level of features and efficiency as the other options that would be ideal. |
Interesting point about using a standard version of avr-gcc, I have just used the latest available at the time, which at the moment is 6.3.0 (also, I'm using Manjaro Linux), and the version that ships with the Arduino ide for Windows is 4.9.2. |
Good news @per1234 , I got serial + mmc working at 3716 bytes. I foresee that there is a bug. Serial flashes first, but if there is a FIRMWARE.BIN on the SD card, that will be flashed as well. So to test, only use one or the other method of flashing. EDIT: I fixed the bug mentioned above, made stk500v1 return something and added some code to main.c. Now mmc flashing is only attempted if serial was unsuccessful. I'm keen for one of you to test my bootloader, I will need help for mcu's other than 328p. Happy flashing :) |
Thank you for the advices. Next week I will start testing and tweaking. thseiler in 2boots commented:
Because of that, AVR-GCC versions smaller than 4.6 produces smaller hex file (at least 10% less). |
@JadinAndrews that's great news, thanks! As soon as I get some time I'll do some testing with all the boards I have on hand as well as a test build for every configuration supported by the Arduino IDE hardware definitions.
I'm no expert but I suspect there are features in the latest AVR-GCC versions that can make up for this, but might need to be enabled: |
Sorry to have been away for so long, I lost my previous git account (SergeantSeven) and created a new one recently. Any news on serial upload support on 1284p boards and others? I see @JadinAndrews managed to accomplish what I could not finish. I'll admit I was grasping for straws when I first started on this. I'm better equipped now to do this kind of work. let me know if anything needs testing or work. |
@NicholasTracy Yeah I kind of come back to this project every few years.. :P I did manage to get serial uploads to work on an ATMega 1284p, but never got around to sorting out the board signature issue. After you flash my build, avrdude thinks the board is an ATMega 1284. IIRC, there is no difference between the two that matters, and the bootloader still works as expected. I never got around to sourcing a 1284p, so if you could test then that would help a lot. I kind of lost interest after getting serial working on the 328p since that is the only board I had on hand, also work and studies went in a different direction for a while. Would be nice if someone could sort this out once and for all. |
I will check it out, It would be nice to have this wrapped up and have a pull request so that the changes can be merged. looks like not a lot has been going on with development, any way you can update your fork with the most recent changes to the master? |
@JadinAndrews : |
@anatom74 : Lastly, try build without sd support by setting: USE_SERIAL_FLASHING, USE_FAT16 and USE_FAT32 to 0 in the makefile. This essentially turns it into a standard bootloader without SD support. It could be that the sd card is being initialized and putting garbage on the uart lines. If you can get it to flash with serial only then it has to be something to do with the watchdog reset flag. |
I managed to get it working (atmega1280), but I see that it is flashing up to 65536 bytes long. Anything bigger will result in verify failure. |
Hmm, I think I got it (though I don't know if this is the right place) by adding following into prog_flash.h: |
@JadinAndrews Hi, I need serial + SD bootloader for my UNO. |
Currently not supported. I'm hoping to add this functionality myself here soon. Any Help is welcome. I'm going to Look at the Optiboot code and see what I can scavenge out of it to fill the gap. any issues I might want to know about before digging in? Will start a new fork soon and submit a pull request when i know it works. Thanks.
The text was updated successfully, but these errors were encountered: