AnsweredAssumed Answered

STM32F103:Problem with USART when use System Tick Timer Delay in us

Question asked by duc.le on Feb 28, 2015
Latest reply on Feb 28, 2015 by Clive One
Hi all,

I am using STM32F103RCT6 and CP2102 as UART controller driver.
I have problem with USART when I use SysTick Timer to generate 1us Delay.
The problem is that when I configure SysTick at frequency 1Mhz, the program does not work.

SysTick_Config(SystemCoreClock / 1000000)   // SystemCoreClock is 72 Mhz

I use SysTick to generate 1us Delay: 

void Delay(__IO uint32_t nTime)

     TimingDelay = nTime;        // Timing Delay is a volatile uint32_t variable
     while(TimingDelay != 0);

void TimingDelay_Decrement(void)
     if (TimingDelay != 0x00)

SysTick handler

void SysTick_Handler(void)
     Tick++;     // my private variable for counting     

That is how I create my Delay function in microsecond.
It works well, but when I want to add USART code, the program doesn't work. 
When I call USART_Configuration(); in main, the program stucks.

void USART_Configuration(void)
     USART_InitTypeDef      USART_InitStructure;
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); 

     /* Configure PA9 for USART Tx as alternate function push-pull */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_Init(GPIOA, &GPIO_InitStructure);

     /* Configure PA10 for USART Rx as input floating */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
     GPIO_Init(GPIOA, &GPIO_InitStructure);     
     /* USARTx configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
     USART_InitStructure.USART_BaudRate = 115200;
     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
     USART_InitStructure.USART_StopBits = USART_StopBits_1;
     USART_InitStructure.USART_Parity = USART_Parity_No;
     USART_InitStructure.USART_HardwareFlowControl =      USART_HardwareFlowControl_None;
     USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;     

     /* USART configuration */
     USART_Init(USART1, &USART_InitStructure);

     /* Enable USART */
     USART_Cmd(USART1, ENABLE);     

I tried to configure SysTick at 100Khz (delay with resolution 10us), it worked.
SysTick_Config(SystemCoreClock / 100000);

But my application needs a delay at us. I don't know what is the reason and how to solve it. Can anyone give me some advice. 

Thank you for reading.