Last active
August 29, 2015 13:56
-
-
Save KunYi/8912040 to your computer and use it in GitHub Desktop.
STM32F429I change debug port, from UART4 to USART1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/board/discoveryf4/board.c b/board/discoveryf4/board.c | |
index 5098469..4277cf4 100644 | |
--- a/board/discoveryf4/board.c | |
+++ b/board/discoveryf4/board.c | |
@@ -7,26 +7,26 @@ | |
#include <platform/stm32f4/usart.h> | |
struct usart_dev console_uart = { | |
- .u_num = 4, | |
+ .u_num = 1, | |
.baud = 115200, | |
- .base = UART4_BASE, | |
- .rcc_apbenr = RCC_UART4_APBENR, | |
- .rcc_reset = RCC_APB1RSTR_USART4RST, | |
+ .base = USART1_BASE, | |
+ .rcc_apbenr = RCC_USART1_APBENR, | |
+ .rcc_reset = RCC_APB2RSTR_USART1RST, | |
.tx = { | |
.port = GPIOA, | |
- .pin = 0, | |
+ .pin = 9, | |
.pupd = GPIO_PUPDR_NONE, | |
.type = GPIO_MODER_ALT, | |
- .func = af_uart4, | |
+ .func = af_usart1, | |
.o_type = GPIO_OTYPER_PP, | |
.speed = GPIO_OSPEEDR_50M, | |
}, | |
.rx = { | |
.port = GPIOA, | |
- .pin = 1, | |
+ .pin = 10, | |
.pupd = GPIO_PUPDR_NONE, | |
.type = GPIO_MODER_ALT, | |
- .func = af_uart4, | |
+ .func = af_usart1, | |
.o_type = GPIO_OTYPER_PP, | |
.speed = GPIO_OSPEEDR_50M, | |
}, | |
diff --git a/board/discoveryf4/board.h b/board/discoveryf4/board.h | |
index 74221ff..7b9d92a 100644 | |
--- a/board/discoveryf4/board.h | |
+++ b/board/discoveryf4/board.h | |
@@ -14,8 +14,8 @@ | |
extern struct usart_dev console_uart; | |
#define BOARD_UART_DEVICE \ | |
- UART4_IRQn | |
+ USART1_IRQn | |
-#define BOARD_UART_HANDLER UART4_HANDLER | |
+#define BOARD_UART_HANDLER USART1_HANDLER | |
#endif /* DISCOVERYF4_BOARD_H_ */ | |
diff --git a/platform/stm32f4/usart.c b/platform/stm32f4/usart.c | |
index deadf05..02c1853 100644 | |
--- a/platform/stm32f4/usart.c | |
+++ b/platform/stm32f4/usart.c | |
@@ -25,13 +25,18 @@ struct usart_regs { | |
/* Calculates the value for the USART_BRR */ | |
/* TODO: Need more precise algorithm */ | |
-static int16_t usart_baud(uint32_t baud) | |
+static int16_t usart_baud(uint32_t base, uint32_t baud) | |
{ | |
uint16_t mantissa; | |
uint16_t fraction; | |
- mantissa = (42000000) / (16 * baud); | |
- fraction = (42000000 / baud) % 16; | |
+ if ((base == USART1_BASE) || (base == USART6_BASE)) { | |
+ mantissa = (42000000*2) / (16 * baud); | |
+ fraction = ((42000000*2) / baud) % 16; | |
+ } else { | |
+ mantissa = (42000000) / (16 * baud); | |
+ fraction = (42000000 / baud) % 16; | |
+ } | |
return (mantissa << 4) | fraction; | |
} | |
@@ -110,7 +115,7 @@ void usart_init(struct usart_dev *usart) | |
uregs->CR2 &= ~(3 << 12); | |
/* Set baud rate */ | |
- uregs->BRR = usart_baud(usart->baud); | |
+ uregs->BRR = usart_baud(usart->base, usart->baud); | |
/* Enable reciever and transmitter */ | |
uregs->CR1 |= (USART_CR1_RE | USART_CR1_TE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment