Skip to content

Commit a89c83f

Browse files
authored
Merge pull request #27 from karlp/l1
Add STM32L1 support, courtesy of @karlp
2 parents b019c6e + 217cf4f commit a89c83f

11 files changed

Lines changed: 464 additions & 2 deletions

File tree

src/dfu.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@
3030
#include "dapboot.h"
3131
#include "config.h"
3232

33+
#ifndef TARGET_DFU_WTRANSFERSIZE
34+
#define TARGET_DFU_WTRANSFERSIZE USB_CONTROL_BUF_SIZE
35+
#endif
36+
3337
const struct usb_dfu_descriptor dfu_function = {
3438
.bLength = sizeof(struct usb_dfu_descriptor),
3539
.bDescriptorType = DFU_FUNCTIONAL,
3640
.bmAttributes = ((DFU_DOWNLOAD_AVAILABLE ? USB_DFU_CAN_DOWNLOAD : 0) |
3741
(DFU_UPLOAD_AVAILABLE ? USB_DFU_CAN_UPLOAD : 0) |
3842
USB_DFU_WILL_DETACH ),
3943
.wDetachTimeout = 255,
40-
.wTransferSize = USB_CONTROL_BUF_SIZE,
44+
.wTransferSize = TARGET_DFU_WTRANSFERSIZE,
4145
.bcdDFUVersion = 0x0110,
4246
};
4347

