first commit
This commit is contained in:
		
						commit
						fba966056a
					
				
					 11 changed files with 1045 additions and 0 deletions
				
			
		
							
								
								
									
										144
									
								
								myapps/first/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								myapps/first/Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,144 @@ | |||
| ######################################
 | ||||
| # target
 | ||||
| ######################################
 | ||||
| TARGET = stm32g0_blinky | ||||
| PART = STM32G030xx	# check for pyocd | ||||
| 
 | ||||
| 
 | ||||
| ######################################
 | ||||
| # building variables
 | ||||
| ######################################
 | ||||
| # debug build?
 | ||||
| DEBUG = 1 | ||||
| # optimization for size
 | ||||
| OPT = -Os | ||||
| 
 | ||||
| 
 | ||||
| #######################################
 | ||||
| # paths
 | ||||
| #######################################
 | ||||
| # Build path
 | ||||
| BUILD_DIR = build | ||||
| VND_DIR = ../../vendor | ||||
| 
 | ||||
| ######################################
 | ||||
| # source
 | ||||
| ######################################
 | ||||
| # C sources
 | ||||
| include hal.mk | ||||
| C_SOURCES += \
 | ||||
| $(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Source/Templates/system_stm32g0xx.c \ | ||||
| src/main.c | ||||
| 
 | ||||
| 
 | ||||
| # ASM sources
 | ||||
| ASM_SOURCES =  \
 | ||||
| $(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Source/Templates/gcc/startup_stm32g030xx.s | ||||
| 
 | ||||
| #######################################
 | ||||
| # binaries
 | ||||
| #######################################
 | ||||
| PREFIX = arm-none-eabi- | ||||
| 
 | ||||
| CC = $(PREFIX)gcc | ||||
| CP = $(PREFIX)objcopy | ||||
| #SZ = $(PREFIX)size
 | ||||
| 
 | ||||
| BIN = $(CP) -O binary -S | ||||
| 
 | ||||
| #######################################
 | ||||
| # CFLAGS
 | ||||
| #######################################
 | ||||
| # cpu
 | ||||
| CPU = \
 | ||||
|  -mcpu=cortex-m0plus \
 | ||||
|  -mthumb | ||||
| 
 | ||||
| DEFINES = -D$(PART) | ||||
| 
 | ||||
| # fpu
 | ||||
| FPU =  | ||||
| 
 | ||||
| # float-abi
 | ||||
| FLOAT-ABI = | ||||
| 
 | ||||
| # mcu
 | ||||
| MCU = $(CPU) $(FPU) $(FLOAT-ABI) | ||||
| 
 | ||||
| # C includes
 | ||||
| C_INCLUDES +=  \
 | ||||
|  -Iinc \
 | ||||
|  -I$(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Core/Include \
 | ||||
|  -I$(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Include | ||||
| 
 | ||||
| # compile gcc flags
 | ||||
| ADDN_CFLAGS = \
 | ||||
|  -Wall \
 | ||||
|  -fno-common \
 | ||||
|  -fdata-sections \
 | ||||
|  -ffunction-sections | ||||
| 
 | ||||
| CFLAGS = $(MCU) $(ADDN_CFLAGS) $(C_INCLUDES) $(OPT) $(DEFINES) | ||||
| 
 | ||||
| ifeq ($(DEBUG), 1) | ||||
| CFLAGS += -ggdb3 | ||||
| endif | ||||
| 
 | ||||
| 
 | ||||
| # Generate dependency information
 | ||||
| #CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
 | ||||
| 
 | ||||
| 
 | ||||
| #######################################
 | ||||
| # LDFLAGS
 | ||||
| #######################################
 | ||||
| # link script
 | ||||
| LDSCRIPT = $(VND_DIR)/Ld/STM32G030F6MX_FLASH.ld | ||||
| 
 | ||||
| LIBDIR =  | ||||
| LDFLAGS =  \
 | ||||
|  $(MCU)  \
 | ||||
|  -T $(LDSCRIPT) \
 | ||||
|  --specs=nano.specs \
 | ||||
|  -Wl,--gc-sections \
 | ||||
|  -Wl,--print-memory-usage \
 | ||||
|  -Wl,--no-warn-rwx-segments | ||||
| 
 | ||||
| # default action: build all
 | ||||
| all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).bin | ||||
| 
 | ||||
| 
 | ||||
| #######################################
 | ||||
| # build the application
 | ||||
| #######################################
 | ||||
| # list of objects
 | ||||
| OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) | ||||
| vpath %.c $(sort $(dir $(C_SOURCES))) | ||||
| 
 | ||||
| $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) | ||||
| 	$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ | ||||
| 
 | ||||
| #$(LUAOBJECTS) $(OBJECTS)
 | ||||
| $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile | ||||
| 	$(CC) $(OBJECTS) $(LDFLAGS) $(ASM_SOURCES) -o $@ | ||||
| 
 | ||||
| $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) | ||||
| 	$(BIN) $< $@	 | ||||
| 	 | ||||
| $(BUILD_DIR): | ||||
| 	mkdir $@		 | ||||
| 
 | ||||
