1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

OP-21/Bootloader Small change. Now turns off interrupts before jumping to code.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1393 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-08-23 21:30:09 +00:00 committed by zedamota
parent 8adbd76a4e
commit f91ae974a7

View File

@ -1,17 +1,17 @@
/******************** (C) COPYRIGHT 2010 STMicroelectronics ******************** /******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name : main.c * File Name : main.c
* Author : MCD Application Team * Author : MCD Application Team
* Version : V3.2.1 * Version : V3.2.1
* Date : 07/05/2010 * Date : 07/05/2010
* Description : Custom HID demo main file * Description : Custom HID demo main file
******************************************************************************** ********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/ *******************************************************************************/
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h" #include "stm32f10x.h"
@ -23,7 +23,7 @@
extern void FLASH_Download(); extern void FLASH_Download();
/* Private typedef -----------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/
typedef void (*pFunction)(void); typedef void (*pFunction)(void);
/* Private define ------------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
@ -31,110 +31,101 @@ pFunction Jump_To_Application;
uint32_t JumpAddress; uint32_t JumpAddress;
/* Extern variables ----------------------------------------------------------*/ /* Extern variables ----------------------------------------------------------*/
uint8_t DeviceState; uint8_t DeviceState;
uint8_t JumpToApp=0; uint8_t JumpToApp = 0;
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
void Delay(__IO uint32_t nCount); void Delay(__IO uint32_t nCount);
void DelayWithDown(__IO uint32_t nCount); void DelayWithDown(__IO uint32_t nCount);
/* Private functions ---------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/
/******************************************************************************* /*******************************************************************************
* Function Name : main. * Function Name : main.
* Description : main routine. * Description : main routine.
* Input : None. * Input : None.
* Output : None. * Output : None.
* Return : None. * Return : None.
*******************************************************************************/ *******************************************************************************/
int main(void) int main(void) {
{
if (((*(__IO uint32_t*)StartOfUserCode) & 0x2FFE0000 ) == 0x20000000)
{ /* Jump to user application */
JumpAddress = *(__IO uint32_t*) (StartOfUserCode + 4); Set_System();
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) StartOfUserCode);
Jump_To_Application();
}
Set_System();
USB_Interrupts_Config(); USB_Interrupts_Config();
Set_USBClock(); Set_USBClock();
USB_Init(); USB_Init();
DeviceState=idle; DeviceState = idle;
while (JumpToApp==0) while (JumpToApp == 0) {
{ STM_EVAL_LEDToggle(LED1);
DelayWithDown(10);//1000000);
}
if (((*(__IO uint32_t*) StartOfUserCode) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */
FLASH_Lock();
RCC_APB2PeriphResetCmd(0xffffffff, ENABLE);
RCC_APB1PeriphResetCmd(0xffffffff, ENABLE);
RCC_APB2PeriphResetCmd(0xffffffff, DISABLE);
RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
_SetCNTR(0); // clear interrupt mask
_SetISTR(0); // clear all requests
STM_EVAL_LEDToggle(LED1); JumpAddress = *(__IO uint32_t*) (StartOfUserCode + 4);
DelayWithDown(10);//1000000); Jump_To_Application = (pFunction) JumpAddress;
} /* Initialize user application's Stack Pointer */
if (((*(__IO uint32_t*)StartOfUserCode) & 0x2FFE0000 ) == 0x20000000) __set_MSP(*(__IO uint32_t*) StartOfUserCode);
{ /* Jump to user application */ Jump_To_Application();
}
JumpAddress = *(__IO uint32_t*) (StartOfUserCode + 4); while (1) {
Jump_To_Application = (pFunction) JumpAddress; STM_EVAL_LEDToggle(LED1);
/* Initialize user application's Stack Pointer */ STM_EVAL_LEDToggle(LED2);
__set_MSP(*(__IO uint32_t*) StartOfUserCode); Delay(1000000);
Jump_To_Application(); }
}
while(1)
{
STM_EVAL_LEDToggle(LED1);
STM_EVAL_LEDToggle(LED2);
Delay(1000000);
}
} }
/******************************************************************************* /*******************************************************************************
* Function Name : Delay * Function Name : Delay
* Description : Inserts a delay time. * Description : Inserts a delay time.
* Input : nCount: specifies the delay time length. * Input : nCount: specifies the delay time length.
* Output : None * Output : None
* Return : None * Return : None
*******************************************************************************/ *******************************************************************************/
void Delay(__IO uint32_t nCount) void Delay(__IO uint32_t nCount) {
{ for (; nCount != 0; nCount--) {
for(; nCount!= 0;nCount--)
{
} }
} }
/******************************************************************************* /*******************************************************************************
* Function Name : Delay * Function Name : Delay
* Description : Inserts a delay time. * Description : Inserts a delay time.
* Input : nCount: specifies the delay time length. * Input : nCount: specifies the delay time length.
* Output : None * Output : None
* Return : None * Return : None
*******************************************************************************/ *******************************************************************************/
void DelayWithDown(__IO uint32_t nCount) void DelayWithDown(__IO uint32_t nCount) {
{ for (; nCount != 0; nCount--) {
for(; nCount!= 0;nCount--) for (__IO uint32_t delay = DownloadDelay; delay != 0; delay--) {
{ }
for(__IO uint32_t delay=DownloadDelay ; delay!=0 ; delay--){} FLASH_Download();
FLASH_Download(); }
}
} }
#ifdef USE_FULL_ASSERT #ifdef USE_FULL_ASSERT
/******************************************************************************* /*******************************************************************************
* Function Name : assert_failed * Function Name : assert_failed
* Description : Reports the name of the source file and the source line number * Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred. * where the assert_param error has occurred.
* Input : - file: pointer to the source file name * Input : - file: pointer to the source file name
* - line: assert_param error line source number * - line: assert_param error line source number
* Output : None * Output : None
* Return : None * Return : None
*******************************************************************************/ *******************************************************************************/
void assert_failed(uint8_t* file, uint32_t line) void assert_failed(uint8_t* file, uint32_t line)
{ {
/* User can add his own implementation to report the file name and line number, /* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */ /* Infinite loop */
while(1) while(1)
{ {
} }
} }
#endif #endif