]> mj.ucw.cz Git - home-hw.git/commitdiff
test-dumploader: A tool for dumping bootloader ROM
authorMartin Mares <mj@ucw.cz>
Wed, 10 Jul 2019 08:21:29 +0000 (10:21 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 10 Jul 2019 08:21:29 +0000 (10:21 +0200)
test-dumploader/Makefile [new file with mode: 0644]
test-dumploader/config.h [new file with mode: 0644]
test-dumploader/kerm [new file with mode: 0644]
test-dumploader/test.c [new file with mode: 0644]

diff --git a/test-dumploader/Makefile b/test-dumploader/Makefile
new file mode 100644 (file)
index 0000000..a8c8937
--- /dev/null
@@ -0,0 +1,6 @@
+ROOT=..
+BINARY=test
+OBJS=test.o
+LIB_OBJS=util-debug.o
+
+include $(ROOT)/mk/bluepill.mk
diff --git a/test-dumploader/config.h b/test-dumploader/config.h
new file mode 100644 (file)
index 0000000..bdfda60
--- /dev/null
@@ -0,0 +1,7 @@
+// Processor clock
+
+#define CPU_CLOCK_MHZ 72
+
+// Debugging port
+
+#define DEBUG_USART USART1
diff --git a/test-dumploader/kerm b/test-dumploader/kerm
new file mode 100644 (file)
index 0000000..988f567
--- /dev/null
@@ -0,0 +1,5 @@
+set port /dev/ttyUSB0
+set speed 115200
+set flow-control none
+set carrier-watch off
+connect
diff --git a/test-dumploader/test.c b/test-dumploader/test.c
new file mode 100644 (file)
index 0000000..bb9f2d2
--- /dev/null
@@ -0,0 +1,94 @@
+#include "util.h"
+
+#include <libopencm3/cm3/cortex.h>
+#include <libopencm3/cm3/nvic.h>
+#include <libopencm3/cm3/systick.h>
+#include <libopencm3/stm32/rcc.h>
+#include <libopencm3/stm32/gpio.h>
+#include <libopencm3/stm32/usart.h>
+
+static void clock_setup(void)
+{
+       rcc_clock_setup_in_hse_8mhz_out_72mhz();
+
+       rcc_periph_clock_enable(RCC_GPIOA);
+       rcc_periph_clock_enable(RCC_GPIOC);
+       rcc_periph_clock_enable(RCC_USART1);
+
+#if 0
+       rcc_periph_reset_pulse(RST_GPIOA);
+       rcc_periph_reset_pulse(RST_GPIOC);
+       rcc_periph_reset_pulse(RST_USART1);
+#endif
+}
+
+static void gpio_setup(void)
+{
+       // PC13 = BluePill LED
+       gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
+       gpio_clear(GPIOC, GPIO13);
+}
+
+static void usart_setup(void)
+{
+       gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
+
+       usart_set_baudrate(USART1, 115200);
+       usart_set_databits(USART1, 8);
+       usart_set_stopbits(USART1, USART_STOPBITS_1);
+       usart_set_mode(USART1, USART_MODE_TX_RX);
+       usart_set_parity(USART1, USART_PARITY_NONE);
+       usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
+
+       usart_enable(USART1);
+}
+
+static volatile u32 ms_ticks;
+
+void sys_tick_handler(void)
+{
+       ms_ticks++;
+}
+
+static void tick_setup(void)
+{
+       systick_set_frequency(1000, 72000000);
+       systick_counter_enable();
+       systick_interrupt_enable();
+}
+
+static void delay_ms(uint ms)
+{
+       u32 start_ticks = ms_ticks;
+       while (ms_ticks - start_ticks < ms)
+               ;
+}
+
+int main(void)
+{
+       clock_setup();
+       gpio_setup();
+       tick_setup();
+       usart_setup();
+
+       for (uint i=0; i<20; i++) {
+               delay_ms(100);
+               gpio_toggle(GPIOC, GPIO13);
+       }
+
+       for (;;) {
+               delay_ms(1000);
+               for (uint i=0; i<2048; i++) {
+                       u32 a = 0x1ffff000 + i;
+                       if (!(i%32)) {
+                               debug_printf("%08x:", a);
+                               gpio_toggle(GPIOC, GPIO13);
+                       }
+                       debug_printf(" %02x", *(byte *)a);
+                       if (i%32 == 31)
+                               debug_putc('\n');
+               }
+       }
+
+       return 0;
+}