diff --git a/src/dapboot.c b/src/dapboot.c index 2b66151..3fa2fed 100644 --- a/src/dapboot.c +++ b/src/dapboot.c @@ -18,6 +18,8 @@ #include #include +#include + #include "dapboot.h" #include "target.h" @@ -34,7 +36,7 @@ static inline void __set_MSP(uint32_t topOfMainStack) { bool validate_application(void) { return ((uint32_t)(APP_INITIAL_STACK) & 0x2FFE0000) == 0x20000000; } - +// 20000000 static void jump_to_application(void) __attribute__ ((noreturn)); static void jump_to_application(void) { @@ -46,23 +48,70 @@ static void jump_to_application(void) { /* Do any necessary early setup for the application */ target_pre_main(); + for (int i=0; i< 5; i++){ + for(int j=0; j<2000000; j++){ + gpio_set(GPIOB, GPIO13); + } + for(int j=0; j<2000000; j++){ + gpio_clear(GPIOB, GPIO13); + } + } + gpio_set(GPIOB, GPIO13); + /* Initialize the application's stack pointer */ __set_MSP((uint32_t)(APP_INITIAL_STACK)); + + // this works + for (int i=0; i< 10; i++){ + for(int j=0; j<1000000; j++){ + gpio_set(GPIOB, GPIO13); + } + for(int j=0; j<100000; j++){ + gpio_clear(GPIOB, GPIO13); + } + } + gpio_set(GPIOB, GPIO13); + + /* Jump to the application entry point */ + // we die here, maybe not jumping to the right address APP_ENTRY_POINT(); + - while (1); + while (1) { + for(int j=0; j<500000; j++){ + gpio_set(GPIOB, GPIO13); + } + for(int j=0; j<500000; j++){ + gpio_clear(GPIOB, GPIO13); + } + } } int main(void) { + /* Setup clocks */ target_clock_setup(); /* Initialize GPIO/LEDs if needed */ target_gpio_setup(); - if (target_get_force_bootloader() || !validate_application()) { + if ( !validate_application()) { + for (int i=0; i< 10; i++){ + for(int j=0; j<700000; j++){ + gpio_set(GPIOB, GPIO13); + } + for(int j=0; j<700000; j++){ + gpio_clear(GPIOB, GPIO13); + } + } + gpio_set(GPIOB, GPIO13); + } + + if (target_get_force_bootloader() + || !validate_application() + ) { /* Setup USB */ { char serial[USB_SERIAL_NUM_LENGTH+1]; diff --git a/src/scripts/build.sh b/src/scripts/build.sh new file mode 100644 index 0000000..1dbed75 --- /dev/null +++ b/src/scripts/build.sh @@ -0,0 +1,2 @@ +make TARGET=STM32F103 + diff --git a/src/scripts/command-to-erase-and-flash.sh b/src/scripts/command-to-erase-and-flash.sh new file mode 100644 index 0000000..b9353a6 --- /dev/null +++ b/src/scripts/command-to-erase-and-flash.sh @@ -0,0 +1,2 @@ +openocd --file interface/jlink.cfg --command "transport select swd" -f target/stm32f1x.cfg -c "init" -c "halt" -c "stm32f1x mass_erase 0" -c "program dapboot.elf verify reset exit" + diff --git a/src/scripts/command-to-flash.sh b/src/scripts/command-to-flash.sh new file mode 100644 index 0000000..f699c85 --- /dev/null +++ b/src/scripts/command-to-flash.sh @@ -0,0 +1,2 @@ +openocd --file interface/jlink.cfg --command "transport select swd" -f target/stm32f1x.cfg -c "program dapboot.elf verify reset exit" + diff --git a/src/scripts/setup-path.sh b/src/scripts/setup-path.sh new file mode 100644 index 0000000..3ceeff4 --- /dev/null +++ b/src/scripts/setup-path.sh @@ -0,0 +1,2 @@ +export PATH=$PATH:~/toolchains/gcc-arm-embedded/bin/ + diff --git a/src/stm32f103/bluepill/config.h b/src/stm32f103/bluepill/config.h index 1f64b7e..b115b77 100644 --- a/src/stm32f103/bluepill/config.h +++ b/src/stm32f103/bluepill/config.h @@ -39,15 +39,17 @@ #define HAVE_LED 1 #endif #ifndef LED_OPEN_DRAIN -#define LED_OPEN_DRAIN 1 +#define LED_OPEN_DRAIN 0 #endif #ifndef LED_GPIO_PORT #define LED_GPIO_PORT GPIOC #endif #ifndef LED_GPIO_PIN -#define LED_GPIO_PIN GPIO13 +#define LED_GPIO_PIN GPIO8 #endif +// PB13 is SCLK which must be high to light led + #ifndef HAVE_BUTTON #define HAVE_BUTTON 1 #endif diff --git a/src/stm32f103/generic/config.h b/src/stm32f103/generic/config.h index 8b526e5..e2483a0 100644 --- a/src/stm32f103/generic/config.h +++ b/src/stm32f103/generic/config.h @@ -22,11 +22,11 @@ #ifndef APP_BASE_ADDRESS #define APP_BASE_ADDRESS (0x08000000 + BOOTLOADER_OFFSET) #endif -#ifndef FLASH_SIZE_OVERRIDE -#define FLASH_SIZE_OVERRIDE 0x20000 -#endif +// #ifndef FLASH_SIZE_OVERRIDE +// #define FLASH_SIZE_OVERRIDE 0x20000 +// #endif #ifndef FLASH_PAGE_SIZE -#define FLASH_PAGE_SIZE 1024 +#define FLASH_PAGE_SIZE 2048 #endif #ifndef DFU_UPLOAD_AVAILABLE #define DFU_UPLOAD_AVAILABLE 1 diff --git a/src/stm32f103/stm32f103x8.ld b/src/stm32f103/stm32f103x8.ld index 5bf2870..add499c 100644 --- a/src/stm32f103/stm32f103x8.ld +++ b/src/stm32f103/stm32f103x8.ld @@ -26,7 +26,7 @@ MEMORY { vectors (rx) : ORIGIN = 0x08000000, LENGTH = 0x150 rom (rx) : ORIGIN = 0x08000150, LENGTH = 0x1EB0 - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K } /* Include the common ld script. */ diff --git a/src/stm32f103/stm32f103x8_high.ld b/src/stm32f103/stm32f103x8_high.ld deleted file mode 100644 index 9e9c124..0000000 --- a/src/stm32f103/stm32f103x8_high.ld +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2015 Karl Palsson - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -/* Linker script for STM32F103x8, 64k flash, 20k RAM. */ - -/* Define memory regions. */ -MEMORY -{ - vectors (rx) : ORIGIN = 0x08000000, LENGTH = 0x150 - rom (rx) : ORIGIN = 0x0800E400, LENGTH = 0x1C00 - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K -} - -/* Include the common ld script. */ -INCLUDE stm32f103/stm32f1.ld diff --git a/src/stm32f103/stm32f103xb_high.ld b/src/stm32f103/stm32f103xb_high.ld deleted file mode 100644 index df2a646..0000000 --- a/src/stm32f103/stm32f103xb_high.ld +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2015 Karl Palsson - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -/* Linker script for STM32F103xB, 128k flash, 20k RAM. */ - -/* Define memory regions. */ -MEMORY -{ - vectors (rx) : ORIGIN = 0x08000000, LENGTH = 0x150 - rom (rx) : ORIGIN = 0x0801E400, LENGTH = 0x1C00 - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K -} - -/* Include the common ld script. */ -INCLUDE stm32f103/stm32f1.ld diff --git a/src/stm32f103/stm32f103xc_high.ld b/src/stm32f103/stm32f103xc_high.ld deleted file mode 100644 index 5c3ed66..0000000 --- a/src/stm32f103/stm32f103xc_high.ld +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This file is part of the libopencm3 project. - * - * Copyright (C) 2015 Karl Palsson - * - * This library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This library 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library. If not, see . - */ - -/* Linker script for STM32F103xC, 256k flash, 48k RAM. */ - -/* Define memory regions. */ -MEMORY -{ - vectors (rx) : ORIGIN = 0x08000000, LENGTH = 0x150 - rom (rx) : ORIGIN = 0x0803E400, LENGTH = 0x1C00 - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 48K -} - -/* Include the common ld script. */ -INCLUDE stm32f103/stm32f1.ld diff --git a/src/stm32f103/target_stm32f103.c b/src/stm32f103/target_stm32f103.c index 1965c0e..187d4b7 100644 --- a/src/stm32f103/target_stm32f103.c +++ b/src/stm32f103/target_stm32f103.c @@ -77,15 +77,15 @@ void target_clock_setup(void) { void target_gpio_setup(void) { /* Enable GPIO clocks */ -#if USES_GPIOA +// #if USES_GPIOA rcc_periph_clock_enable(RCC_GPIOA); -#endif -#if USES_GPIOB +// #endif +// #if USES_GPIOB rcc_periph_clock_enable(RCC_GPIOB); -#endif -#if USES_GPIOC +// #endif +// #if USES_GPIOC rcc_periph_clock_enable(RCC_GPIOC); -#endif +// #endif /* Disable SWD if PA13 and/or PA14 are used for another purpose */ #if ((HAVE_LED && LED_GPIO_PORT == GPIOA && (LED_GPIO_PORT == GPIO13 || LED_GPIO_PORT == GPIO14)) || \ @@ -98,20 +98,40 @@ void target_gpio_setup(void) { } #endif + /* Setup LEDs */ -#if HAVE_LED - { +// #if HAVE_LED + // { const uint8_t mode = GPIO_MODE_OUTPUT_10_MHZ; - const uint8_t conf = (LED_OPEN_DRAIN ? GPIO_CNF_OUTPUT_OPENDRAIN - : GPIO_CNF_OUTPUT_PUSHPULL); - if (LED_OPEN_DRAIN) { - gpio_set(LED_GPIO_PORT, LED_GPIO_PIN); - } else { - gpio_clear(LED_GPIO_PORT, LED_GPIO_PIN); + // const uint8_t conf = (LED_OPEN_DRAIN ? GPIO_CNF_OUTPUT_OPENDRAIN + // : GPIO_CNF_OUTPUT_PUSHPULL); + // if (LED_OPEN_DRAIN) { + // gpio_set(LED_GPIO_PORT, LED_GPIO_PIN); + // } else { + // gpio_clear(LED_GPIO_PORT, LED_GPIO_PIN); + // } + + gpio_clear(GPIOC, GPIO8); // CS provides ground + gpio_set_mode(GPIOC, mode, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO8); + gpio_clear(GPIOC, GPIO8); + // } + + gpio_set(GPIOB, GPIO13); // SCLK provides VDD + gpio_set_mode(GPIOB, mode, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); + gpio_set(GPIOB, GPIO13); + for (int i=0; i< 20; i++){ + for(int j=0; j<300000; j++){ + gpio_set(GPIOB, GPIO13); + } + for(int j=0; j<300000; j++){ + gpio_clear(GPIOB, GPIO13); } - gpio_set_mode(LED_GPIO_PORT, mode, conf, LED_GPIO_PIN); } -#endif + gpio_set(GPIOB, GPIO13); + + + +// #endif /* Setup the internal pull-up/pull-down for the button */ #if HAVE_BUTTON diff --git a/src/usb_conf.h b/src/usb_conf.h index e773e5b..3c1dc12 100644 --- a/src/usb_conf.h +++ b/src/usb_conf.h @@ -21,6 +21,12 @@ #include + + + +// 0x0483, 0x29 + +#define USB_VID 0x0483 #ifndef USB_VID #define USB_VID 0x1209 #endif @@ -29,6 +35,7 @@ #define USB_VENDOR_STRING "Devanarchy" #endif +#define USB_PID 0x29 #ifndef USB_PID #define USB_PID 0xdb42 #endif