AnsweredAssumed Answered

UART0 blocks due to UART_S1_TDRE_MASK checking

Question asked by Kai Liu on Oct 23, 2013
Latest reply on Apr 22, 2018 by Mark Butcher

I am revising AN4379 bootloader and find some bugs. It is hard to debug step by step, since its interaction between host OS requires real-time tools. UART printf is quite useful. I have tried semihost printf, but it is too slow to print all buffer content.


So I tried my best to add UART0 on FRDM-KL25Z to print some information.


The current situation is: UART0_D can be written once, but I can not find it on my terminal software. Then all the following characters printed are blocked at:




     while(!(UART0_S1 & UART_S1_TDRE_MASK)){};     /*stops here after sending first char*/

     UART0_D = (uint_8)ch;


I cross-checked my previous working source for USB host project. The initialization is same.



            SIM_SOPT2 |= SIM_SOPT2_UART0SRC(1);

            SIM_SCGC5 |=

            PORTA_PCR1 |= PORT_PCR_MUX(0x2);

            PORTA_PCR2 |= PORT_PCR_MUX(0x2);

            SIM_SCGC4 |= SIM_SCGC4_UART0_MASK;

            UART0_C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK );

            UART0_C1 = 0;



            ubd = (uint_16)((48000 * 1000)/(UART_BAUDRATE * 16));


            UART0_BDH = UART_BDH_SBR(((ubd & 0x1F00) >> 8));

            UART0_BDL = (uint_8)(ubd & UART_BDL_SBR_MASK);

            UART0_C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK );


How to set UART0_S1_TDRE_MASK to (1) after sending first one?

According to its reference manual, to clear UART0_S1_TDRE, write to UART data register (UART0_D).

0: Transmit data buffer is full

1: Transmit data buffer is empty

More interesting point, when I manually enter characters into UART0_D in register window, they are printed out on terminal window. What's different between manually entering and programmatic way?

Allan K Liu