| #######################################
 | ||||
| # Program
 | ||||
| #######################################
 | ||||
| 
 | ||||
| flash: $(BUILD_DIR)/$(TARGET).bin | ||||
| 	pyocd load --target $(PART) $(BUILD_DIR)/$(TARGET).bin | ||||
| 
 | ||||
| #######################################
 | ||||
| # clean up
 | ||||
| #######################################
 | ||||
| clean: | ||||
| 	-rm -fR $(BUILD_DIR) | ||||
|    | ||||
| # *** EOF ***
 | ||||
							
								
								
									
										159
									
								
								myapps/first/Makefile.bkp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										159
									
								
								myapps/first/Makefile.bkp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,159 @@ | |||
| ###################################### | ||||
| # target | ||||
| ###################################### | ||||
| TARGET = stm32g0_blinky | ||||
| PART = STM32G030xx	# check for pyocd | ||||
| 
 | ||||
| 
 | ||||
| ###################################### | ||||
| # building variables | ||||
| ###################################### | ||||
| # debug build? | ||||
| DEBUG = 1 | ||||
| # optimization for size | ||||
| OPT = -Os | ||||
| 
 | ||||
| 
 | ||||
| ####################################### | ||||
| # paths | ||||
| ####################################### | ||||
| # Build path | ||||
| BUILD_DIR = build | ||||
| VND_DIR = ../../vendor | ||||
| 
 | ||||
