Thursday, October 27, 2016

STM32F3 Discovery + libopencm3, using USART.

I made STM32 development environment by gcc + libopencm3.
libopencm3 examples include using USART  for STM32F429, but STM32F3 is nothing.
So, I refer usart_console program for STM32F4 then successfully run on the STM32F3 discovery board.
I changed USART register name for running on STM32F3.

void console_putc(char c)
{
        uint32_t        reg;
        do {
                reg = USART_ISR(CONSOLE_UART);
        } while ((reg & USART_ISR_TXE) == 0);
        USART_TDR(CONSOLE_UART) = (uint32_t) c & 0xff;
}

char console_getc(int wait)
{
        uint32_t        reg;
        do {
                reg = USART_ISR(CONSOLE_UART);
        } while ((wait != 0) && ((reg & USART_ISR_RXNE) == 0));
        return (reg & USART_ISR_RXNE) ? USART_RDR(CONSOLE_UART) : '\000';
}


USART_ISR is "Interrupt and status register".(STM32F4 is USART_SR)
USART_TDR is "Transmit Data Register".(STM32F4 is USART_DR)
USART_RDR is "Receive Data Register".(STM32F4 is USART_DR)

Some constitution of registers are different from STM32F4 in STM32F3.
  

Have a good your computing!


No comments:

Post a Comment