1 /*
2 *
3 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
37 //----------------------------------------------------------------------------
38 // Purpose: Prepare the AM335x SOC so CCS can connect to the PRU as if it were
39 // any other standalone CPU.
40 //
41 // This script is only intended to be used as described in
42 // http://processors.wiki.ti.com/index.php/PRU-ICSS_Debug_on_AM335x
43 // In particular, it does NOT WORK as a standalone script.
44 //
45 // Presumptions:
46 // - Target system is BeagleBone Black or BeagleBone White
47 // - The target configuration has launched
48 // - PRU connection occurs after this script runs
49 //----------------------------------------------------------------------------
51 //----------------------------------------------------------------------------
52 // Constants
53 //----------------------------------------------------------------------------
54 var AM335X_INPUT_EN = 1 << 5;
55 var AM335X_PULL_DISA = 1 << 3;
56 var AM335X_PIN_OUTPUT = AM335X_PULL_DISA;
57 var AM335X_PIN_INPUT = AM335X_INPUT_EN | AM335X_PULL_DISA;
59 //----------------------------------------------------------------------------
60 // Invoke the main function in this file
61 //----------------------------------------------------------------------------
62 startup_pru();
64 //****************************************************************************
65 // STARTUP_PRU
66 //****************************************************************************
67 function startup_pru()
68 {
69 var errCode = 0;
71 //-------------------------------------------------------------------------
72 // Import the DSS packages into our namespace to save on typing
73 //-------------------------------------------------------------------------
74 importPackage(Packages.com.ti.debug.engine.scripting);
75 importPackage(Packages.com.ti.ccstudio.scripting.environment);
76 importPackage(Packages.java.lang);
78 //-------------------------------------------------------------------------
79 // Create our scripting environment object - which is the main entry
80 // point into any script and the factory for creating other Scriptable
81 // servers and Sessions
82 //-------------------------------------------------------------------------
83 script = ScriptingEnvironment.instance();
85 //-------------------------------------------------------------------------
86 // Get the Debug Server and start a Debug Session
87 //-------------------------------------------------------------------------
88 debugServer = script.getServer("DebugServer.1");
90 //-------------------------------------------------------------------------
91 // Open a session on the Debug Access Port (DAP)
92 //-------------------------------------------------------------------------
93 var debugSessionDAP = debugServer.openSession("*", "CS_DAP_M3");
95 //-------------------------------------------------------------------------
96 // Connect to the DAP. Error check.
97 //-------------------------------------------------------------------------
98 print("Connecting to DAP");
99 try
100 {
101 debugSessionDAP.target.connect();
102 }
103 catch (ex)
104 {
105 throw "Aborting!";
106 }
108 //-------------------------------------------------------------------------
109 // Init steps for PRU carried out by the DAP
110 //-------------------------------------------------------------------------
111 print("Enabling JTAG clock");
112 debugSessionDAP.expression.evaluate(
113 "*((unsigned int*) 0x44e00414 ) |= 0x02;");
115 print("Configuring PRU pins");
116 PRU_PINMUX_Config(debugSessionDAP.memory);
118 print("Enabling ICSS clock");
119 debugSessionDAP.expression.evaluate(
120 "*((unsigned int*) 0x44e00140 ) = 0x02;");
121 debugSessionDAP.expression.evaluate(
122 "*((unsigned int*) 0x44E000E8 ) = 0x02;");
124 print("Resetting ICSS");
125 debugSessionDAP.expression.evaluate(
126 "*((unsigned int*) 0x44E00C00 ) |= 0x2;");
127 debugSessionDAP.expression.evaluate(
128 "*((unsigned int*) 0x44E00C00 ) &= ~0x2;");
130 print("Done");
131 }
133 //****************************************************************************
134 // PRU_PINMUX_Config
135 //****************************************************************************
136 function PRU_PINMUX_Config(dsDAP_mem)
137 {
138 // GEL_TextOut("****** PRU Cape GPI/O PINMUX is being configured ***** \n","Output",1,1,1);
140 //-------------------------------------------------------------------------
141 // LEDS
142 //-------------------------------------------------------------------------
143 //red led = pru0 r30_3 ARM pin c12
144 dsDAP_mem.writeData(0, 0x44e1099c, AM335X_PIN_OUTPUT | 5, 32); //mode 5
146 //green led = pru0 r30_2 arm pin d12
147 dsDAP_mem.writeData(0, 0x44e10998, AM335X_PIN_OUTPUT | 5, 32); //mode 5
149 //blue led = pru0 r30_0 arm pin a13
150 dsDAP_mem.writeData(0, 0x44e10990, AM335X_PIN_OUTPUT | 5, 32); //mode 5
152 //orange led = pru0 r30_1 arm pin b13
153 dsDAP_mem.writeData(0, 0x44e10994, AM335X_PIN_OUTPUT | 5, 32); //mode 5
155 //RGB_0 led = pru1 r30_2 arm pin r3
156 dsDAP_mem.writeData(0, 0x44e108AC, AM335X_PIN_OUTPUT | 5, 32); //mode 5
158 //RGB_1 led = pru1 r30_3 arm pin r4
159 dsDAP_mem.writeData(0, 0x44e108B0, AM335X_PIN_OUTPUT | 5, 32); //mode 5
161 //RGB_2 led = pru0 r30_4 arm pin t1
162 dsDAP_mem.writeData(0, 0x44e108B4, AM335X_PIN_OUTPUT | 5, 32); //mode 5
164 //-------------------------------------------------------------------------
165 // Switches
166 //-------------------------------------------------------------------------
167 //switch 1 = pru0 r31_5 c13
168 dsDAP_mem.writeData(0, 0x44e109a4, AM335X_PIN_INPUT | 6, 32); //mode 6
170 //switch 2 = pru0 r31_7 a14
171 dsDAP_mem.writeData(0, 0x44e109ac, AM335X_PIN_INPUT | 6, 32); //mode 6
173 //-------------------------------------------------------------------------
174 // Audio
175 //-------------------------------------------------------------------------
176 //audio data pr1 r30_0 r1
177 dsDAP_mem.writeData(0, 0x44e108a0, AM335X_PIN_OUTPUT | 5, 32); //mode 5
179 //audio clk pr1 r30_1 r2
180 dsDAP_mem.writeData(0, 0x44e108a4, AM335X_PIN_OUTPUT | 5, 32); //mode 5
182 //audio sync pr1 r30_2 r3
183 dsDAP_mem.writeData(0, 0x44e108a8, AM335X_PIN_OUTPUT | 5, 32); //mode 5
185 //-------------------------------------------------------------------------
186 // UART
187 //-------------------------------------------------------------------------
188 //Uart txd d15
189 dsDAP_mem.writeData(0, 0x44e10984, AM335X_PIN_OUTPUT | 5, 32); //mode 5
191 //UART rxd d16
192 dsDAP_mem.writeData(0, 0x44e10980, AM335X_PIN_INPUT | 5, 32); //mode 5
194 //UART rts b17
195 dsDAP_mem.writeData(0, 0x44e1097C, AM335X_PIN_OUTPUT | 5, 32); //mode 5
197 //UART cts a17
198 dsDAP_mem.writeData(0, 0x44e10978, AM335X_PIN_INPUT | 5, 32); //mode 5
200 //-------------------------------------------------------------------------
201 // LCD
202 //-------------------------------------------------------------------------
203 //lcd rs t3
204 dsDAP_mem.writeData(0, 0x44e108B8, AM335X_PIN_OUTPUT | 4, 32); //mode 4
206 //lcd r/w t4
207 dsDAP_mem.writeData(0, 0x44e108BC, AM335X_PIN_OUTPUT | 4, 32); //mode 4
209 //lcd e v5
210 dsDAP_mem.writeData(0, 0x44e108E8, AM335X_PIN_OUTPUT | 4, 32); //mode 4
212 //lcd data4 b16
213 dsDAP_mem.writeData(0, 0x44e10958, AM335X_PIN_OUTPUT | 6, 32); //mode 6
215 //lcd data5 a16
216 dsDAP_mem.writeData(0, 0x44e1095C, AM335X_PIN_OUTPUT | 6, 32); //mode 6
218 //lcd data6 u5
219 dsDAP_mem.writeData(0, 0x44e108e0, AM335X_PIN_OUTPUT | 4, 32); //mode 4
221 //lcd data7 r5
222 dsDAP_mem.writeData(0, 0x44e108e4, AM335X_PIN_OUTPUT | 4, 32); //mode 4
224 //-------------------------------------------------------------------------
225 // TEMP SENSOR
226 //-------------------------------------------------------------------------
227 //gpmc ad14 - input (GPI direct)
228 dsDAP_mem.writeData(0, 0x44E10838, AM335X_PIN_INPUT | 6, 32); //mode 6
230 //lcd data7 - output (DIGIO)
231 dsDAP_mem.writeData(0, 0x44E108BC, AM335X_PIN_OUTPUT | 4, 32); //mode 4
232 }