Skip to content

Commit 14f65bb

Browse files
committed
added target lpc1754
1 parent cf48f41 commit 14f65bb

File tree

22 files changed

+1691
-1
lines changed

22 files changed

+1691
-1
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
strategy:
2121
matrix:
22-
cpu: [atsam3x8e, atsam4s2b, lpc802, lpc1752, lpc1756, lpc1759, lpc1788, lpc55s66, max32625, max32660, mb9bf566k, stm32f103, stm32f407, stm32h723, tmpm373]
22+
cpu: [atsam3x8e, atsam4s2b, lpc802, lpc1752, lpc1754, lpc1756, lpc1759, lpc1788, lpc55s66, max32625, max32660, mb9bf566k, stm32f103, stm32f407, stm32h723, tmpm373]
2323

2424
steps:
2525
- uses: actions/checkout@v4

targets/chip/lpc1754/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lpc1754.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 lpc1754 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=armv7-m")
16+
target_compile_options(target_cpu_options INTERFACE "-mcpu=cortex-m3")
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=armv7-m")
21+
target_link_options(target_cpu_options INTERFACE "-mcpu=cortex-m3")
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 lpc1754 target drivers
35+
set(SOURCES
36+
${CMAKE_CURRENT_SOURCE_DIR}/../../arm/vector_table/cortex-m3.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+
)

targets/chip/lpc1754/io/can.hpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#ifndef KLIB_LPC1754_CAN_HPP
2+
#define KLIB_LPC1754_CAN_HPP
3+
4+
#include <cstdint>
5+
6+
#include <targets/core/nxp/lpc175x/can.hpp>
7+
#include "pins.hpp"
8+
9+
namespace klib::lpc1754::io::periph::detail::can {
10+
enum class mode {
11+
rd,
12+
td,
13+
};
14+
15+
template <typename Pin, mode Type, typename Periph>
16+
struct can {
17+
// pin of the peripheral
18+
using pin = Pin;
19+
20+
// type of the pin
21+
constexpr static mode type = Type;
22+
23+
// alternate function
24+
using periph = Periph;
25+
};
26+
}
27+
28+
namespace klib::lpc1754::io::periph::lqfp_80 {
29+
template <
30+
typename Td = pins::package::lqfp_80::p38
31+
>
32+
struct can0 {
33+
// peripheral id (e.g can0, can1)
34+
constexpr static uint32_t id = 0;
35+
36+
// peripheral clock bit position
37+
constexpr static uint32_t clock_id = 13;
38+
39+
// interrupt id (including the arm vector table)
40+
constexpr static uint32_t interrupt_id = 41;
41+
42+
// port to the CAN hardware
43+
static inline CAN1_Type *const port = CAN1;
44+
45+
// amount of hardware buffers for transmitting data
46+
constexpr static uint32_t tx_buffers = 3;
47+
48+
// pins allowed per output pin. Used for determining if a pin is valid on compile time
49+
using td_pins = std::tuple<
50+
detail::can::can<pins::package::lqfp_80::p38, detail::can::mode::td, core::lpc175x::io::detail::alternate::func_1>,
51+
detail::can::can<pins::package::lqfp_80::p44, detail::can::mode::td, core::lpc175x::io::detail::alternate::func_3>
52+
>;
53+
54+
// pin configuration. Uses above mapping ()
55+
using rd = detail::can::can<pins::package::lqfp_80::p37, detail::can::mode::rd, core::lpc175x::io::detail::alternate::func_1>;
56+
using td = std::tuple_element<klib::io::peripheral::get_index<Td, td_pins>(), td_pins>::type;
57+
};
58+
59+
struct can1 {
60+
// peripheral id (e.g can0, can1)
61+
constexpr static uint32_t id = 1;
62+
63+
// peripheral clock bit position
64+
constexpr static uint32_t clock_id = 14;
65+
66+
// interrupt id (including the arm vector table)
67+
constexpr static uint32_t interrupt_id = 41;
68+
69+
// port to the CAN hardware
70+
static inline CAN1_Type *const port = CAN2;
71+
72+
// amount of hardware buffers for transmitting data
73+
constexpr static uint32_t tx_buffers = 3;
74+
75+
// P2.7 and P2.8 (80 pin package does not have the following so only 1 configuration for can1)
76+
using rd = detail::can::can<pins::package::lqfp_80::p51, detail::can::mode::rd, core::lpc175x::io::detail::alternate::func_1>;
77+
using td = detail::can::can<pins::package::lqfp_80::p50, detail::can::mode::td, core::lpc175x::io::detail::alternate::func_1>;
78+
};
79+
}
80+
81+
namespace klib::lpc1754::io {
82+
/**
83+
* @brief lpc1754 can driver
84+
*
85+
* @tparam Can
86+
* @tparam CanTxBuffers amount of tx hardware buffers used. Can help
87+
* when a protocol needs a specific order of messages
88+
*/
89+
template <typename Can, uint32_t CanTxBuffers = Can::tx_buffers>
90+
using can = core::lpc175x::io::can<Can, CanTxBuffers>;
91+
}
92+
93+
#endif

