1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-21/Flight Bootloader - Now if USB not connected it jumps directly to FW. If connected it will wait 5 seconds for command, then jumps. Also changed led flashing to PWM and created a timer for the delays.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1409 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-08-25 22:31:14 +00:00 committed by zedamota
parent 38df030773
commit d71ade8227
8 changed files with 151 additions and 23 deletions

View File

@ -92,7 +92,7 @@ SRC += $(HIDSYSTEM)/usb_istr.c
SRC += $(HIDSYSTEM)/usb_prop.c
SRC += $(HIDSYSTEM)/usb_pwr.c
SRC += $(HIDSYSTEM)/stm3210e_eval.c
SRC += $(HIDSYSTEM)/stopwatch.c
## CMSIS for STM32
SRC += $(CMSISDIR)/core_cm3.c
@ -112,7 +112,7 @@ SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c
SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c
#SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c
#SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c
#SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c
#SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c
#SRC += $(STMSPDSRCDIR)/stm32f10x_wwdg.c
SRC += $(STMSPDSRCDIR)/misc.c

View File

@ -301,8 +301,7 @@ void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_DISCONNECT |
RCC_APB2Periph_GPIO_IOAIN , ENABLE);
#ifndef USE_STM3210C_EVAL
/* USB_DISCONNECT used as USB pull-up */
@ -312,10 +311,7 @@ void GPIO_Configuration(void)
GPIO_Init(USB_DISCONNECT, &GPIO_InitStructure);
#endif /* USE_STM3210C_EVAL */
/* Configure Potentiometer IO as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_IOAIN_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIO_IOAIN, &GPIO_InitStructure);
}
/*******************************************************************************

View File

@ -48,10 +48,7 @@
#endif /* USE_STM3210B_EVAL */
#define RCC_APB2Periph_GPIO_IOAIN RCC_APB2Periph_GPIOC
#define GPIO_IOAIN GPIOC
#define GPIO_IOAIN_PIN GPIO_Pin_4 /* PC.04 */
#define ADC_AIN_CHANNEL ADC_Channel_14
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */

View File

@ -0,0 +1,29 @@
#ifndef _STOPWATCH_H
#define _STOPWATCH_H
/////////////////////////////////////////////////////////////////////////////
// Global definitions
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Global Types
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Prototypes
/////////////////////////////////////////////////////////////////////////////
extern s32 STOPWATCH_Init(u32 resolution);
extern s32 STOPWATCH_Reset(void);
extern u32 STOPWATCH_ValueGet(void);
/////////////////////////////////////////////////////////////////////////////
// Export global variables
/////////////////////////////////////////////////////////////////////////////
#endif /* _STOPWATCH_H */

View File

