Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions bsp/stm32/stm32f103-blue-pill/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ BSP_DIR := .
RTT_DIR := ../../..

PKGS_DIR := packages
choice
prompt "Select SOC"
default SOC_STM32F103C8
config SOC_STM32F103C8
bool "STM32F103C8"
select SOC_SERIES_STM32F1
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN

config SOC_STM32F103C8
bool
select SOC_SERIES_STM32F1
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
default y

config SOC_STM32F103C6
bool "STM32F103C6"
select SOC_SERIES_STM32F1
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select RT_USING_SMALL_MEM
select RT_USING_SMALL_MEM_AS_HEAP
select RT_KLIBC_USING_LIBC_VSSCANF
endchoice

source "$(RTT_DIR)/Kconfig"
osource "$PKGS_DIR/Kconfig"
Expand Down
31 changes: 30 additions & 1 deletion bsp/stm32/stm32f103-blue-pill/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ KEY FEATURES

## 2 Onboard Resources

- MCU:STM32F103C8T6 @72MHz, 64KB FLASH (can be extended to 128KB) , 20KB RAM
- MCU:STM32F103C8T6 @72MHz, 64KB FLASH (can be extended to 128KB) , 20KB RAM (STM32F103C6T6 with 32KB FLASH, 10KB RAM is also supported)

- Peripherals

Expand Down Expand Up @@ -308,6 +308,35 @@ According to ST official datasheet, STM32F103C8 has 64KB of Flash. However, STM3



### 4.3 How to use STM32F103C6 variant

This BSP also supports Blue Pill boards equipped with the **STM32F103C6** (32KB Flash, 10KB RAM).

To configure for STM32F103C6:
1. Run `scons --menuconfig`
2. Under **Select SOC**, select `STM32F103C6` (this automatically selects the Small Memory Algorithm heap and lightweight libc vsscanf).
3. Due to the 32KB Flash and 10KB RAM limits, optimize the following in `menuconfig`:
- **RT-Thread Kernel → Memory Management**:
- Set **System Heap Memory Management** to `Small Memory Algorithm` (`RT_USING_SMALL_MEM_AS_HEAP`)
- Uncheck `Using memheap Memory Algorithm` (`RT_USING_MEMHEAP`)
- **RT-Thread Kernel**:
- Uncheck `Enable debugging features` (`RT_USING_DEBUG`)
- **RT-Thread Kernel → Inter-Thread communication**:
- Uncheck `Enable event flag` (`RT_USING_EVENT`)
- Uncheck `Enable mailbox` (`RT_USING_MAILBOX`)
- Uncheck `Enable message queue` (`RT_USING_MESSAGEQUEUE`)
- **RT-Thread Components → Device Drivers**:
- Uncheck `Enable serial DMA mode` (`RT_SERIAL_USING_DMA`)
- **RT-Thread Components → MSH: command shell**:
- Uncheck `Keeping description in symbol table` (`FINSH_USING_DESCRIPTION`)
- Uncheck `command option completion enable` (`FINSH_USING_OPTION_COMPLETION`)
- Set `The shell thread stack size` to `2048` (`FINSH_THREAD_STACK_SIZE`)
4. Save and exit menuconfig.
5. Clean and build the firmware:
```bash
scons -c && scons
```

## 5 Read more

