<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14456/error-when-using-c-with-twi</link><description>I am trying to use gcc to compile a c++ code for nRF52. I am using the TWI library and am getting the error below. Can anyone help me rewriting this macro so that it compiles normally ? 
 Compiling file: main.cpp
In file included from main.cpp:6:0:</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 08 Mar 2018 09:46:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14456/error-when-using-c-with-twi" /><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/123384?ContentTypeID=1</link><pubDate>Thu, 08 Mar 2018 09:46:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58582ba1-75a6-471d-81e7-0e7145b3359d</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The SDK team confirmed that this is indeed finally fixed in SDK 15.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/122375?ContentTypeID=1</link><pubDate>Thu, 01 Mar 2018 01:54:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2520fecd-6715-4796-b49a-ad4d79d3bb4e</guid><dc:creator>Jeffrey Haynes</dc:creator><description>&lt;p&gt;Can Nordic please make this change in the SDK?&amp;nbsp; I&amp;#39;ve had to make it several times now by hand.&amp;nbsp; Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55221?ContentTypeID=1</link><pubDate>Wed, 04 Oct 2017 10:44:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98f1444e-94e0-4156-9d61-5f1be76d635c</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi Bojan. The SDK team agreed with your thoughts, and the issue is added on the to-do list. Though it might not be included in the SDK before a couple of releases into the future.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55218?ContentTypeID=1</link><pubDate>Mon, 02 Oct 2017 11:42:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c283fff-d656-4288-a7b1-cf13e4cbd727</guid><dc:creator>Bojan Potocnik</dc:creator><description>&lt;p&gt;Martin, may I ask why is this not changed in the SDK itself (using SDK v14.0.0)?
Considering the fact that the union &lt;em&gt;reg&lt;/em&gt; in &lt;em&gt;nrf_drv_uart_t&lt;/em&gt; struct typedef (file &lt;em&gt;nrf_drv_twi.h&lt;/em&gt;) is always defined with at least two members (&lt;em&gt;p_regs&lt;/em&gt; and &lt;em&gt;p_twim&lt;/em&gt; or &lt;em&gt;p_regs&lt;/em&gt; and &lt;em&gt;p_twi&lt;/em&gt;) and &lt;em&gt;p_regs&lt;/em&gt; pointer is always present, why don&amp;#39;t you just do:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;.reg = { .p_regs = NRF_DRV_TWI_PERIPHERAL(id) }, \
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;if you are already casting &lt;em&gt;NRF_DRV_TWI_PERIPHERAL(id)&lt;/em&gt; macro to void *? Otherwise, there shall be:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#if defined(TWIM_IN_USE)
    .reg = { .p_twim = (NRF_TWIM_Type *) NRF_DRV_TWI_PERIPHERAL(id) }, \
#elif defined(TWI_IN_USE)
    .reg = { .p_twi = (NRF_TWI_Type *) NRF_DRV_TWI_PERIPHERAL(id) }, \
#endif
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The same goes for &lt;em&gt;NRF_DRV_UART_INSTANCE(id)&lt;/em&gt; which also throws -fpermissive error using C++.
Is solution with &lt;em&gt;.p_regs&lt;/em&gt; not used because of &lt;em&gt;missing initializer&lt;/em&gt; warning?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55222?ContentTypeID=1</link><pubDate>Tue, 29 Aug 2017 06:06:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05132d9d-6a89-44e1-9f33-e8f26ff68fa9</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;Yes i have solved it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55217?ContentTypeID=1</link><pubDate>Thu, 24 Aug 2017 08:43:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccae49ee-2279-46a2-b4e6-e6a4b56d5044</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;So you solved it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55220?ContentTypeID=1</link><pubDate>Thu, 10 Aug 2017 15:36:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3dc7a4bc-3548-4777-9fc8-ec68b4673033</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;I&amp;#39;m sorry. The M was missing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55219?ContentTypeID=1</link><pubDate>Thu, 10 Aug 2017 15:33:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8cd70d05-f643-4637-9ef9-2637cfeb218f</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;In sdk14 i get&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;In file included from ../../../main.cpp:56:0:
../../../../../../components/drivers_nrf/twi_master/nrf_drv_twi.h:173:1: error: &amp;#39;nrf_drv_twi_t::&amp;lt;unnamed union&amp;gt;&amp;#39; has no non-static data member named &amp;#39;p_twi&amp;#39;
 }
 ^
