@@ -69,10 +69,7 @@ unsigned long pin_swdio = PIN_OB_SWDIO; // GPIO msak for SWDIO signal
69
69
static void nrf_prerun_board_config (void )
70
70
{
71
71
// Work around for setting the correct board id based on GPIOs
72
- uint8_t bit1 ;
73
- uint8_t bit2 ;
74
- uint8_t bit3 ;
75
- uint8_t gpio_id ;
72
+ uint8_t bit1 , bit2 , bit3 , gpio_id ;
76
73
77
74
PIOB -> PIO_PER = (1 << 1 ); // Enable PIO pin PB1
78
75
PIOB -> PIO_PER = (1 << 2 ); // Enable PIO pin PB2
@@ -137,37 +134,37 @@ static void nrf_prerun_board_config(void)
137
134
// External target detection:
138
135
// supports nRF51-DK, nRF52-DK, nRF52840-DK
139
136
140
- // EXT_VTG (high if external target is powered)
137
+ // Configure GPIO for detection
138
+ // - EXT_VTG (high if external target is powered)
141
139
PIOB -> PIO_PUDR = (1 << 6 ); // pull-up disable
142
140
PIOB -> PIO_ODR = (1 << 6 ); // input
143
141
PIOB -> PIO_PER = (1 << 6 ); // GPIO control
144
- bit1 = (PIOB -> PIO_PDSR >> 6 ) & 1 ; // Read PB6
145
-
146
- // EXT_GND_DETECT (low if external target is connected)
142
+ // - EXT_GND_DETECT (low if external target is connected)
147
143
PIOB -> PIO_PUER = (1 << 18 ); // pull-up enable
148
144
PIOB -> PIO_ODR = (1 << 18 ); // input
149
145
PIOB -> PIO_PER = (1 << 18 ); // GPIO control
150
- bit2 = (PIOB -> PIO_PDSR >> 18 ) & 1 ; // Read PB18
151
- PIOB -> PIO_PUDR = (1 << 18 ); // pull-up disable
152
-
153
- // nonzero if external target is detected
154
- target_ext = bit1 & !bit2 ;
155
-
156
- // SH_VTG (high if shield-mounted target is powered)
146
+ // - SH_VTG (high if shield-mounted target is powered)
157
147
PIOB -> PIO_PUDR = (1 << 5 ); // pull-up disable
158
148
PIOB -> PIO_ODR = (1 << 5 ); // input
159
149
PIOB -> PIO_PER = (1 << 5 ); // GPIO control
160
- bit1 = (PIOB -> PIO_PDSR >> 5 ) & 1 ; // Read PB5
161
-
162
- // SH_GND_DETECT (low if shield-mounted target is connected)
150
+ // - SH_GND_DETECT (low if shield-mounted target is connected)
163
151
PIOB -> PIO_PUER = (1 << 23 ); // pull-up enable
164
152
PIOB -> PIO_ODR = (1 << 23 ); // input
165
153
PIOB -> PIO_PER = (1 << 23 ); // GPIO control
166
- bit2 = (PIOB -> PIO_PDSR >> 23 ) & 1 ; // Read PB23
167
- PIOB -> PIO_PUDR = (1 << 23 ); // pull-up disable
154
+
155
+ // nonzero if external target is detected
156
+ bit1 = (PIOB -> PIO_PDSR >> 6 ) & 1 ; // Read PB6
157
+ bit2 = (PIOB -> PIO_PDSR >> 18 ) & 1 ; // Read PB18
158
+ target_ext = bit1 & !bit2 ;
168
159
169
160
// nonzero if shield-mounted target is detected
170
- target_shield = bit1 & !bit2 ;
161
+ bit1 = (PIOB -> PIO_PDSR >> 5 ) & 1 ; // Read PB5
162
+ bit2 = (PIOB -> PIO_PDSR >> 23 ) & 1 ; // Read PB23
163
+ target_shield = bit1 & !bit2 ;
164
+
165
+ // Disable pull-ups for detection
166
+ PIOB -> PIO_PUDR = (1 << 18 ); // pull-up disable
167
+ PIOB -> PIO_PUDR = (1 << 23 ); // pull-up disable
171
168
172
169
// if external/shield target is detected, re-route SWD signals
173
170
if (target_ext ) {
0 commit comments