Skip to content

Commit ef6284c

Browse files
Added process to reinitialize qspi if qspi_init is called twice without free.
1 parent 95a5d60 commit ef6284c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/cy_qspi_api.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,35 @@
2525
extern "C" {
2626
#endif
2727

28+
#if CY_IP_MXSMIF_INSTANCES == 1
29+
static cyhal_qspi_t* qspi_ptr = NULL;
30+
#else
31+
#error Unhandled number of SMIF instances
32+
#endif
33+
2834
qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel, uint32_t hz, uint8_t mode)
2935
{
30-
return CY_RSLT_SUCCESS == cyhal_qspi_init(&(obj->hal_qspi), io0, io1, io2, io3, NC, NC, NC, NC, sclk, ssel, hz, mode) ? QSPI_STATUS_OK : QSPI_STATUS_ERROR;
36+
// If qspi has already been initialized, free and reinit.
37+
if(qspi_ptr != NULL)
38+
{
39+
cyhal_qspi_free(qspi_ptr);
40+
qspi_ptr = NULL;
41+
}
42+
43+
cy_rslt_t result = cyhal_qspi_init(&(obj->hal_qspi), io0, io1, io2, io3, NC, NC, NC, NC, sclk, ssel, hz, mode);
44+
if(CY_RSLT_SUCCESS != result)
45+
{
46+
return QSPI_STATUS_ERROR;
47+
}
48+
49+
qspi_ptr = &(obj->hal_qspi);
50+
return QSPI_STATUS_OK;
3151
}
3252

3353
qspi_status_t qspi_free(qspi_t *obj)
3454
{
3555
cyhal_qspi_free(&(obj->hal_qspi));
56+
qspi_ptr = NULL;
3657
return QSPI_STATUS_OK;
3758
}
3859

0 commit comments

Comments
 (0)