forked from vedderb/bldc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit eaebf61
Showing
35 changed files
with
6,673 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,256 @@ | ||
############################################################################## | ||
# Build global options | ||
# NOTE: Can be overridden externally. | ||
# | ||
|
||
# Compiler options here. | ||
ifeq ($(USE_OPT),) | ||
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99 | ||
USE_OPT += -DSTM32F40_41xxx | ||
endif | ||
|
||
# C specific options here (added to USE_OPT). | ||
ifeq ($(USE_COPT),) | ||
USE_COPT = | ||
endif | ||
|
||
# C++ specific options here (added to USE_OPT). | ||
ifeq ($(USE_CPPOPT),) | ||
USE_CPPOPT = -fno-rtti | ||
endif | ||
|
||
# Enable this if you want the linker to remove unused code and data | ||
ifeq ($(USE_LINK_GC),) | ||
USE_LINK_GC = yes | ||
endif | ||
|
||
# If enabled, this option allows to compile the application in THUMB mode. | ||
ifeq ($(USE_THUMB),) | ||
USE_THUMB = yes | ||
endif | ||
|
||
# Enable this if you want to see the full log while compiling. | ||
ifeq ($(USE_VERBOSE_COMPILE),) | ||
USE_VERBOSE_COMPILE = yes | ||
endif | ||
|
||
# | ||
# Build global options | ||
############################################################################## | ||
|
||
############################################################################## | ||
# Architecture or project specific options | ||
# | ||
|
||
# Enables the use of FPU on Cortex-M4. | ||
ifeq ($(USE_FPU),) | ||
USE_FPU = yes | ||
endif | ||
|
||
# Enable this if you really want to use the STM FWLib. | ||
ifeq ($(USE_FWLIB),) | ||
USE_FWLIB = yes | ||
endif | ||
|
||
# | ||
# Architecture or project specific options | ||
############################################################################## | ||
|
||
############################################################################## | ||
# Project, sources and paths | ||
# | ||
|
||
# Define project name here | ||
PROJECT = BLDC_4_ChibiOS | ||
|
||
# Imported source files and paths | ||
CHIBIOS = ../../ChibiOS-RT-master | ||
include $(CHIBIOS)/boards/ST_STM32F4_DISCOVERY/board.mk | ||
include $(CHIBIOS)/os/hal/platforms/STM32F4xx/platform.mk | ||
include $(CHIBIOS)/os/hal/hal.mk | ||
include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F4xx/port.mk | ||
include $(CHIBIOS)/os/kernel/kernel.mk | ||
|
||
# Define linker script file here | ||
LDSCRIPT= $(PORTLD)/STM32F407xG.ld | ||
#LDSCRIPT= $(PORTLD)/STM32F407xG_CCM.ld | ||
|
||
# C sources that can be compiled in ARM or THUMB mode depending on the global | ||
# setting. | ||
CSRC = $(PORTSRC) \ | ||
$(KERNSRC) \ | ||
$(TESTSRC) \ | ||
$(HALSRC) \ | ||
$(PLATFORMSRC) \ | ||
$(BOARDSRC) \ | ||
$(CHIBIOS)/os/various/chprintf.c \ | ||
$(CHIBIOS)/os/various/shell.c \ | ||
$(CHIBIOS)/os/various/syscalls.c \ | ||
main.c \ | ||
myUSB.c \ | ||
irq_handlers.c \ | ||
buffer.c \ | ||
comm.c \ | ||
crc.c \ | ||
digital_filter.c \ | ||
ledpwm.c \ | ||
mcpwm.c \ | ||
servo_dec.c \ | ||
utils.c \ | ||
servo.c \ | ||
packet.c \ | ||
terminal.c | ||
|
||
# C++ sources that can be compiled in ARM or THUMB mode depending on the global | ||
# setting. | ||
CPPSRC = | ||
|
||
# C sources to be compiled in ARM mode regardless of the global setting. | ||
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler | ||
# option that results in lower performance and larger code size. | ||
ACSRC = | ||
|
||
# C++ sources to be compiled in ARM mode regardless of the global setting. | ||
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler | ||
# option that results in lower performance and larger code size. | ||
ACPPSRC = | ||
|
||
# C sources to be compiled in THUMB mode regardless of the global setting. | ||
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler | ||
# option that results in lower performance and larger code size. | ||
TCSRC = | ||
|
||
# C sources to be compiled in THUMB mode regardless of the global setting. | ||
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler | ||
# option that results in lower performance and larger code size. | ||
TCPPSRC = | ||
|
||
# List ASM source files here | ||
ASMSRC = $(PORTASM) | ||
|
||
INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ | ||
$(HALINC) $(PLATFORMINC) $(BOARDINC) \ | ||
$(CHIBIOS)/os/various/devices_lib/accel \ | ||
$(CHIBIOS)/os/various \ | ||
$(CHIBIOS)/os/various $(CC2520INC) | ||
|
||
# | ||
# Project, sources and paths | ||
############################################################################## | ||
|
||
############################################################################## | ||
# Compiler settings | ||
# | ||
|
||
MCU = cortex-m4 | ||
|
||
#TRGT = arm-elf- | ||
#TRGT = ~/sat/bin/arm-none-eabi- | ||
TRGT = arm-none-eabi- | ||
CC = $(TRGT)gcc | ||
CPPC = $(TRGT)g++ | ||
# Enable loading with g++ only if you need C++ runtime support. | ||
# NOTE: You can use C++ even without C++ support if you are careful. C++ | ||
# runtime support makes code size explode. | ||
LD = $(TRGT)gcc | ||
#LD = $(TRGT)g++ | ||
CP = $(TRGT)objcopy | ||
AS = $(TRGT)gcc -x assembler-with-cpp | ||
OD = $(TRGT)objdump | ||
SIZE = $(TRGT)size | ||
HEX = $(CP) -O ihex | ||
BIN = $(CP) -O binary | ||
|
||
# ARM-specific options here | ||
AOPT = | ||
|
||
# THUMB-specific options here | ||
TOPT = -mthumb -DTHUMB | ||
|
||
# Define C warning options here | ||
CWARN = -Wall -Wextra -Wstrict-prototypes | ||
|
||
# Define C++ warning options here | ||
CPPWARN = -Wall -Wextra | ||
|
||
# | ||
# Compiler settings | ||
############################################################################## | ||
|
||
############################################################################## | ||
# Start of default section | ||
# | ||
|
||
# List all default C defines here, like -D_DEBUG=1 | ||
DDEFS = | ||
|
||
# List all default ASM defines here, like -D_DEBUG=1 | ||
DADEFS = | ||
|
||
# List all default directories to look for include files here | ||
DINCDIR = | ||
|
||
# List the default directory to look for the libraries here | ||
DLIBDIR = | ||
|
||
# List all default libraries here | ||
DLIBS = | ||
|
||
# | ||
# End of default section | ||
############################################################################## | ||
|
||
############################################################################## | ||
# Start of user section | ||
# | ||
|
||
# List all user C define here, like -D_DEBUG=1 | ||
UDEFS = | ||
|
||
# Define ASM defines here | ||
UADEFS = | ||
|
||
# List all user directories here | ||
UINCDIR = | ||
|
||
# List the user directory to look for the libraries here | ||
ULIBDIR = | ||
|
||
# List all user libraries here | ||
ULIBS = -lm | ||
|
||
# | ||
# End of user defines | ||
############################################################################## | ||
|
||
ifeq ($(USE_FPU),yes) | ||
USE_OPT += -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fsingle-precision-constant -Wdouble-promotion | ||
DDEFS += -DCORTEX_USE_FPU=TRUE | ||
else | ||
DDEFS += -DCORTEX_USE_FPU=FALSE | ||
endif | ||
|
||
ifeq ($(USE_FWLIB),yes) | ||
include $(CHIBIOS)/ext/stdperiph_stm32f4/stm32lib.mk | ||
CSRC += $(STM32SRC) | ||
INCDIR += $(STM32INC) | ||
USE_OPT += -DUSE_STDPERIPH_DRIVER | ||
endif | ||
|
||
include $(CHIBIOS)/os/ports/GCC/ARMCMx/rules.mk | ||
|
||
# Print size | ||
all: | ||
$(SIZE) build/$(PROJECT).elf | ||
|
||
build/$(PROJECT).bin: build/$(PROJECT).elf | ||
$(BIN) build/$(PROJECT).elf build/$(PROJECT).bin | ||
|
||
# Program | ||
upload: build/$(PROJECT).bin | ||
qstlink2 --cli --erase --write build/$(PROJECT).bin | ||
|
||
debug-start: | ||
openocd -f stm32-bv_openocd.cfg | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is the source code for my custom BLDC controller. I will post a link to a complete tutorial on my homepage soon. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
Copyright 2012-2014 Benjamin Vedder [email protected] | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* | ||
* buffer.c | ||
* | ||
* Created on: 13 maj 2013 | ||
* Author: benjamin | ||
*/ | ||
|
||
#include "buffer.h" | ||
|
||
void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index) { | ||
buffer[(*index)++] = number >> 24; | ||
buffer[(*index)++] = number >> 16; | ||
buffer[(*index)++] = number >> 8; | ||
buffer[(*index)++] = number; | ||
} | ||
|
||
void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index) { | ||
buffer[(*index)++] = number >> 24; | ||
buffer[(*index)++] = number >> 16; | ||
buffer[(*index)++] = number >> 8; | ||
buffer[(*index)++] = number; | ||
} | ||
|
||
void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index) { | ||
buffer[(*index)++] = number >> 8; | ||
buffer[(*index)++] = number; | ||
} | ||
|
||
void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index) { | ||
buffer[(*index)++] = number >> 8; | ||
buffer[(*index)++] = number; | ||
} | ||
|
||
int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index) { | ||
int16_t res = ((uint16_t) buffer[*index]) << 8 | | ||
((uint16_t) buffer[*index + 1]); | ||
*index += 2; | ||
return res; | ||
} | ||
|
||
uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index) { | ||
uint16_t res = ((uint16_t) buffer[*index]) << 8 | | ||
((uint16_t) buffer[*index + 1]); | ||
*index += 2; | ||
return res; | ||
} | ||
|
||
int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index) { | ||
int32_t res = ((uint32_t) buffer[*index]) << 24 | | ||
((uint32_t) buffer[*index]) << 16 | | ||
((uint32_t) buffer[*index]) << 8 | | ||
((uint32_t) buffer[*index + 1]); | ||
*index += 4; | ||
return res; | ||
} | ||
|
||
uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index) { | ||
uint32_t res = ((uint32_t) buffer[*index]) << 24 | | ||
((uint32_t) buffer[*index]) << 16 | | ||
((uint32_t) buffer[*index]) << 8 | | ||
((uint32_t) buffer[*index + 1]); | ||
*index += 4; | ||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* buffer.h | ||
* | ||
* Created on: 13 maj 2013 | ||
* Author: benjamin | ||
*/ | ||
|
||
#ifndef BUFFER_H_ | ||
#define BUFFER_H_ | ||
|
||
#include <stdint.h> | ||
|
||
void buffer_append_int32(uint8_t* buffer, int32_t number, int32_t *index); | ||
void buffer_append_uint32(uint8_t* buffer, uint32_t number, int32_t *index); | ||
void buffer_append_int16(uint8_t* buffer, int16_t number, int32_t *index); | ||
void buffer_append_uint16(uint8_t* buffer, uint16_t number, int32_t *index); | ||
int16_t buffer_get_int16(const uint8_t *buffer, int32_t *index); | ||
uint16_t buffer_get_uint16(const uint8_t *buffer, int32_t *index); | ||
int32_t buffer_get_int32(const uint8_t *buffer, int32_t *index); | ||
uint32_t buffer_get_uint32(const uint8_t *buffer, int32_t *index); | ||
|
||
#endif /* BUFFER_H_ */ |
Oops, something went wrong.