Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions src/dapboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <string.h>
#include <libopencm3/cm3/vector.h>
#include <libopencm3/stm32/gpio.h>


#include "dapboot.h"
#include "target.h"
Expand All @@ -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) {
Expand All @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
make TARGET=STM32F103

2 changes: 2 additions & 0 deletions src/scripts/command-to-erase-and-flash.sh
Original file line number Diff line number Diff line change
@@ -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"

2 changes: 2 additions & 0 deletions src/scripts/command-to-flash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
openocd --file interface/jlink.cfg --command "transport select swd" -f target/stm32f1x.cfg -c "program dapboot.elf verify reset exit"

2 changes: 2 additions & 0 deletions src/scripts/setup-path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export PATH=$PATH:~/toolchains/gcc-arm-embedded/bin/

6 changes: 4 additions & 2 deletions src/stm32f103/bluepill/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/stm32f103/generic/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/stm32f103/stm32f103x8.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
31 changes: 0 additions & 31 deletions src/stm32f103/stm32f103x8_high.ld

This file was deleted.

31 changes: 0 additions & 31 deletions src/stm32f103/stm32f103xb_high.ld

This file was deleted.

31 changes: 0 additions & 31 deletions src/stm32f103/stm32f103xc_high.ld

This file was deleted.

52 changes: 36 additions & 16 deletions src/stm32f103/target_stm32f103.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) || \
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/usb_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@

#include <libopencm3/usb/usbd.h>




// 0x0483, 0x29

#define USB_VID 0x0483
#ifndef USB_VID
#define USB_VID 0x1209
#endif
Expand All @@ -29,6 +35,7 @@
#define USB_VENDOR_STRING "Devanarchy"
#endif

#define USB_PID 0x29
#ifndef USB_PID
#define USB_PID 0xdb42
#endif
Expand Down