Skip to content

Commit 2997ca2

Browse files
author
moonxraccoon
committed
Initial commit
1 parent bc11ecb commit 2997ca2

20 files changed

+2327
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.pio
2+
.clang_complete
3+
.gcc-flags.json
4+
.ccls

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Uncomment lines below if you have problems with $PATH
2+
#SHELL := /bin/bash
3+
#PATH := /usr/local/bin:$(PATH)
4+
5+
all:
6+
pio -f -c vim run
7+
8+
flash:
9+
pio -f -c vim run --target upload
10+
11+
clean:
12+
pio -f -c vim run --target clean
13+
14+
program:
15+
pio -f -c vim run --target program
16+
17+
uploadfs:
18+
pio -f -c vim run --target uploadfs
19+
20+
update:
21+
pio -f -c vim update

compile_commands.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"command": "/home/moonraccoon/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-as -o .pio/build/genericSTM32F411CE/FrameworkCMSIS/gcc/startup_stm32f411xe.o /home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Source/Templates/gcc/startup_stm32f411xe.S",
4+
"directory": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp",
5+
"file": "/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Source/Templates/gcc/startup_stm32f411xe.S"
6+
},
7+
{
8+
"command": "/home/moonraccoon/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc -o .pio/build/genericSTM32F411CE/FrameworkCMSIS/system_stm32f4xx.o -c -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -DPLATFORMIO=60002 -DSTM32F411xE -DSTM32F4xx -DF_CPU=100000000L -I/home/moonraccoon/.platformio/packages/framework-cmsis/CMSIS/Include -I/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Include /home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Source/Templates/system_stm32f4xx.c",
9+
"directory": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp",
10+
"file": "/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Source/Templates/system_stm32f4xx.c"
11+
},
12+
{
13+
"command": "/home/moonraccoon/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/genericSTM32F411CE/src/field.o -c -fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -DPLATFORMIO=60002 -DSTM32F411xE -DSTM32F4xx -DF_CPU=100000000L -Iinclude -Isrc -I/home/moonraccoon/.platformio/packages/framework-cmsis/CMSIS/Include -I/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Include src/field.cpp",
14+
"directory": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp",
15+
"file": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp/src/field.cpp"
16+
},
17+
{
18+
"command": "/home/moonraccoon/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/genericSTM32F411CE/src/main.o -c -fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -DPLATFORMIO=60002 -DSTM32F411xE -DSTM32F4xx -DF_CPU=100000000L -Iinclude -Isrc -I/home/moonraccoon/.platformio/packages/framework-cmsis/CMSIS/Include -I/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Include src/main.cpp",
19+
"directory": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp",
20+
"file": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp/src/main.cpp"
21+
},
22+
{
23+
"command": "/home/moonraccoon/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/genericSTM32F411CE/src/pin.o -c -fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -DPLATFORMIO=60002 -DSTM32F411xE -DSTM32F4xx -DF_CPU=100000000L -Iinclude -Isrc -I/home/moonraccoon/.platformio/packages/framework-cmsis/CMSIS/Include -I/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Include src/pin.cpp",
24+
"directory": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp",
25+
"file": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp/src/pin.cpp"
26+
},
27+
{
28+
"command": "/home/moonraccoon/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/genericSTM32F411CE/src/port.o -c -fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -DPLATFORMIO=60002 -DSTM32F411xE -DSTM32F4xx -DF_CPU=100000000L -Iinclude -Isrc -I/home/moonraccoon/.platformio/packages/framework-cmsis/CMSIS/Include -I/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Include src/port.cpp",
29+
"directory": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp",
30+
"file": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp/src/port.cpp"
31+
},
32+
{
33+
"command": "/home/moonraccoon/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/genericSTM32F411CE/src/registers.o -c -fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -DPLATFORMIO=60002 -DSTM32F411xE -DSTM32F4xx -DF_CPU=100000000L -Iinclude -Isrc -I/home/moonraccoon/.platformio/packages/framework-cmsis/CMSIS/Include -I/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Include src/registers.cpp",
34+
"directory": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp",
35+
"file": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp/src/registers.cpp"
36+
},
37+
{
38+
"command": "/home/moonraccoon/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-g++ -o .pio/build/genericSTM32F411CE/src/stm32f4.o -c -fno-rtti -fno-exceptions -Os -ffunction-sections -fdata-sections -Wall -mthumb -mcpu=cortex-m4 -DPLATFORMIO=60002 -DSTM32F411xE -DSTM32F4xx -DF_CPU=100000000L -Iinclude -Isrc -I/home/moonraccoon/.platformio/packages/framework-cmsis/CMSIS/Include -I/home/moonraccoon/.platformio/packages/framework-cmsis-stm32f4/Include src/stm32f4.cpp",
39+
"directory": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp",
40+
"file": "/home/moonraccoon/Documents/Dev/ARM/libstm32f4-cpp/src/stm32f4.cpp"
41+
}
42+
]

extra_script.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
Import("env")
3+
4+
env.Replace(COMPILATIONDB_PATH=os.path.join("$PROJECT_DIR", "compile_commands.json"))

include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

