@@ -85,10 +85,15 @@ void BoardInit(void)
85
85
select = REG32 (GPFSEL4 );
86
86
select &= ~(7 << 6 );
87
87
#elif RPI == 3
88
- /* GPIO 29 is select register 2, number 9. 3 bits per GPIO so 9 */
89
- /* Clear the 3 bit range (7) starting at bit 21 */
88
+ /* GPIO 29 is select register 2, number 9. 9 * 3 bits is bit 27 */
89
+ /* Clear the 3 bit range (7) starting at bit 27 */
90
90
select = REG32 (GPFSEL2 );
91
91
select &= ~(7 << 27 );
92
+ #elif RPI == 0
93
+ /* GPIO 16 is select register 1, number 6. 6 * 3 bits is bit 18 */
94
+ /* Clear the 3 bit range (7) starting at bit 18 */
95
+ select = REG32 (GPFSEL1 );
96
+ select &= ~(7 << 18 );
92
97
#else
93
98
/* GPIO 47 is 7th register in GPFSEL4, so 7 * 3 bits or bit 21. */
94
99
/* Clear the 3 bit range (7) starting at bit 21 */
@@ -107,12 +112,22 @@ void BoardInit(void)
107
112
/* Configure LED (GPIO 29) starting at bit 27, as output (1). */
108
113
select |= (GPIO_OUTPUT << 27 );
109
114
REG32 (GPFSEL2 ) = select ;
115
+ #elif RPI == 0
116
+ /* Configure LED (GPIO 16) starting at bit 18, as output (1). */
117
+ select |= (GPIO_OUTPUT << 18 );
118
+ REG32 (GPFSEL1 ) = select ;
110
119
#else
111
120
/* Configure the LED (GPIO 47) starting at bit 21, as output (1). */
112
121
select |= (GPIO_OUTPUT << 21 );
113
122
REG32 (GPFSEL4 ) = select ;
114
123
#endif
115
124
125
+ #if RPI == 4
126
+ /* GPIO 42, 2 bits per PUP GPIO */
127
+ select = REG32 (GPIO_PUP_PDN_CNTRL_REG2 );
128
+ select &= ~(3 << ((42 - 32 ) * 2 )); // clear old value
129
+ REG32 (GPIO_PUP_PDN_CNTRL_REG2 ) = select | (GPPUP_PULL_UP ) << ((42 - 32 ) * 2 );
130
+ #else
116
131
/* GPPUD - GPio Pin Up Down configuration */
117
132
/* (0) disable pull up and pull down to float the GPIO */
118
133
/* (1 << 0) enable pull down (low) */
@@ -124,10 +139,7 @@ void BoardInit(void)
124
139
/* Sleep for one hundred of a second to activate last command. */
125
140
usleep (MICROS_PER_SECOND / 100 );
126
141
127
- #if RPI == 4
128
- /* Push GPPUD settings to GPPUDCLK1 GPIO 42. */
129
- REG32 (GPPUDCLK1 ) = (1 << (42 - 32 )); /* GPIO 42 */
130
- #elif RPI == 3
142
+ #if RPI == 3
131
143
/* Push GPPUD settings to GPPUDCLK0 GPIO 29. */
132
144
REG32 (GPPUDCLK0 ) = (1 << 29 ); /* GPIO 29 */
133
145
#else
@@ -137,8 +149,21 @@ void BoardInit(void)
137
149
138
150
/* Sleep for one hundred of a second to activate last command. */
139
151
usleep (MICROS_PER_SECOND / 100 );
152
+ #endif /* RPI == 4 */
153
+
140
154
141
155
#if ENABLE_JTAG
156
+ #if RPI == 4
157
+ /* 2 bits per PUP GPIO */
158
+ select = REG32 (GPIO_PUP_PDN_CNTRL_REG1 );
159
+ select &= ~(3 << ((22 - 16 ) * 2 )); // Clear old GPIO 22 value
160
+ select &= ~(3 << ((23 - 16 ) * 2 )); // Clear old GPIO 23 value
161
+ select &= ~(3 << ((24 - 16 ) * 2 )); // Clear old GPIO 24 value
162
+ select &= ~(3 << ((25 - 16 ) * 2 )); // Clear old GPIO 25 value
163
+ select &= ~(3 << ((26 - 16 ) * 2 )); // Clear old GPIO 26 value
164
+ select &= ~(3 << ((27 - 16 ) * 2 )); // Clear old GPIO 27 value
165
+ REG32 (GPIO_PUP_PDN_CNTRL_REG1 ) = select ; /* commit changes */
166
+ #else
142
167
/* Disable pull up/down for the next configured GPIO. */
143
168
REG32 (GPPUD ) = GPPUD_OFF ;
144
169
usleep (MICROS_PER_MILLISECOND ); /* 1ms hold time */
@@ -147,6 +172,7 @@ void BoardInit(void)
147
172
REG32 (GPPUDCLK0 ) = (1 << 22 ) | (1 << 23 ) | (1 << 24 ) | (1 << 25 ) |
148
173
(1 << 26 ) | (1 << 27 );
149
174
usleep (MICROS_PER_MILLISECOND ); /* 1ms hold time */
175
+ #endif
150
176
151
177
// Select level alternate 4 to enable JTAG
152
178
select = REG32 (GPFSEL2 );
@@ -174,13 +200,21 @@ void BoardInit(void)
174
200
select |= GPIO_ALT0 << 15 ; //set gpio15 to alt0
175
201
REG32 (GPFSEL1 ) = select ;
176
202
203
+ #if RPI == 4
204
+ /* UART is GPIO 14 and 15 with 2 bits per PUP GPIO */
205
+ select = REG32 (GPIO_PUP_PDN_CNTRL_REG0 );
206
+ select &= ~(3 << (14 * 2 )); // Clear GPIO 14 value
207
+ select &= ~(3 << (15 * 2 )); // Clear GPIO 15 value
208
+ REG32 (GPIO_PUP_PDN_CNTRL_REG0 ) = select ; /* commit changes */
209
+ #else
177
210
/* Disable pull up/down for the next configured GPIO. */
178
211
REG32 (GPPUD ) = GPPUD_OFF ;
179
212
usleep (MICROS_PER_MILLISECOND ); /* 1ms hold time */
180
213
181
214
/* Configure no pull up/down for Rx and Tx GPIOs. */
182
215
REG32 (GPPUDCLK0 ) = (1 << 14 ) | (1 << 15 ); /* GPIO 14 and 15 */
183
216
usleep (MICROS_PER_MILLISECOND ); /* hold time */
217
+ #endif
184
218
185
219
/* Initialize the primary UART. */
186
220
Uart0Init ();
@@ -223,13 +257,21 @@ void BoardInit(void)
223
257
select |= GPIO_ALT5 << 15 ; //set gpio15 to alt5
224
258
REG32 (GPFSEL1 ) = select ;
225
259
260
+ #if RPI == 4
261
+ /* UART is GPIO 14 and 15 with 2 bits per PUP GPIO */
262
+ select = REG32 (GPIO_PUP_PDN_CNTRL_REG0 );
263
+ select &= ~(3 << (14 * 2 )); // Clear old GPIO 14 value
264
+ select &= ~(3 << (15 * 2 )); // Clear old GPIO 15 value
265
+ REG32 (GPIO_PUP_PDN_CNTRL_REG0 ) = select ; /* commit changes */
266
+ #else
226
267
/* Disable pull up/down clock. */
227
268
REG32 (GPPUD ) = GPPUD_OFF ;
228
269
usleep (MICROS_PER_MILLISECOND );
229
270
230
271
/* Commit pull up/down disable for Rx and Tx GPIOs. */
231
272
REG32 (GPPUDCLK0 ) = (1 << 14 ) | (1 << 15 );
232
273
usleep (MICROS_PER_MILLISECOND ); // 1ms hold time
274
+ #endif
233
275
234
276
/* Initialize the secondary UART. */
235
277
Uart1Init ();
@@ -295,6 +337,9 @@ void LedOn(void)
295
337
#elif RPI == 3
296
338
/* RPI 3 has LED at GPIO 29, so set GPIO 29. */
297
339
REG32 (GPSET0 ) = 1 << 29 ;
340
+ #elif RPI == 0
341
+ /* RPI 1A and B have LED at GPIO 16, so set GPIO 16. */
342
+ REG32 (GPSET0 ) = 1 << 16 ;
298
343
#else
299
344
/* Other RPIs have LED at GPIO 47, so set GPIO 47. */
300
345
REG32 (GPSET1 ) = 1 << (47 - 32 );
@@ -314,6 +359,9 @@ void LedOff(void)
314
359
#elif RPI == 3
315
360
/* RPI 3 has LED at GPIO 29, so clear GPIO 29. */
316
361
REG32 (GPCLR0 ) = 1 << 29 ;
362
+ #elif RPI == 0
363
+ /* RPI 1A and B have LED at GPIO 16, so clear GPIO 16. */
364
+ REG32 (GPCLR0 ) = 1 << 16 ;
317
365
#else
318
366
/* Other RPIs have LED at GPIO 47, so clear GPIO 47. */
319
367
REG32 (GPCLR1 ) = 1 << (47 - 32 );
0 commit comments