Skip to content

Commit

Permalink
* Cleanup ld script generation
Browse files Browse the repository at this point in the history
* Add mco example
  • Loading branch information
cnlohr committed Feb 12, 2024
1 parent bddf3b9 commit ccba923
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
11 changes: 6 additions & 5 deletions ch32v003fun/ch32v003fun.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ LDFLAGS+=-T $(LINKER_SCRIPT) -Wl,--gc-sections -L$(CH32V003FUN)/../misc -lgcc

ifeq ($(TARGET_MCU), CH32V003)

COMPILED_FILES:=$(SYSTEM_C) $(TARGET).$(TARGET_EXT) $(ADDITIONAL_C_FILES)

$(TARGET).elf : $(COMPILED_FILES) $(LINKER_SCRIPT)
$(PREFIX)-gcc -o $@ $(COMPILED_FILES) $(CFLAGS) $(LDFLAGS)
FILES_TO_COMPILE:=$(SYSTEM_C) $(TARGET).$(TARGET_EXT) $(ADDITIONAL_C_FILES)

endif

Expand Down Expand Up @@ -102,7 +99,11 @@ 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)
$(PREFIX)-gcc -E -P -x c -DTARGET_MCU=$(TARGET_MCU) $(CH32V003FUN)/ch32v003fun.ld > $(GENERATED_LD_FILE)


$(TARGET).elf : $(FILES_TO_COMPILE) $(LINKER_SCRIPT)
$(PREFIX)-gcc -o $@ $(FILES_TO_COMPILE) $(CFLAGS) $(LDFLAGS)

cv_flash : $(TARGET).bin
make -C $(MINICHLINK) all
Expand Down
6 changes: 0 additions & 6 deletions ch32v003fun/ch32v10xfun.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,3 @@ GENERATED_LD_FILE:=$(CH32V003FUN)/generated_$(TARGET_MCU_PACKAGE).ld
LINKER_SCRIPT:=$(GENERATED_LD_FILE)
FILES_TO_COMPILE:=$(SYSTEM_C) $(TARGET).$(TARGET_EXT) $(ADDITIONAL_C_FILES)

$(GENERATED_LD_FILE) :
$(PREFIX)-gcc -E -P -x c -DMCU_PACKAGE=$(MCU_PACKAGE) -DMCU_TYPE=CH32V10x $(CH32V003FUN)/ch32v003fun.ld > $(GENERATED_LD_FILE)

$(TARGET).elf : $(GENERATED_LD_FILE) $(FILES_TO_COMPILE)
echo $(FILES_TO_COMPILE)
$(PREFIX)-gcc -o $@ $(FILES_TO_COMPILE) $(CFLAGS) $(LDFLAGS)
5 changes: 0 additions & 5 deletions ch32v003fun/ch32v20xfun.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,4 @@ GENERATED_LD_FILE:=$(CH32V003FUN)/generated_$(TARGET_MCU_PACKAGE).ld
LINKER_SCRIPT:=$(GENERATED_LD_FILE)
FILES_TO_COMPILE:=$(SYSTEM_C) $(TARGET).$(TARGET_EXT) $(ADDITIONAL_C_FILES)

$(GENERATED_LD_FILE) :
$(PREFIX)-gcc -E -P -x c -DMCU_PACKAGE=$(MCU_PACKAGE) -DMCU_TYPE=CH32V20x $(CH32V003FUN)/ch32v003fun.ld > $(GENERATED_LD_FILE)

$(TARGET).elf : $(GENERATED_LD_FILE) $(FILES_TO_COMPILE)
echo $(FILES_TO_COMPILE)
$(PREFIX)-gcc -o $@ $(FILES_TO_COMPILE) $(CFLAGS) $(LDFLAGS)
6 changes: 0 additions & 6 deletions ch32v003fun/ch32v30xfun.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,3 @@ GENERATED_LD_FILE:=$(CH32V003FUN)/generated_$(TARGET_MCU_PACKAGE).ld
LINKER_SCRIPT:=$(GENERATED_LD_FILE)
FILES_TO_COMPILE:=$(SYSTEM_C) $(TARGET).$(TARGET_EXT) $(ADDITIONAL_C_FILES)

$(GENERATED_LD_FILE) :
$(PREFIX)-gcc -E -P -x c -DMCU_PACKAGE=$(MCU_PACKAGE) -DMCU_TYPE=CH32V20x $(CH32V003FUN)/ch32v003fun.ld > $(GENERATED_LD_FILE)


$(TARGET).elf : $(GENERATED_LD_FILE) $(FILES_TO_COMPILE)
$(PREFIX)-gcc -o $@ $(FILES_TO_COMPILE) $(CFLAGS) $(LDFLAGS)
11 changes: 11 additions & 0 deletions examples_v20x/mcotest/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
all : flash

TARGET:=mcotest
TARGET_MCU:=CH32V203

include ../../ch32v003fun/ch32v003fun.mk

flash : cv_flash
clean : cv_clean


7 changes: 7 additions & 0 deletions examples_v20x/mcotest/funconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _FUNCONFIG_H
#define _FUNCONFIG_H

// #define CH32V20x 1

#endif

18 changes: 18 additions & 0 deletions examples_v20x/mcotest/mcotest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "ch32v003fun.h"
#include <stdio.h>

int main()
{
SystemInit();

funGpioInitAll();

funPinMode( PA8, GPIO_CFGLR_OUT_50Mhz_AF_PP );

RCC->CFGR0 = RCC_CFGR0_MCO_PLL;

while(1)
{
}
}

0 comments on commit ccba923

Please sign in to comment.