-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: LAMBS Pierre-Antoine <[email protected]>
- Loading branch information
0 parents
commit e21f775
Showing
12 changed files
with
290 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,8 @@ | ||
*.elf | ||
*.o | ||
*.bin | ||
*.swp | ||
tags | ||
|
||
libopencm3/ | ||
toolchain/ |
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,19 @@ | ||
Simple projet for my stm32f103 (the cheap 3$ board) | ||
|
||
Install | ||
cross-arm-linux-gnueabi | ||
cross-arm-linux-gnueabi-libc | ||
openocd | ||
|
||
Build: | ||
|
||
cd src | ||
make | ||
|
||
Flash: | ||
Connect stm flasher | ||
cd src | ||
make write | ||
|
||
|
||
sudo openocd -f ../config/openocd.cfg -c init -c "halt" -c "stm32f1x mass_erase 0" -c "flash erase_check 0" -c "flash write_bank 0 stm32_firmware.bin 0" -c "reset run" |
Binary file not shown.
Binary file not shown.
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,5 @@ | ||
source [find interface/stlink-v2.cfg] | ||
|
||
transport select hla_swd | ||
|
||
source [find target/stm32f1x.cfg] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,11 @@ | ||
#!/bin/sh | ||
|
||
printf "Extract toolchain from archive\n" | ||
|
||
tar xvf archive/gcc-arm-none-eabi.tar.bz2 -C toolchain | ||
|
||
printf "Extract libopencm3 from archive\n" | ||
|
||
tar xvf archive/libopencm3.tar -C libopencm3 | ||
|
||
exit 0 |
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,84 @@ | ||
BIN=stm32_firmware.bin | ||
ELF=stm32_firmware.elf | ||
|
||
LIBOPENCM3=../libopencm3/lib/libopencm3_stm32f1.a | ||
|
||
SRC=main.c | ||
|
||
LKR_SCRIPT = linker/stm32f103x8.ld | ||
|
||
ARM_TOOLCHAIN_PATH=../toolchain/bin | ||
ARM_TOOLCHAIN_PRFIX=arm-none-eabi- | ||
|
||
CROSS_COMPILE=$(ARM_TOOLCHAIN_PATH)/$(ARM_TOOLCHAIN_PRFIX) | ||
|
||
CC=$(CROSS_COMPILE)gcc | ||
AR=$(CROSS_COMPILE)ar | ||
CP=$(CROSS_COMPILE)objcopy | ||
LD=$(CROSS_COMPILE)ld | ||
LDCONFIG=$(CROSS_COMPILE)ldconfig | ||
STRIP=$(CROSS_COMPILE)strip | ||
|
||
INCLUDE=-I. \ | ||
-I./../libopencm3/include/libopencmsis/stm32/f1/ \ | ||
-I./../libopencm3/include/ | ||
|
||
CFLAGS=-c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb -DSTM32F1 | ||
LDFLAGS=-nostartfiles -specs=nano.specs -mcpu=cortex-m3 -mthumb -T$(LKR_SCRIPT) $(LIBOPENCM3) | ||
CPFLAGS=-Obinary | ||
ASFLAGS=-c -mcpu=cortex-m3 -mthumb | ||
|
||
OBJECTS=$(SRC:.c=.o) | ||
|
||
all:$(BIN) | ||
@echo "[ build $(BIN) ]" | ||
|
||
%.o:%.c | ||
@ echo Cross Compile | ||
@$(CC) $(INCLUDE) $(CFLAGS) $< -o $@ | ||
|
||
$(ELF):$(OBJECTS) | ||
@ echo Create ELF | ||
@$(CC) -o $(ELF) $(OBJECTS) $(LDFLAGS) | ||
|
||
$(BIN): $(LIBOPENCM3) $(ELF) | ||
@ echo objcopy elf to bin | ||
@ $(CP) $(CPFLAGS) $(ELF) $(BIN) | ||
|
||
libopencm3: | ||
cd ../libopencm3/ && PATH=$PATH:$PWD/../toolchain/bin/ $(MAKE) | ||
|
||
.PHONY:clean | ||
|
||
clean: | ||
@echo "[ clean project ]" | ||
@rm -f $(OBJECTS) | ||
@rm -f $(BIN) | ||
@rm -f $(ELF) | ||
|
||
clean_lib: | ||
@cd ../libopencm3/ && $(MAKE) clean | ||
|
||
write:$(ELF) | ||
openocd -f ../config/openocd.cfg -c "init" \ | ||
-c "reset halt" \ | ||
-c "flash probe 0" \ | ||
-c "flash protect 0 0 63 off" \ | ||
-c "reset halt" \ | ||
-c "stm32f1x mass_erase 0" \ | ||
-c "flash write_image stm32_firmware.elf" \ | ||
-c "reset run" \ | ||
-c "exit" | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,106 @@ | ||
/* | ||
* This file is part of the libopencm3 project. | ||
* | ||
* Copyright (C) 2009 Uwe Hermann <[email protected]> | ||
* | ||
* This library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This library 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* Generic linker script for STM32 targets using libopencm3. */ | ||
|
||
/* Memory regions must be defined in the ld script which includes this one. */ | ||
|
||
/* Enforce emmition of the vector table. */ | ||
EXTERN (vector_table) | ||
|
||
/* Define the entry point of the output file. */ | ||
ENTRY(reset_handler) | ||
|
||
/* Define sections. */ | ||
SECTIONS | ||
{ | ||
.text : { | ||
*(.vectors) /* Vector table */ | ||
*(.text*) /* Program code */ | ||
. = ALIGN(4); | ||
*(.rodata*) /* Read-only data */ | ||
. = ALIGN(4); | ||
} >rom | ||
|
||
/* C++ Static constructors/destructors, also used for __attribute__ | ||
* ((constructor)) and the likes */ | ||
.preinit_array : { | ||
. = ALIGN(4); | ||
__preinit_array_start = .; | ||
KEEP (*(.preinit_array)) | ||
__preinit_array_end = .; | ||
} >rom | ||
.init_array : { | ||
. = ALIGN(4); | ||
__init_array_start = .; | ||
KEEP (*(SORT(.init_array.*))) | ||
KEEP (*(.init_array)) | ||
__init_array_end = .; | ||
} >rom | ||
.fini_array : { | ||
. = ALIGN(4); | ||
__fini_array_start = .; | ||
KEEP (*(.fini_array)) | ||
KEEP (*(SORT(.fini_array.*))) | ||
__fini_array_end = .; | ||
} >rom | ||
|
||
/* | ||
* Another section used by C++ stuff, appears when using newlib with | ||
* 64bit (long long) printf support | ||
*/ | ||
.ARM.extab : { | ||
*(.ARM.extab*) | ||
} >rom | ||
.ARM.exidx : { | ||
__exidx_start = .; | ||
*(.ARM.exidx*) | ||
__exidx_end = .; | ||
} >rom | ||
|
||
. = ALIGN(4); | ||
_etext = .; | ||
|
||
.data : { | ||
_data = .; | ||
*(.data*) /* Read-write initialized data */ | ||
. = ALIGN(4); | ||
_edata = .; | ||
} >ram AT >rom | ||
_data_loadaddr = LOADADDR(.data); | ||
|
||
.bss : { | ||
*(.bss*) /* Read-write zero initialized data */ | ||
*(COMMON) | ||
. = ALIGN(4); | ||
_ebss = .; | ||
} >ram | ||
|
||
/* | ||
* The .eh_frame section appears to be used for C++ exception handling. | ||
* You may need to fix this if you're using C++. | ||
*/ | ||
/DISCARD/ : { *(.eh_frame) } | ||
|
||
. = ALIGN(4); | ||
end = .; | ||
} | ||
|
||
PROVIDE(_stack = ORIGIN(ram) + LENGTH(ram)); | ||
|
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,31 @@ | ||
/* | ||
* This file is part of the libopencm3 project. | ||
* | ||
* Copyright (C) 2015 Karl Palsson <[email protected]> | ||
* | ||
* This library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This library 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/* Linker script for STM32F103x8, 64k flash, 20k RAM. */ | ||
|
||
/* Define memory regions. */ | ||
MEMORY | ||
{ | ||
rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K | ||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K | ||
} | ||
|
||
/* Include the common ld script. */ | ||
INCLUDE linker/libopencm3_stm32f1.ld | ||
|
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,21 @@ | ||
#include <libopencm3/stm32/rcc.h> | ||
#include <libopencm3/stm32/gpio.h> | ||
#include "main.h" | ||
|
||
int main(void) | ||
{ | ||
int i; | ||
rcc_periph_clock_enable(RCC_GPIOC); | ||
|
||
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); | ||
|
||
while(1){ | ||
|
||
gpio_toggle(GPIOC, GPIO13); /* LED on/off */ | ||
for (i = 0; i < 400000; i++){ /* Wait a bit. */ | ||
__asm__("nop"); | ||
} | ||
|
||
} | ||
return 0; | ||
} |
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,5 @@ | ||
#ifndef __MAIN_H__ | ||
#define __MAIN_H__ | ||
|
||
|
||
#endif |