From f2744bec303b91f81837b14412619aae7d7dcb09 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Wed, 15 Jul 2015 14:09:36 +0900 Subject: [PATCH] upgrade to chopstx 0.07 --- ChangeLog | 5 +++++ chopstx | 2 +- src/gnuk.ld.in | 31 +++++++++++++++---------------- src/sys.c | 33 +++++++++++++++++++++++---------- src/sys.h | 12 ++++++++++++ 5 files changed, 56 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19c3375..6be41e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2015-07-15 Niibe Yutaka + * chopstx: Update to 0.07. + * src/sys.c: Update. + * src/sys.h: Update. + * src/gnuk.ld.in: Update. + * tool/stlinkv2.py (stlinkv2.get_chip_id): New. Detect flash size, too. (main): Call stlinkv2.get_chip_id after MCU reset and stop. diff --git a/chopstx b/chopstx index 2bb0e0d..bdaae56 160000 --- a/chopstx +++ b/chopstx @@ -1 +1 @@ -Subproject commit 2bb0e0de5d7d25d0bb036e6ee9cc0c94b62375ec +Subproject commit bdaae5661d374d8bc7fe2a3244c10f535180bc2a diff --git a/src/gnuk.ld.in b/src/gnuk.ld.in index a7d19de..8e4e6dc 100644 --- a/src/gnuk.ld.in +++ b/src/gnuk.ld.in @@ -18,10 +18,6 @@ MEMORY ram : org = 0x20000000, len = @MEMORY_SIZE@k } -/* __flash_start__: flash ROM start address regardless of DFU_SUPPORT */ -__flash_start__ = 0x08001000; -__flash_end__ = ORIGIN(flash) + LENGTH(flash); - __ram_start__ = ORIGIN(ram); __ram_size__ = LENGTH(ram); __ram_end__ = __ram_start__ + __ram_size__; @@ -32,18 +28,20 @@ SECTIONS .sys : ALIGN(4) SUBALIGN(4) { - _sys = .; - KEEP(*(.vectors)) - . = ALIGN(16); - *(.sys.version) - build/sys.o(.text) - build/sys.o(.text.*) - build/sys.o(.rodata) - build/sys.o(.rodata.*) - . = ALIGN(1024); - *(.sys.0) - *(.sys.1) - *(.sys.2) + _sys = .; + KEEP(*(.vectors)) + . = ALIGN(16); + KEEP(*(.sys.version)) + KEEP(*(.sys.board_id)) + KEEP(*(.sys.board_name)) + build/sys.o(.text) + build/sys.o(.text.*) + build/sys.o(.rodata) + build/sys.o(.rodata.*) + . = ALIGN(1024); + *(.sys.0) + *(.sys.1) + *(.sys.2) } > flash0 _text = .; @@ -64,6 +62,7 @@ SECTIONS *(.glue_7t) *(.glue_7) *(.gcc*) + . = ALIGN(8); } > flash .ARM.extab : {*(.ARM.extab* .gnu.linkonce.armextab.*)} > flash diff --git a/src/sys.c b/src/sys.c index 0f0c1ac..586a79f 100644 --- a/src/sys.c +++ b/src/sys.c @@ -243,16 +243,19 @@ flash_check_blank (const uint8_t *p_start, size_t size) return 1; } -extern uint8_t __flash_start__, __flash_end__; +#define FLASH_START_ADDR 0x08000000 /* Fixed for all STM32F1. */ +#define FLASH_OFFSET 0x1000 /* First pages are not-writable. */ +#define FLASH_START (FLASH_START_ADDR+FLASH_OFFSET) +#define CHIP_ID_REG ((uint32_t *)0xe0042000) +#define FLASH_SIZE_REG ((uint16_t *)0x1ffff7e0) static int flash_write (uint32_t dst_addr, const uint8_t *src, size_t len) { int status; - uint32_t flash_start = (uint32_t)&__flash_start__; - uint32_t flash_end = (uint32_t)&__flash_end__; + uint32_t flash_end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024; - if (dst_addr < flash_start || dst_addr + len > flash_end) + if (dst_addr < FLASH_START || dst_addr + len > flash_end) return 0; while (len) @@ -305,17 +308,21 @@ flash_protect (void) static void __attribute__((naked)) flash_erase_all_and_exec (void (*entry)(void)) { - uint32_t addr = (uint32_t)&__flash_start__; - uint32_t end = (uint32_t)&__flash_end__; + uint32_t addr = FLASH_START; + uint32_t end = FLASH_START_ADDR + (*FLASH_SIZE_REG)*1024; + uint32_t page_size = 1024; int r; + if (((*CHIP_ID_REG) & 0xfff) == 0x0414) + page_size = 2048; + while (addr < end) { r = flash_erase_page (addr); if (r != 0) break; - addr += FLASH_PAGE_SIZE; + addr += page_size; } if (addr >= end) @@ -415,7 +422,13 @@ handler vector[] __attribute__ ((section(".vectors"))) = { const uint8_t sys_version[8] __attribute__((section(".sys.version"))) = { 3*2+2, /* bLength */ - 0x03, /* bDescriptorType = USB_STRING_DESCRIPTOR_TYPE*/ - /* sys version: "2.0" */ - '2', 0, '.', 0, '0', 0, + 0x03, /* bDescriptorType = USB_STRING_DESCRIPTOR_TYPE */ + /* sys version: "2.1" */ + '2', 0, '.', 0, '1', 0, }; + +const uint32_t __attribute__((section(".sys.board_id"))) +sys_board_id = BOARD_ID; + +const uint8_t __attribute__((section(".sys.board_name"))) +sys_board_name[] = BOARD_NAME; diff --git a/src/sys.h b/src/sys.h index 25d33f1..3127341 100644 --- a/src/sys.h +++ b/src/sys.h @@ -1,4 +1,16 @@ +#define BOARD_ID_CQ_STARM 0xc5480875 +#define BOARD_ID_FST_01_00 0x613870a9 +#define BOARD_ID_FST_01 0x696886af +#define BOARD_ID_MAPLE_MINI 0x7a445272 +#define BOARD_ID_OLIMEX_STM32_H103 0xf92bb594 +#define BOARD_ID_STBEE_MINI 0x1f341961 +#define BOARD_ID_STBEE 0x945c37e8 +#define BOARD_ID_STM32_PRIMER2 0x21e5798d +#define BOARD_ID_STM8S_DISCOVERY 0x2f0976bb + extern const uint8_t sys_version[8]; +extern const uint32_t sys_board_id; +extern const uint8_t sys_board_name[]; typedef void (*handler)(void); extern handler vector[16];