mirror of https://github.com/FOME-Tech/openblt.git
139 lines
5.9 KiB
C
139 lines
5.9 KiB
C
|
/************************************************************************************//**
|
||
|
* \file Demo\ARMCM3_STM32F2_Olimex_STM32P207_GCC\Boot\main.c
|
||
|
* \brief Bootloader application source file.
|
||
|
* \ingroup Boot_ARMCM3_STM32F2_Olimex_STM32F207_GCC
|
||
|
* \internal
|
||
|
*----------------------------------------------------------------------------------------
|
||
|
* C O P Y R I G H T
|
||
|
*----------------------------------------------------------------------------------------
|
||
|
* Copyright (c) 2016 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 have received a copy of the GNU General Public License along with OpenBLT. It
|
||
|
* should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||
|
*
|
||
|
* \endinternal
|
||
|
****************************************************************************************/
|
||
|
|
||
|
/****************************************************************************************
|
||
|
* Include files
|
||
|
****************************************************************************************/
|
||
|
#include "boot.h" /* bootloader generic header */
|
||
|
#include "stm32f2xx.h" /* STM32 registers and drivers */
|
||
|
|
||
|
|
||
|
/****************************************************************************************
|
||
|
* Function prototypes
|
||
|
****************************************************************************************/
|
||
|
static void Init(void);
|
||
|
|
||
|
|
||
|
/************************************************************************************//**
|
||
|
** \brief This is the entry point for the bootloader application and is called
|
||
|
** by the reset interrupt vector after the C-startup routines executed.
|
||
|
** \return Program return code.
|
||
|
**
|
||
|
****************************************************************************************/
|
||
|
int main(void)
|
||
|
{
|
||
|
/* initialize the microcontroller */
|
||
|
Init();
|
||
|
/* initialize the bootloader */
|
||
|
BootInit();
|
||
|
|
||
|
/* start the infinite program loop */
|
||
|
while (1)
|
||
|
{
|
||
|
/* run the bootloader task */
|
||
|
BootTask();
|
||
|
}
|
||
|
|
||
|
/* program should never get here */
|
||
|
return 0;
|
||
|
} /*** end of main ***/
|
||
|
|
||
|
|
||
|
/************************************************************************************//**
|
||
|
** \brief Initializes the microcontroller.
|
||
|
** \return none.
|
||
|
**
|
||
|
****************************************************************************************/
|
||
|
static void Init(void)
|
||
|
{
|
||
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
#if (BOOT_FILE_LOGGING_ENABLE > 0) && (BOOT_COM_UART_ENABLE == 0)
|
||
|
USART_InitTypeDef USART_InitStructure;
|
||
|
#endif
|
||
|
|
||
|
|
||
|
/* enable peripheral clock for LED_STAT1 (PF8) */
|
||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
|
||
|
/* enable peripheral clock for Tamper button (PC13) */
|
||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
|
||
|
/* enable UART peripheral clock */
|
||
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||
|
/* enable GPIO peripheral clock for transmitter and receiver pins */
|
||
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
|
||
|
|
||
|
/* configure PF8 with as output with internal pull-up */
|
||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||
|
GPIO_Init(GPIOF, &GPIO_InitStructure);
|
||
|
/* turn the LED off */
|
||
|
GPIO_ResetBits(GPIOF, GPIO_Pin_8);
|
||
|
|
||
|
/* configure the pushbutton pin as input */
|
||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
|
||
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||
|
|
||
|
|
||
|
#if (BOOT_FILE_LOGGING_ENABLE > 0) || (BOOT_COM_UART_ENABLE > 0)
|
||
|
/* connect the pin to the peripherals alternate function */
|
||
|
GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
|
||
|
GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
|
||
|
/* 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_8;
|
||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||
|
/* configure USART Rx as alternate function */
|
||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
|
||
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||
|
#endif
|
||
|
|
||
|
#if (BOOT_FILE_LOGGING_ENABLE > 0) && (BOOT_COM_UART_ENABLE == 0)
|
||
|
/* configure UART communication parameters */
|
||
|
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(USART3, &USART_InitStructure);
|
||
|
/* enable UART */
|
||
|
USART_Cmd(USART3, ENABLE);
|
||
|
#endif
|
||
|
} /*** end of Init ***/
|
||
|
|
||
|
|
||
|
/*********************************** end of main.c *************************************/
|