summaryrefslogtreecommitdiffstats
path: root/boot
diff options
context:
space:
mode:
authorroot <root@ka-ata-killa.ourano.james.local>2021-03-02 12:54:03 +0000
committerroot <root@ka-ata-killa.ourano.james.local>2021-03-02 12:54:03 +0000
commit8c7ee88332652e7e79f6c1e4baacabe2183f7e8e (patch)
treea26ca60a089015822fa81ef44567927c1d8e334d /boot
parent3d48137c00511b3f2d35511482d1a76f8d06382d (diff)
downloadclock-8c7ee88332652e7e79f6c1e4baacabe2183f7e8e.tar.gz
clock-8c7ee88332652e7e79f6c1e4baacabe2183f7e8e.tar.bz2
clock-8c7ee88332652e7e79f6c1e4baacabe2183f7e8e.zip
working, with hybrid FLL/PLL, new refclk input and support for max7219 displays, neo 5 and neo 7 and a bazillion other fixes
Diffstat (limited to 'boot')
-rw-r--r--boot/Makefile4
-rw-r--r--boot/bootloader.c27
-rw-r--r--boot/delay.c1
-rw-r--r--boot/dfu.c4
-rw-r--r--boot/max7219.c169
-rw-r--r--boot/prototypes.h3
-rw-r--r--boot/usb.c4
7 files changed, 184 insertions, 28 deletions
diff --git a/boot/Makefile b/boot/Makefile
index e744d9a..b4d340c 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -21,6 +21,8 @@
CSRCS=bootloader.c usb.c dfu.c delay.c usart.c max7219.c
PROG = bootloader
+HOST=tick
+
CPROTO=cproto
V=1
BINARY = ${PROG}
@@ -44,6 +46,8 @@ protos: ${CSRCS}
${CPROTO} -E "${CPP} $(CPPFLAGS)" -e -v ${CSRCS} > prototypes.h.tmp
/bin/mv -f prototypes.h.tmp prototypes.h
+fl: ${PROG}.hex
+ ssh ${HOST} flash_stm32 < ${PROG}.hex
tidy:
astyle -A3 -s2 --attach-extern-c -L -c -w -Y -m0 -f -p -H -U -k3 -xj -xd ${CSRCS}
diff --git a/boot/bootloader.c b/boot/bootloader.c
index 27b6b98..a5932f0 100644
--- a/boot/bootloader.c
+++ b/boot/bootloader.c
@@ -20,7 +20,7 @@
#include "project.h"
-#define BOOTLOADER_BUTTON GPIO15
+#define BOOTLOADER_BUTTON GPIO12
#define BOOTLOADER_BUTTON_PORT GPIOE
@@ -92,12 +92,22 @@ int main (void)
{
rcc_periph_clock_enable (RCC_GPIOE);
+ rcc_periph_clock_enable (RCC_GPIOB);
+ rcc_periph_clock_enable (RCC_GPIOG);
MAP_INPUT_PU (BOOTLOADER_BUTTON);
+ if ((dfu_flag != 0xfee1dead) && (GET (BOOTLOADER_BUTTON))) {
+
- if ((dfu_flag != 0xfee1dead) && (GET(BOOTLOADER_BUTTON))) {
/* Boot the application if it's valid. */
if ((* (volatile uint32_t *)APP_ADDRESS & 0x2FFE0000) == 0x20020000) {
+
+ max7219 ("boot");
+
+ rcc_periph_clock_disable (RCC_GPIOE);
+ rcc_periph_clock_disable (RCC_GPIOB);
+ rcc_periph_clock_disable (RCC_GPIOG);
+
/* Set vector table base address. */
SCB_VTOR = APP_ADDRESS & 0xFFFF;
/* Initialise master stack pointer. */
@@ -106,17 +116,15 @@ int main (void)
"g" (* (volatile uint32_t *)APP_ADDRESS),
"r" (* (uint32_t *) (APP_ADDRESS + 4))
: "memory");
- }
- }
-
-
+ } else
+ max7219 ("nofw dfu");
+ } else
+ max7219 ("dfu");
dfu_flag = 0;
rcc_periph_clock_enable (RCC_SYSCFG);
- rcc_periph_clock_enable (RCC_GPIOB);
- rcc_periph_clock_enable (RCC_GPIOG);
rcc_clock_setup_hsi_3v3 (&hsi_16mhz_3v3_48);
@@ -126,10 +134,9 @@ int main (void)
RCC_AHB2RSTR &= ~RCC_AHB2RSTR_OTGFSRST;
RCC_AHB1RSTR &= ~RCC_AHB1RSTR_ETHMACRST;
- max7219_init();
usart_init();
- usart2_xmit_str("\r\nDFU Bootloader\r\n");
+ usart2_xmit_str ("\r\nDFU Bootloader\r\n");
delay_ms (100);
usart_init();
usart2_xmit_str ("Ready\r\n");
diff --git a/boot/delay.c b/boot/delay.c
index 132081a..d30b6ca 100644
--- a/boot/delay.c
+++ b/boot/delay.c
@@ -36,6 +36,7 @@ delay_ms (uint32_t d)
delay_ms_count = d;
while (delay_ms_count);
+
ticker_off();
}
diff --git a/boot/dfu.c b/boot/dfu.c
index f931a6e..4054520 100644
--- a/boot/dfu.c
+++ b/boot/dfu.c
@@ -36,7 +36,7 @@ static struct {
const struct usb_dfu_descriptor dfu_function = {
.bLength = sizeof (struct usb_dfu_descriptor),
.bDescriptorType = DFU_FUNCTIONAL,
- .bmAttributes = USB_DFU_CAN_DOWNLOAD,
+ .bmAttributes = USB_DFU_CAN_DOWNLOAD | USB_DFU_WILL_DETACH,
.wDetachTimeout = 255,
.wTransferSize = 1024,
.bcdDFUVersion = 0x011A,
@@ -115,6 +115,8 @@ static int usbdfu_getstatus_complete (usbd_device *usbd_dev, struct usb_setup_da
uint32_t *dat = (uint32_t *) (prog.buf + i);
flash_program_word (baseaddr + i, *dat);
}
+
+ max7219_report_addr (baseaddr);
}
flash_lock();
diff --git a/boot/max7219.c b/boot/max7219.c
index 3e06562..7a374eb 100644
--- a/boot/max7219.c
+++ b/boot/max7219.c
@@ -91,32 +91,173 @@ write_regs (uint8_t reg, uint8_t data1, uint8_t data2, uint8_t data3)
set (0, 1, 0);
}
+#define SDP 0x80
+#define SA 0x40
+#define SB 0x20
+#define SC 0x10
+#define SD 0x08
+#define SE 0x04
+#define SF 0x02
+#define SG 0x01
+
+static uint8_t hex (unsigned v)
+{
+ switch (v) {
+ case 0:
+ case '0':
+ return SA | SF | SB | SE | SC | SD;
+
+ case 1:
+ case '1':
+ return SB | SC;
+
+ case 2:
+ case '2':
+ case 'z':
+ return SA | SB | SG | SE | SD;
+
+ case 3:
+ case '3':
+ return SA | SB | SG | SC | SD;
+
+ case 4:
+ case '4':
+ return SF | SG | SB | SC;
+
+ case 5:
+ case '5':
+ case 's':
+ return SA | SF | SG | SC | SD;
+
+ case 6:
+ case '6':
+ return SA | SF | SG | SE | SC | SD;
+
+ case 7:
+ case '7':
+ return SA | SB | SC;
+
+ case 8:
+ case '8':
+ return SA | SF | SB | SG | SE | SC | SD;
+
+ case 9:
+ case '9':
+ case 'g':
+ return SA | SF | SB | SG | SC | SD;
+
+ case 0xa:
+ case 'a':
+ return SA | SF | SB | SG | SE | SC;
+
+ case 0xb:
+ case 'b':
+ return SF | SG | SE | SC | SD;
+
+ case 0xc:
+ case 'c':
+ return SG | SE | SD;
+
+ case 0xd:
+ case 'd':
+ return SB | SG | SE | SC | SD;
+
+ case 0xe:
+ case 'e':
+ return SA | SF | SG | SE | SD;
+
+ case 0xf:
+ case 'f':
+ return SA | SF | SG | SE;
+
+ case 'h':
+ return SF | SG | SE | SC;
+
+ case 'i':
+ return SE;
+
+ case 'j':
+ return SB | SC | SD;
+
+ case 'k':
+ case 'x':
+ return SF | SB | SG | SE | SC;
+
+ case 'l':
+ return SF | SE | SD;
+
+ case 'm':
+ case 'n':
+ return SG | SE | SC;
+
+ case 'o':
+ return SG | SE | SC | SD;
+
+ case 'p':
+ return SA | SF | SB | SG | SE;
+
+ case 'q':
+ return SA | SF | SB | SG | SC;
+
+ case 'r':
+ return SG | SE;
+
+ case 't':
+ return SF | SG | SE | SD;
+
+ case 'u':
+ case 'w':
+ return SE | SC | SD;
+
+ case 'y':
+ return SF | SB | SG | SC | SD;
+
+ case '-':
+ return SG;
+
+ case '.':
+ return SDP;
+
+ }
+
+ return 0;
+}
+
+void max7219_report_addr (uint32_t baseaddr)
+{
+ unsigned i;
+
+ for (i = 1; i <= 8; ++i) {
+ write_regs (i, hex (baseaddr & 0xf), 0, 0);
+ baseaddr >>= 4;
+ }
+}
+
+
void
-max7219_init (void)
+max7219 (const char *str)
{
MAP_OUTPUT_PP (SCK);
MAP_OUTPUT_PP (NCS);
MAP_OUTPUT_PP (MOSI);
+ unsigned reg;
set (0, 1, 0);
- write_reg (0xc, 0x1); //Power up
- write_reg (0xf, 0x0); //normal mode
+ write_reg (0xc, 0x1); //Power up
+ write_reg (0xf, 0x0); //normal mode
+
+ write_reg (0x9, 0x0); //No decode
+ write_reg (0xb, 0x7); //8 digits
+ write_regs (0xa, 15, 15, 15); //max brightness
- write_reg (0x9, 0x0); //No decode
- write_reg (0xb, 0x7); //8 digits
- write_regs (0xa,15,15,15); //max brightness
- write_reg (1,0);
- write_reg (2,0);
- write_reg (3,0);
- write_reg (4,0);
- write_reg (5,0);
- write_regs (6,0xbe,0,0);
- write_regs (7,0x47,0,0);
- write_regs (8,0x3d,0,0);
+ for (reg = 8; reg && *str; reg--, str++)
+ write_regs (reg, hex (*str) | (!str[1] ? SDP : 0), 0, 0);
+ for (; reg; reg--)
+ write_reg (reg, 0);
}
diff --git a/boot/prototypes.h b/boot/prototypes.h
index 17cc0fa..74f6b60 100644
--- a/boot/prototypes.h
+++ b/boot/prototypes.h
@@ -24,4 +24,5 @@ extern void usart2_xmit_xdigit(unsigned d);
extern void usart2_xmit_uint32(uint32_t v);
extern void usart_init(void);
/* max7219.c */
-extern void max7219_init(void);
+extern void max7219_report_addr(uint32_t baseaddr);
+extern void max7219(const char *str);
diff --git a/boot/usb.c b/boot/usb.c
index e8d2e20..1454750 100644
--- a/boot/usb.c
+++ b/boot/usb.c
@@ -15,8 +15,8 @@ const struct usb_device_descriptor dev = {
.bDeviceSubClass = 0,
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
- .idVendor = ID_VENDOR,
- .idProduct = ID_PRODUCT,
+ .idVendor = 0x0483,
+ .idProduct = 0xdf11,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,