- [[STM32 Blue Pill Board Schematic]](https://stm32duinoforum.com/forum/images/c/c1/wiki_subdomain/Vcc-gnd.com-STM32F103C8-schematic.pdf)
Expand Down
31 changes: 30 additions & 1 deletion bsp/stm32/stm32f103-blue-pill/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ STM32F103C8T6最小系统,采用SWD调试接口,可以用3个接口就能完

该开发板常用 **板载资源** 如下:

- MCU:STM32F103C8T6,主频 72MHz,64KB FLASH(实际可烧录128KB) ,20KB RAM
- MCU:STM32F103C8T6,主频 72MHz,64KB FLASH(实际可烧录128KB) ,20KB RAM(同时支持 STM32F103C6T6,32KB FLASH,10KB RAM)
- 外部 RAM:无
- 外部 FLASH:无
- 常用外设
Expand Down Expand Up @@ -113,6 +113,35 @@ msh >



#### 使用 STM32F103C6 芯片变体

本 BSP 同时支持搭载 **STM32F103C6**(32KB Flash,10KB RAM)的开发板。

配置 STM32F103C6 步骤:
1. 打开终端,执行 `scons --menuconfig`;
2. 在 **Select SOC** 中选择 `STM32F103C6`(会自动配置小内存算法堆及轻量化 libc vsscanf);
3. 受限于 32KB Flash 和 10KB RAM,需做如下裁剪优化配置:
- **RT-Thread Kernel → Memory Management**:
- 将 **System Heap Memory Management** 设置为 `Small Memory Algorithm` (`RT_USING_SMALL_MEM_AS_HEAP`)
- 取消勾选 `Using memheap Memory Algorithm` (`RT_USING_MEMHEAP`)
- **RT-Thread Kernel**:
- 取消勾选 `Enable debugging features` (`RT_USING_DEBUG`)
- **RT-Thread Kernel → Inter-Thread communication**:
- 取消勾选 `Enable event flag` (`RT_USING_EVENT`)
- 取消勾选 `Enable mailbox` (`RT_USING_MAILBOX`)
- 取消勾选 `Enable message queue` (`RT_USING_MESSAGEQUEUE`)
- **RT-Thread Components → Device Drivers**:
- 取消勾选 `Enable serial DMA mode` (`RT_SERIAL_USING_DMA`)
- **RT-Thread Components → MSH: command shell**:
- 取消勾选 `Keeping description in symbol table` (`FINSH_USING_DESCRIPTION`)
- 取消勾选 `command option completion enable` (`FINSH_USING_OPTION_COMPLETION`)
- 将 `The shell thread stack size` 修改为 `2048` (`FINSH_THREAD_STACK_SIZE`)
4. 保存并退出 menuconfig;
5. 执行编译:
```bash
scons -c && scons
```

## 注意事项

- 只能用USB转TTL连接PC机 ;
Expand Down
18 changes: 18 additions & 0 deletions bsp/stm32/stm32f103-blue-pill/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ menu "Onboard Peripheral Drivers"

config BSP_USING_ARDUINO
bool "Compatible with Arduino Ecosystem (RTduino)"
depends on !SOC_STM32F103C6
select PKG_USING_RTDUINO
select BSP_USING_STLINK_TO_USART
select BSP_USING_UART2
Expand Down Expand Up @@ -138,6 +139,7 @@ menu "On-chip Peripheral Drivers"

menuconfig BSP_USING_UART3
bool "Enable UART3"
depends on !SOC_STM32F103C6
default n
if BSP_USING_UART3
config BSP_UART3_RX_USING_DMA
Expand Down Expand Up @@ -251,8 +253,24 @@ menu "On-chip Peripheral Drivers"
default n
select RT_USING_SPI
if BSP_USING_SPI
config BSP_USING_SPI1
bool "Enable SPI1 BUS"
default n

config BSP_SPI1_TX_USING_DMA
bool "Enable SPI1 TX DMA"
depends on BSP_USING_SPI1
default n

config BSP_SPI1_RX_USING_DMA
bool "Enable SPI1 RX DMA"
depends on BSP_USING_SPI1
select BSP_SPI1_TX_USING_DMA
default n

config BSP_USING_SPI2
bool "Enable SPI2 BUS"
depends on !SOC_STM32F103C6
default n

config BSP_SPI2_TX_USING_DMA
Expand Down
10 changes: 10 additions & 0 deletions bsp/stm32/stm32f103-blue-pill/board/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@
extern "C" {
#endif

#if defined(SOC_STM32F103C8)
#define STM32_FLASH_START_ADRESS ((uint32_t)0x08000000)
#define STM32_FLASH_SIZE (128 * 1024)
#define STM32_FLASH_END_ADDRESS ((uint32_t)(STM32_FLASH_START_ADRESS + STM32_FLASH_SIZE))

/* Internal SRAM memory size[Kbytes] <8-64>, Default: 64*/
#define STM32_SRAM_SIZE 20
#define STM32_SRAM_END (0x20000000 + STM32_SRAM_SIZE * 1024)
#else
#define STM32_FLASH_START_ADRESS ((uint32_t)0x08000000)
#define STM32_FLASH_SIZE (32 * 1024)
#define STM32_FLASH_END_ADDRESS ((uint32_t)(STM32_FLASH_START_ADRESS + STM32_FLASH_SIZE))

/* Internal SRAM memory size[Kbytes] <8-64>, Default: 64*/
#define STM32_SRAM_SIZE 10
#define STM32_SRAM_END (0x20000000 + STM32_SRAM_SIZE * 1024)
#endif

#if defined(__ARMCC_VERSION)
extern int Image$$RW_IRAM1$$ZI$$Limit;
Expand Down
7 changes: 5 additions & 2 deletions bsp/stm32/stm32f103-blue-pill/board/linker_scripts/link.lds
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
*/

/* Program Entry, set to mark it as "used" and avoid gc */
_ROM_SIZE = DEFINED(_ROM_SIZE) ? _ROM_SIZE : 128k;
_RAM_SIZE = DEFINED(_RAM_SIZE) ? _RAM_SIZE : 20k;

MEMORY
{
ROM (rx) : ORIGIN = 0x08000000, LENGTH = 128k /* 128KB flash */
RAM (rw) : ORIGIN = 0x20000000, LENGTH = 20k /* 20K sram */
ROM (rx) : ORIGIN = 0x08000000, LENGTH = _ROM_SIZE
RAM (rw) : ORIGIN = 0x20000000, LENGTH = _RAM_SIZE
}
ENTRY(Reset_Handler)
_system_stack_size = 0x400;
Expand Down
14 changes: 11 additions & 3 deletions bsp/stm32/stm32f103-blue-pill/rtconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@
DEVICE = ' -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections'
CFLAGS = DEVICE + ' -Dgcc'
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -Wa,-mimplicit-it=thumb '
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rt-thread.map,-cref,-u,Reset_Handler -T board/linker_scripts/link.lds'
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rt-thread.map,-cref,-u,Reset_Handler -T board/linker_scripts/link.lds '

CPATH = ''
LPATH = ''

opt_level = ' -O2'
if os.path.exists('rtconfig.h'):
with open('rtconfig.h', 'r') as f:
content = f.read()
if 'SOC_STM32F103C6' in content:
opt_level = ' -Os'
LFLAGS += ' -Wl,--defsym=_ROM_SIZE=32k,--defsym=_RAM_SIZE=10k --specs=nano.specs'

if BUILD == 'debug':
CFLAGS += ' -O2 -gdwarf-2 -g'
CFLAGS += opt_level + ' -gdwarf-2 -g'
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2'
CFLAGS += opt_level

CXXFLAGS = CFLAGS

Expand Down
Loading