../../../main.cpp:71:36: note: in expansion of macro &amp;#39;NRF_DRV_TWI_INSTANCE&amp;#39;
 static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55223?ContentTypeID=1</link><pubDate>Tue, 02 Aug 2016 19:56:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25085a30-6f2a-4f86-a514-16c0cf3db36a</guid><dc:creator>All4here</dc:creator><description>&lt;p&gt;i found solution too.&lt;/p&gt;
&lt;p&gt;just change with this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;.reg = { .p_twi = (NRF_TWI_Type*)NRF_DRV_TWI_PERIPHERAL(id) },         \
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55216?ContentTypeID=1</link><pubDate>Tue, 14 Jun 2016 12:44:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d8098de-b155-47e7-9c53-03fb1e49958b</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I just realized that in your error it says NRF_TWI&lt;strong&gt;M&lt;/strong&gt;_Type so I guess you are using EasyDMA. Hence the code above should probably say&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;.reg          = {.p_twim = NRF_DRV_TWI_PERIPHERAL(id)},         \
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Although if you still get the same error then obviously it wasn&amp;#39;t the problem.&lt;/p&gt;
&lt;p&gt;I googled a bit and the error seems related to converting pointers and types back and forth, so maybe it is worth a shot to explicitly cast NRF_DRV_TWI_PERIPHERAL(id) to a NRF_TWIM_Type like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;.reg          = {.p_twim = (NRF_TWIM_Type*)NRF_DRV_TWI_PERIPHERAL(id)},         \
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&amp;#39;m unable to test it here right now. If that doesn&amp;#39;t work then I&amp;#39;m out of ideas I&amp;#39;m afraid. I talked to the developer of the driver and he didn&amp;#39;t have any further suggestions either.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55215?ContentTypeID=1</link><pubDate>Mon, 13 Jun 2016 15:53:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6beffb57-32e9-4f2d-b684-e63b87dfe6cc</guid><dc:creator>Tony</dc:creator><description>&lt;p&gt;Thanks Martin for your reply. I tried that and still am getting same error. Any other workarounds ?
Thanks much !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Error when using c++ with TWI</title><link>https://devzone.nordicsemi.com/thread/55214?ContentTypeID=1</link><pubDate>Mon, 13 Jun 2016 11:22:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc05c919-5ca0-4bbb-b12b-2857eaab23d9</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;In this line in the header file:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;.reg          = {NRF_DRV_TWI_PERIPHERAL(id)},       \
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;we assign things to a union, but without specifying which particular element in the union. Some compilers might not like that. Can you please try to change&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define NRF_DRV_TWI_INSTANCE(id)                        \
{                                                       \
    .reg          = {NRF_DRV_TWI_PERIPHERAL(id)},       \
    .drv_inst_idx = CONCAT_3(TWI, id, _INSTANCE_INDEX), \
    .use_easy_dma = CONCAT_3(TWI, id, _USE_EASY_DMA)    \
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define NRF_DRV_TWI_INSTANCE(id)                        \
{                                                       \
    .reg          = {.p_twi = NRF_DRV_TWI_PERIPHERAL(id)},         \
    .drv_inst_idx = CONCAT_3(TWI, id, _INSTANCE_INDEX), \
    .use_easy_dma = CONCAT_3(TWI, id, _USE_EASY_DMA)    \
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;in nrf_drw_twi.h?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>