Skip to content

Commit

Permalink
Fixup ld files for 003
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Feb 12, 2024
1 parent dceb8e1 commit fca0738
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ch32v003fun/ch32v003fun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ void SystemInit()
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
#endif
#if defined(FUNCONF_USE_PLL) && FUNCONF_USE_PLL
RCC->CFGR0 = RCC_HPRE_DIV1 | PLL_MULTIPLICATION;
RCC->CFGR0 = BASE_CFGR0;
RCC->CTLR = BASE_CTLR | RCC_HSION | RCC_PLLON; // Use HSI, enable PLL.
#else
RCC->CFGR0 = RCC_HPRE_DIV1; // PLLCLK = HCLK = SYSCLK = APB1
Expand Down
29 changes: 29 additions & 0 deletions ch32v003fun/ch32v003fun.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@

#include "funconfig.h"

/*****************************************************************************
CH32V003 BASICS

1. Be sure to see configuration section below!

2. Backend Initialization
SystemInit();

3. Arduino-like I/O
funGpioInitAll();
funPinMode( PA2, GPIO_CFGLR_OUT_10Mhz_PP );
funDigitalWrite( PA2, FUN_HIGH );
funDigitalWrite( PA2, FUN_HIGH );

4. Delays
Delay_Us(n)
Delay_Ms(n)
DelaySysTick( uint32_t n );

5. printf
printf, _write may be semihosted, or printed to UART.

poll_input, handle_debug_input may be used with semihsoting.

Note: Semihosting appears to currently only work on the CH32V003 (may be improved in future)
*/



/*****************************************************************************
CH32V003 Fun Configs:

Expand Down
10 changes: 5 additions & 5 deletions ch32v003fun/ch32v003fun.ld
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ ENTRY( InterruptVector )

MEMORY
{
#if TARGET_MCU == CH32V10x
#if TARGET_MCU == CH32V003
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 2K
#elif TARGET_MCU == CH32V10x
#if MCU_PACKAGE == 1
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
Expand All @@ -13,7 +16,6 @@ MEMORY
#error "Unknown MCU package"
#endif
#elif TARGET_MCU == CH32V20x

#if MCU_PACKAGE == 1
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
Expand All @@ -37,9 +39,7 @@ MEMORY
#error "Unknown MCU package"
#endif
#else
// CH32V003
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 16K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 2K
#error "Unknown MCU target"
#endif
}

Expand Down
7 changes: 6 additions & 1 deletion ch32v003fun/ch32v003fun.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ ifeq ($(TARGET_MCU),CH32V003)
-DCH32V003=1 \
-I. -Wall $(EXTRA_CFLAGS)

LINKER_SCRIPT?=$(CH32V003FUN)/ch32v003fun.ld
GENERATED_LD_FILE?=$(CH32V003FUN)/generated_ch32v003.ld
LINKER_SCRIPT?=$(GENERATED_LD_FILE)
else
ifeq ($(findstring CH32V10,$(TARGET_MCU)),CH32V10)
include $(CH32V003FUN)/ch32v10xfun.mk
Expand Down Expand Up @@ -98,6 +99,10 @@ clangd_clean :

FLASH_COMMAND?=$(MINICHLINK)/minichlink -w $< $(WRITE_SECTION) -b

$(GENERATED_LD_FILE) :
$(PREFIX)-gcc -E -P -x c -DTARGET_MCU=CH32V003 $(CH32V003FUN)/ch32v003fun.ld > $(GENERATED_LD_FILE)


cv_flash : $(TARGET).bin
make -C $(MINICHLINK) all
$(FLASH_COMMAND)
Expand Down
Binary file modified examples/blink/blink.bin
Binary file not shown.

0 comments on commit fca0738

Please sign in to comment.