144 lines
6.5 KiB
C
144 lines
6.5 KiB
C
/****************************************************************************************
|
|
| Description: bootloader application source file
|
|
| File Name: main.c
|
|
|
|
|
|----------------------------------------------------------------------------------------
|
|
| C O P Y R I G H T
|
|
|----------------------------------------------------------------------------------------
|
|
| Copyright (c) 2013 by Feaser http://www.feaser.com All rights reserved
|
|
|
|
|
|----------------------------------------------------------------------------------------
|
|
| L I C E N S E
|
|
|----------------------------------------------------------------------------------------
|
|
| This file is part of OpenBLT. OpenBLT is free software: you can redistribute it and/or
|
|
| modify it under the terms of the GNU General Public License as published by the Free
|
|
| Software Foundation, either version 3 of the License, or (at your option) any later
|
|
| version.
|
|
|
|
|
| OpenBLT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
| without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
| PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
| You should have received a copy of the GNU General Public License along with OpenBLT.
|
|
| If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
| A special exception to the GPL is included to allow you to distribute a combined work
|
|
| that includes OpenBLT without being obliged to provide the source code for any
|
|
| proprietary components. The exception text is included at the bottom of the license
|
|
| file <license.html>.
|
|
|
|
|
****************************************************************************************/
|
|
|
|
/****************************************************************************************
|
|
* Include files
|
|
****************************************************************************************/
|
|
#include "boot.h" /* bootloader generic header */
|
|
#include "stm32f4xx.h" /* STM32 registers */
|
|
#include "stm32f4xx_conf.h" /* STM32 peripheral drivers */
|
|
|
|
|
|
/****************************************************************************************
|
|
* Function prototypes
|
|
****************************************************************************************/
|
|
static void Init(void);
|
|
|
|
|
|
/****************************************************************************************
|
|
** NAME: main
|
|
** PARAMETER: none
|
|
** RETURN VALUE: none
|
|
** DESCRIPTION: This is the entry point for the bootloader application and is called
|
|
** by the reset interrupt vector after the C-startup routines executed.
|
|
**
|
|
****************************************************************************************/
|
|
void main(void)
|
|
{
|
|
/* initialize the microcontroller */
|
|
Init();
|
|
/* initialize the bootloader */
|
|
BootInit();
|
|
|
|
/* start the infinite program loop */
|
|
while (1)
|
|
{
|
|
/* run the bootloader task */
|
|
BootTask();
|
|
}
|
|
} /*** end of main ***/
|
|
|
|
|
|
/****************************************************************************************
|
|
** NAME: Init
|
|
** PARAMETER: none
|
|
** RETURN VALUE: none
|
|
** DESCRIPTION: Initializes the microcontroller. The interrupts are disabled, the
|
|
** clocks are configured and the flash wait states are configured.
|
|
**
|
|
****************************************************************************************/
|
|
static void Init(void)
|
|
{
|
|
#if (BOOT_COM_UART_ENABLE > 0)
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
#elif (BOOT_FILE_SYS_ENABLE > 0)
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
USART_InitTypeDef USART_InitStructure;
|
|
#endif
|
|
|
|
/* disable all interrupts to prevent possible jump back to the user program */
|
|
__disable_irq();
|
|
/* initialize the system and its clocks */
|
|
SystemInit();
|
|
#if (BOOT_COM_UART_ENABLE > 0)
|
|
/* enable UART peripheral clock */
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
|
|
/* enable GPIO peripheral clock for transmitter and receiver pins */
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
|
/* connect the pin to the peripherals alternate function */
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
|
|
/* configure USART Tx as alternate function */
|
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
/* configure USART Rx as alternate function */
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
#elif (BOOT_FILE_SYS_ENABLE > 0)
|
|
/* enable UART peripheral clock */
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
|
|
/* enable GPIO peripheral clock for transmitter and receiver pins */
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
|
/* connect the pin to the peripherals alternate function */
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
|
|
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
|
|
/* configure USART Tx as alternate function */
|
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
/* configure USART Rx as alternate function */
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
/* initialize the uart for the specified communication speed */
|
|
USART_InitStructure.USART_BaudRate = BOOT_COM_UART_BAUDRATE;
|
|
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(USART6, &USART_InitStructure);
|
|
/* enable UART */
|
|
USART_Cmd(USART6, ENABLE);
|
|
#endif
|
|
} /*** end of Init ***/
|
|
|
|
|
|
/*********************************** end of main.c *************************************/
|