Initial
This commit is contained in:
commit
7aecefd053
3 changed files with 72 additions and 0 deletions
15
README.md
Normal file
15
README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# STM32 Example
|
||||
|
||||
This is unfinished work in progress.
|
||||
The goal is to create a simple C example of a STM32F103C8T6 Blue Pill board running a simple program.
|
||||
|
||||
`sudo dnf install arm-none-eabi-gcc-cs stlink`
|
||||
|
||||
- [STM32F103C8T6 Blue Pill](https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html)
|
||||
- [STM32F103C8T6 Blue Pill Datasheet](https://www.st.com/resource/en/datasheet/stm32f103c8.pdf)
|
||||
- [Bare Metal C on the Blue Pill](https://leap.tardate.com/arm/stm32f103c8t6/baremetal/)
|
||||
- [Bare Metal C on the Blue Pill Source Code](https://github.com/tardate/LittleArduinoProjects/tree/master/ARM/STM32F103C8T6/BareMetal)
|
||||
- [Bare Metal Embedded playlist](https://www.youtube.com/playlist?list=PLERTijJOmYrDiiWd10iRHY0VRHdJwUH4g)
|
||||
- [Getting Started With STM32](https://stm32-base.org/guides/getting-started)
|
||||
- [STM32-base source](https://github.com/STM32-base/STM32-base) and the specific [F1 Template](https://github.com/STM32-base/STM32-base-F1-template)
|
||||
- [stm32_bare_metal repository](https://github.com/mensi/stm32_bare_metal)
|
22
blink.c
Normal file
22
blink.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "stm32f103xb.h"
|
||||
|
||||
#define LED_PIN GPIO_PIN_13
|
||||
#define LED_PORT GPIOC
|
||||
|
||||
void delay(uint32_t count) {
|
||||
for(uint32_t i = 0; i < count; i++);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN; // Enable clock for GPIOC
|
||||
GPIOC->CRH &= ~(GPIO_CRH_CNF13 | GPIO_CRH_MODE13); // Clear CNF and MODE bits for pin 13
|
||||
GPIOC->CRH |= GPIO_CRH_MODE13_0; // Output mode, max speed 10 MHz
|
||||
|
||||
while (1) {
|
||||
GPIOC->BSRR = LED_PIN; // Set pin high (turn LED on)
|
||||
delay(1000000); // Delay
|
||||
GPIOC->BSRR = LED_PIN << 16; // Reset pin (turn LED off)
|
||||
delay(1000000); // Delay
|
||||
}
|
||||
}
|
||||
|
35
makefile
Normal file
35
makefile
Normal file
|
@ -0,0 +1,35 @@
|
|||
# Toolchain
|
||||
CC = arm-none-eabi-gcc
|
||||
OBJCOPY = arm-none-eabi-objcopy
|
||||
STFLASH = st-flash
|
||||
|
||||
# Compiler flags
|
||||
CFLAGS = -std=c99 -Wall -Wextra -Werror -g -mthumb -mcpu=cortex-m3
|
||||
|
||||
# Object files
|
||||
OBJS = blink.o
|
||||
|
||||
# Output files
|
||||
ELF = blink.elf
|
||||
BIN = blink.bin
|
||||
|
||||
# Targets
|
||||
.PHONY: all clean flash
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(BIN): $(ELF)
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
$(ELF): $(OBJS)
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) $(ELF) $(BIN)
|
||||
|
||||
flash: $(BIN)
|
||||
$(STFLASH) --reset write $< 0x8000000
|
||||
|
Loading…
Reference in a new issue