Skip to content

Commit eaebf61

Browse files
committed
first commit
0 parents  commit eaebf61

35 files changed

+6673
-0
lines changed

Makefile

+256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
##############################################################################
2+
# Build global options
3+
# NOTE: Can be overridden externally.
4+
#
5+
6+
# Compiler options here.
7+
ifeq ($(USE_OPT),)
8+
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99
9+
USE_OPT += -DSTM32F40_41xxx
10+
endif
11+
12+
# C specific options here (added to USE_OPT).
13+
ifeq ($(USE_COPT),)
14+
USE_COPT =
15+
endif
16+
17+
# C++ specific options here (added to USE_OPT).
18+
ifeq ($(USE_CPPOPT),)
19+
USE_CPPOPT = -fno-rtti
20+
endif
21+
22+
# Enable this if you want the linker to remove unused code and data
23+
ifeq ($(USE_LINK_GC),)
24+
USE_LINK_GC = yes
25+
endif
26+
27+
# If enabled, this option allows to compile the application in THUMB mode.
28+
ifeq ($(USE_THUMB),)
29+
USE_THUMB = yes
30+
endif
31+
32+
# Enable this if you want to see the full log while compiling.
33+
ifeq ($(USE_VERBOSE_COMPILE),)
34+
USE_VERBOSE_COMPILE = yes
35+
endif
36+
37+
#
38+
# Build global options
39+
##############################################################################
40+
41+
##############################################################################
42+
# Architecture or project specific options
43+
#
44+
45+
# Enables the use of FPU on Cortex-M4.
46+
ifeq ($(USE_FPU),)
47+
USE_FPU = yes
48+
endif
49+
50+
# Enable this if you really want to use the STM FWLib.
51+
ifeq ($(USE_FWLIB),)
52+
USE_FWLIB = yes
53+
endif
54+
55+
#
56+
# Architecture or project specific options
57+
##############################################################################
58+
59+
##############################################################################
60+
# Project, sources and paths
61+
#
62+
63+
# Define project name here
64+
PROJECT = BLDC_4_ChibiOS
65+
66+
# Imported source files and paths
67+
CHIBIOS = ../../ChibiOS-RT-master
68+
include $(CHIBIOS)/boards/ST_STM32F4_DISCOVERY/board.mk
69+
include $(CHIBIOS)/os/hal/platforms/STM32F4xx/platform.mk
70+
include $(CHIBIOS)/os/hal/hal.mk
71+
include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F4xx/port.mk
72+
include $(CHIBIOS)/os/kernel/kernel.mk
73+
74+
# Define linker script file here
75+
LDSCRIPT= $(PORTLD)/STM32F407xG.ld
76+
#LDSCRIPT= $(PORTLD)/STM32F407xG_CCM.ld
77+
78+
# C sources that can be compiled in ARM or THUMB mode depending on the global
79+
# setting.
80+
CSRC = $(PORTSRC) \
81+
$(KERNSRC) \
82+
$(TESTSRC) \
83+
$(HALSRC) \
84+
$(PLATFORMSRC) \
85+
$(BOARDSRC) \
86+
$(CHIBIOS)/os/various/chprintf.c \
87+
$(CHIBIOS)/os/various/shell.c \
88+
$(CHIBIOS)/os/various/syscalls.c \
89+
main.c \
90+
myUSB.c \
91+
irq_handlers.c \
92+
buffer.c \
93+
comm.c \
94+
crc.c \
95+
digital_filter.c \
96+
ledpwm.c \
97+
mcpwm.c \
98+
servo_dec.c \
99+
utils.c \
100+
servo.c \
101+
packet.c \
102+
terminal.c
103+
104+
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
105+
# setting.
106+
CPPSRC =
107+
108+
# C sources to be compiled in ARM mode regardless of the global setting.
109+
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
110+
# option that results in lower performance and larger code size.
111+
ACSRC =
112+
113+
# C++ sources to be compiled in ARM mode regardless of the global setting.
114+
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
115+
# option that results in lower performance and larger code size.
116+
ACPPSRC =
117+
118+
# C sources to be compiled in THUMB mode regardless of the global setting.
119+
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
120+
# option that results in lower performance and larger code size.
121+
TCSRC =
122+
123+
# C sources to be compiled in THUMB mode regardless of the global setting.
124+
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
125+
# option that results in lower performance and larger code size.
126+
TCPPSRC =
127+
128+
# List ASM source files here
129+
ASMSRC = $(PORTASM)
130+
131+
INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
132+
$(HALINC) $(PLATFORMINC) $(BOARDINC) \
133+
$(CHIBIOS)/os/various/devices_lib/accel \
134+
$(CHIBIOS)/os/various \
135+
$(CHIBIOS)/os/various $(CC2520INC)
136+
137+
#
138+
# Project, sources and paths
139+
##############################################################################
140+
141+
##############################################################################
142+
# Compiler settings
143+
#
144+
145+
MCU = cortex-m4
146+
147+
#TRGT = arm-elf-
148+
#TRGT = ~/sat/bin/arm-none-eabi-
149+
TRGT = arm-none-eabi-
150+
CC = $(TRGT)gcc
151+
CPPC = $(TRGT)g++
152+
# Enable loading with g++ only if you need C++ runtime support.
153+
# NOTE: You can use C++ even without C++ support if you are careful. C++
154+
# runtime support makes code size explode.
155+
LD = $(TRGT)gcc
156+
#LD = $(TRGT)g++
157+
CP = $(TRGT)objcopy
158+
AS = $(TRGT)gcc -x assembler-with-cpp
159+
OD = $(TRGT)objdump
160+
SIZE = $(TRGT)size
161+
HEX = $(CP) -O ihex
162+
BIN = $(CP) -O binary
163+
164+
# ARM-specific options here
165+
AOPT =
166+
167+
# THUMB-specific options here
168+
TOPT = -mthumb -DTHUMB
169+
170+
# Define C warning options here
171+
CWARN = -Wall -Wextra -Wstrict-prototypes
172+
173+
# Define C++ warning options here
174+
CPPWARN = -Wall -Wextra
175+
176+
#
177+
# Compiler settings
178+
##############################################################################
179+
180+
##############################################################################
181+
# Start of default section
182+
#
183+
184+
# List all default C defines here, like -D_DEBUG=1
185+
DDEFS =
186+
187+
# List all default ASM defines here, like -D_DEBUG=1
188+
DADEFS =
189+
190+
# List all default directories to look for include files here
191+
DINCDIR =
192+
193+
# List the default directory to look for the libraries here
194+
DLIBDIR =
195+
196+
# List all default libraries here
197+
DLIBS =
198+
199+
#
200+
# End of default section
201+
##############################################################################
202+
203+
##############################################################################
204+
# Start of user section
205+
#
206+
207+
# List all user C define here, like -D_DEBUG=1
208+
UDEFS =
209+
210+
# Define ASM defines here
211+
UADEFS =
212+
213+
# List all user directories here
214+
UINCDIR =
215+
216+
# List the user directory to look for the libraries here
217+
ULIBDIR =
218+
219+
# List all user libraries here
220+
ULIBS = -lm
221+
222+
#
223+
# End of user defines
224+
##############################################################################
225+
226+
ifeq ($(USE_FPU),yes)
227+
USE_OPT += -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion
228+
DDEFS += -DCORTEX_USE_FPU=TRUE
229+
else
230+
DDEFS += -DCORTEX_USE_FPU=FALSE
231+
endif
232+
233+
ifeq ($(USE_FWLIB),yes)
234+
include $(CHIBIOS)/ext/stdperiph_stm32f4/stm32lib.mk
235+
CSRC += $(STM32SRC)
236+
INCDIR += $(STM32INC)
237+
USE_OPT += -DUSE_STDPERIPH_DRIVER
238+
endif
239+
240+
include $(CHIBIOS)/os/ports/GCC/ARMCMx/rules.mk
241+
242+
# Print size
243+
all:
244+
$(SIZE) build/$(PROJECT).elf
245+
246+
build/$(PROJECT).bin: build/$(PROJECT).elf
247+
$(BIN) build/$(PROJECT).elf build/$(PROJECT).bin
248+
249+
# Program
250+
upload: build/$(PROJECT).bin
251+
qstlink2 --cli --erase --write build/$(PROJECT).bin
252+
253+
debug-start:
254+
openocd -f stm32-bv_openocd.cfg
255+
256+

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is the source code for my custom BLDC controller. I will post a link to a complete tutorial on my homepage soon.

