Skip to content

Commit 48255ab

Browse files
adustm0xc0170
authored andcommitted
Implement qspi_free function
1 parent 5b8688a commit 48255ab

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F413xH/objects.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ struct trng_s {
4646

4747
struct qspi_s {
4848
QSPI_HandleTypeDef handle;
49+
PinName io0;
50+
PinName io1;
51+
PinName io2;
52+
PinName io3;
53+
PinName sclk;
54+
PinName ssel;
4955
};
5056

5157
#include "common_objects.h"

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F469xI/objects.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ struct trng_s {
6060

6161
struct qspi_s {
6262
QSPI_HandleTypeDef handle;
63+
PinName io0;
64+
PinName io1;
65+
PinName io2;
66+
PinName io3;
67+
PinName sclk;
68+
PinName ssel;
6369
};
6470

6571
#include "common_objects.h"

targets/TARGET_STM/TARGET_STM32F7/TARGET_STM32F746xG/objects.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ struct trng_s {
6060

6161
struct qspi_s {
6262
QSPI_HandleTypeDef handle;
63+
PinName io0;
64+
PinName io1;
65+
PinName io2;
66+
PinName io3;
67+
PinName sclk;
68+
PinName ssel;
6369
};
6470

6571
#include "common_objects.h"

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L475xG/objects.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ struct trng_s {
6060

6161
struct qspi_s {
6262
QSPI_HandleTypeDef handle;
63+
PinName io0;
64+
PinName io1;
65+
PinName io2;
66+
PinName io3;
67+
PinName sclk;
68+
PinName ssel;
6369
};
6470

6571
#include "common_objects.h"

targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/objects.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ struct trng_s {
6060

6161
struct qspi_s {
6262
QSPI_HandleTypeDef handle;
63+
PinName io0;
64+
PinName io1;
65+
PinName io2;
66+
PinName io3;
67+
PinName sclk;
68+
PinName ssel;
6369
};
6470

6571
#include "common_objects.h"

targets/TARGET_STM/qspi_api.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,19 @@ qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinN
173173
// tested all combinations, take first
174174
obj->handle.Instance = (QUADSPI_TypeDef *)qspi_data_first;
175175

176-
// TODO pinmap here for pins (enable clock)
176+
// pinmap for pins (enable clock)
177+
obj->io0 = io0;
177178
pinmap_pinout(io0, PinMap_QSPI_DATA);
179+
obj->io1 = io1;
178180
pinmap_pinout(io1, PinMap_QSPI_DATA);
181+
obj->io2 = io2;
179182
pinmap_pinout(io2, PinMap_QSPI_DATA);
183+
obj->io3 = io3;
180184
pinmap_pinout(io3, PinMap_QSPI_DATA);
181185

186+
obj->sclk = sclk;
182187
pinmap_pinout(sclk, PinMap_QSPI_SCLK);
188+
obj->ssel = ssel;
183189
pinmap_pinout(ssel, PinMap_QSPI_SSEL);
184190

185191
if (HAL_QSPI_Init(&obj->handle) != HAL_OK) {
@@ -191,8 +197,26 @@ qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinN
191197

192198
qspi_status_t qspi_free(qspi_t *obj)
193199
{
194-
// TODO
195-
//return QSPI_STATUS_ERROR;
200+
if(HAL_QSPI_DeInit(&obj->handle) != HAL_OK) {
201+
return QSPI_STATUS_ERROR;
202+
}
203+
204+
// Reset QSPI
205+
__HAL_RCC_QSPI_FORCE_RESET();
206+
__HAL_RCC_QSPI_RELEASE_RESET();
207+
208+
// Disable interface clock for QSPI
209+
__HAL_RCC_QSPI_CLK_DISABLE();
210+
211+
// Configure GPIOs
212+
pin_function(obj->io0, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
213+
pin_function(obj->io1, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
214+
pin_function(obj->io2, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
215+
pin_function(obj->io3, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
216+
pin_function(obj->sclk, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
217+
pin_function(obj->ssel, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
218+
219+
(void)(obj);
196220
return QSPI_STATUS_OK;
197221
}
198222

0 commit comments

Comments
 (0)