@@ -52,6 +52,9 @@ static const nrf_drv_spi_t nordic_nrf5_spi_instance[3] = {
52
52
NRF_DRV_SPI_INSTANCE (2 )
53
53
};
54
54
55
+ /* Keep track of which instance has been initialized. */
56
+ static bool nordic_nrf5_spi_initialized [3 ] = { false, false, false };
57
+
55
58
/* Forware declare interrupt handler. */
56
59
#if DEVICE_SPI_ASYNCH
57
60
static void nordic_nrf5_spi_event_handler (nrf_drv_spi_evt_t const * p_event , void * p_context );
@@ -93,8 +96,10 @@ static void spi_configure_driver_instance(spi_t *obj)
93
96
/* Update applied, reset flag. */
94
97
spi_inst -> update = false;
95
98
96
- /* clean up and initialize peripheral. */
97
- nrf_drv_spi_uninit (& nordic_nrf5_spi_instance [instance ]);
99
+ /* Clean up and uninitialize peripheral if already initialized. */
100
+ if (nordic_nrf5_spi_initialized [instance ]) {
101
+ nrf_drv_spi_uninit (& nordic_nrf5_spi_instance [instance ]);
102
+ }
98
103
99
104
#if DEVICE_SPI_ASYNCH
100
105
/* Set callback handler in asynchronous mode. */
@@ -107,6 +112,10 @@ static void spi_configure_driver_instance(spi_t *obj)
107
112
/* Set callback handler to NULL in synchronous mode. */
108
113
nrf_drv_spi_init (& nordic_nrf5_spi_instance [instance ], & (spi_inst -> config ), NULL , NULL );
109
114
#endif
115
+
116
+ /* Mark instance as initialized. */
117
+ nordic_nrf5_spi_initialized [instance ] = true;
118
+
110
119
/* Claim ownership of peripheral. */
111
120
object_owner_spi2c_set (instance , obj );
112
121
}
@@ -201,6 +210,9 @@ void spi_free(spi_t *obj)
201
210
202
211
/* Use driver uninit to free instance. */
203
212
nrf_drv_spi_uninit (& nordic_nrf5_spi_instance [instance ]);
213
+
214
+ /* Mark instance as uninitialized. */
215
+ nordic_nrf5_spi_initialized [instance ] = false;
204
216
}
205
217
206
218
/** Configure the SPI format
0 commit comments