| ###################################### | ||||
| # source | ||||
| ###################################### | ||||
| # C sources | ||||
| include hal.mk | ||||
| C_SOURCES += \ | ||||
| $(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Source/Templates/system_stm32g0xx.c \ | ||||
| src/main.c | ||||
| 
 | ||||
| 
 | ||||
| # ASM sources | ||||
| LDLIBS1 =  \ | ||||
| $(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Source/Templates/gcc/startup_stm32g030xx.s | ||||
| 
 | ||||
| ####################################### | ||||
| # binaries | ||||
| ####################################### | ||||
| PREFIX = arm-none-eabi- | ||||
| 
 | ||||
| CC = $(PREFIX)gcc | ||||
| CP = $(PREFIX)objcopy | ||||
| #SZ = $(PREFIX)size | ||||
| 
 | ||||
| BIN = $(CP) -O binary -S | ||||
| 
 | ||||
| ####################################### | ||||
| # CFLAGS | ||||
| ####################################### | ||||
| # cpu | ||||
| CPU = \ | ||||
|  -mcpu=cortex-m0plus \ | ||||
|  -mthumb | ||||
| 
 | ||||
| DEFINES = -D$(PART) | ||||
| 
 | ||||
| # fpu | ||||
| FPU =  | ||||
| 
 | ||||
| # float-abi | ||||
| FLOAT-ABI = | ||||
| 
 | ||||
| # mcu | ||||
| MCU = $(CPU) $(FPU) $(FLOAT-ABI) | ||||
| 
 | ||||
| # C includes | ||||
| C_INCLUDES +=  \ | ||||
|  -Iinc \ | ||||
|  -I$(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Core/Include \ | ||||
|  -I$(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Include | ||||
| 
 | ||||
| # compile gcc flags | ||||
| ADDN_CFLAGS = \ | ||||
| # -std=c99 \ | ||||
|  -Wall \ | ||||
|  -fno-common \ | ||||
|  -fdata-sections \ | ||||
|  -ffunction-sections | ||||
| 
 | ||||
| CFLAGS = $(MCU) $(ADDN_CFLAGS) $(C_INCLUDES) $(OPT) $(DEFINES) | ||||
| 
 | ||||
| ifeq ($(DEBUG), 1) | ||||
| CFLAGS += -ggdb3 | ||||
| endif | ||||
| 
 | ||||
| 
 | ||||
| # Generate dependency information | ||||
| #CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" | ||||
| 
 | ||||
| 
 | ||||
| ####################################### | ||||
| # LDFLAGS | ||||
| ####################################### | ||||
| # link script | ||||
| LDSCRIPT = $(VND_DIR)/Ld/STM32G030F6MX_FLASH.ld | ||||
| 
 | ||||
| # libraries | ||||
| GROUP_START =-Wl,--start-group | ||||
| GROUP_END =-Wl,--end-group | ||||
| 
 | ||||
| PROJECT_LIBS = \ | ||||
|  -lgcc \ | ||||
|  -lc \ | ||||
|  -lm \ | ||||
|  -lnosys | ||||
| 
 | ||||
| 
 | ||||
| LIBS = $(GROUP_START) $(PROJECT_LIBS) $(GROUP_END) | ||||
| LIBDIR =  | ||||
| LDFLAGS =  \ | ||||
|  $(MCU)  \ | ||||
|  -T $(LDSCRIPT) \ | ||||
|  --specs=nano.specs \ | ||||
|  --specs=nosys.specs \ | ||||
|  -Xlinker -Map=$(BUILD_DIR)/$(TARGET).map \ | ||||
|  -Wl,--gc-sections \ | ||||
|  -Wl,--print-memory-usage \ | ||||
|  -Wl,--no-warn-rwx-segments | ||||
| 
 | ||||
| # default action: build all | ||||
| all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).bin | ||||
| 
 | ||||
| 
 | ||||
| ####################################### | ||||
| # build the application | ||||
| ####################################### | ||||
| # list of objects | ||||
| OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) | ||||
| vpath %.c $(sort $(dir $(C_SOURCES))) | ||||
| 
 | ||||
| $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) | ||||
| 	$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ | ||||
| 
 | ||||
| #$(LUAOBJECTS) $(OBJECTS) | ||||
| $(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile | ||||
| 	$(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS1) -o $@ | ||||
| 
 | ||||
| $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) | ||||
| 	$(BIN) $< $@	 | ||||
| 	 | ||||
| $(BUILD_DIR): | ||||
| 	mkdir $@		 | ||||
| 
 | ||||
| ####################################### | ||||
| # Program | ||||
| ####################################### | ||||
| 
 | ||||
| flash: $(BUILD_DIR)/$(TARGET).bin | ||||
| 	pyocd load --target $(PART) $(BUILD_DIR)/$(TARGET).bin | ||||
| 
 | ||||
| ####################################### | ||||
| # clean up | ||||
| ####################################### | ||||
| clean: | ||||
| 	-rm -fR $(BUILD_DIR) | ||||
|    | ||||
| # *** EOF *** | ||||
							
								
								
									
										0
									
								
								myapps/first/hal.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								myapps/first/hal.mk
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										17
									
								
								myapps/first/src/main.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								myapps/first/src/main.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | |||
| //#include <stdint.h>
 | ||||
| #include "stm32g0xx.h" | ||||
| 
 | ||||
| #define LED_PIN 4 | ||||
| 
 | ||||
| int main(void) | ||||
| { | ||||
|   RCC->IOPENR |= RCC_IOPENR_GPIOAEN; | ||||
|   GPIOA->MODER |= GPIO_MODER_MODE5_0; | ||||
|    | ||||
|   while(1) | ||||
|   { | ||||
|     GPIOA->ODR ^= (1<<LED_PIN);  // toggle diodes
 | ||||
|     for (uint32_t i = 0; i < 1000000; i++); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue