<?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>nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8140/nrf52832-uart-tx-works-only-with-nrf_uarte0-read-after-endtx</link><description>Greetings,
There is a bit of strange operation in UARTE peripheral in nrf52832 with the DK. In the simple code below, if both of the if statements with comments &amp;#39;Check 1&amp;#39; and &amp;#39;Check 2&amp;#39; are removed the &amp;#39;hello&amp;#39; prints are not sent and I get some junk value</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 21 Jul 2015 11:07:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8140/nrf52832-uart-tx-works-only-with-nrf_uarte0-read-after-endtx" /><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29252?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 11:07:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8c08f47-ce87-4621-b4bb-bdb1b9d556b9</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;That would be useful - since putting memory pointers in registers is &amp;#39;new&amp;#39; for the nRF52 it&amp;#39;s possible other people will fall over something similar.&lt;/p&gt;
&lt;p&gt;I need to go take another crack at getting the nordic stuff compiled with clang. I like clang, it optimizes well and it&amp;#39;s got great ARM support (thanks to Apple). However it compiles the SVC softdevice code entirely broken and I haven&amp;#39;t come up with a way to sort that out yet. That&amp;#39;s another &amp;#39;implementation dependent&amp;#39; thing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29254?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 10:50:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0b45d40-7b03-4791-9d4e-ccbc15ec33b8</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Thanks a ton for following up with the question and diving so deep for this. And even though there are some bits of unanswered parts, I guess we can rest in peace that this should bother any driver implementations.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29251?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 10:34:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28198c46-1e1d-4326-840d-ae1255b5e6d0</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I agree,  i do not think that it is going to be a big problem and it was good exercise.
What is still unanswered is about the piece of assembly we add in end which makes compiler allocate space. I see that you have asked that question but still remain unexplained.&lt;/p&gt;
&lt;p&gt;I will ask this information to be very visible in the migration guide from nRF51 to nRF52&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29253?ContentTypeID=1</link><pubDate>Tue, 21 Jul 2015 10:22:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:951c081f-de99-43d7-b411-5cd5f6c79db8</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;And the answer - which I have come around to believing, is the code falls into &amp;#39;implementation dependent&amp;#39; and gcc is within its rights to decide that string isn&amp;#39;t used and remove it.&lt;/p&gt;
&lt;p&gt;Since the code was a piece of test code and not something anyone would be likely to write for real, initialized string on the stack going to a register and then wait for it to clock out, I don&amp;#39;t think it&amp;#39;s going to be a huge problem. It was however an interesting intellectual exercise.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29250?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 15:13:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49025ceb-b56b-4073-b6d1-67acb9f94483</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Here is his &lt;a href="https://answers.launchpad.net/gcc-arm-embedded/+question/269333"&gt;question&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29249?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 15:00:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3b3aacb-f889-4682-95e5-03580f3ebba8</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Thanks RK for filing bug in GCC, can you point us to that GCC bug you filed. In case someone is aiming at you, then we can support you :)
I do not believe that GCC will change anything or to that matter do not think that they will agree that it is a GCC bug.
But we need some explanation of why it works if we change [] to *, or adding some asm in the end. Because we want to know why GCC thinks these two are different. That explanation is the best outcome I expect from this&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29248?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 14:36:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9bca3c52-324a-4dcc-a156-abffec0615c8</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;So, I was testing the simplified code that Aryan posted, which I modified a little. Now &amp;#39;hello&amp;#39; gets printed only when &lt;strong&gt;at least&lt;/strong&gt; one of the #if statement is &amp;#39;1&amp;#39; when the optimization level is O1 or greater. With O0 or Og, it works in any case.&lt;/p&gt;
&lt;p&gt;It is strange that just adding a NOP before or after can change the way GCC initializes the string.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_clock.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_uart.h&amp;quot;