targets/chip/lpc1754/io/clocks.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef KLIB_LPC1754_CLOCKS_HPP
2+
#define KLIB_LPC1754_CLOCKS_HPP
3+
4+
#include <targets/core/nxp/lpc175x/clocks.hpp>
5+
6+
namespace klib::lpc1754::io {
7+
using clocks = klib::core::lpc175x::io::clocks;
8+
}
9+
10+
#endif

targets/chip/lpc1754/io/dma.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef KLIB_LPC1754_DMA_HPP
2+
#define KLIB_LPC1754_DMA_HPP
3+
4+
#include <array>
5+
6+
#include <targets/core/nxp/lpc175x/dma.hpp>
7+
8+
namespace klib::lpc1754::io::periph {
9+
struct dma0 {
10+
// peripheral id (e.g dma0, dma1)
11+
constexpr static uint32_t id = 0;
12+
13+
// interrupt id (including the arm vector table)
14+
constexpr static uint32_t interrupt_id = 42;
15+
16+
// peripheral clock bit position
17+
constexpr static uint32_t clock_id = 29;
18+
19+
// port to the GPDMA hardware
20+
static inline GPDMA_Type *const port = GPDMA;
21+
22+
// available channels in the dma
23+
constexpr static uint32_t max_channels = 8;
24+
};
25+
}
26+
27+
namespace klib::lpc1754::io {
28+
template <typename Dma>
29+
using dma = core::lpc175x::io::dma<Dma>;
30+
31+
template <typename Dma, uint8_t Channel, typename Source, typename Destination>
32+
using dma_channel = core::lpc175x::io::dma_channel<Dma, Channel, Source, Destination>;
33+
}
34+
35+
#endif

targets/chip/lpc1754/io/flash.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef KLIB_LPC1754_FLASH_HPP
2+
#define KLIB_LPC1754_FLASH_HPP
3+
4+
#include <cstdint>
5+
6+
#include <targets/core/nxp/lpc17xx/flash.hpp>
7+
8+
namespace klib::lpc1754::io {
9+
using flash = core::lpc17xx::io::flash;
10+
}
11+
12+
#endif

targets/chip/lpc1754/io/i2c.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef KLIB_LPC1754_I2C_HPP
2+
#define KLIB_LPC1754_I2C_HPP
3+
4+
#include <cstdint>
5+
6+
#include <lpc1754.hpp>
7+
8+
namespace klib::lpc1754::io::periph {
9+
struct i2c0 {
10+
// peripheral id (e.g i2c0, i2c1)
11+
constexpr static uint32_t id = 0;
12+
13+
// interrupt id (including the arm vector table)
14+
constexpr static uint32_t interrupt_id = 26;
15+
16+
// port to the I2C hardware
17+
static inline I2C0_Type *const port = I2C0;
18+
};
19+
20+
struct i2c1 {
21+
// peripheral id (e.g i2c0, i2c1)
22+
constexpr static uint32_t id = 1;
23+
24+
// interrupt id (including the arm vector table)
25+
constexpr static uint32_t interrupt_id = 27;
26+
27+
// port to the I2C hardware
28+
static inline I2C0_Type *const port = I2C1;
29+
};
30+
31+
struct i2c2 {
32+
// peripheral id (e.g i2c0, i2c1)
33+
constexpr static uint32_t id = 2;
34+
35+
// interrupt id (including the arm vector table)
36+
constexpr static uint32_t interrupt_id = 28;
37+
38+
// port to the I2C hardware
39+
static inline I2C0_Type *const port = I2C2;
40+
};
41+
}
42+
43+
#endif

0 commit comments

Comments
 (0)