Skip to content

Commit 5cec9e1

Browse files
committed
💥 emergency commit
1 parent 74b4794 commit 5cec9e1

File tree

13 files changed

+166
-90
lines changed

13 files changed

+166
-90
lines changed

cpp/.vscode/c_cpp_properties.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
{
44
"name": "STM32",
55
"includePath": [
6-
"${workspaceFolder}/**"
6+
"${workspaceFolder}/**",
7+
"${workspaceFolder}/lib/usart",
8+
"${workspaceFolder}/lib/**"
79
],
810
"defines": [
911
"STM32F103xB"
1012
],
11-
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
13+
"compilerPath": "/Applications/ARM/bin/arm-none-eabi-gcc",
1214
"cStandard": "gnu17",
1315
"cppStandard": "gnu++17",
1416
"intelliSenseMode": "gcc-arm"

cpp/.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Cortex Debug",
99
"cwd": "${workspaceFolder}",
10-
"executable": "./build/dma-usart.elf",
10+
"executable": "./build/blink.elf",
1111
"request": "launch",
1212
"type": "cortex-debug",
1313
"runToEntryPoint": "main",

cpp/Makefile

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ CXXSTD := c++17
1515

1616
# Project specific configuration
1717
BUILD_DIR := build
18-
BUILD_TYPE ?= Debug
18+
BUILD_TYPE ?= Release
1919
SRC_DIR := src lib/gpio
20-
INC_DIRS = include lib/gpio
20+
INC_DIRS = include lib/gpio lib/usart lib/system
2121

2222

2323
PREFIX ?= arm-none-eabi
@@ -47,17 +47,22 @@ INC_FLAGS = $(addprefix -I,$(INC_DIRS))
4747

4848
# Target-specific flags
4949
CPU_FLAGS ?= -mfloat-abi=$(FLOAT_ABI) -m$(INSTR_SET) -mcpu=$(CPU)
50+
CPPFLAGS ?=$(DEFS) $(INC_FLAGS) -MMD
5051

51-
CPPFLAGS ?= -MMD $(DEFS) $(INC_FLAGS)
52-
CFLAGS ?=$(CPU_FLAGS) $(OPT)
53-
CXXFLAGS :=$(CFLAGS) -fno-exceptions -fno-rtti
54-
LDFLAGS ?=$(CPU_FLAGS)
55-
52+
ifeq ($(BUILD_TYPE), Debug)
53+
CFLAGS += -g -gdwarf-2
54+
CXXFLAGS += -g -gdwarf-2
55+
LDFLAGS += -g -gdwarf-2
5656

57+
else
58+
CFLAGS += $(OPT)
59+
CXXFLAGS += $(OPT)
60+
ASFLAGS += $(OPT)
61+
endif
5762

5863
# Do not link stdlib with executable
5964
CFLAGS += -nostdlib -fno-tree-loop-distribute-patterns -fdata-sections -ffunction-sections
60-
CXXFLAGS += -nostdlib -fno-tree-loop-distribute-patterns -fdata-sections -ffunction-sections
65+
CXXFLAGS += -nostdlib -fno-tree-loop-distribute-patterns -fdata-sections -ffunction-sections -fno-exceptions -fno-rtti
6166
LDFLAGS += -nostdlib -fno-tree-loop-distribute-patterns
6267

6368

@@ -69,15 +74,15 @@ CXXFLAGS += -Wall -Wextra -Wundef -Wshadow -Wredundant-decls -Weffc++ -Werror
6974
LDFLAGS += -T $(LDSCRIPT)
7075
LDFLAGS += -Wl,-Map=$(basename $@).map
7176

72-
all: size bin
73-
size: $(BUILD_DIR)/$(TARGET).size
74-
elf: $(BUILD_DIR)/$(TARGET).elf
75-
bin: $(BUILD_DIR)/$(TARGET).bin
76-
hex: $(BUILD_DIR)/$(TARGET).hex
77-
srec: $(BUILD_DIR)/$(TARGET).srec
78-
list: $(BUILD_DIR)/$(TARGET).list
77+
all : size bin
78+
size : $(BUILD_DIR)/$(TARGET).size
79+
elf : $(BUILD_DIR)/$(TARGET).elf
80+
bin : $(BUILD_DIR)/$(TARGET).bin
81+
hex : $(BUILD_DIR)/$(TARGET).hex
82+
srec : $(BUILD_DIR)/$(TARGET).srec
83+
list : $(BUILD_DIR)/$(TARGET).list
7984

80-
asm: $(ASMS)
85+
asm : $(ASMS)
8186

8287

8388
%.size: %.elf
@@ -90,21 +95,21 @@ asm: $(ASMS)
9095
$(BUILD_DIR)/%.s:%.cpp
9196
@mkdir -p $(dir $@)
9297
@echo "AS" $< " ==> " $@
93-
$(CXX) $(CPPFLAGS) $(CXXLAGS) -o $@ -S $<
98+
$(CXX) $(CPU_FLAGS) $(CPPFLAGS) $(CXXLAGS) -o $@ -S $<
9499

95100
$(BUILD_DIR)/%.o:%.c
96101
@mkdir -p $(dir $@)
97102
@echo "CC" $< " ==> " $@
98-
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
103+
$(CC) $(CPU_FLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
99104

100105
$(BUILD_DIR)/%.o:%.cpp
101106
@mkdir -p $(dir $@)
102107
@echo "CXX" $< " ==> " $@
103-
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
108+
$(CXX) $(CPU_FLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<
104109

105110
$(BUILD_DIR)/$(TARGET).elf: $(OBJS)
106111
@echo "Linking sources into "$@
107-
$(CC) $(LDFLAGS) -o $@ $^
112+
$(CC) $(CPU_FLAGS) $(LDFLAGS) -o $@ $^
108113

109114

110115
flash: bin

cpp/lib/dma/dma.hpp

Whitespace-only changes.

cpp/lib/gpio/gpio.hpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <stm32f1xx.h>
2121
#include <stdint.h>
2222

23+
#pragma once
2324
class GPIO
2425
{
2526
public:
@@ -111,19 +112,10 @@ class GPIO
111112
GPIO(GPIO_TypeDef *port, PIN newPin) : pin{newPin}, PORT{port} {}
112113

113114
/**
114-
* @brief Enable clock source for Port A
115-
*/
116-
static void enable_PortA();
117-
118-
/**
119-
* @brief Enable clock source for Port B
120-
*/
121-
static void enable_PortB();
122-
123-
/**
124-
* @brief Enable clock source for Port C
115+
* @brief Enable Clock source for GPIO port
116+
* @param port GPIO port instance
125117
*/
126-
static void enable_PortC();
118+
constexpr static void enable_port(GPIO_TypeDef *port);
127119

128120
/**
129121
* @brief Destroy the GPIO object
@@ -169,11 +161,20 @@ inline GPIO &GPIO::operator=(const GPIO &gpio)
169161
return *this;
170162
}
171163

172-
inline void GPIO::enable_PortA() { RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; }
173-
inline void GPIO::enable_PortB() { RCC->APB2ENR |= RCC_APB2ENR_IOPBEN; }
174-
inline void GPIO::enable_PortC()
164+
constexpr inline void GPIO::enable_port(GPIO_TypeDef *port)
175165
{
176-
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
166+
if (port == GPIOA)
167+
{
168+
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
169+
}
170+
else if (port == GPIOB)
171+
{
172+
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
173+
}
174+
else if (port == GPIOC)
175+
{
176+
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
177+
}
177178
}
178179

179180
inline void GPIO::setMode(MODE mode)
@@ -211,8 +212,8 @@ inline void GPIO::setConfig(GPIO_TypeDef *port, PIN newPin, CNF config)
211212
}
212213
}
213214

214-
inline void GPIO::toggle() { this->PORT->ODR ^= 1 << this->pin; };
215-
inline void GPIO::toggle(GPIO_TypeDef *port, PIN newPin) { port->ODR ^= 1 << newPin; };
215+
inline void GPIO::toggle() { this->PORT->ODR ^= 1 << this->pin; }
216+
inline void GPIO::toggle(GPIO_TypeDef *port, PIN newPin) { port->ODR ^= 1 << newPin; }
216217

217218
inline void GPIO::write(PIN_STATE state)
218219
{

cpp/lib/system/system.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include<system.hpp>
2+
3+
4+
uint32_t Core::clock = 8000000U;
5+
volatile uint32_t Core::ms_ticks = 0;
6+
7+
void SysTick_Handler(void){
8+
Core::ms_ticks ++;
9+
}

cpp/lib/system/system.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stm32f1xx.h>
2+
3+
namespace Core
4+
{
5+
uint32_t clock;
6+
volatile uint32_t ms_ticks;
7+
} // namespace Core
8+
9+
void delay_ms(uint32_t ms)
10+
{
11+
uint64_t final = ms + Core::ms_ticks;
12+
while (Core::ms_ticks < final)
13+
{
14+
__asm("nop");
15+
}
16+
}

cpp/lib/uart/usart.hpp

Lines changed: 0 additions & 18 deletions
This file was deleted.

cpp/lib/usart/usart.cpp

Whitespace-only changes.

0 commit comments

Comments
 (0)