mirror of https://github.com/rusefi/openblt.git
134 lines
5.7 KiB
C
134 lines
5.7 KiB
C
|
/************************************************************************************//**
|
||
|
* \file Demo\ARMCM4_STM32F3_Nucleo_F303K8_IAR\Boot\main.c
|
||
|
* \brief Bootloader application source file.
|
||
|
* \ingroup Boot_ARMCM4_STM32F3_Nucleo_F303K8_IAR
|
||
|
* \internal
|
||
|
*----------------------------------------------------------------------------------------
|
||
|
* C O P Y R I G H T
|
||
|
*----------------------------------------------------------------------------------------
|
||
|
* Copyright (c) 2017 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 "stm32f30x.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 None.
|
||
|
**
|
||
|
****************************************************************************************/
|
||
|
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 ***/
|
||
|
|
||
|
|
||
|
/************************************************************************************//**
|
||
|
** \brief Initializes the microcontroller.
|
||
|
** \return none.
|
||
|
**
|
||
|
****************************************************************************************/
|
||
|
static void Init(void)
|
||
|
{
|
||
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||
|
|
||
|
/* enable the GPIO_LED Clock */
|
||
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
|
||
|
|
||
|
/* configure the GPIO_LED pin */
|
||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
|
||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||
|
/* turn the LED off */
|
||
|
GPIO_ResetBits(GPIOB, GPIO_Pin_3);
|
||
|
|
||
|
/* configure the D1 (PA9) pin as digital input for backdoor entry */
|
||
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
|
||
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
|
||
|
#if (BOOT_COM_UART_ENABLE > 0)
|
||
|
/* enable UART peripheral clock */
|
||
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||
|
/* enable GPIO peripheral clock for transmitter and receiver pins */
|
||
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
||
|
/* connect the pin to the peripherals alternate function */
|
||
|
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_7);
|
||
|
GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_AF_7);
|
||
|
/* 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_2;
|
||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
/* configure USART Rx as alternate function */
|
||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
|
||
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
#endif
|
||
|
|
||
|
#if (BOOT_COM_CAN_ENABLE > 0)
|
||
|
/* enable clocks for CAN1 transmitter and receiver pins */
|
||
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
|
||
|
/* select alternate function for the CAN1 pins */
|
||
|
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_9);
|
||
|
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_9);
|
||
|
/* configure CAN1 RX and TX pins */
|
||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
|
||
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||
|
/* enable CAN1 clock */
|
||
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);
|
||
|
#endif
|
||
|
} /*** end of Init ***/
|
||
|
|
||
|
|
||
|
/*********************************** end of main.c *************************************/
|