<?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>Kinetis MicrocontrollersのトピックPeripheral usage endianness observation</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Peripheral-usage-endianness-observation/m-p/355093#M17681</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just made an observation on the Kinetis that might save some frustration, I just went through this and discovered a nasty little surprise.&amp;nbsp; If you're writing to registers that have high bytes and low bytes associated with them (example:&amp;nbsp; Watchdog registers), the memory maps provided by Freescale do provide a accessors for the whole word, but DON'T USE THEM!&amp;nbsp; The Kinetis ARM is little-endian.&amp;nbsp; The peripheral registers, however, are not arranged that way.&amp;nbsp; I was trying to figure out why the watchdog timeout was much longer than expected, but found out the example given in the user's manual doesn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the example given in the Kinetis KE06 user's manual (page 220), it shows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WDOG_TOVAL = 1000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is supposed to to load the timeout value with 1000 for a 1-second timeout using the 1kHz clock.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although there is a 16 bit accessor provided with that name, you should not use this, it won't work correctly.&amp;nbsp; In the example above, what happens is it writes 0xE8 to WDOG_TOVALH and 0x03 to WDOG_TOVALL, so instead of a count of 1000 (decimal), you have a count of 59,395.&amp;nbsp; This happens because WDOG_TOVALH is at 0x40052004, and WDOG_TOVALL is at 0x40052005.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, when writing to peripheral registers, you must do byte reads/writes to the individual registers.&amp;nbsp; Another example is the UART baud rate registers, these will have the same problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Mar 2015 18:03:53 GMT</pubDate>
    <dc:creator>davidsherman</dc:creator>
    <dc:date>2015-03-26T18:03:53Z</dc:date>
    <item>
      <title>Peripheral usage endianness observation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Peripheral-usage-endianness-observation/m-p/355093#M17681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just made an observation on the Kinetis that might save some frustration, I just went through this and discovered a nasty little surprise.&amp;nbsp; If you're writing to registers that have high bytes and low bytes associated with them (example:&amp;nbsp; Watchdog registers), the memory maps provided by Freescale do provide a accessors for the whole word, but DON'T USE THEM!&amp;nbsp; The Kinetis ARM is little-endian.&amp;nbsp; The peripheral registers, however, are not arranged that way.&amp;nbsp; I was trying to figure out why the watchdog timeout was much longer than expected, but found out the example given in the user's manual doesn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the example given in the Kinetis KE06 user's manual (page 220), it shows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WDOG_TOVAL = 1000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is supposed to to load the timeout value with 1000 for a 1-second timeout using the 1kHz clock.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although there is a 16 bit accessor provided with that name, you should not use this, it won't work correctly.&amp;nbsp; In the example above, what happens is it writes 0xE8 to WDOG_TOVALH and 0x03 to WDOG_TOVALL, so instead of a count of 1000 (decimal), you have a count of 59,395.&amp;nbsp; This happens because WDOG_TOVALH is at 0x40052004, and WDOG_TOVALL is at 0x40052005.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, when writing to peripheral registers, you must do byte reads/writes to the individual registers.&amp;nbsp; Another example is the UART baud rate registers, these will have the same problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2015 18:03:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Peripheral-usage-endianness-observation/m-p/355093#M17681</guid>
      <dc:creator>davidsherman</dc:creator>
      <dc:date>2015-03-26T18:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Peripheral usage endianness observation</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Peripheral-usage-endianness-observation/m-p/355094#M17682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi David&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the case of the watchdog, the user's manual points out the implementation details with:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_0.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/47505iE46218EA994FD6C3/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_0.png" alt="pastedImage_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However, in the case of the KE manuals, &lt;SPAN style="text-decoration: underline;"&gt;&lt;EM&gt;all do have an error in their example of the usage&lt;/EM&gt;&lt;/SPAN&gt; of &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;WDOG_TOVAL = 1000;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When accessing such non-native registers the method to use is something like&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;WDOG_TOVAL = BIG_SHORT_WORD(1000);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;where &lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;#define BIG_SHORT_WORD(x) &lt;/TD&gt;&lt;TD&gt;(unsigned short)((x &amp;lt;&amp;lt; 8) | (x &amp;gt;&amp;gt; 8))&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Essentially one needs to always check the peripheral implementation details (some are native and some may not be - others even have a control bit to select whether they are little - or big endian [eg. ENET's buffer descriptors])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kinetis: &lt;A href="http://www.utasker.com/kinetis.html" title="http://www.utasker.com/kinetis.html"&gt;µTasker Kinetis support&lt;/A&gt;&lt;/P&gt;&lt;P&gt;KE: &lt;A href="http://www.utasker.com/kinetis/FRDM-KE02Z.html" title="http://www.utasker.com/kinetis/FRDM-KE02Z.html"&gt;µTasker FRDM-KE02Z support&lt;/A&gt; / &lt;A href="http://www.utasker.com/kinetis/FRDM-KE02Z40M.html" title="http://www.utasker.com/kinetis/FRDM-KE02Z40M.html"&gt;µTasker FRDM-KE02Z40M support&lt;/A&gt; / &lt;A href="http://www.utasker.com/kinetis/FRDM-KE06Z.html" title="http://www.utasker.com/kinetis/FRDM-KE06Z.html"&gt;µTasker FRDM-KE06Z support&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For the complete "out-of-the-box" Kinetis experience and faster time to market&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2015 20:03:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Peripheral-usage-endianness-observation/m-p/355094#M17682</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2015-03-26T20:03:20Z</dc:date>
    </item>
  </channel>
</rss>

