Bootload from SD card to sector 0, and jump to sector 24 where new firmware resides
Fork of Panel-Controller-Bootloader by
Diff: usart.c
- Revision:
- 0:c3a652eff606
diff -r 000000000000 -r c3a652eff606 usart.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usart.c Tue Apr 21 09:30:11 2015 +0000 @@ -0,0 +1,51 @@ +#include "usart.h" + +void USART_Initialise(void) +{ + USART_InitTypeDef usartConfig; + + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); + RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); + USART_Cmd(USART1, ENABLE); + + usartConfig.USART_BaudRate = 115200; + usartConfig.USART_WordLength = USART_WordLength_8b; + usartConfig.USART_StopBits = USART_StopBits_1; + usartConfig.USART_Parity = USART_Parity_No; + usartConfig.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; + usartConfig.USART_HardwareFlowControl = + USART_HardwareFlowControl_None; + USART_Init(USART1, &usartConfig); + + GPIO_InitTypeDef gpioConfig; + + //PA9 = USART1.TX => Alternative Function Output + gpioConfig.GPIO_Mode = GPIO_Mode_AF_PP; + gpioConfig.GPIO_Pin = GPIO_Pin_9; + gpioConfig.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_Init(GPIOA, &gpioConfig); + + //PA10 = USART1.RX => Input + gpioConfig.GPIO_Mode = GPIO_Mode_IN_FLOATING; + gpioConfig.GPIO_Pin = GPIO_Pin_10; + GPIO_Init(GPIOA, &gpioConfig); +} + +void USART_SendString(char* message) +{ + while(*message) + { + while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); + USART_SendData(USART1, *message++); + } +} + +unsigned char USART_ReadByteSync(USART_TypeDef *USARTx) +{ + while ((USARTx->SR & USART_SR_RXNE) == 0) + { + } + + return (unsigned char)USART_ReceiveData(USARTx); +}