F4Discovery ボード (STM32F407 ベース) で UART (USART1) を使用しようとすると問題が発生します。私は STM32 と Keil (私が使用している IDE) にかなり慣れていません。これが私のコードです:
#include "stm32f4_discovery.h"
#include "stm32f4xx_usart.h"
#include "stm32f4xx.h"
void usartSetup(void);
void USART_PutChar(uint8_t ch);
int main (void) {
usartSetup();
USART_PutChar(0); //I realise this won't send a 0
USART_PutChar(8); //I realise this won't send an 8
USART_PutChar(255); //I realise this won't send a 255
while (1) {
//loop forever
}
}
void usartSetup (void) {
USART_InitTypeDef USART_InitStructure;
//USART_StructInit(&USART_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
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_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}
void USART_PutChar(uint8_t ch) {
USART_SendData(USART1, (uint16_t) 0x49);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, (uint16_t) 0x49);
}
誰かが助けてくれたらとてもありがたいです。UART1 TX から 0x49 を送信することはなく (ピン PA9 と PB6 をチェック済み)、その間 (USART_GetFlagStatus...) で際限なくスタックします。Keil デバッガーを使用して観察していると、しばらくすると動かなくなることがわかります。
stm32f4xx_usart.c ドライバーをプロジェクトに含めています。
ありがとう!