int main(void)
{
    /* Configure TX and RX pins from board.h */
    nrf_gpio_cfg_output(TX_PIN_NUMBER);
    nrf_gpio_cfg_input(RX_PIN_NUMBER, GPIO_PIN_CNF_PULL_Disabled);
    NRF_UARTE0-&amp;gt;ENABLE = (UARTE_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; UARTE_ENABLE_ENABLE_Pos);
    NRF_UARTE0-&amp;gt;PSEL.TXD = TX_PIN_NUMBER;
    NRF_UARTE0-&amp;gt;PSEL.RTS = RX_PIN_NUMBER;

    nrf_gpio_cfg_output(RTS_PIN_NUMBER);
    nrf_gpio_cfg_input(CTS_PIN_NUMBER, GPIO_PIN_CNF_PULL_Disabled);
    NRF_UARTE0-&amp;gt;PSEL.RTS = RTS_PIN_NUMBER;
    NRF_UARTE0-&amp;gt;PSEL.CTS = CTS_PIN_NUMBER;
    NRF_UARTE0-&amp;gt;CONFIG = (UARTE_CONFIG_HWFC_Enabled &amp;lt;&amp;lt; UARTE_CONFIG_HWFC_Pos);

    /* Configure other UART parameters, BAUD rate is defined in nrf52-uart.h    */
    NRF_UARTE0-&amp;gt;BAUDRATE = (UARTE_BAUDRATE_BAUDRATE_Baud460800 &amp;lt;&amp;lt; UARTE_BAUDRATE_BAUDRATE_Pos);

    while(true) 
    {

	nrf_delay_ms(1000);

#if 1
	volatile
#endif 
	uint8_t str[] = &amp;quot;hello\n&amp;quot;;
	uint32_t len = 6;

#if 0		//Pre NOP
        register uint32_t delay asm (&amp;quot;r0&amp;quot;) = 1;
    __ASM volatile (
          &amp;quot; NOP&amp;quot;
           : &amp;quot;+r&amp;quot; (delay)); 
#endif
        NRF_UARTE0-&amp;gt;TXD.PTR = (uint32_t)((uint8_t *) str);
        NRF_UARTE0-&amp;gt;TXD.MAXCNT = (uint32_t) len;

        NRF_UARTE0-&amp;gt;TASKS_STARTTX = 1;
        NRF_UARTE0-&amp;gt;EVENTS_ENDTX = 0;
        while((0 == NRF_UARTE0-&amp;gt;EVENTS_ENDTX));

#if 0		//Post NOP
        register uint32_t delay1 asm (&amp;quot;r0&amp;quot;) = 1;
    __ASM volatile (
          &amp;quot; NOP&amp;quot;
           : &amp;quot;+r&amp;quot; (delay1)); 
#endif
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29247?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 12:29:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0866aea-8bb4-4ac5-a99a-5c416a3ec5a0</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;RK, I like your Yoda sentence &amp;#39;Bug should I file?&amp;#39; :) I&amp;#39;m glad to have been at least the spark in finding a bug in GCC.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t have any issue now because the code in my question is just when I was playing around to understand the UARTE peripheral. Now I have made a ping-pong buffers based driver and It works well. I&amp;#39;ll make it open source in a few days.&lt;/p&gt;
&lt;p&gt;In any case I&amp;#39;ll do the tests that you suggested in some time. And I&amp;#39;ll play around seeing how this will affect the original issue, i.e. it working only when there is some UARTE register read or delay after the while loop waiting for EVENT_ENDTX.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29246?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 11:49:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ad2f64c-ff59-4537-ac40-2d7dbefdcf0f</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I went to file this as a bug against ARM GCC to find you it&amp;#39;s &amp;#39;highly recommended&amp;#39; to ask a question in the answers section before filing a new bug, so I&amp;#39;ve done that. I will now probably get my head shot off by the GCC C-heads for writing invalid C, but that&amp;#39;s life.&lt;/p&gt;
&lt;p&gt;Prithvi - I&amp;#39;ve been working on this at the asm level, not actually testing it - can you try&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;changing the uint8_t[] to a char * pointer&lt;/li&gt;
&lt;li&gt;alternatively adding &amp;#39;volatile&amp;#39; to that uint8_t[] str pointer (although that&amp;#39; stupid&amp;quot;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;and seeing if that actually also works around your underlying issue as well as doing the reads does? I&amp;#39;m concerned that we may have found an issue, but that may not actually be your issue!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29245?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 06:46:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b2a4d2a-84df-46fd-be3e-428d1099375e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I meant to ask if it did the same on Cortex-M0, because we tell the gcc compiler about the cpu explicitly
I just verified it and it does the same thing. I tested it with this code on nRF51 (cortex-M0)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void)
{
    char str[] = &amp;quot;hello\n&amp;quot;;
    NRF_UART0-&amp;gt;TXD = (uint32_t)str;
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29244?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 06:31:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:370c4cd0-6781-4efe-8e90-19656370dcd9</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;No it doesn&amp;#39;t end up in flash. It doesn&amp;#39;t end up anywhere in the binary. And apart from that you can see it&amp;#39;s not loaded and the SP is what&amp;#39;s set into the tx ptr uninitialized.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29243?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 06:29:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e913ab99-1267-48f9-b127-fbd8b4910851</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;There&amp;#39;s no NRF dependency in the code at all, neither 51 nor 52. It would do the same on either. However the 51 doesn&amp;#39;t have data pointers for uart, just a Tx register which takes a byte, so there&amp;#39;s not an equivalent case.
I don&amp;#39;t know if it&amp;#39;s a bug. The register is defined as volatile uint32, I don&amp;#39;t know what inference it&amp;#39;s allowed to draw about the use of data passed to it. I suspect if we report it as a gcc bug someone may explain why initializing stack based strings and passing them to registers is undefined behavior. It&amp;#39;s odd that char*works but char[] doesn&amp;#39;t.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29242?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 06:27:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60284e0c-429b-4ae2-87ca-da2c93f18565</guid><dc:creator>Krzysztof Chruscinski</dc:creator><description>&lt;p&gt;DIdn&amp;#39;t read all, but isn&amp;#39;t it possible that &amp;quot;hello&amp;quot; ends up in flash? UARTE can work only on RAM data locations.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29241?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 06:11:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67cfd698-6b06-4513-af66-1b7d19a3086a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Excellent, we are getting close. Did you see if this behavior is same with GCC on nRF51? If not then GCC is not following standard on one of them. Sounds like a bug&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29240?ContentTypeID=1</link><pubDate>Fri, 17 Jul 2015 05:27:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d76db24e-bf79-47b9-bca8-46f7a5ec58a9</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Not really an answer but the comments are too restricted.&lt;/p&gt;
&lt;p&gt;I have a shorter version which exhibits the same optimisation &amp;#39;issue&amp;#39;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdint.h&amp;gt;

struct UART
{
    __volatile uint32_t padding[200];
    __volatile uint32_t TXD;
};

#define NRF_UARTE0 ((struct UART*)0x40002000)

int main(void)
{
    char str[] = &amp;quot;hello\n&amp;quot;;
    NRF_UARTE0-&amp;gt;TXD = (uint32_t)str;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;when compiled main looks like this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;00000000 &amp;lt;main&amp;gt;:
   0:   4b03            ldr     r3, [pc, #12]   ; (10 &amp;lt;main+0x10&amp;gt;)
   2:   b082            sub     sp, #8
   4:   2000            movs    r0, #0
   6:   f8c3 d320       str.w   sp, [r3, #800]  ; 0x320
   a:   b002            add     sp, #8
   c:   4770            bx      lr
   e:   bf00            nop
  10:   40002000        .word   0x40002000
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What&amp;#39;s happening is space is reserved on the stack for &amp;#39;str&amp;#39; and that address is put into TXD but it&amp;#39;s never initialised with &amp;#39;hello\n&amp;quot;&lt;/p&gt;
&lt;p&gt;An easy workaround is to change &lt;code&gt;char str[] = &amp;quot;hello\n&amp;quot;;&lt;/code&gt; to &lt;code&gt;char *str=&amp;quot;hello\n&amp;quot;;&lt;/code&gt;, then the output looks like this (making the variable volatile does the same thing)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;00000000 &amp;lt;main&amp;gt;:
   0:   4b02            ldr     r3, [pc, #8]    ; (c &amp;lt;main+0xc&amp;gt;)
   2:   4a03            ldr     r2, [pc, #12]   ; (10 &amp;lt;main+0x10&amp;gt;)
   4:   f8c3 2320       str.w   r2, [r3, #800]  ; 0x320
   8:   2000            movs    r0, #0
   a:   4770            bx      lr
   c:   40002000        .word   0x40002000
  10:   00000000        .word   0x00000000
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The contents of the address at main+0x10 is fixed up at link time to point to the .rodata initialised string.&lt;/p&gt;
&lt;p&gt;This is compiled at -Os however -O1 does the same (as does -O2).&lt;/p&gt;
&lt;p&gt;So what appears to be happening is space is reserved for the string on the stack, but it&amp;#39;s not initialised. If you make the string longer you get more space reserved (ie sub sp, #8 becomes sub sp, #).&lt;/p&gt;
&lt;p&gt;If you call strlen() on it, it initialises the string properly. So gcc has decided that it needs to allocate space on the stack for the string, however the contents isn&amp;#39;t used so it doesn&amp;#39;t bother to initialise it. This may or may not be related to how the register is defined at uint32_t but changing it around hasn&amp;#39;t helped.&lt;/p&gt;
&lt;p&gt;Is this a gcc bug? If it is it&amp;#39;s not recent, I tried it with last year&amp;#39;s Q1 release and it&amp;#39;s still there. I think it&amp;#39;s a bug myself and the memory should be initialised but there may be some bizarre C rule I don&amp;#39;t know which makes that code undefined and allows the compiler to make the choice it does.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29239?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 15:17:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aaee6563-6141-4d5e-90ee-7c7482f836a0</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;just copy the code from my comments to blinky main.c file in nRF52 SDk and use the existing makefile.
It took me a lot of time to narrow it down to that single ASM r0 write and the compiler go bananas without it : )&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29238?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 14:17:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78325fe3-29aa-405d-b297-81a544c6f807</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;s&amp;#39;ok - I can work through this as it is, would be good if I could build it myself. I can see some odd differences already. The TX PTR is loaded from the contents of the SP, however in the asm version that&amp;#39;s properly set up beforehand (see address 60: where it&amp;#39;s copied from r2) but in the other version it&amp;#39;s not set up at all as far as I can tell, so it should have random garbage in it. There&amp;#39;s also no link to the string at the end of the assembly (that word at 0x88 in the asm version but missing from the other version), so yes it seems it was optimised out. However the registers are still written so .. currently making no sense at all.&lt;/p&gt;
&lt;p&gt;And why the addition of the r0 asm in there makes a difference is currently also beyond me.&lt;/p&gt;
&lt;p&gt;Will look some more, perhaps I&amp;#39;ll see if I can set up a makefile and build it too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29237?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 14:01:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd4416c0-1401-478d-b1de-8b8370e9484c</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;do not have ELF, i  have been on this for long time. Take rest and we can help Prithvi tomorrow.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29236?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 13:45:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4bbf373e-5b0c-4a5f-ac73-b3aabfd11de0</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;I&amp;quot;ll look - possibly in the morning as it&amp;#39;s getting a bit late here now and I&amp;#39;ve been staring at this for a while. Do you happen to have the two .elf files for those as well as the disassembly? They&amp;#39;ll have even more information about where the strings are stored and I can stuff them through Hopper. If not, no problem, I really need to get my nrf52 environement properly set up so I can compile this stuff.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29235?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 13:38:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79a14fcc-6315-4d8b-876e-cabafec2a059</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;If this ASM dump makes any sense, this has to be with GCC, Now the code i pasted works exactly like what Prithviraj sees.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29234?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 13:31:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:964b65f3-1cc4-4b51-a426-a4fd50d62c08</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;RK, you can probably help me out here
I have made this code simple&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_clock.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;nrf_uart.h&amp;quot;

int main(void)
{
    /* Configure TX and RX pins from board.h */
    nrf_gpio_cfg_output(TX_PIN_NUMBER);
    nrf_gpio_cfg_input(RX_PIN_NUMBER, GPIO_PIN_CNF_PULL_Disabled);
    NRF_UARTE0-&amp;gt;ENABLE = (UARTE_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; UARTE_ENABLE_ENABLE_Pos);
    NRF_UARTE0-&amp;gt;PSEL.TXD = TX_PIN_NUMBER;
    NRF_UARTE0-&amp;gt;PSEL.RTS = RX_PIN_NUMBER;

    nrf_gpio_cfg_output(RTS_PIN_NUMBER);
    nrf_gpio_cfg_input(CTS_PIN_NUMBER, GPIO_PIN_CNF_PULL_Disabled);
    NRF_UARTE0-&amp;gt;PSEL.RTS = RTS_PIN_NUMBER;
    NRF_UARTE0-&amp;gt;PSEL.CTS = CTS_PIN_NUMBER;
    NRF_UARTE0-&amp;gt;CONFIG = (UARTE_CONFIG_HWFC_Enabled &amp;lt;&amp;lt; UARTE_CONFIG_HWFC_Pos);

    /* Configure other UART parameters, BAUD rate is defined in nrf52-uart.h    */
    NRF_UARTE0-&amp;gt;BAUDRATE = (UARTE_BAUDRATE_BAUDRATE_Baud115200 &amp;lt;&amp;lt; UARTE_BAUDRATE_BAUDRATE_Pos);

    uint8_t str[] = &amp;quot;hello\n&amp;quot;;
    uint32_t len = 6;

    while(true) 
    {
        NRF_UARTE0-&amp;gt;TXD.PTR = (uint32_t)((uint8_t *) str);
        NRF_UARTE0-&amp;gt;TXD.MAXCNT = (uint32_t) len;

        NRF_UARTE0-&amp;gt;TASKS_STARTTX = 1;
        NRF_UARTE0-&amp;gt;EVENTS_ENDTX = 0;
        while((0 == NRF_UARTE0-&amp;gt;EVENTS_ENDTX));
        register uint32_t delay asm (&amp;quot;r0&amp;quot;) = 1;
    __ASM volatile (
          &amp;quot; NOP&amp;quot;
           : &amp;quot;+r&amp;quot; (delay));
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;With flags -O3, If i remove the ASM in the last, then it writes some garbage. If i add that ASM it does not. The problem does not seem to be write buffer, looking into the generated ASM, it looks like GCC is optimizing away below when no asm is used&lt;/p&gt;
&lt;p&gt;uint8_t str[] = &amp;quot;hello\n&amp;quot;;
uint32_t len = 6;&lt;/p&gt;
&lt;p&gt;I am attaching two assembly dump files with and without the ASM code in the last.
With ASM, look that there are few extra instructions while assigning str = hello&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29233?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 13:03:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea8e77e2-59cf-45fe-bbe0-12db8c16bf4c</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Aryan, I&amp;#39;m massively relieved if it&amp;#39;s not a GCC bug so no need to apologise for that.&lt;/p&gt;
&lt;p&gt;PS I don&amp;#39;t know if you do this or not, you said that optimized gcc is hard to follow (and it is). I always compile optimised but still add full debug info, the code is still scrambled but at least it has source in it.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been looking at that code for a while and don&amp;#39;t see what&amp;#39;s wrong. Wondered if it could be due to the write buffer on the Cortex M4 delaying the TASKS_STARTTX=1 write and the while loop exiting instantly but that doesn&amp;#39;t seem very likely. Have you tried setting EVENTS_TXSTOPPED to 0 explicitly before starting the transmission?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29232?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 12:54:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3f18a4d-8aba-488f-8e8f-661bc819cc90</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;If you have other things to take care of, go ahead. As of now, I&amp;#39;m reading the EVENTS_ENDTX, just in case and it works. So, no problem.
Having said that, it&amp;#39;ll be good to get to the bottom of this. :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29231?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 12:50:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93848160-b6e1-46ca-b099-2240f74c2c60</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Wait PrithviRaj,
i have to test few more things
I will have to update my answer&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 uart tx works only with NRF_UARTE0 read after EndTx</title><link>https://devzone.nordicsemi.com/thread/29230?ContentTypeID=1</link><pubDate>Thu, 16 Jul 2015 12:47:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:adfef01d-f4a4-4734-b950-4a0a3a91a3b0</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Thanks a lot Aryan for taking the time and effort to investigate this. Ya, I realized that setting STOPTX to 0 is stupid. :) I&amp;#39;m running on Linux.
This bug is getting stranger by the minute.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>