f9micro / f9-kernel

An efficient and secure microkernel built for ARM Cortex-M cores, inspired by L4
Other
682 stars 145 forks source link

USART2 output garbled message with incorrect usart_baud() #90

Closed benwei closed 10 years ago

benwei commented 10 years ago

Hi All,

run 'make config' to choose USART2 for STM32F4-Discovery, but I got garbled message usart2 (PA2, PA3)

It worked well if I modified code as follow code. Did any one have same issue?

diff --git a/platform/stm32f4/usart.c b/platform/stm32f4/usart.c
index 2653d10..0c3c9d9 100644
--- a/platform/stm32f4/usart.c
+++ b/platform/stm32f4/usart.c
@@ -30,7 +30,7 @@ static int16_t usart_baud(uint32_t base, uint32_t baud)
        uint16_t mantissa;
        uint16_t fraction;

-       if ((base == USART1_BASE) || (base == USART2_BASE)) {
+       if ((base == USART1_BASE)) {
                mantissa = (84000000) / (16 *  baud);
                fraction = (84000000 / baud) % 16;
        } else {
        mantissa = (42000000) / (16 *  baud);
        fraction = (42000000 / baud) % 16;
    }

    return (mantissa << 4) | fraction;
}
arcbbb commented 10 years ago

For your information, I read the datasheet and found that USART1 and USART6 are on APB2 which frequency is 84MHz, while USART2, USART3, UART4, and UART5 are on APB1 which frequency is 42 MHz (max). Maybe it is a typo. Reference: [1] STM UM1472 User Manual STM32F4DISCOVERY: P12. Figure 6. STM32F407VGT6 block diagram

jserv commented 10 years ago

Thanks to @benwei ! Fixed and merged in git commit 4369d2b59ce9ecb5beea613cfe21ac59e774a324