Skip to content

Commit

Permalink
Added Bluetooth flash command
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurenceb committed Sep 24, 2012
1 parent c507672 commit 3d1b2e4
Show file tree
Hide file tree
Showing 11 changed files with 1,024 additions and 941 deletions.
38 changes: 38 additions & 0 deletions bootload.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "stm32f10x.h"
#include "core_cm3.h"
#include "main.h"
#include "ff.h"

void BootLoader(void) {
void (*SysMemBootJump)(void) = (void (*)(void)) (*((uint32_t *) 0x1FFF0004));
__set_PRIMASK(1);
RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
//RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
__set_MSP(0x20001000);
SysMemBootJump();
}

__attribute__((externally_visible)) void USART1_IRQHandler(void) {
static uint8_t dat[4];
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
//Clear pending bit and read the data.
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
*(uint32_t*)dat<<=8; //Works on little endian architectures
dat[0]=USART_ReceiveData(USART1);//Send "btld" to enter bootloader
if(dat[3]=='b' && dat[2]=='t' && dat[1]=='l' && dat[0]=='d') {
if(file_opened) {
char c[]="\r\nFirmware update\r\n";
uint8_t a;
f_write(&FATFS_logfile,c,sizeof(c),&a); //Write the error to the file
f_sync(&FATFS_logfile); //Flush buffers
f_truncate(&FATFS_logfile); //Truncate the lenght - fix pre allocation
f_close(&FATFS_logfile); //Close any opened file
}
BootLoader();
}
}
}

Binary file added bootload.o
Binary file not shown.
18 changes: 12 additions & 6 deletions interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ void ISR_Config(void) {
/* Enable and set SYSTICK Interrupt to the fifth priority */
NVIC_InitStructure.NVIC_IRQChannel = SysTick_IRQn; //The 100hz timer triggered interrupt
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;//Pre-emption priority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x05; //5th subpriority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x05; //6th subpriority
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; //The 100hz timer triggered interrupt
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; //The ADC watchdog triggered interrupt
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;//Low Pre-emption priority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x06; //6th subpriority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x06; //7th subpriority
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//Now we configure the I2C Event ISR
Expand All @@ -39,6 +39,12 @@ void ISR_Config(void) {
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; //Highest group priority
//NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enabling interrupt from USART1 - bluetooth commands, e.g. enter bootloader*/
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//UAVtalk Rx triggered interrupt
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;//Low pre-emption priority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //Third highest group - above the dma
//NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

/**
Expand Down Expand Up @@ -67,7 +73,7 @@ void EXTI_ONOFF_EN(void) {
/* Enable and set EXTI0 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //The WKUP triggered interrupt
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;//Lower pre-emption priority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x07; //low group priority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x07; //lowest group priority
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
Expand All @@ -83,7 +89,7 @@ void DMA_ISR_Config(void) {
/* Enable and set DMA1 Interrupt to the sixth priority */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;//The DMA complete/half complete triggered interrupt
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;//Higher pre-emption priority - can nest inside USB/SD
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x04; //6th subpriority
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x04; //5th subpriority
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
Expand Down Expand Up @@ -159,7 +165,7 @@ __attribute__((externally_visible)) void DMAChannel1_IRQHandler(void) {


/**
* @brief This function handles ADC1-2 interrupt requests.- Should only be from the analogu watchdog
* @brief This function handles ADC1-2 interrupt requests.- Should only be from the analog watchdog
* @param None
* @retval None
*/
Expand Down
Binary file modified interrupts.o
Binary file not shown.
9 changes: 6 additions & 3 deletions jtag/stm32loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,19 @@ def _wait_for_ask(self, info = ""):


def reset(self):
time.sleep(0.5)
self.sp.setRTS(1)
time.sleep(0.5)
self.sp.setRTS(0)
time.sleep(0.5)

def initChip(self):
# Set boot
self.sp.setDTR(1)
self.reset()
self.sp.setDTR(0)
self.sp.write("btld")
time.sleep(0.5)
#self.sp.setDTR(1)
#self.reset()
#self.sp.setDTR(0)
#self.sp.close()
#self.sp=open("/dev/rfcomm3","rb+")
self.sp.write("\x7F") # Syncro
Expand Down
Binary file modified main.bin
Binary file not shown.
Binary file modified main.elf
Binary file not shown.
Loading

0 comments on commit 3d1b2e4

Please sign in to comment.