add uart to spi flasher
parent
5630e71813
commit
d5e3805671
|
@ -18,6 +18,7 @@
|
|||
#include "drivers/drivers.h"
|
||||
#include "drivers/spi.h"
|
||||
#include "drivers/usb.h"
|
||||
#include "drivers/uart.h"
|
||||
|
||||
#include "crypto/rsa.h"
|
||||
#include "crypto/sha.h"
|
||||
|
@ -26,9 +27,6 @@
|
|||
|
||||
#include "spi_flasher.h"
|
||||
|
||||
int puts(const char *a) { return 0; }
|
||||
void puth(unsigned int i) {}
|
||||
|
||||
void __initialize_hardware_early() {
|
||||
early();
|
||||
}
|
||||
|
@ -51,7 +49,7 @@ int main() {
|
|||
|
||||
// validate length
|
||||
int len = (int)_app_start[0];
|
||||
if ((len < 8) || (((uint32_t)&_app_start[0] + RSANUMBYTES) >= 0x8100000)) fail();
|
||||
if ((len < 8) || (len > (0x1000000 - 0x4000 - 4 - RSANUMBYTES))) goto fail;
|
||||
|
||||
// compute SHA hash
|
||||
uint8_t digest[SHA_DIGEST_SIZE];
|
||||
|
@ -70,7 +68,9 @@ int main() {
|
|||
#endif
|
||||
|
||||
// here is a failure
|
||||
fail:
|
||||
fail();
|
||||
return 0;
|
||||
good:
|
||||
// jump to flash
|
||||
((void(*)()) _app_start[1])();
|
||||
|
|
|
@ -52,7 +52,7 @@ int putc(uart_ring *q, char elem);
|
|||
|
||||
int puts(const char *a);
|
||||
void puth(unsigned int i);
|
||||
void hexdump(void *a, int l);
|
||||
void hexdump(const void *a, int l);
|
||||
|
||||
|
||||
// ********************* ADC *********************
|
||||
|
|
|
@ -204,11 +204,11 @@ void puth2(unsigned int i) {
|
|||
}
|
||||
}
|
||||
|
||||
void hexdump(void *a, int l) {
|
||||
void hexdump(const void *a, int l) {
|
||||
int i;
|
||||
for (i=0;i<l;i++) {
|
||||
if (i != 0 && (i&0xf) == 0) puts("\n");
|
||||
puth2(((unsigned char*)a)[i]);
|
||||
puth2(((const unsigned char*)a)[i]);
|
||||
puts(" ");
|
||||
}
|
||||
puts("\n");
|
||||
|
|
11
board/main.c
11
board/main.c
|
@ -177,13 +177,13 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) {
|
|||
switch (setup->b.wValue.w) {
|
||||
case 0:
|
||||
if (hardwired) {
|
||||
puts("-> entering bootloader\n");
|
||||
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
set_led(LED_BLUE, 1);
|
||||
while(1);
|
||||
puts("-> entering softloader\n");
|
||||
enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC;
|
||||
NVIC_SystemReset();
|
||||
break;
|
||||
|
@ -408,12 +408,15 @@ int main() {
|
|||
// shouldn't have interrupts here, but just in case
|
||||
__disable_irq();
|
||||
|
||||
// init devices
|
||||
// init early devices
|
||||
clock_init();
|
||||
periph_init();
|
||||
detect();
|
||||
|
||||
// print hello
|
||||
puts("\n\n\n************************ MAIN START ************************\n");
|
||||
|
||||
// detect the revision and init the GPIOs
|
||||
detect();
|
||||
puts("config:\n");
|
||||
#ifdef PANDA
|
||||
puts(revision == PANDA_REV_C ? " panda rev c\n" : " panda rev a or b\n");
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
uint32_t *prog_ptr = NULL;
|
||||
int unlocked = 0;
|
||||
|
||||
void debug_ring_callback(uart_ring *ring) {}
|
||||
|
||||
int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) {
|
||||
int resp_len = 0;
|
||||
|
||||
|
@ -114,11 +116,14 @@ int spi_cb_rx(uint8_t *data, int len, uint8_t *data_out) {
|
|||
}
|
||||
|
||||
void soft_flasher_start() {
|
||||
puts("\n\n\n************************ FLASHER START ************************\n");
|
||||
|
||||
enter_bootloader_mode = 0;
|
||||
|
||||
RCC->AHB1ENR |= RCC_AHB1ENR_DMA2EN;
|
||||
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
|
||||
RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;
|
||||
RCC->APB1ENR |= RCC_APB1ENR_USART2EN;
|
||||
|
||||
// A4,A5,A6,A7: setup SPI
|
||||
set_gpio_alternate(GPIOA, 4, GPIO_AF5_SPI1);
|
||||
|
@ -126,11 +131,18 @@ void soft_flasher_start() {
|
|||
set_gpio_alternate(GPIOA, 6, GPIO_AF5_SPI1);
|
||||
set_gpio_alternate(GPIOA, 7, GPIO_AF5_SPI1);
|
||||
|
||||
// A2,A3: USART 2 for debugging
|
||||
set_gpio_alternate(GPIOA, 2, GPIO_AF7_USART2);
|
||||
set_gpio_alternate(GPIOA, 3, GPIO_AF7_USART2);
|
||||
|
||||
// A11,A12: USB
|
||||
set_gpio_alternate(GPIOA, 11, GPIO_AF10_OTG_FS);
|
||||
set_gpio_alternate(GPIOA, 12, GPIO_AF10_OTG_FS);
|
||||
GPIOA->OSPEEDR = GPIO_OSPEEDER_OSPEEDR11 | GPIO_OSPEEDER_OSPEEDR12;
|
||||
|
||||
// enable main uart
|
||||
uart_init(USART2, 115200);
|
||||
|
||||
// flasher
|
||||
spi_init();
|
||||
|
||||
|
|
Loading…
Reference in New Issue