@ -19,8 +19,10 @@
#include "hw_config.h"
#include "stm32_eval.h"
#include "common.h"
#include "platform_config.h"
#include "stopwatch.h"
extern void FLASH_Download();
#define BSL_HOLD_STATE ((USB_DISCONNECT->IDR & USB_DISCONNECT_PIN) ? 0 : 1)
/* Private typedef -----------------------------------------------------------*/
typedef void (*pFunction)(void);
@ -29,6 +31,11 @@ typedef void (*pFunction)(void);
/* Private variables ---------------------------------------------------------*/
pFunction Jump_To_Application;
uint32_t JumpAddress;
uint32_t cnt;
uint32_t pwm_period;
uint32_t pwm_sweep_steps;
/* Extern variables ----------------------------------------------------------*/
uint8_t DeviceState;
uint8_t JumpToApp = 0;
@ -47,17 +54,38 @@ void DelayWithDown(__IO uint32_t nCount);
int main(void) {
Set_System();
if (BSL_HOLD_STATE==0) {
USB_Interrupts_Config();
Set_USBClock();
USB_Init();
DeviceState = idle;
STOPWATCH_Init(100);
}
else
JumpToApp = TRUE;
STOPWATCH_Reset();
while (JumpToApp == 0) {
STM_EVAL_LEDToggle(LED1);
DelayWithDown(10);//1000000);
cnt = STOPWATCH_ValueGet(); // the reference counter (incremented each 100 uS)
pwm_period = 50; // *100 uS -> 5 mS
pwm_sweep_steps =100; // * 5 mS -> 500 mS
uint32_t pwm_duty = ((cnt / pwm_period) % pwm_sweep_steps)
/ (pwm_sweep_steps / pwm_period);
if ((cnt % (2 * pwm_period * pwm_sweep_steps)) > pwm_period
* pwm_sweep_steps)
pwm_duty = pwm_period - pwm_duty; // negative direction each 50*100 ticks
uint32_t led_on = ((cnt % pwm_period) > pwm_duty) ? 1 : 0;
if(led_on==0)
STM_EVAL_LEDOn(LED1);
else
STM_EVAL_LEDOff(LED1);
if(STOPWATCH_ValueGet()>100*pwm_period*pwm_sweep_steps)
STOPWATCH_Reset();
if(STOPWATCH_ValueGet()>50000)
JumpToApp=TRUE;
//DelayWithDown(10);//1000000);
}
if (((*(__IO uint32_t*) StartOfUserCode) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */
FLASH_Lock();
@ -74,6 +102,7 @@ int main(void) {
__set_MSP(*(__IO uint32_t*) StartOfUserCode);
Jump_To_Application();
}
while (1) {
STM_EVAL_LEDToggle(LED1);
STM_EVAL_LEDToggle(LED2);

View File

@ -0,0 +1,75 @@
/////////////////////////////////////////////////////////////////////////////
// Include files
/////////////////////////////////////////////////////////////////////////////
#include "stm32_eval.h"
#include "stm32f10x_tim.h"
/////////////////////////////////////////////////////////////////////////////
// Local definitions
/////////////////////////////////////////////////////////////////////////////
#define STOPWATCH_TIMER_BASE TIM6
#define STOPWATCH_TIMER_RCC RCC_APB1Periph_TIM6
uint32_t STOPWATCH_Init(u32 resolution)
{
// enable timer clock
if( STOPWATCH_TIMER_RCC == RCC_APB2Periph_TIM1 || STOPWATCH_TIMER_RCC == RCC_APB2Periph_TIM8 )
RCC_APB2PeriphClockCmd(STOPWATCH_TIMER_RCC, ENABLE);
else
RCC_APB1PeriphClockCmd(STOPWATCH_TIMER_RCC, ENABLE);
// time base configuration
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 0xffff; // max period
TIM_TimeBaseStructure.TIM_Prescaler = (72 * resolution)-1; // <resolution> uS accuracy @ 72 MHz
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(STOPWATCH_TIMER_BASE, &TIM_TimeBaseStructure);
// enable interrupt request
TIM_ITConfig(STOPWATCH_TIMER_BASE, TIM_IT_Update, ENABLE);
// start counter
TIM_Cmd(STOPWATCH_TIMER_BASE, ENABLE);
return 0; // no error
}
/////////////////////////////////////////////////////////////////////////////
//! Resets the stopwatch
//! \return < 0 on errors
/////////////////////////////////////////////////////////////////////////////
uint32_t STOPWATCH_Reset(void)
{
// reset counter
STOPWATCH_TIMER_BASE->CNT = 1; // set to 1 instead of 0 to avoid new IRQ request
TIM_ClearITPendingBit(STOPWATCH_TIMER_BASE, TIM_IT_Update);
return 0; // no error
}
/////////////////////////////////////////////////////////////////////////////
//! Returns current value of stopwatch
//! \return 1..65535: valid stopwatch value
//! \return 0xffffffff: counter overrun
/////////////////////////////////////////////////////////////////////////////
uint32_t STOPWATCH_ValueGet(void)
{
uint32_t value = STOPWATCH_TIMER_BASE->CNT;
if( TIM_GetITStatus(STOPWATCH_TIMER_BASE, TIM_IT_Update) != RESET )
value = 0xffffffff;
return value;
}

View File

@ -103,7 +103,7 @@ const uint8_t CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] =
0x03, /* bmAttributes: Interrupt endpoint */
0x40, /* diff:0x40 wMaxPacketSize: 2 Bytes max */
0x00,
0x08, /* diff:0x08 bInterval: Polling Interval (32 ms) */
0x01, /* diff:0x08 bInterval: Polling Interval (32 ms) */
/* 34 */
0x07, /* bLength: Endpoint Descriptor size */
@ -114,7 +114,7 @@ const uint8_t CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] =
0x03, /* bmAttributes: Interrupt endpoint */
0x40, /* diff:0x40 wMaxPacketSize: 2 Bytes max */
0x00,
0x08, /* diff:0x08 bInterval: Polling Interval (20 ms) */
0x01, /* diff:0x08 bInterval: Polling Interval (20 ms) */
/* 41 */
}
; /* diff:lots CustomHID_ConfigDescriptor */

View File

@ -23,6 +23,8 @@
#include "common.h"
#include "hw_config.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/