Skip to content

Commit d084093

Browse files
committed
target: Add Koshin board support
1 parent 2fe6322 commit d084093

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

src/stm32f103/koshin/config.h

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2023, Xiaoyu Hong
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 CONFIG_H_INCLUDED
20+
#define CONFIG_H_INCLUDED
21+
22+
#ifndef APP_BASE_ADDRESS
23+
#define APP_BASE_ADDRESS (0x08000000 + BOOTLOADER_OFFSET)
24+
#endif
25+
#ifndef FLASH_SIZE_OVERRIDE
26+
#define FLASH_SIZE_OVERRIDE 0x20000
27+
#endif
28+
#ifndef FLASH_PAGE_SIZE
29+
#define FLASH_PAGE_SIZE 1024
30+
#endif
31+
#ifndef DFU_UPLOAD_AVAILABLE
32+
#define DFU_UPLOAD_AVAILABLE 1
33+
#endif
34+
#ifndef DFU_DOWNLOAD_AVAILABLE
35+
#define DFU_DOWNLOAD_AVAILABLE 1
36+
#endif
37+
38+
#ifndef HAVE_LED
39+
#define HAVE_LED 1
40+
#endif
41+
#ifndef LED_ACTIVE_HIGH
42+
#define LED_ACTIVE_HIGH 1
43+
#endif
44+
#ifndef LED_OPEN_DRAIN
45+
#define LED_OPEN_DRAIN 0
46+
#endif
47+
#ifndef LED_GPIO_PORT
48+
#define LED_GPIO_PORT GPIOB
49+
#endif
50+
#ifndef LED_GPIO_PIN
51+
#define LED_GPIO_PIN GPIO5
52+
#endif
53+
54+
#ifndef HAVE_BUTTON
55+
#define HAVE_BUTTON 1
56+
#endif
57+
#ifndef BUTTON_ACTIVE_HIGH
58+
#define BUTTON_ACTIVE_HIGH 1
59+
#endif
60+
#ifndef BUTTON_GPIO_PORT
61+
#define BUTTON_GPIO_PORT GPIOB
62+
#endif
63+
#ifndef BUTTON_GPIO_PIN
64+
#define BUTTON_GPIO_PIN GPIO2
65+
#endif
66+
67+
#ifndef BUTTON_USES_PULL
68+
#define BUTTON_USES_PULL 0
69+
#endif
70+
71+
#ifndef BUTTON_SAMPLE_DELAY_CYCLES
72+
#define BUTTON_SAMPLE_DELAY_CYCLES 1440000
73+
#endif
74+
75+
#ifndef HAVE_USB_PULLUP_CONTROL
76+
#define HAVE_USB_PULLUP_CONTROL 1
77+
#endif
78+
#ifndef USB_PULLUP_GPIO_PORT
79+
#define USB_PULLUP_GPIO_PORT GPIOA
80+
#endif
81+
#ifndef USB_PULLUP_GPIO_PIN
82+
#define USB_PULLUP_GPIO_PIN GPIO15
83+
#endif
84+
#ifndef USB_PULLUP_ACTIVE_HIGH
85+
#define USB_PULLUP_ACTIVE_HIGH 1
86+
#endif
87+
#ifndef USB_PULLUP_OPEN_DRAIN
88+
#define USB_PULLUP_OPEN_DRAIN 0
89+
#endif
90+
91+
#ifndef USES_GPIOA
92+
#define USES_GPIOA 1
93+
#endif
94+
95+
#ifndef USES_GPIOB
96+
#define USES_GPIOB 1
97+
#endif
98+
99+
#ifndef USES_GPIOC
100+
#define USES_GPIOC 1
101+
#endif
102+
103+
#ifndef USES_HSE_12M
104+
#define USES_HSE_12M 1
105+
#endif
106+
107+
#endif

src/stm32f103/target_stm32f103.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ void target_clock_setup(void) {
6969
The clock tolerance doesn't meet the official USB spec, but
7070
it's better than nothing. */
7171
rcc_clock_setup_in_hsi_out_48mhz();
72+
#else
73+
#ifdef USES_HSE_12M
74+
rcc_clock_setup_in_hse_12mhz_out_72mhz();
7275
#else
7376
/* Set system clock to 72 MHz from an external crystal */
7477
rcc_clock_setup_in_hse_8mhz_out_72mhz();
7578
#endif
79+
#endif
7680
}
7781

7882
void target_gpio_setup(void) {
@@ -98,13 +102,20 @@ void target_gpio_setup(void) {
98102
}
99103
#endif
100104

105+
#if (HAVE_USB_PULLUP_CONTROL && USB_PULLUP_GPIO_PORT == GPIOA && \
106+
(USB_PULLUP_GPIO_PIN == GPIO15))
107+
{
108+
rcc_periph_clock_enable(RCC_AFIO);
109+
AFIO_MAPR |= AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON;
110+
}
111+
#endif
101112
/* Setup LEDs */
102113
#if HAVE_LED
103114
{
104115
const uint8_t mode = GPIO_MODE_OUTPUT_10_MHZ;
105116
const uint8_t conf = (LED_OPEN_DRAIN ? GPIO_CNF_OUTPUT_OPENDRAIN
106117
: GPIO_CNF_OUTPUT_PUSHPULL);
107-
if (LED_OPEN_DRAIN) {
118+
if (LED_OPEN_DRAIN || LED_ACTIVE_HIGH) {
108119
gpio_set(LED_GPIO_PORT, LED_GPIO_PIN);
109120
} else {
110121
gpio_clear(LED_GPIO_PORT, LED_GPIO_PIN);

src/targets.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ ifeq ($(TARGET),STM32F103)
2020
LDSCRIPT := ./stm32f103/stm32f103x8.ld
2121
ARCH = STM32F1
2222
endif
23+
ifeq ($(TARGET),KOSHIN)
24+
TARGET_COMMON_DIR := ./stm32f103
25+
TARGET_SPEC_DIR := ./stm32f103/koshin
26+
LDSCRIPT := ./stm32f103/stm32f103x8.ld
27+
ARCH = STM32F1
28+
endif
2329
ifeq ($(TARGET),BLUEPILL)
2430
TARGET_COMMON_DIR := ./stm32f103
2531
TARGET_SPEC_DIR := ./stm32f103/bluepill

0 commit comments

Comments
 (0)