This repository has been archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging Colin's master branch, including a couple of fixes.
- Loading branch information
Showing
45 changed files
with
893 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ docs/html | |
*.pyc | ||
*.gcno | ||
*.gcda | ||
*.swp | ||
libswiftnav/lcov | ||
/tags | ||
/libopencm3_for_ctags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
BINARY = bootloader | ||
|
||
OBJS = bootloader.o \ | ||
../src/debug.o \ | ||
../src/settings.o \ | ||
../src/error.o \ | ||
../src/hw/usart.o \ | ||
../src/hw/usart_rx.o \ | ||
../src/hw/usart_tx.o \ | ||
../src/hw/leds.o \ | ||
../src/hw/stm_flash.o \ | ||
|
||
CFLAGS += -I../src/ | ||
|
||
SWIFTNAV_ROOT ?= .. | ||
|
||
LDSCRIPT ?= $(SWIFTNAV_ROOT)/bootloader/bootloader.ld | ||
|
||
include $(SWIFTNAV_ROOT)/stm32/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Use stm32_flash.py (in scripts directory) to upload new firmware using | ||
the bootloader, via | ||
|
||
"./stm32flash.py [filename.bin]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* bootloader for the Swift Navigation Piksi GPS Receiver | ||
* | ||
* Copyright (C) 2010 Gareth McMullin <[email protected]> | ||
* Copyright (C) 2011 Piotr Esden-Tempski <[email protected]> | ||
* Copyright (C) 2013 Swift Navigation Inc <www.swift-nav.com> | ||
* | ||
* Contact: Colin Beighley <[email protected]> | ||
* | ||
* Based on luftboot, a bootloader for the Paparazzi UAV project. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <libopencm3/cm3/scb.h> | ||
|
||
#include "main.h" | ||
#include "hw/leds.h" | ||
#include "debug.h" | ||
#include "hw/stm_flash.h" | ||
#include "hw/usart.h" | ||
|
||
#define APP_ADDRESS 0x08010000 | ||
#define STACK_ADDRESS 0x10010000 | ||
|
||
u8 pc_wants_bootload = 0; | ||
u8 current_app_valid = 0; | ||
|
||
void jump_to_app_callback(u8 buff[] __attribute__((unused))){ | ||
/* Disable peripherals used in the bootloader */ | ||
debug_disable(); | ||
/* Set vector table base address */ | ||
SCB_VTOR = APP_ADDRESS & 0x1FFFFF00; | ||
/* Initialise master stack pointer */ | ||
asm volatile ("msr msp, %0"::"g"(*(volatile u32*)APP_ADDRESS)); | ||
/* Jump to application */ | ||
(*(void(**)())(APP_ADDRESS + 4))(); | ||
} | ||
|
||
void pc_wants_bootload_callback(u8 buff[] __attribute__((unused))){ | ||
pc_wants_bootload = 1; | ||
} | ||
|
||
int main(void) | ||
{ | ||
/* Setup and turn on LEDs */ | ||
led_setup(); | ||
led_on(LED_GREEN); | ||
led_on(LED_RED); | ||
|
||
/* Setup UART and debug interface for | ||
* transmitting and receiving callbacks */ | ||
debug_setup(); | ||
|
||
/* Add callbacks for erasing, programming and reading flash */ | ||
stm_flash_callbacks_setup(); | ||
|
||
/* Add callback for jumping to application after bootloading is finished */ | ||
static msg_callbacks_node_t jump_to_app_node; | ||
debug_register_callback(MSG_JUMP_TO_APP, &jump_to_app_callback, | ||
&jump_to_app_node); | ||
|
||
/* Add callback for PC to tell bootloader it wants to load program */ | ||
static msg_callbacks_node_t pc_wants_bootload_node; | ||
debug_register_callback(MSG_BOOTLOADER_HANDSHAKE,&pc_wants_bootload_callback, | ||
&pc_wants_bootload_node); | ||
|
||
/* rom (rx) : ORIGIN = 0x08010000, LENGTH = 896K */ | ||
/* Send message to PC indicating bootloader is ready to load program */ | ||
debug_send_msg(MSG_BOOTLOADER_HANDSHAKE,0,0); | ||
|
||
/* Is current application we are programmed with valid? Check this | ||
* by seeing if the first address of the application contains the | ||
* correct stack address */ | ||
current_app_valid = (*(volatile u32*)APP_ADDRESS == STACK_ADDRESS) ? 1:0; | ||
|
||
/* | ||
* Wait a bit for response from PC. If it doesn't respond by calling | ||
* pc_wants_bootload_callback and we have a valid application, | ||
* then boot the application | ||
* TODO : might as well make this as long as FPGA takes to configure itself | ||
* from the configuration flash, as it doesn't add to the startup time | ||
*/ | ||
for (u64 i=0; i<100000; i++){ | ||
DO_EVERY(3000, | ||
led_toggle(LED_GREEN); | ||
led_toggle(LED_RED); | ||
debug_send_msg(MSG_BOOTLOADER_HANDSHAKE,0,0); | ||
); | ||
debug_process_messages(); /* to service pc_wants_bootload_callback */ | ||
if (pc_wants_bootload) break; | ||
} | ||
if ((pc_wants_bootload) || !(current_app_valid)){ | ||
/* | ||
* We expect PC application passing application data to call | ||
* jump_to_app_callback to break us out of this while loop after it has | ||
* finished sending flash programming callbacks | ||
*/ | ||
while(1){ | ||
debug_process_messages(); | ||
DO_EVERY(50000, | ||
DO_EVERY(2, | ||
led_toggle(LED_GREEN); | ||
); | ||
led_toggle(LED_RED); | ||
/* | ||
* In case PC application was started after we entered the loop. It | ||
* is expecting to get a bootloader handshake message before it will | ||
* send flash programming callbacks | ||
*/ | ||
debug_send_msg(MSG_BOOTLOADER_HANDSHAKE,0,0); | ||
); | ||
} | ||
} | ||
|
||
/* Looks like the PC didn't want to update - boot the existing application */ | ||
jump_to_app_callback(NULL); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* bootloader for the Swift Navigation Piksi GPS Receiver | ||
* | ||
* Copyright (C) 2013 Swift Navigation Inc <www.swift-nav.com> | ||
* | ||
* Contacts: Fergus Noble <[email protected]> | ||
* Colin Beighley <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* Define memory regions. */ | ||
MEMORY | ||
{ | ||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 896K | ||
settings_flash (r) : ORIGIN = 0x080E0000, LENGTH = 128K | ||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K | ||
/* STM32F4 Core Coupled Memory, not accesible by peripherals or DMA. */ | ||
ccm (rwx) : ORIGIN = 0x10000000, LENGTH = 64K | ||
} | ||
|
||
/* Include the common ld script. */ | ||
INCLUDE libopencm3_stm32f4.ld | ||
|
||
SECTIONS { | ||
_stack_size = 65536; | ||
_stack = ORIGIN(ccm)+LENGTH(ccm); | ||
_stack_begin = _stack - _stack_size; | ||
|
||
.settings_area : { | ||
_settings_area = .; | ||
*(.settings_area*) | ||
_esettings_area = .; | ||
} > settings_flash | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.