{"id":1647,"date":"2015-06-27T16:36:19","date_gmt":"2015-06-27T14:36:19","guid":{"rendered":"http:\/\/majek.mamy.to\/?p=1647"},"modified":"2018-03-17T23:59:07","modified_gmt":"2018-03-17T22:59:07","slug":"writing-to-internal-flash-on-arduino","status":"publish","type":"post","link":"https:\/\/majek.sh\/en\/writing-to-internal-flash-on-arduino\/","title":{"rendered":"Writing to internal FLASH on Arduino"},"content":{"rendered":"<p><\/p>\n<h1>History<\/h1>\n<p>In LCD88 I use internal flash as storage for model definitions. Of course, these should be editable without reflashing all firmware:-)<\/p>\n<p>On AVR chips writing to flash is only possible from bootloader section, so I needed such feature in my bootloader.<br \/>\nI adapted my old X-MODEM bootloader to provide some entry points to functions writing flash. But because of using X-MODEM as communication protocol, using it was quite difficult for ordinary people. Then, I came up with idea that bootloader compatible with Arduino could solve this accessibility issue.<br \/>\nNowadays, all things that can be invented, are invented and done by some people, so I started to find ready-made bootloader with all needed features. Most promising was <a href=\"https:\/\/github.com\/Optiboot\/optiboot\" target=\"_blank\">Optiboot<\/a>, but it lacked possibility to use it for writing flash by application.<\/p>\n<p>Time was passing by and I was very surprised that I can&#8217;t find ready-made solution. More surprising was that on Arduino forum writing to flash by application was perceived as &#8216;mission impossible&#8217;. Every topic about it ended by failure or with getting external memory for storage (flash, fram or simply SD card), or advice to write your own bootloader:-)<\/p>\n<p>My conclusion after all this research was: I must write my own bootloader or contribute to some other project to add such functionality. Then I gave a first look at the code of Optiboot, it&#8217;s issues and I found <a href=\"https:\/\/github.com\/Optiboot\/optiboot\/issues\/52\" target=\"_blank\">issue #52<\/a> with one promising patch at the end. But this patch didn&#8217;t fit to my needs, as I need fill-erase-write sequence to not using RAM as buffer, and it doesn&#8217;t do that that way.<\/p>\n<p>A year passed by and I returned to Optiboot. This time I was going to do it by mysef. It was time of learning C, hacks used in avr-gcc, bugs in different verions of avr-gcc, learning Github flows, branching, merging, even writing in Arduino as I needed to provide some working example of using this feature. But finally I made it! \ud83d\ude42<\/p>\n<h1>Writing to flash<\/h1>\n<p>Optiboot with possibility to write to flash by applications could be downloaded from my &#8216;supermaster&#8217; branch (also with some fixes not available yet in upstream): <a href=\"https:\/\/github.com\/majekw\/optiboot\/tree\/supermaster\" target=\"_blank\">https:\/\/github.com\/majekw\/optiboot\/tree\/supermaster<\/a>. It includes also example Arduino sketch (<em>flash_program<\/em>, heavily commented) writing to flash using new Optiboot.<\/p>\n<p>So, feel free to use this long waited feature in Arduino world, and spread new, now better Optiboot bootloader.<\/p>","protected":false},"excerpt":{"rendered":"<p>History In LCD88 I use internal flash as storage for model definitions. Of course, these should be editable without reflashing all firmware:-) On AVR chips writing to flash is only possible from bootloader section, so I needed such feature in <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/majek.sh\/en\/writing-to-internal-flash-on-arduino\/\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[38,50,41],"_links":{"self":[{"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/posts\/1647"}],"collection":[{"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/comments?post=1647"}],"version-history":[{"count":19,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/posts\/1647\/revisions"}],"predecessor-version":[{"id":1735,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/posts\/1647\/revisions\/1735"}],"wp:attachment":[{"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/media?parent=1647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/categories?post=1647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/majek.sh\/en\/wp-json\/wp\/v2\/tags?post=1647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}