Skip to content

Commit 43c7050

Browse files
Tavish Narukantavish
authored andcommitted
hal: add startup code for TMS570LC43
Adds soc init code including MPU configuration and PLL errata handling for the TI Hercules family SoC TMS570LC43xx. Portions of this code were taken or adapter from Halcogen code generator. This HAL is not really complete, as the currently implemented drivers do not depend on Halcogen and so were not needed. Signed-off-by: Tavish Naruka <t-naruka@ispace-inc.com>
1 parent 391f7cb commit 43c7050

File tree

6 files changed

+903
-0
lines changed

6 files changed

+903
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
add_subdirectory(simplelink)
22
add_subdirectory(simplelink_lpf3)
33
add_subdirectory(mspm0)
4+
add_subdirectory(hercules/tms570lc43)

hercules/tms570lc43/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
if(CONFIG_HAS_TMS570_HALCOGEN_CODE)
2+
zephyr_include_directories(
3+
include
4+
)
5+
6+
zephyr_library()
7+
zephyr_library_compile_definitions(${COMPILER})
8+
zephyr_library_sources(
9+
source/soc_init.c
10+
source/asm_funcs.S
11+
source/soc_pll_errata.c
12+
)
13+
endif()

hercules/tms570lc43/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Halcogen exported code for TMS570LC43xx MCU
2+
===========================================
3+
4+
There is no HAL available from TI to download and include for TMS570
5+
or hercules series per se, we have code generated by their tool Halcogen
6+
fo this family if chips.
7+
8+
This directory contains code exported and adapted from that, and the
9+
reason to include it here is simply due to licensing of the said code.
10+
11+
The modifications are mainly to make the code less verbose while still
12+
mostly keeping it similar. The assembly portions in particular are
13+
mostly as is.
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-3-Clause
3+
*
4+
* Copyright (C) 2025 ispace, inc.
5+
*
6+
* Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com
7+
*
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions
11+
* are met:
12+
*
13+
* Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
*
16+
* Redistributions in binary form must reproduce the above copyright
17+
* notice, this list of conditions and the following disclaimer in the
18+
* documentation and/or other materials provided with the
19+
* distribution.
20+
*
21+
* Neither the name of Texas Instruments Incorporated nor the names of
22+
* its contributors may be used to endorse or promote products derived
23+
* from this software without specific prior written permission.
24+
*
25+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
*/
38+
39+
#include <zephyr/linker/sections.h>
40+
#include <zephyr/toolchain.h>
41+
#include <zephyr/arch/cpu.h>
42+
43+
/* Exports */
44+
GTEXT(_mpuInit_)
45+
GTEXT(soc_reset_hook)
46+
47+
#define MINITGCR =#0xFFFFFF5C
48+
#define MSIENA =#0xFFFFFF60
49+
#define MSTCGSTAT =#0xFFFFFF68
50+
51+
#define r1Base =#0x00000000
52+
#define r2Base =#0x00000000
53+
#define r3Base =#0x08000000
54+
#define r4Base =#0xF8000000
55+
#define r5Base =#0x60000000
56+
#define r6Base =#0x80000000
57+
#define r7Base =#0xF0000000
58+
#define r8Base =#0x00000000
59+
#define r9Base =#0x00000000
60+
#define r10Base =#0x00000000
61+
#define r11Base =#0x00000000
62+
#define r12Base =#0x00000000
63+
#define r13Base =#0x00000000
64+
#define r14Base =#0x00000000
65+
#define r15Base =#0x00000000
66+
#define r16Base =#0xFFF80000
67+
68+
/**
69+
* initialise memory areas (adapted from _memInit_ generated by Halcogen)
70+
* NOTE: do not use callee saved registers
71+
*/
72+
SECTION_FUNC(TEXT, soc_reset_hook)
73+
ldr r12, MINITGCR /* Load MINITGCR register address */
74+
mov r10, #0xA
75+
str r10, [r12] /* Enable global memory hardware initialization */
76+
77+
ldr r11, MSIENA /* Load MSIENA register address */
78+
mov r10, #0x1 /* Bit position 0 of MSIENA corresponds to SRAM */
79+
str r10, [r11] /* Enable auto hardware initalisation for SRAM */
80+
mloop: /* Loop till memory hardware initialization comletes */
81+
ldr r9, MSTCGSTAT /* check MSTCGSTAT */
82+
ldr r10, [r9]
83+
tst r10, #0x100
84+
beq mloop
85+
86+
ldr r11, MSIENA /* Load MSIENA register address */
87+
mov r10, #0x4 /* Bit position 2 of MSIENA corresponds to VIM RAM */
88+
str r10, [r11] /* Enable auto hardware initalisation for VIM RAM */
89+
mloop2: /* Loop till memory hardware initialization comletes */
90+
ldr r9, MSTCGSTAT /* check MSTCGSTAT */
91+
ldr r10, [r9]
92+
tst r10, #0x100
93+
beq mloop2
94+
95+
mov r10, #5
96+
str r10, [r12] /* Disable global memory hardware initialization */
97+
98+
/* now stack is usable */
99+
push {lr}
100+
bl soc_platform_init
101+
pop {lr}
102+
103+
bx lr
104+
105+
SECTION_FUNC(TEXT, _mpuInit_)
106+
/* Disable mpu */
107+
mrc p15, #0, r0, c1, c0, #0
108+
bic r0, r0, #1
109+
dsb
110+
mcr p15, #0, r0, c1, c0, #0
111+
isb
112+
/* Disable background region */
113+
mrc p15, #0, r0, c1, c0, #0
114+
bic r0, r0, #0x20000
115+
mcr p15, #0, r0, c1, c0, #0
116+
/* Setup region 1 */
117+
mov r0, #0
118+
mcr p15, #0, r0, c6, c2, #0
119+
ldr r0, r1Base
120+
mcr p15, #0, r0, c6, c1, #0
121+
mov r0, #0x0008
122+
orr r0, r0, #0x1000
123+
mcr p15, #0, r0, c6, c1, #4
124+
movw r0, #((1 << 15) + (1 << 14) + (1 << 13) + (1 << 12) + (1 << 11) + (1 << 10) + (1 << 9) + (1 << 8) + (0x1F << 1) + (1))
125+
mcr p15, #0, r0, c6, c1, #2
126+
/* Setup region 2 */
127+
mov r0, #1
128+
mcr p15, #0, r0, c6, c2, #0
129+
ldr r0, r2Base
130+
mcr p15, #0, r0, c6, c1, #0
131+
/* non cached flash */
132+
mov r0, #0x000C
133+
/* cached flash */
134+
/* mov r0, #0x0002 */
135+
orr r0, r0, #0x0600
136+
mcr p15, #0, r0, c6, c1, #4
137+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x15 << 1) + (1))
138+
mcr p15, #0, r0, c6, c1, #2
139+
/* Setup region 3 */
140+
mov r0, #2
141+
mcr p15, #0, r0, c6, c2, #0
142+
ldr r0, r3Base
143+
mcr p15, #0, r0, c6, c1, #0
144+
mov r0, #0x000B
145+
orr r0, r0, #0x1300
146+
mcr p15, #0, r0, c6, c1, #4
147+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x12 << 1) + (1))
148+
mcr p15, #0, r0, c6, c1, #2
149+
/* Setup region 4 */
150+
mov r0, #3
151+
mcr p15, #0, r0, c6, c2, #0
152+
ldr r0, r4Base
153+
mcr p15, #0, r0, c6, c1, #0
154+
mov r0, #0x0010
155+
orr r0, r0, #0x1300
156+
mcr p15, #0, r0, c6, c1, #4
157+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (1 << 10) + (1 << 9) + (1 << 8) + (0x1A << 1) + (1))
158+
mcr p15, #0, r0, c6, c1, #2
159+
/* Setup region 5 */
160+
mov r0, #4
161+
mcr p15, #0, r0, c6, c2, #0
162+
ldr r0, r5Base
163+
mcr p15, #0, r0, c6, c1, #0
164+
mov r0, #0x0000
165+
orr r0, r0, #0x0300
166+
mcr p15, #0, r0, c6, c1, #4
167+
movw r0, #((1 << 15) + (1 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x1B << 1) + (1))
168+
mcr p15, #0, r0, c6, c1, #2
169+
/* Setup region 6 */
170+
mov r0, #5
171+
mcr p15, #0, r0, c6, c2, #0
172+
ldr r0, r6Base
173+
mcr p15, #0, r0, c6, c1, #0
174+
mov r0, #0x0006
175+
orr r0, r0, #0x0300
176+
mcr p15, #0, r0, c6, c1, #4
177+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x1A << 1) + (1))
178+
mcr p15, #0, r0, c6, c1, #2
179+
/* Setup region 7 */
180+
mov r0, #6
181+
mcr p15, #0, r0, c6, c2, #0
182+
ldr r0, r7Base
183+
mcr p15, #0, r0, c6, c1, #0
184+
mov r0, #0x0008
185+
orr r0, r0, #0x1200
186+
mcr p15, #0, r0, c6, c1, #4
187+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x16 << 1) + (1))
188+
mcr p15, #0, r0, c6, c1, #2
189+
/* Setup region 8 */
190+
mov r0, #7
191+
mcr p15, #0, r0, c6, c2, #0
192+
ldr r0, r8Base
193+
mcr p15, #0, r0, c6, c1, #0
194+
mov r0, #0x0010
195+
orr r0, r0, #0x1200
196+
mcr p15, #0, r0, c6, c1, #4
197+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x04 << 1) + (0))
198+
mcr p15, #0, r0, c6, c1, #2
199+
/* Setup region 9 */
200+
mov r0, #8
201+
mcr p15, #0, r0, c6, c2, #0
202+
ldr r0, r9Base
203+
mcr p15, #0, r0, c6, c1, #0
204+
mov r0, #0x0006
205+
orr r0, r0, #0x1200
206+
mcr p15, #0, r0, c6, c1, #4
207+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x04 << 1) + (0))
208+
mcr p15, #0, r0, c6, c1, #2
209+
/* Setup region 10 */
210+
mov r0, #9
211+
mcr p15, #0, r0, c6, c2, #0
212+
ldr r0, r10Base
213+
mcr p15, #0, r0, c6, c1, #0
214+
mov r0, #0x000C
215+
orr r0, r0, #0x1300
216+
mcr p15, #0, r0, c6, c1, #4
217+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x04 << 1) + (0))
218+
mcr p15, #0, r0, c6, c1, #2
219+
/* Setup region 11 */
220+
mov r0, #10
221+
mcr p15, #0, r0, c6, c2, #0
222+
ldr r0, r11Base
223+
mcr p15, #0, r0, c6, c1, #0
224+
mov r0, #0x0006
225+
orr r0, r0, #0x0600
226+
mcr p15, #0, r0, c6, c1, #4
227+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x04 << 1) + (0))
228+
mcr p15, #0, r0, c6, c1, #2
229+
/* Setup region 12 */
230+
mov r0, #11
231+
mcr p15, #0, r0, c6, c2, #0
232+
ldr r0, r12Base
233+
mcr p15, #0, r0, c6, c1, #0
234+
mov r0, #0x0006
235+
orr r0, r0, #0x1600
236+
mcr p15, #0, r0, c6, c1, #4
237+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x04 << 1) + (0))
238+
mcr p15, #0, r0, c6, c1, #2
239+
/* Setup region 13 */
240+
mov r0, #12
241+
mcr p15, #0, r0, c6, c2, #0
242+
ldr r0, r13Base
243+
mcr p15, #0, r0, c6, c1, #0
244+
mov r0, #0x0006
245+
orr r0, r0, #0x1600
246+
mcr p15, #0, r0, c6, c1, #4
247+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x04 << 1) + (0))
248+
mcr p15, #0, r0, c6, c1, #2
249+
/* Setup region 14 */
250+
mov r0, #13
251+
mcr p15, #0, r0, c6, c2, #0
252+
ldr r0, r14Base
253+
mcr p15, #0, r0, c6, c1, #0
254+
mov r0, #0x0006
255+
orr r0, r0, #0x1600
256+
mcr p15, #0, r0, c6, c1, #4
257+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x04 << 1) + (0))
258+
mcr p15, #0, r0, c6, c1, #2
259+
/* Setup region 15 */
260+
mov r0, #14
261+
mcr p15, #0, r0, c6, c2, #0
262+
ldr r0, r15Base
263+
mcr p15, #0, r0, c6, c1, #0
264+
mov r0, #0x0006
265+
orr r0, r0, #0x1600
266+
mcr p15, #0, r0, c6, c1, #4
267+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x04 << 1) + (0))
268+
mcr p15, #0, r0, c6, c1, #2
269+
/* Setup region 16 */
270+
mov r0, #15
271+
mcr p15, #0, r0, c6, c2, #0
272+
ldr r0, r16Base
273+
mcr p15, #0, r0, c6, c1, #0
274+
mov r0, #0x0010
275+
orr r0, r0, #0x1200
276+
mcr p15, #0, r0, c6, c1, #4
277+
movw r0, #((0 << 15) + (0 << 14) + (0 << 13) + (0 << 12) + (0 << 11) + (0 << 10) + (0 << 9) + (0 << 8) + (0x12 << 1) + (1))
278+
mcr p15, #0, r0, c6, c1, #2
279+
280+
/* Enable mpu */
281+
mrc p15, #0, r0, c1, c0, #0
282+
orr r0, r0, #1
283+
dsb
284+
mcr p15, #0, r0, c1, c0, #0
285+
isb
286+
bx lr

0 commit comments

Comments
 (0)