<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic AN4368 USB Host Bootloader bugs when using gcc tools in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/AN4368-USB-Host-Bootloader-bugs-when-using-gcc-tools/m-p/345646#M16841</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have been using the code based on the AN4368 bootloader project for some Coldfire devices, and it loaded S19 files produced by Codewarrior fine.&amp;nbsp; I recently started working with Kinetis and ported the application projects to the gcc compiler under Codewarrior.&amp;nbsp; After figuring out how to configure the project to generate an S-record file, (from this page &lt;A href="http://mcuoneclipse.com/2012/09/13/s-record-generation-with-gcc-for-armkinetis/" title="http://mcuoneclipse.com/2012/09/13/s-record-generation-with-gcc-for-armkinetis/"&gt;S-Record Generation with gcc for ARM/Kinetis | MCU on Eclipse&lt;/A&gt;) I found that the bootloader wouldn't load them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first issue was that the first line produced in the S19 file did not start with "S003" as the bootloader expects (see S19_RECORD_HEADER in Bootloader.h), and as the original Codewarrior linker created.&amp;nbsp; Depending on which method I use from the page listed above, my S-record files started with either "S00A" or "S010".&amp;nbsp; I changed the S19_RECORD_HEADER define to 0x53300000, and changed this line in the FlashApplication function from Loader.c:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if(header ==(uint_32)(S19_RECORD_HEADER))&lt;/P&gt;&lt;P&gt;to this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if((header &amp;amp; 0XFFFF0000) == (uint_32)(S19_RECORD_HEADER))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This allowed it to recognize the different S19 headers, but it still failed to flash.&amp;nbsp; By stepping through the code I realized the checksum comparison was failing and I found the problem in the FlashLineS19 function.&amp;nbsp; There are two lines like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i = offset; i &amp;lt; (length - 5); i++)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The length calculation wasn't properly accounting for 16 and 24-bit formats (S1 and S2 records).&amp;nbsp; I changed those two lines to this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i = offset; i &amp;lt; (length - 2 - type); i++)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The gcc linker produced 24-bit (S2 record) formatted lines, but the position of the checksum and data length calculations weren't accounting for those.&amp;nbsp; It works now for S2 records, although I haven't confirmed again with S3 or for that matter S1 records.&amp;nbsp; The math is simple enough however, that I think it will work fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There might be a way to specify to the linker to create 32-bit records instead, but I still think the bootloader should handle S1 and S2 records, since it seems to have been intended to do so.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know if you see any problems with my changes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[Edit] I found another issue with the bootloader, although not specifically related to gcc.&amp;nbsp; The previous Coldfire devices I was using had Flash sizes of 512KiB, while the new Kinetis device has 1MiB.&amp;nbsp; After changing the MAX_FLASH1_ADDRESS value in Bootloader.h from 0x7FFFF to 0xFFFFF, the bootloader would erase forever.&amp;nbsp; I found that the erase_flash function in main.c of the bootloader used an 8-bit index ("i") to iterate through the Flash space and the calculated limit exceeded 255 with the higher Flash size.&amp;nbsp; I changed this to a 32-bit uint and it erased twice as much as before.&amp;nbsp; I haven't verified it properly erased that top area but I assume it did since it's a fairly straightforward function.&amp;nbsp; I also haven't tried flashing an image that uses more that the lower 512KiB (- 48KiB) of Flash, so I'm not certain there aren't other similar issues on the programming end.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 07 Sep 2014 00:24:20 GMT</pubDate>
    <dc:creator>ARQuattr</dc:creator>
    <dc:date>2014-09-07T00:24:20Z</dc:date>
    <item>
      <title>AN4368 USB Host Bootloader bugs when using gcc tools</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/AN4368-USB-Host-Bootloader-bugs-when-using-gcc-tools/m-p/345646#M16841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have been using the code based on the AN4368 bootloader project for some Coldfire devices, and it loaded S19 files produced by Codewarrior fine.&amp;nbsp; I recently started working with Kinetis and ported the application projects to the gcc compiler under Codewarrior.&amp;nbsp; After figuring out how to configure the project to generate an S-record file, (from this page &lt;A href="http://mcuoneclipse.com/2012/09/13/s-record-generation-with-gcc-for-armkinetis/" title="http://mcuoneclipse.com/2012/09/13/s-record-generation-with-gcc-for-armkinetis/"&gt;S-Record Generation with gcc for ARM/Kinetis | MCU on Eclipse&lt;/A&gt;) I found that the bootloader wouldn't load them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first issue was that the first line produced in the S19 file did not start with "S003" as the bootloader expects (see S19_RECORD_HEADER in Bootloader.h), and as the original Codewarrior linker created.&amp;nbsp; Depending on which method I use from the page listed above, my S-record files started with either "S00A" or "S010".&amp;nbsp; I changed the S19_RECORD_HEADER define to 0x53300000, and changed this line in the FlashApplication function from Loader.c:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if(header ==(uint_32)(S19_RECORD_HEADER))&lt;/P&gt;&lt;P&gt;to this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if((header &amp;amp; 0XFFFF0000) == (uint_32)(S19_RECORD_HEADER))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This allowed it to recognize the different S19 headers, but it still failed to flash.&amp;nbsp; By stepping through the code I realized the checksum comparison was failing and I found the problem in the FlashLineS19 function.&amp;nbsp; There are two lines like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i = offset; i &amp;lt; (length - 5); i++)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The length calculation wasn't properly accounting for 16 and 24-bit formats (S1 and S2 records).&amp;nbsp; I changed those two lines to this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (i = offset; i &amp;lt; (length - 2 - type); i++)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The gcc linker produced 24-bit (S2 record) formatted lines, but the position of the checksum and data length calculations weren't accounting for those.&amp;nbsp; It works now for S2 records, although I haven't confirmed again with S3 or for that matter S1 records.&amp;nbsp; The math is simple enough however, that I think it will work fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There might be a way to specify to the linker to create 32-bit records instead, but I still think the bootloader should handle S1 and S2 records, since it seems to have been intended to do so.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please let me know if you see any problems with my changes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[Edit] I found another issue with the bootloader, although not specifically related to gcc.&amp;nbsp; The previous Coldfire devices I was using had Flash sizes of 512KiB, while the new Kinetis device has 1MiB.&amp;nbsp; After changing the MAX_FLASH1_ADDRESS value in Bootloader.h from 0x7FFFF to 0xFFFFF, the bootloader would erase forever.&amp;nbsp; I found that the erase_flash function in main.c of the bootloader used an 8-bit index ("i") to iterate through the Flash space and the calculated limit exceeded 255 with the higher Flash size.&amp;nbsp; I changed this to a 32-bit uint and it erased twice as much as before.&amp;nbsp; I haven't verified it properly erased that top area but I assume it did since it's a fairly straightforward function.&amp;nbsp; I also haven't tried flashing an image that uses more that the lower 512KiB (- 48KiB) of Flash, so I'm not certain there aren't other similar issues on the programming end.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Sep 2014 00:24:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/AN4368-USB-Host-Bootloader-bugs-when-using-gcc-tools/m-p/345646#M16841</guid>
      <dc:creator>ARQuattr</dc:creator>
      <dc:date>2014-09-07T00:24:20Z</dc:date>
    </item>
  </channel>
</rss>