notes/peripheral-structure.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# General Peripheral Structure
2+
## Target GPIO example usage
3+
4+
Blinking Pin PB8:
5+
```cpp
6+
#include "stm32f4.h"
7+
/*
8+
* PB is an object of a "Port" class created in the
9+
* header/source file
10+
*
11+
* PB[x] should return Pin "x" of that port -> "Pin" is also a class/struct
12+
*/
13+
using namespace stm32f4::periph;
14+
15+
int main(void) {
16+
// enable clock on Port B
17+
PB.clock_enable();
18+
// setup PB8 as an output pin
19+
PB[8].make_output();
20+
while (true) {
21+
// Pull PB8 high
22+
PB[8] = 1; // OR
23+
PB[8].high();
24+
delay_ms(500);
25+
26+
// Pull PB8 low
27+
PB[8] = 0; // OR
28+
PB[8].low();
29+
delay_ms(500);
30+
}
31+
return 0;
32+
}
33+
```
34+
35+
```
36+
stm32f4:
37+
regs:
38+
gpioreg:
39+
attr:
40+
fields
41+
class ...:
42+
43+
periph:
44+
port:
45+
46+
47+
```

platformio.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:genericSTM32F411CE]
12+
platform = ststm32
13+
board = genericSTM32F411CE
14+
framework = cmsis
15+
16+
build_flags = -Wl,--undefined,_printf_float
17+
18+
upload_protocol = stlink
19+
debug_tool = stlink

src/field.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "field.h"
2+
#include <cstdint>
3+
4+
uint32_t bit[32] = {
5+
(1 << 0), (1 << 1), (1 << 2), (1 << 3),
6+
(1 << 4), (1 << 5), (1 << 6), (1 << 7),
7+
(1 << 8), (1 << 9), (1 << 10), (1 << 11),
8+
(1 << 12), (1 << 13), (1 << 14), (1 << 15),
9+
(1 << 16), (1 << 17), (1 << 18), (1 << 19),
10+
(1 << 20), (1 << 21), (1 << 22), (1 << 23),
11+
(1 << 24), (1 << 25), (1 << 26), (1 << 27),
12+
(1 << 28), (1 << 29), (1 << 30)
13+
};

src/field.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#pragma once
2+
#include <cstdint>
3+
4+
/*
5+
General Idea:
6+
7+
There is the Field type which has a 32-bit register specified to it
8+
and there is a Reg type where the whole register is specified with it's
9+
fields
10+
11+
The field class can also contain a bitfield to easily access all the bits.
12+
*/
13+
14+
using reg_type = uint32_t;
15+
16+
enum bits {
17+
bit0 = (1 << 0), bit1 = (1 << 1), bit2 = (1 << 2), bit3 = (1 << 3), bit4 = (1 << 4), bit5 = (1 << 5), bit6 = (1 << 6), bit7 = (1 << 7),
18+
bit8 = (1 << 8), bit9 = (1 << 9), bit10 = (1 << 10), bit11 = (1 << 11),
19+
bit12 = (1 << 12), bit13 = (1 << 13), bit14 = (1 << 14), bit15 = (1 << 15),
20+
bit16 = (1 << 16), bit17 = (1 << 17), bit18 = (1 << 18), bit19 = (1 << 19),
21+
bit20 = (1 << 20), bit21 = (1 << 21), bit22 = (1 << 22), bit23 = (1 << 23),
22+
bit24 = (1 << 24), bit25 = (1 << 25), bit26 = (1 << 26), bit27 = (1 << 27),
23+
bit28 = (1 << 28), bit29 = (1 << 29), bit30 = (1 << 30), bit31 = (1 << 31),
24+
};
25+
26+
extern uint32_t bit[32];
27+
28+
template<unsigned int sz>
29+
struct RegisterTrait{};
30+
31+
template<>
32+
struct RegisterTrait<8> {
33+
using regtype = uint8_t;
34+
};
35+
36+
template<>
37+
struct RegisterTrait<16> {
38+
using regtype = uint16_t;
39+
};
40+
41+
template<>
42+
struct RegisterTrait<32> {
43+
using regtype = uint32_t;
44+
};
45+
46+
template<>
47+
struct RegisterTrait<64> {
48+
using regtype = uint64_t;
49+
};
50+
51+
template<uint8_t bs>
52+
class Field {
53+
54+
protected:
55+
using regtype = typename RegisterTrait<bs>::regtype;
56+
regtype* reg_;
57+
public:
58+
59+
60+
explicit Field(regtype reg_addr) {
61+
reg_ = reinterpret_cast<regtype*>(reg_addr);
62+
};
63+
~Field() = default;
64+
65+
66+
inline regtype read() const {
67+
return *reg_;
68+
}
69+
70+
inline void write(regtype value) const {
71+
*reg_ = value;
72+
}
73+
74+
inline void modify(regtype value) const {
75+
*reg_ |= value;
76+
}
77+
78+
inline void clear(regtype value) const {
79+
*reg_ &= ~value;
80+
}
81+
82+
inline void operator=(regtype value) const {
83+
*reg_ = value;
84+
}
85+
86+
inline bool is_set(regtype value) const {
87+
return *reg_ & value;
88+
}
89+
};

0 commit comments

Comments
 (0)