Skip to content

Commit 585a68b

Browse files
committed
started with the stm32f469
1 parent 55449df commit 585a68b

4 files changed

Lines changed: 311 additions & 0 deletions

File tree

targets/chip/stm32f469/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stm32f469.h
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# export our linkerscript
2+
set(TARGET_LINKERSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linkerscript.ld" PARENT_SCOPE)
3+
4+
# set the stm32f469 cpu options as a seperate target so the driver layer can link agains klib
5+
add_library(target_cpu_options INTERFACE)
6+
set_target_properties(target_cpu_options PROPERTIES FOLDER "klib")
7+
8+
# alias projectname::target_cpu_options to target_cpu_options
9+
add_library(${PROJECT_NAME}::target_cpu_options ALIAS target_cpu_options)
10+
11+
# include the arm directory for all the cmsis files
12+
target_include_directories(target_cpu_options INTERFACE ${CMAKE_SOURCE_DIR}/targets/arm/)
13+
14+
# set the cpu options for the compiler
15+
target_compile_options(target_cpu_options INTERFACE "-march=armv7e-m")
16+
target_compile_options(target_cpu_options INTERFACE "-mcpu=cortex-m4")
17+
target_compile_options(target_cpu_options INTERFACE "-mthumb")
18+
19+
# set the cpu options for the linker
20+
target_link_options(target_cpu_options INTERFACE "-march=armv7e-m")
21+
target_link_options(target_cpu_options INTERFACE "-mcpu=cortex-m4")
22+
target_link_options(target_cpu_options INTERFACE "-mthumb")
23+
24+
# other compiler settings
25+
target_compile_options(target_cpu_options INTERFACE "-Wno-attributes")
26+
target_compile_options(target_cpu_options INTERFACE "-fno-non-call-exceptions")
27+
target_compile_options(target_cpu_options INTERFACE "-fno-common")
28+
target_compile_options(target_cpu_options INTERFACE "-ffunction-sections")
29+
target_compile_options(target_cpu_options INTERFACE "-fdata-sections")
30+
target_compile_options(target_cpu_options INTERFACE "-fno-exceptions")
31+
target_compile_options(target_cpu_options INTERFACE "-fno-asynchronous-unwind-tables")
32+
33+
34+
# cpu stm32f469 target drivers
35+
set(SOURCES
36+
${CMAKE_CURRENT_SOURCE_DIR}/../../arm/vector_table/cortex-m4.cpp
37+
)
38+
39+
set(HEADERS_PRIVATE
40+
41+
)
42+
43+
set(HEADERS_PUBLIC
44+
45+
)
46+
47+
# add the target_cpu library
48+
add_library(target_cpu OBJECT
49+
${SOURCES}
50+
${HEADERS_PUBLIC}
51+
${HEADERS_PRIVATE}
52+
)
53+
set_target_properties(target_cpu PROPERTIES FOLDER "klib")
54+
55+
# alias projectname::target_cpu to target_cpu
56+
add_library(${PROJECT_NAME}::target_cpu ALIAS target_cpu)
57+
58+
# enable C++20 support for the library
59+
target_compile_features(target_cpu PUBLIC cxx_std_20)
60+
61+
# set the target_cpu for klib
62+
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME)
63+
set(TARGET_CPU ${TARGET_CPU_FOLDER} PARENT_SCOPE)
64+
target_compile_definitions(target_cpu PUBLIC "TARGET_CPU=${TARGET_CPU}")
65+
66+
# add target specific compile options
67+
target_compile_options(target_cpu PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-Wno-volatile>)
68+
69+
# link to klib and target_cpu_options
70+
target_link_libraries(target_cpu PUBLIC target_cpu_options)
71+
target_link_libraries(target_cpu PUBLIC klib)
72+
73+
# Global includes. Used by all targets
74+
# Note:
75+
# - header can be included by C++ code `#include <target/target.hpp>`
76+
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
77+
target_include_directories(
78+
target_cpu PUBLIC
79+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
80+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
81+
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
82+
)
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
SEARCH_DIR(.);
2+
3+
/*
4+
Format configurations
5+
*/
6+
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm");
7+
OUTPUT_ARCH(arm);
8+
9+
10+
/*
11+
The stack size used by the application. NOTE: you need to adjust according to your application.
12+
*/
13+
STACK_SIZE = 0x2000;
14+
15+
/*
16+
Memories definitions
17+
*/
18+
MEMORY
19+
{
20+
rom (rx) : org = 0x00000000, len = 2m
21+
ccm (rwx) : org = 0x10000000, len = 64k
22+
/* ram0, ram1 and ram2 in one continuous block */
23+
ram0 (rwx) : org = 0x20000000, len = 320k
24+
/* ram1 (rwx) : org = 0x20028000, len = 32k */
25+
/* ram2 (rwx) : org = 0x20030000, len = 128k */
26+
27+
/* fmc memory regions, len is the maximum. Not the actual size */
28+
fmc0 (rwx) : org = 0x60000000, len = 512m
29+
fmc1 (rwx) : org = 0x80000000, len = 512m
30+
fmc2 (rwx) : org = 0xa0000000, len = 512m
31+
fmc3 (rwx) : org = 0xd0000000, len = 512m
32+
}
33+
34+
/*
35+
Entry point
36+
*/
37+
ENTRY( __reset_handler );
38+
39+
/*
40+
Sections
41+
*/
42+
SECTIONS
43+
{
44+
/* Vector table. Has the initial stack pointer and the initial
45+
structure for the arm interrupts */
46+
VECTORS() > rom
47+
48+
/* Text segment, stores all user code */
49+
.text (READONLY) :
50+
{
51+
. = ALIGN(4);
52+
/* text segment */
53+
*(.text .text.* .gnu.linkonce.t.*);
54+
/* glue arm to thumb code, glue thumb to arm code*/
55+
*(.glue_7t .glue_7);
56+
/* c++ exceptions */
57+
*(.eh_frame .eh_frame_hdr)
58+
/* exception unwinding information */
59+
60+
. = ALIGN(4);
61+
*(.ARM.extab* .gnu.linkonce.armextab.*);
62+
*(.ARM.exidx*)
63+
64+
. = ALIGN(4);
65+
KEEP(*(.init));
66+
. = ALIGN(4);
67+
KEEP(*(.fini));
68+
69+
. = ALIGN(4);
70+
} > rom
71+
72+
/* Read only data */
73+
RODATA() > rom
74+
75+
/* Support C constructors, and C destructors in both user code
76+
and the C library. This also provides support for C++ code. */
77+
CONSTRUCTOR_SECTION(preinit_array) > rom
78+
CONSTRUCTOR_SECTION(init_array) > rom
79+
CONSTRUCTOR_SECTION(fini_array) > rom
80+
81+
/* Stack segment */
82+
STACK(STACK_SIZE) > ram0
83+
84+
/* Data that needs to be initialized to a value different than 0 */
85+
.data :
86+
{
87+
. = ALIGN(4);
88+
PROVIDE(__data_init_start = LOADADDR(.data));
89+
PROVIDE(__data_start = .);
90+
91+
. = ALIGN(4);
92+
*(SORT_BY_ALIGNMENT(.data))
93+
*(SORT_BY_ALIGNMENT(.data.*))
94+
*(SORT_BY_ALIGNMENT(.gnu.linkonce.d.*))
95+
. = ALIGN(4);
96+
97+
PROVIDE(__data_end = .);
98+
PROVIDE(__data_init_end = LOADADDR(.data));
99+
} > ram0 AT > rom
100+
101+
/* Data that needs to be initialized to 0 */
102+
.bss (NOLOAD) :
103+
{
104+
. = ALIGN(4);
105+
PROVIDE(__bss_start = .);
106+
107+
*(SORT_BY_ALIGNMENT(.bss))
108+
*(SORT_BY_ALIGNMENT(.bss.*))
109+
*(SORT_BY_ALIGNMENT(.gnu.linkonce.b.*))
110+
*(COMMON);
111+
. = ALIGN(4);
112+
113+
PROVIDE(__bss_end = .);
114+
} > ram0
115+
116+
/* fmc memory */
117+
DATA_SECTION(fmc0, fmc0, rom)
118+
DATA_SECTION(fmc1, fmc1, rom)
119+
DATA_SECTION(fmc2, fmc2, rom)
120+
DATA_SECTION(fmc3, fmc3, rom)
121+
BSS_SECTION(fmc0, fmc0)
122+
BSS_SECTION(fmc1, fmc1)
123+
BSS_SECTION(fmc2, fmc2)
124+
BSS_SECTION(fmc3, fmc3)
125+
126+
/* create a table to initialize the data sections on a secondary memory */
127+
DATA_MULTISECTION_TABLE(
128+
DATA_SECTION_ENTRY(fmc0)
129+
DATA_SECTION_ENTRY(fmc1)
130+
DATA_SECTION_ENTRY(fmc2)
131+
DATA_SECTION_ENTRY(fmc3)
132+
DATA_SECTION_ENTRY_END()
133+
) > rom
134+
135+
/* create a table to initialize the bss sections on a secondary memory */
136+
BSS_MULTISECTION_TABLE(
137+
BSS_SECTION_ENTRY(fmc0)
138+
BSS_SECTION_ENTRY(fmc1)
139+
BSS_SECTION_ENTRY(fmc2)
140+
BSS_SECTION_ENTRY(fmc3)
141+
BSS_SECTION_ENTRY_END()
142+
) > rom
143+
144+
/* Heap segment */
145+
.heap (NOLOAD) :
146+
{
147+
. = ALIGN(4);
148+
PROVIDE(__heap_start = .);
149+
PROVIDE(__heap_end = (ORIGIN(ram0) + LENGTH(ram0)));
150+
} > ram0
151+
152+
/* Remove information from the standard libraries */
153+
/DISCARD/ :
154+
{
155+
libc.a ( * )
156+
libm.a ( * )
157+
libgcc.a ( * )
158+
*(.note.GNU-stack)
159+
}
160+
161+
.ARM.attributes 0 : { KEEP(*(.ARM.attributes)) }
162+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#ifndef KLIB_STM32F469_HPP
2+
#define KLIB_STM32F469_HPP
3+
4+
#include <klib/irq.hpp>
5+
6+
#include "stm32f469.h"
7+
8+
namespace klib::stm32f469 {
9+
// irq for the stm32f469
10+
using irq = klib::irq::KLIB_IRQ<0, 16 + 93>;
11+
12+
/**
13+
* @brief Get the current cpu id
14+
*
15+
* @return uint32_t
16+
*/
17+
static uint32_t get_cpu_id() {
18+
// NOTE: this mcu only has 1 core. So we always
19+
// return id 0
20+
return 0;
21+
}
22+
23+
/**
24+
* @brief Enable a interrupt
25+
*
26+
* @tparam Irq
27+
*/
28+
template <uint32_t Irq>
29+
static void enable_irq() {
30+
static_assert(Irq >= static_cast<uint32_t>(irq::arm_vector::count), "Invalid IRQ given to enable");
31+
32+
// enable the irq
33+
NVIC_EnableIRQ(static_cast<IRQn_Type>(Irq - static_cast<uint32_t>(irq::arm_vector::count)));
34+
}
35+
36+
/**
37+
* @brief Disable a interrupt
38+
*
39+
* @tparam Irq
40+
*/
41+
template <uint32_t Irq>
42+
static void disable_irq() {
43+
static_assert(Irq >= static_cast<uint32_t>(irq::arm_vector::count), "Invalid IRQ given to disable");
44+
45+
// disable the irq
46+
NVIC_DisableIRQ(static_cast<IRQn_Type>(Irq - static_cast<uint32_t>(irq::arm_vector::count)));
47+
}
48+
49+
/**
50+
* @brief Global enable interrupts.
51+
*
52+
*/
53+
static void enable_irq() {
54+
__enable_irq();
55+
}
56+
57+
/**
58+
* @brief Global disable interrupts. Prevents any interrupt from triggering
59+
*
60+
*/
61+
static void disable_irq() {
62+
__disable_irq();
63+
}
64+
}
65+
66+
#endif

0 commit comments

Comments
 (0)