booting to dfu, detaching, fast flash write

This commit is contained in:
Conor Patrick
2018-12-04 20:23:06 -05:00
parent b475c8391a
commit 173b8833ce
6 changed files with 61 additions and 7 deletions

View File

@@ -14,11 +14,20 @@ flash: solo.hex bootloader.hex
STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect
STM32_Programmer_CLI -c port=SWD -halt -d all.hex -rst
flash_dfu: solo.hex bootloader.hex
python merge_hex.py solo.hex bootloader.hex all.hex
# STM32_Programmer_CLI -c port=usb1 -halt -e all --readunprotect
STM32_Programmer_CLI -c port=usb1 -halt -d all.hex
flashboot: solo.hex bootloader.hex
python merge_hex.py solo.hex bootloader.hex all.hex
STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect
STM32_Programmer_CLI -c port=SWD -halt -d bootloader.hex -rst
# tell ST DFU to enter application
detach:
STM32_Programmer_CLI -c port=usb1 -ob nBOOT0=1
bootloader.hex:
echo "You need to build the bootloader first."

View File

@@ -70,8 +70,6 @@ all: $(TARGET).elf
clean:
rm -f *.o src/*.o src/*.elf bootloader/*.o $(OBJ)
detach:
STM32_Programmer_CLI -c port=usb1 -ob nBOOT0=1
cbor:
cd ../../tinycbor/ && make clean

View File

@@ -63,6 +63,7 @@ int is_authorized_to_boot()
int bootloader_bridge(int klen, uint8_t * keyh)
{
static int has_erased = 0;
int i;
BootloaderReq * req = (BootloaderReq * )keyh;
uint8_t hash[32];
uint8_t version = 1;
@@ -103,6 +104,8 @@ int bootloader_bridge(int klen, uint8_t * keyh)
}
flash_write((uint32_t)ptr,req->payload, len);
break;
case BootDone:
printf1(TAG_BOOT, "BootDone: ");
@@ -149,7 +152,7 @@ int bootloader_bridge(int klen, uint8_t * keyh)
printf1(TAG_BOOT, "BootReboot.\r\n");
device_reboot();
break;
#ifndef SOLO_HACKER
#ifdef SOLO_HACKER
case BootBootloader:
printf1(TAG_BOOT, "BootBootloader.\r\n");
flash_option_bytes_init(1);

View File

@@ -139,6 +139,39 @@ void flash_write(uint32_t addr, uint8_t * data, size_t sz)
}
// NOT YET working
void flash_write_fast(uint32_t addr, uint32_t * data)
{
__disable_irq();
while (FLASH->SR & (1<<16))
;
FLASH->SR = FLASH->SR;
// Select fast program action
FLASH->CR |= (1<<18);
int i;
for(i = 0; i < 64; i++)
{
*(volatile uint32_t*)addr = (*data);
addr+=4;
data++;
}
while (FLASH->SR & (1<<16))
;
if(FLASH->SR & (1<<1))
{
printf2(TAG_ERR,"program NOT successful %lx\r\n", FLASH->SR);
}
FLASH->SR = (1<<0);
FLASH->CR &= ~(1<<18);
__enable_irq();
}
void flash_lock()
{
FLASH->CR |= (1U<<31);

View File

@@ -4,6 +4,7 @@
void flash_erase_page(uint8_t page);
void flash_write_dword(uint32_t addr, uint64_t data);
void flash_write(uint32_t addr, uint8_t * data, size_t sz);
void flash_write_fast(uint32_t addr, uint32_t * data);
void flash_option_bytes_init(int boot_from_dfu);
#define FLASH_PAGE_SIZE 2048