mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-05 21:52:10 +01:00
OP-21/Flight Bootloader - Added more Led status modes. Fixed downloading for bigger packet format.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1436 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
16361dea12
commit
2142467751
@ -32,9 +32,11 @@ typedef void (*pFunction)(void);
|
|||||||
pFunction Jump_To_Application;
|
pFunction Jump_To_Application;
|
||||||
uint32_t JumpAddress;
|
uint32_t JumpAddress;
|
||||||
|
|
||||||
uint32_t cnt;
|
/// LEDs PWM
|
||||||
uint32_t pwm_period;
|
uint32_t period1 = 50; // *100 uS -> 5 mS
|
||||||
uint32_t pwm_sweep_steps;
|
uint32_t sweep_steps1 = 100; // * 5 mS -> 500 mS
|
||||||
|
uint32_t period2 = 50; // *100 uS -> 5 mS
|
||||||
|
uint32_t sweep_steps2 = 100; // * 5 mS -> 500 mS
|
||||||
|
|
||||||
/* Extern variables ----------------------------------------------------------*/
|
/* Extern variables ----------------------------------------------------------*/
|
||||||
uint8_t DeviceState;
|
uint8_t DeviceState;
|
||||||
@ -42,6 +44,7 @@ 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);
|
||||||
|
uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count);
|
||||||
/* Private functions ---------------------------------------------------------*/
|
/* Private functions ---------------------------------------------------------*/
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -54,37 +57,76 @@ void DelayWithDown(__IO uint32_t nCount);
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
|
|
||||||
Set_System();
|
Set_System();
|
||||||
if (BSL_HOLD_STATE==0) {
|
if (BSL_HOLD_STATE == 0) {
|
||||||
|
|
||||||
USB_Interrupts_Config();
|
USB_Interrupts_Config();
|
||||||
Set_USBClock();
|
Set_USBClock();
|
||||||
USB_Init();
|
USB_Init();
|
||||||
DeviceState = idle;
|
DeviceState = idle;
|
||||||
STOPWATCH_Init(100);
|
STOPWATCH_Init(100);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
JumpToApp = TRUE;
|
JumpToApp = TRUE;
|
||||||
STOPWATCH_Reset();
|
STOPWATCH_Reset();
|
||||||
|
|
||||||
while (JumpToApp == 0) {
|
while (JumpToApp == 0) {
|
||||||
|
|
||||||
cnt = STOPWATCH_ValueGet(); // the reference counter (incremented each 100 uS)
|
//pwm_period = 50; // *100 uS -> 5 mS
|
||||||
pwm_period = 50; // *100 uS -> 5 mS
|
//pwm_sweep_steps =100; // * 5 mS -> 500 mS
|
||||||
pwm_sweep_steps =100; // * 5 mS -> 500 mS
|
|
||||||
uint32_t pwm_duty = ((cnt / pwm_period) % pwm_sweep_steps)
|
switch (DeviceState) {
|
||||||
/ (pwm_sweep_steps / pwm_period);
|
case Last_operation_Success:
|
||||||
if ((cnt % (2 * pwm_period * pwm_sweep_steps)) > pwm_period
|
case uploadingStarting:
|
||||||
* pwm_sweep_steps)
|
case DFUidle:
|
||||||
pwm_duty = pwm_period - pwm_duty; // negative direction each 50*100 ticks
|
period1 = 50;
|
||||||
uint32_t led_on = ((cnt % pwm_period) > pwm_duty) ? 1 : 0;
|
sweep_steps1 = 100;
|
||||||
if(led_on==0)
|
STM_EVAL_LEDOff(LED2);
|
||||||
|
period2 = 0;
|
||||||
|
break;
|
||||||
|
case uploading:
|
||||||
|
period1 = 50;
|
||||||
|
sweep_steps1 = 100;
|
||||||
|
period2 = 25;
|
||||||
|
sweep_steps2 = 50;
|
||||||
|
break;
|
||||||
|
case downloading:
|
||||||
|
period1 = 25;
|
||||||
|
sweep_steps1 = 50;
|
||||||
|
STM_EVAL_LEDOff(LED2);
|
||||||
|
period2 = 0;
|
||||||
|
break;
|
||||||
|
case idle:
|
||||||
|
period1 = 0;
|
||||||
STM_EVAL_LEDOn(LED1);
|
STM_EVAL_LEDOn(LED1);
|
||||||
else
|
period2=0;
|
||||||
STM_EVAL_LEDOff(LED1);
|
break;
|
||||||
if(STOPWATCH_ValueGet()>100*pwm_period*pwm_sweep_steps)
|
default://error
|
||||||
|
period1 = 50;
|
||||||
|
sweep_steps1 = 100;
|
||||||
|
period2 = 50;
|
||||||
|
sweep_steps2 = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (period1 != 0) {
|
||||||
|
if (LedPWM(period1, sweep_steps1, STOPWATCH_ValueGet()))
|
||||||
|
STM_EVAL_LEDOn(LED1);
|
||||||
|
else
|
||||||
|
STM_EVAL_LEDOff(LED1);
|
||||||
|
} else
|
||||||
|
STM_EVAL_LEDOn(LED1);
|
||||||
|
|
||||||
|
if (period2 != 0) {
|
||||||
|
if (LedPWM(period2, sweep_steps2, STOPWATCH_ValueGet()))
|
||||||
|
STM_EVAL_LEDOn(LED2);
|
||||||
|
else
|
||||||
|
STM_EVAL_LEDOff(LED2);
|
||||||
|
} else
|
||||||
|
STM_EVAL_LEDOff(LED2);
|
||||||
|
|
||||||
|
if (STOPWATCH_ValueGet() > 100 * 50 * 100)
|
||||||
STOPWATCH_Reset();
|
STOPWATCH_Reset();
|
||||||
if(STOPWATCH_ValueGet()>50000 && DeviceState == idle)
|
if ((STOPWATCH_ValueGet() > 60000) && (DeviceState == idle))
|
||||||
JumpToApp=TRUE;
|
JumpToApp = TRUE;
|
||||||
|
FLASH_Download();
|
||||||
//DelayWithDown(10);//1000000);
|
//DelayWithDown(10);//1000000);
|
||||||
}
|
}
|
||||||
if (((*(__IO uint32_t*) StartOfUserCode) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */
|
if (((*(__IO uint32_t*) StartOfUserCode) & 0x2FFE0000) == 0x20000000) { /* Jump to user application */
|
||||||
@ -104,12 +146,27 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
STM_EVAL_LEDToggle(LED1);
|
if (LedPWM(50, 100, STOPWATCH_ValueGet())) {
|
||||||
STM_EVAL_LEDToggle(LED2);
|
STM_EVAL_LEDOn(LED2);
|
||||||
Delay(1000000);
|
STM_EVAL_LEDOff(LED1);
|
||||||
|
} else {
|
||||||
|
STM_EVAL_LEDOn(LED1);
|
||||||
|
STM_EVAL_LEDOff(LED2);
|
||||||
|
}
|
||||||
|
if (STOPWATCH_ValueGet() > 2*50 * 100)
|
||||||
|
STOPWATCH_Reset();
|
||||||
|
FLASH_Download();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
uint32_t LedPWM(uint32_t pwm_period, uint32_t pwm_sweep_steps, uint32_t count) {
|
||||||
|
uint32_t pwm_duty = ((count / pwm_period) % pwm_sweep_steps)
|
||||||
|
/ (pwm_sweep_steps / pwm_period);
|
||||||
|
if ((count % (2 * pwm_period * pwm_sweep_steps)) > pwm_period
|
||||||
|
* pwm_sweep_steps)
|
||||||
|
pwm_duty = pwm_period - pwm_duty; // negative direction each 50*100 ticks
|
||||||
|
return ((count % pwm_period) > pwm_duty) ? 1 : 0;
|
||||||
|
}
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Function Name : Delay
|
* Function Name : Delay
|
||||||
* Description : Inserts a delay time.
|
* Description : Inserts a delay time.
|
||||||
|
@ -52,7 +52,7 @@ uint32_t aux;
|
|||||||
volatile uint32_t downPacketCurrent=0;
|
volatile uint32_t downPacketCurrent=0;
|
||||||
uint32_t downPacketTotal=0;
|
uint32_t downPacketTotal=0;
|
||||||
uint8_t downType=0;
|
uint8_t downType=0;
|
||||||
|
uint32_t downSizeOfLastPacket=0;
|
||||||
uint32_t MemLocations[3]=
|
uint32_t MemLocations[3]=
|
||||||
{
|
{
|
||||||
StartOfUserCode, StartOfUserCode-SizeOfHash, StartOfUserCode-SizeOfHash-SizeOfDescription
|
StartOfUserCode, StartOfUserCode-SizeOfHash, StartOfUserCode-SizeOfHash-SizeOfDescription
|
||||||
@ -67,22 +67,34 @@ uint8_t *FLASH_If_Read (uint32_t SectorAddress, uint32_t DataLength)
|
|||||||
return (uint8_t*)(SectorAddress);
|
return (uint8_t*)(SectorAddress);
|
||||||
}
|
}
|
||||||
void FLASH_Download() {
|
void FLASH_Download() {
|
||||||
if (DeviceState == downloading) {
|
if ((DeviceState == downloading) && (GetEPTxStatus(ENDP1)==EP_TX_NAK)) {
|
||||||
|
uint8_t packetSize;
|
||||||
Buffer[0] = 0x01;
|
Buffer[0] = 0x01;
|
||||||
Buffer[1] = Download;
|
Buffer[1] = Download;
|
||||||
Buffer[2] = downPacketCurrent >> 24;
|
Buffer[2] = downPacketCurrent >> 24;
|
||||||
Buffer[3] = downPacketCurrent >> 16;
|
Buffer[3] = downPacketCurrent >> 16;
|
||||||
Buffer[4] = downPacketCurrent >> 8;
|
Buffer[4] = downPacketCurrent >> 8;
|
||||||
Buffer[5] = downPacketCurrent;
|
Buffer[5] = downPacketCurrent;
|
||||||
Buffer[6] = *FLASH_If_Read(MemLocations[downType]+downPacketCurrent*4, 0);
|
if(downPacketCurrent==downPacketTotal)
|
||||||
Buffer[7] = *FLASH_If_Read(MemLocations[downType] + 1+downPacketCurrent*4, 0);
|
{
|
||||||
Buffer[8] = *FLASH_If_Read(MemLocations[downType] + 2+downPacketCurrent*4, 0);
|
packetSize=downSizeOfLastPacket;
|
||||||
Buffer[9] = *FLASH_If_Read(MemLocations[downType] + 3+downPacketCurrent*4, 0);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
packetSize=14;
|
||||||
|
}
|
||||||
|
for(int x=0;x<packetSize;++x)
|
||||||
|
{
|
||||||
|
Buffer[6+x*4] = *FLASH_If_Read(MemLocations[downType]+ downPacketCurrent*4+x*4, 0);
|
||||||
|
Buffer[7+x*4] = *FLASH_If_Read(MemLocations[downType] + 1+downPacketCurrent*4+x*4, 0);
|
||||||
|
Buffer[8+x*4] = *FLASH_If_Read(MemLocations[downType] + 2+downPacketCurrent*4+x*4, 0);
|
||||||
|
Buffer[9+x*4] = *FLASH_If_Read(MemLocations[downType] + 3+downPacketCurrent*4+x*4, 0);
|
||||||
|
}
|
||||||
USB_SIL_Write(EP1_IN, (uint8_t*) Buffer, 64);
|
USB_SIL_Write(EP1_IN, (uint8_t*) Buffer, 64);
|
||||||
downPacketCurrent=downPacketCurrent+1;
|
downPacketCurrent=downPacketCurrent+1;
|
||||||
if(downPacketCurrent>downPacketTotal)
|
if(downPacketCurrent>downPacketTotal)
|
||||||
{
|
{
|
||||||
STM_EVAL_LEDOn(LED2);
|
// STM_EVAL_LEDOn(LED2);
|
||||||
DeviceState=Last_operation_Success;
|
DeviceState=Last_operation_Success;
|
||||||
Aditionals=(uint32_t)Download;
|
Aditionals=(uint32_t)Download;
|
||||||
}
|
}
|
||||||
@ -103,7 +115,6 @@ void EP1_OUT_Callback(void)
|
|||||||
|
|
||||||
/* Read received data (2 bytes) */
|
/* Read received data (2 bytes) */
|
||||||
USB_SIL_Read(EP1_OUT, Receive_Buffer);
|
USB_SIL_Read(EP1_OUT, Receive_Buffer);
|
||||||
|
|
||||||
Command=Receive_Buffer[1];
|
Command=Receive_Buffer[1];
|
||||||
EchoReqFlag=(Command>>7);
|
EchoReqFlag=(Command>>7);
|
||||||
EchoAnsFlag=(Command>>6) & 0x01;
|
EchoAnsFlag=(Command>>6) & 0x01;
|
||||||
@ -225,6 +236,7 @@ void EP1_OUT_Callback(void)
|
|||||||
downPacketCurrent=0;
|
downPacketCurrent=0;
|
||||||
downPacketTotal=Count;
|
downPacketTotal=Count;
|
||||||
DeviceState=downloading;
|
DeviceState=downloading;
|
||||||
|
downSizeOfLastPacket=Data1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user