LC-Studio STM32F103V board UART

So as to make the communication with the microcontroller possible during execution, I set up the serial line of my development board. The board has a STM32F103 in 100-pin flat package (TFQP100) connected to a MAX232 [1] transceiver.

UART1:

Pin67 PA08 UART1_CK
Pin68 PA09 UART1_TX
Pin69 PA10 UART1_RX
Pin70 PA11 UART1_CTS
Pin71 PA12 UART1_RTS

UART2:

Pin23 PA00 UART2_CTS
Pin24 PA01 UART2_RTS
Pin25 PA02 UART2_TX
Pin26 PA03 UART2_RX
Pin29 PA04 UART2_CK

The MAX232 actually contains two transceivers which are connected to UART1 and UART2. Two jumpers are available on the board for selecting the output.

Here is a simple test code for USART1, trying to get maximum transmit speed at 115200bit/s (the microcontroller supports up to 4Mbps, but the transceiver does not go so far).

/* SYSCLK is 48 MHz */
uint8_t i = 0;
const uint8_t msg[] = {'h', 'e', 'l', 'l', 'o', ' '};

/* USART1 is in APB2 peripherals
* enable APB2 clock (for USART1 only!) */
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;

/* For UART1 communication (TX:PA9, RX:PA10) */
/* PA9 */
GPIOA->CRH &= ~(GPIO_CRH_MODE9 | GPIO_CRH_CNF9);        /* clear */
GPIOA->CRH |= (GPIO_CRH_MODE9 | GPIO_CRH_CNF9) & 0xAAAAAAAA;    /* set */
/* PA10 */
GPIOA->CRH &= ~(GPIO_CRH_MODE10 | GPIO_CRH_CNF10);      /* clear */
GPIOA->CRH |= (GPIO_CRH_MODE10 | GPIO_CRH_CNF10) & 0x88888888;  /* set */

/* Baudrate 115200 bit/s (115200 = 48 MHz/(16*26)) */
USART1->BRR = 0x1A << 4; /* mantissa = 26, fraction = 0 */
/* enable UART, data = 8bits, Tx Enable, Rx Enable, No parity (default), One stop bit (default) */
USART1->CR1 = USART_CR1_UE | USART_CR1_M | USART_CR1_TE | USART_CR1_RE;

for(;;) {
        if(USART1->SR & USART_SR_TXE)
        {
                USART1->DR = msg[c++ % sizeof(msg)];
        }
}

Tadaaa! The microcontroller can now communicate the IDCODE of the FPGA over serial line.

[1]MAX232 datasheet: http://www.ti.com/lit/ds/symlink/max232.pdf