@@ -165,7 +169,7 @@ static int dfu_control_class_request(usbd_device *usbd_dev,
165169
#if DFU_DOWNLOAD_AVAILABLE
166170
case STATE_DFU_DNLOAD_SYNC: {
167171
dfu_set_state(STATE_DFU_DNBUSY);
168-
bwPollTimeout = 100;
172+
bwPollTimeout = target_get_timeout();
169173
*complete = &dfu_on_download_request;
170174
break;
171175
}

src/dummy.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void target_get_serial_number(char* dest, size_t max_chars) __attribute__((weak)
2626
void target_log(const char* str) __attribute__((weak));
2727
void target_manifest_app(void) __attribute__((weak));
2828
void target_pre_main(void) __attribute__((weak));
29+
size_t target_get_timeout(void) __attribute__((weak));
2930

3031
void target_get_serial_number(char* dest, size_t max_chars) {
3132
(void)max_chars;
@@ -46,3 +47,8 @@ void target_pre_main(void)
4647
{
4748

4849
}
50+
51+
size_t target_get_timeout(void)
52+
{
53+
return 100;
54+
}

src/rules.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ ifeq ($(ARCH),STM32F1)
4444
OOCD_BOARD ?= target/stm32f1x.cfg
4545
OPENCM3_TARGET = "stm32/f1"
4646
endif
47+
ifeq ($(ARCH),STM32L1)
48+
LIBNAME = opencm3_stm32l1
49+
DEFS += -DSTM32L1
50+
FP_FLAGS ?= -msoft-float
51+
ARCH_FLAGS = -mthumb -mcpu=cortex-m3 $(FP_FLAGS) -mfix-cortex-m3-ldrd
52+
OOCD_BOARD ?= target/stm32l1.cfg
53+
OPENCM3_TARGET = "stm32/l1"
54+
endif
4755

4856
LIBNAME ?= opencm3_stm32f0
4957
DEFS ?= -DSTM32F0

src/stm32l1/backup.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2016, Devan Lai
3+
* 2020, Karl Palsson, ported to L1
4+
*
5+
* Permission to use, copy, modify, and/or distribute this software
6+
* for any purpose with or without fee is hereby granted, provided
7+
* that the above copyright notice and this permission notice
8+
* appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11+
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12+
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13+
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
14+
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16+
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18+
*/
19+
20+
#include <libopencm3/stm32/rcc.h>
21+
#include <libopencm3/stm32/rtc.h>
22+
#include <libopencm3/stm32/pwr.h>
23+
24+
#include "backup.h"
25+
26+
void backup_write(enum BackupRegister reg, uint32_t value)
27+
{
28+
rcc_periph_clock_enable(RCC_PWR);
29+
pwr_disable_backup_domain_write_protect();
30+
RTC_BKPXR(reg) = value;
31+
pwr_enable_backup_domain_write_protect();
32+
}
33+
34+
uint32_t backup_read(enum BackupRegister reg)
35+
{
36+
return RTC_BKPXR(reg);
37+
}

src/stm32l1/backup.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2016, Devan Lai
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software
5+
* for any purpose with or without fee is hereby granted, provided
6+
* that the above copyright notice and this permission notice
7+
* appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10+
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
* WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12+
* AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13+
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15+
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#ifndef BACKUP_H_INCLUDED
20+
#define BACKUP_H_INCLUDED
21+
22+
enum BackupRegister {
23+
BKP0 = 0,
24+
BKP1,
25+
BKP2,
26+
BKP3,
27+
BKP4,
28+
};
29+
30+
extern void backup_write(enum BackupRegister reg, uint32_t value);
31+
extern uint32_t backup_read(enum BackupRegister reg);
32+
33+
#endif

src/stm32l1/generic/config.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* 2020 - Karl Palsson <karlp@tweak.net.au>
3+
* Considered to be released into the public domain, or where not available
4+
* under your choice of the following spdx identifiers:
5+
* MIT, ISC, Apache-2.0, BSD-1-Clause, BSD-2-Clause, BSD-3-Clause,
6+
* CC-BY-4.0, GPL-2.0-or-later, LGPL-2.0-or-later
7+
* Pick whatever makes your integration life easier
8+
*
9+
* defauly config.h settings
10+
*/
11+
12+
#pragma once
13+
14+
#define APP_BASE_ADDRESS (0x08000000 + BOOTLOADER_OFFSET)
15+
#define FLASH_PAGE_SIZE 128
16+
#define DFU_UPLOAD_AVAILABLE 1
17+
#define DFU_DOWNLOAD_AVAILABLE 1
18+
#define TARGET_DFU_WTRANSFERSIZE 128
19+
20+
#define HAVE_LED 0
21+
#define HAVE_BUTTON 0
22+
#define HAVE_USB_PULLUP_CONTROL 0

src/stm32l1/stm32l1-base.ld

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* This file is part of the libopencm3 project.
3+
*
4+
* Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
5+
*
6+
* This library is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
/* Generic linker script for STM32 targets using libopencm3. */
21+
22+
/* Memory regions must be defined in the ld script which includes this one. */
23+
24+
/* Enforce emmition of the vector table. */
25+
EXTERN (vector_table)
26+
27+
/* Define the entry point of the output file. */
28+
ENTRY(reset_handler)
29+
30+
/* Define sections. */
31+
SECTIONS
32+
{
33+
.vectors : {
34+
*(.vectors) /* Vector table */
35+
} >vectors
36+
37+
.text : {
38+
*(.text*) /* Program code */
39+
. = ALIGN(4);
40+
*(.rodata*) /* Read-only data */
41+
. = ALIGN(4);
42+
} >rom
43+
44+
/* C++ Static constructors/destructors, also used for __attribute__
45+
* ((constructor)) and the likes */
46+
.preinit_array : {
47+
. = ALIGN(4);
48+
__preinit_array_start = .;
49+
KEEP (*(.preinit_array))
50+
__preinit_array_end = .;
51+
} >rom
52+
.init_array : {
53+
. = ALIGN(4);
54+
__init_array_start = .;
55+
KEEP (*(SORT(.init_array.*)))
56+
KEEP (*(.init_array))
57+
__init_array_end = .;
58+
} >rom
59+
.fini_array : {
60+
. = ALIGN(4);
61+
__fini_array_start = .;
62+
KEEP (*(.fini_array))
63+
KEEP (*(SORT(.fini_array.*)))
64+
__fini_array_end = .;
65+
} >rom
66+
67+
/*
68+
* Another section used by C++ stuff, appears when using newlib with
69+
* 64bit (long long) printf support
70+
*/
71+
.ARM.extab : {
72+
*(.ARM.extab*)
73+
} >rom
74+
.ARM.exidx : {
75+
__exidx_start = .;
76+
*(.ARM.exidx*)
77+
__exidx_end = .;
78+
} >rom
79+
80+
. = ALIGN(4);
81+
_etext = .;
82+
83+
.data : {
84+
_data = .;
85+
*(.data*) /* Read-write initialized data */
86+
. = ALIGN(4);
87+
_edata = .;
88+
} >ram AT >rom
89+
_data_loadaddr = LOADADDR(.data);
90+
91+
.bss : {
92+
*(.bss*) /* Read-write zero initialized data */
93+
*(COMMON)
94+
. = ALIGN(4);
95+
_ebss = .;
96+
} >ram
97+
98+
/*
99+
* The .eh_frame section appears to be used for C++ exception handling.
100+
* You may need to fix this if you're using C++.
101+
*/
102+
/DISCARD/ : { *(.eh_frame) }
103+
104+
. = ALIGN(4);
105+
end = .;
106+
}
107+
108+
PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram));
109+

src/stm32l1/stm32l1-standard.ld

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* 2020 - Karl Palsson <karlp@tweak.net.au>
3+
* Considered to be released into the public domain, or where not available
4+
* under your choice of the following spdx identifiers:
5+
* MIT, ISC, Apache-2.0, BSD-1-Clause, BSD-2-Clause, BSD-3-Clause,
6+
* CC-BY-4.0, GPL-2.0-or-later, LGPL-2.0-or-later
7+
* Pick whatever makes your integration life easier
8+
*
9+
* Linker script for STM32L1 parts. Bootloader only for 8k, and all parts
10+
* have at least 10k RAM, (-A parts have 32K RAM, but 10 is enough)
11+
*/
12+
13+
/* Define memory regions. */
14+
MEMORY
15+
{
16+
vectors (rx) : ORIGIN = 0x08000000, LENGTH = 0x150
17+
rom (rx) : ORIGIN = 0x08000150, LENGTH = 0x1EB0
18+
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 10K
19+
}
20+
21+
/* Include the common ld script. */
22+
INCLUDE stm32l1/stm32l1-base.ld

0 commit comments

Comments
 (0)