<?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 Re: How to use FIOSET (Best/Better practice) in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-use-FIOSET-Best-Better-practice/m-p/1302198#M45741</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I think the essence of your question is the definition of the unsigned int and uint32_t, it is dependent on the compiler. For Keil tools, I check the stedint.h as the following part. Because of the line:typedef unsigned int uint32_t; the the "unsigned int" and "uint32_t" are the same thing.&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;void  set_FIOPIN(int port, int pin)
{
   unsigned int *rp = (unsigned int *)(0x2009c018 + port*0x20);
   *rp |=  (1&amp;lt;&amp;lt;pin);
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;LPC_GPIO1-&amp;gt;FIOSET1 |= (1 &amp;lt;&amp;lt; 23);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above code is the same,&amp;nbsp; there is not any difference for Keil tools.&lt;/P&gt;
&lt;P&gt;So pls check the definition of "unsigned int" based your compiler, and check if it is defined as&amp;nbsp; uint32_t or uint16_t?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it can help you&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;XiangJun Rong&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;stdint.h file in Keil tools:&lt;/P&gt;
&lt;P&gt;/* exact-width signed integer types */&lt;BR /&gt;typedef signed char int8_t;&lt;BR /&gt;typedef signed short int int16_t;&lt;BR /&gt;typedef signed int int32_t;&lt;BR /&gt;typedef signed __INT64 int64_t;&lt;/P&gt;
&lt;P&gt;/* exact-width unsigned integer types */&lt;BR /&gt;typedef unsigned char uint8_t;&lt;BR /&gt;typedef unsigned short int uint16_t;&lt;BR /&gt;typedef unsigned int uint32_t;&lt;BR /&gt;typedef unsigned __INT64 uint64_t;&lt;/P&gt;
&lt;P&gt;/* 7.18.1.2 */&lt;/P&gt;
&lt;P&gt;/* smallest type of at least n bits */&lt;BR /&gt;/* minimum-width signed integer types */&lt;BR /&gt;typedef signed char int_least8_t;&lt;BR /&gt;typedef signed short int int_least16_t;&lt;BR /&gt;typedef signed int int_least32_t;&lt;BR /&gt;typedef signed __INT64 int_least64_t;&lt;/P&gt;
&lt;P&gt;/* minimum-width unsigned integer types */&lt;BR /&gt;typedef unsigned char uint_least8_t;&lt;BR /&gt;typedef unsigned short int uint_least16_t;&lt;BR /&gt;typedef unsigned int uint_least32_t;&lt;BR /&gt;typedef unsigned __INT64 uint_least64_t;&lt;/P&gt;
&lt;P&gt;/* 7.18.1.3 */&lt;/P&gt;
&lt;P&gt;/* fastest minimum-width signed integer types */&lt;BR /&gt;typedef signed int int_fast8_t;&lt;BR /&gt;typedef signed int int_fast16_t;&lt;BR /&gt;typedef signed int int_fast32_t;&lt;BR /&gt;typedef signed __INT64 int_fast64_t;&lt;/P&gt;
&lt;P&gt;/* fastest minimum-width unsigned integer types */&lt;BR /&gt;typedef unsigned int uint_fast8_t;&lt;BR /&gt;typedef unsigned int uint_fast16_t;&lt;BR /&gt;typedef unsigned int uint_fast32_t;&lt;BR /&gt;typedef unsigned __INT64 uint_fast64_t;&lt;/P&gt;
&lt;P&gt;/* 7.18.1.4 integer types capable of holding object pointers */&lt;BR /&gt;#if __sizeof_ptr == 8&lt;BR /&gt;typedef signed __INT64 intptr_t;&lt;BR /&gt;typedef unsigned __INT64 uintptr_t;&lt;BR /&gt;#else&lt;BR /&gt;typedef signed int intptr_t;&lt;BR /&gt;typedef unsigned int uintptr_t;&lt;BR /&gt;#endif&lt;/P&gt;</description>
    <pubDate>Mon, 05 Jul 2021 05:12:39 GMT</pubDate>
    <dc:creator>xiangjun_rong</dc:creator>
    <dc:date>2021-07-05T05:12:39Z</dc:date>
    <item>
      <title>How to use FIOSET (Best/Better practice)</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-use-FIOSET-Best-Better-practice/m-p/1301740#M45726</link>
      <description>&lt;P&gt;I have a LPC1759 on a custom board. I'm trying to learn how to program that chip, but it's been a few years since I've done embedded programming. So far I have been able to setup with the GNU arm toolchain and VSCode and I been able to blink some LED, played with basic ADC, RIT, and a few other little things.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I'm quite rusty on C and embedded, I struggle sometimes with my understanding of things. I was browsing some other people's code, and I found this code snippet (also for lpc1759) and It raised some questions:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;void  set_FIOPIN(int port, int pin)
{
   unsigned int *rp = (unsigned int *)(0x2009c018 + port*0x20);
   *rp |=  (1&amp;lt;&amp;lt;pin);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; This code will SET a FIOPIN, if I understand It correctly. So, I was wondering if one could not also set a FIOPIN by this way:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;LPC_GPIO1-&amp;gt;FIOSET1 |= (1 &amp;lt;&amp;lt; 23);&lt;/LI-CODE&gt;&lt;P&gt;And why is one way preferred over the other?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, in the first snippet, the address&amp;nbsp;0x2009C018 (this is the address of FIO0SET, according to UM3690 manual, p 132) but why is this address not defined in the header file &lt;STRONG&gt;lpc17xx.h&lt;/STRONG&gt; ? Anyone knows? Any special reason? I can see other things in &lt;STRONG&gt;lpc17xx.h&lt;/STRONG&gt; like:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#define LPC_GPIO0_BASE        (LPC_GPIO_BASE + 0x00000)&lt;/LI-CODE&gt;&lt;P&gt;And I'm thinking, in the first code snippet that It would look better to use a defined address instead of hard coding an address. I dont know, what is a better practice here?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, would it not be better practice to use &lt;STRONG&gt;(uint32_t *)&lt;/STRONG&gt; instead &lt;STRONG&gt;(unsigned int *)&lt;/STRONG&gt;?&lt;/P&gt;&lt;P&gt;Just trying to expand my knowledge.&lt;/P&gt;&lt;P&gt;Best regards!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 09:43:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-use-FIOSET-Best-Better-practice/m-p/1301740#M45726</guid>
      <dc:creator>bmildh</dc:creator>
      <dc:date>2021-07-02T09:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to use FIOSET (Best/Better practice)</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-use-FIOSET-Best-Better-practice/m-p/1302198#M45741</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I think the essence of your question is the definition of the unsigned int and uint32_t, it is dependent on the compiler. For Keil tools, I check the stedint.h as the following part. Because of the line:typedef unsigned int uint32_t; the the "unsigned int" and "uint32_t" are the same thing.&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;void  set_FIOPIN(int port, int pin)
{
   unsigned int *rp = (unsigned int *)(0x2009c018 + port*0x20);
   *rp |=  (1&amp;lt;&amp;lt;pin);
}&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;LPC_GPIO1-&amp;gt;FIOSET1 |= (1 &amp;lt;&amp;lt; 23);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above code is the same,&amp;nbsp; there is not any difference for Keil tools.&lt;/P&gt;
&lt;P&gt;So pls check the definition of "unsigned int" based your compiler, and check if it is defined as&amp;nbsp; uint32_t or uint16_t?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope it can help you&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;
&lt;P&gt;XiangJun Rong&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;stdint.h file in Keil tools:&lt;/P&gt;
&lt;P&gt;/* exact-width signed integer types */&lt;BR /&gt;typedef signed char int8_t;&lt;BR /&gt;typedef signed short int int16_t;&lt;BR /&gt;typedef signed int int32_t;&lt;BR /&gt;typedef signed __INT64 int64_t;&lt;/P&gt;
&lt;P&gt;/* exact-width unsigned integer types */&lt;BR /&gt;typedef unsigned char uint8_t;&lt;BR /&gt;typedef unsigned short int uint16_t;&lt;BR /&gt;typedef unsigned int uint32_t;&lt;BR /&gt;typedef unsigned __INT64 uint64_t;&lt;/P&gt;
&lt;P&gt;/* 7.18.1.2 */&lt;/P&gt;
&lt;P&gt;/* smallest type of at least n bits */&lt;BR /&gt;/* minimum-width signed integer types */&lt;BR /&gt;typedef signed char int_least8_t;&lt;BR /&gt;typedef signed short int int_least16_t;&lt;BR /&gt;typedef signed int int_least32_t;&lt;BR /&gt;typedef signed __INT64 int_least64_t;&lt;/P&gt;
&lt;P&gt;/* minimum-width unsigned integer types */&lt;BR /&gt;typedef unsigned char uint_least8_t;&lt;BR /&gt;typedef unsigned short int uint_least16_t;&lt;BR /&gt;typedef unsigned int uint_least32_t;&lt;BR /&gt;typedef unsigned __INT64 uint_least64_t;&lt;/P&gt;
&lt;P&gt;/* 7.18.1.3 */&lt;/P&gt;
&lt;P&gt;/* fastest minimum-width signed integer types */&lt;BR /&gt;typedef signed int int_fast8_t;&lt;BR /&gt;typedef signed int int_fast16_t;&lt;BR /&gt;typedef signed int int_fast32_t;&lt;BR /&gt;typedef signed __INT64 int_fast64_t;&lt;/P&gt;
&lt;P&gt;/* fastest minimum-width unsigned integer types */&lt;BR /&gt;typedef unsigned int uint_fast8_t;&lt;BR /&gt;typedef unsigned int uint_fast16_t;&lt;BR /&gt;typedef unsigned int uint_fast32_t;&lt;BR /&gt;typedef unsigned __INT64 uint_fast64_t;&lt;/P&gt;
&lt;P&gt;/* 7.18.1.4 integer types capable of holding object pointers */&lt;BR /&gt;#if __sizeof_ptr == 8&lt;BR /&gt;typedef signed __INT64 intptr_t;&lt;BR /&gt;typedef unsigned __INT64 uintptr_t;&lt;BR /&gt;#else&lt;BR /&gt;typedef signed int intptr_t;&lt;BR /&gt;typedef unsigned int uintptr_t;&lt;BR /&gt;#endif&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jul 2021 05:12:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-use-FIOSET-Best-Better-practice/m-p/1302198#M45741</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2021-07-05T05:12:39Z</dc:date>
    </item>
  </channel>
</rss>