buffer.c

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright 2012-2014 Benjamin Vedder [email protected]
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
/*
19+
* buffer.c
20+
*
21+
* Created on: 13 maj 2013
22+
* Author: benjamin
23+
*/
24+
25+
#include "buffer.h"
26+
27+
void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) {
28+
buffer[(*index)++] = number >> 24;
29+
buffer[(*index)++] = number >> 16;
30+
buffer[(*index)++] = number >> 8;
31+
buffer[(*index)++] = number;
32+
}
33+
34+
void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) {
35+
buffer[(*index)++] = number >> 24;
36+
buffer[(*index)++] = number >> 16;
37+
buffer[(*index)++] = number >> 8;
38+
buffer[(*index)++] = number;
39+
}
40+
41+
void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) {
42+
buffer[(*index)++] = number >> 8;
43+
buffer[(*index)++] = number;
44+
}
45+
46+
void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) {
47+
buffer[(*index)++] = number >> 8;
48+
buffer[(*index)++] = number;
49+
}
50+
51+
int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) {
52+
int16_t res = ((uint16_t) buffer[*index]) << 8 |
53+
((uint16_t) buffer[*index + 1]);
54+
*index += 2;
55+
return res;
56+
}
57+
58+
uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) {
59+
uint16_t res = ((uint16_t) buffer[*index]) << 8 |
60+
((uint16_t) buffer[*index + 1]);
61+
*index += 2;
62+
return res;
63+
}
64+
65+
int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) {
66+
int32_t res = ((uint32_t) buffer[*index]) << 24 |
67+
((uint32_t) buffer[*index]) << 16 |
68+
((uint32_t) buffer[*index]) << 8 |
69+
((uint32_t) buffer[*index + 1]);
70+
*index += 4;
71+
return res;
72+
}
73+
74+
uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) {
75+
uint32_t res = ((uint32_t) buffer[*index]) << 24 |
76+
((uint32_t) buffer[*index]) << 16 |
77+
((uint32_t) buffer[*index]) << 8 |
78+
((uint32_t) buffer[*index + 1]);
79+
*index += 4;
80+
return res;
81+
}

buffer.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* buffer.h
3+
*
4+
* Created on: 13 maj 2013
5+
* Author: benjamin
6+
*/
7+
8+
#ifndef BUFFER_H_
9+
#define BUFFER_H_
10+
11+
#include <stdint.h>
12+
13+
void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index);
14+
void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index);
15+
void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index);
16+
void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index);
17+
int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index);
18+
uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index);
19+
int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index);
20+
uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index);
21+
22+
#endif /* BUFFER_H_ */

0 commit comments

Comments
 (0)