Skip to content

Commit a639176

Browse files
author
Jamie Smith
authored
Fix declaring OSPIFBlockDevice and QSPIFBlockDevice as globals, fix some STM32U585 issues (ARMmbed#167)
* Attempt to fix declaring an OSPIFBlockDevice as a global object * Astyle format * Add B_U585_IOT02A upload method support and default OSPIF mappings. Guard against incorrect case on upload method * Also fix the same error in QSPIFBlockDevice * Fix compile error for mbed-wifi * Provide ScopedMutexLock for unittests mode
1 parent a9f8e09 commit a639176

File tree

12 files changed

+247
-75
lines changed

12 files changed

+247
-75
lines changed

connectivity/drivers/wifi/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ endif()
1414
add_subdirectory(esp8266-driver)
1515

1616
target_link_libraries(mbed-wifi
17-
INTERFACE
17+
PUBLIC
18+
mbed-rtos-flags
1819
mbed-netsocket-api
1920
)

rtos/tests/UNITTESTS/doubles/rtos/Mutex.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
#include <inttypes.h>
2121
#include "rtos/mbed_rtos_types.h"
2222
#include "rtos/internal/mbed_rtos1_types.h"
23+
#include "ScopedLock.h"
2324

2425
namespace rtos {
2526

27+
class Mutex;
28+
typedef mbed::ScopedLock<Mutex> ScopedMutexLock;
29+
2630
class Mutex {
2731
public:
2832
Mutex();

storage/blockdevice/COMPONENT_OSPIF/include/OSPIF/OSPIFBlockDevice.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,8 @@ class OSPIFBlockDevice : public mbed::BlockDevice {
404404
// OSPI Driver Object
405405
mbed::OSPI _ospi;
406406

407-
// Static List of different OSPI based Flash devices csel that already exist
408-
// Each OSPI Flash device csel can have only 1 OSPIFBlockDevice instance
409-
// _devices_mutex is used to lock csel list - only one OSPIFBlockDevice instance per csel is allowed
410-
static SingletonPtr<rtos::Mutex> _devices_mutex;
407+
// Number of active OSPIFBlockDevice chip select pins
411408
static int _number_of_active_ospif_flash_csel;
412-
static PinName *_active_ospif_flash_csel_arr;
413409

414410
int _unique_device_status;
415411
PinName _csel;

storage/blockdevice/COMPONENT_OSPIF/mbed_lib.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
"target_overrides": {
2929
"MX25LM51245G": {
3030
"OSPI_FREQ": "66000000"
31+
},
32+
"B_U585_IOT02A": {
33+
"OSPI_IO0": "PF_0",
34+
"OSPI_IO1": "PF_1",
35+
"OSPI_IO2": "PF_2",
36+
"OSPI_IO3": "PF_3",
37+
"OSPI_IO4": "PH_9",
38+
"OSPI_IO5": "PH_10",
39+
"OSPI_IO6": "PH_11",
40+
"OSPI_IO7": "PH_12",
41+
"OSPI_SCK": "PF_4",
42+
"OSPI_CSN": "PI_5",
43+
"OSPI_DQS": "PF_12"
3144
}
3245
}
3346
}

storage/blockdevice/COMPONENT_OSPIF/source/OSPIFBlockDevice.cpp

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,22 @@ static const uint8_t _sfdp_basic_param_table[64] = {0x30, 0xFF, 0xFB, 0xFF, 0xFF
178178
static const uint8_t _sfdp_4_byte_inst_table[8] = {0x7F, 0xEF, 0xFF, 0xFF, 0x21, 0x5C, 0xDC, 0x14};
179179
#endif
180180

181-
/* Init function to initialize Different Devices CS static list */
182-
static PinName *generate_initialized_active_ospif_csel_arr();
183-
// Static Members for different devices csel
184-
// _devices_mutex is used to lock csel list - only one OSPIFBlockDevice instance per csel is allowed
185-
SingletonPtr<rtos::Mutex> OSPIFBlockDevice::_devices_mutex;
181+
/*
182+
* Get the global mutex used to protect the chip select pin array (below).
183+
* It will be initialized on first use.
184+
*/
185+
static rtos::Mutex &get_devices_mutex();
186+
187+
/*
188+
* Get the global array of active chip select pins.
189+
* Each OSPI Flash device csel can have only 1 OSPIFBlockDevice instance.
190+
*
191+
* This function should be called with the devices mutex locked.
192+
*/
193+
static PinName *get_active_ospif_csel_arr();
194+
195+
186196
int OSPIFBlockDevice::_number_of_active_ospif_flash_csel = 0;
187-
PinName *OSPIFBlockDevice::_active_ospif_flash_csel_arr = generate_initialized_active_ospif_csel_arr();
188197

189198
/********* Public API Functions *********/
190199
/****************************************/
@@ -859,63 +868,79 @@ int OSPIFBlockDevice::change_mode(int mode)
859868
/********************************/
860869
/* Different Device Csel Mgmt */
861870
/********************************/
862-
static PinName *generate_initialized_active_ospif_csel_arr()
871+
872+
static rtos::Mutex &get_devices_mutex()
863873
{
864-
PinName *init_arr = new PinName[OSPIF_MAX_ACTIVE_FLASH_DEVICES];
865-
for (int i_ind = 0; i_ind < OSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
866-
init_arr[i_ind] = NC;
874+
static rtos::Mutex devicesMutex;
875+
return devicesMutex;
876+
}
877+
878+
879+
static PinName *get_active_ospif_csel_arr()
880+
{
881+
// Declare the active csel array info as local static variables.
882+
// This makes sure it's initialized on first use, so even if an OSPIFBlockDevice is declared
883+
// globally and constructed before the globals in this file, things will still work correctly.
884+
static bool active_csel_arr_initialized = false;
885+
static PinName active_csel_arr[OSPIF_MAX_ACTIVE_FLASH_DEVICES];
886+
887+
if (!active_csel_arr_initialized) {
888+
for (int i_ind = 0; i_ind < OSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
889+
active_csel_arr[i_ind] = NC;
890+
}
891+
active_csel_arr_initialized = true;
867892
}
868-
return init_arr;
893+
894+
return active_csel_arr;
869895
}
870896

871897
int OSPIFBlockDevice::add_new_csel_instance(PinName csel)
872898
{
873-
int status = 0;
874-
_devices_mutex->lock();
899+
rtos::ScopedMutexLock lock(get_devices_mutex());
900+
901+
PinName *active_ospif_flash_csel_arr = get_active_ospif_csel_arr();
902+
875903
if (_number_of_active_ospif_flash_csel >= OSPIF_MAX_ACTIVE_FLASH_DEVICES) {
876-
status = -2;
877-
goto exit_point;
904+
return -2;
878905
}
879906

880907
// verify the device is unique(no identical csel already exists)
881908
for (int i_ind = 0; i_ind < OSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
882-
if (_active_ospif_flash_csel_arr[i_ind] == csel) {
883-
status = -1;
884-
goto exit_point;
909+
if (active_ospif_flash_csel_arr[i_ind] == csel) {
910+
return -1;
885911
}
886912
}
887913

888914
// Insert new csel into existing device list
889915
for (int i_ind = 0; i_ind < OSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
890-
if (_active_ospif_flash_csel_arr[i_ind] == NC) {
891-
_active_ospif_flash_csel_arr[i_ind] = csel;
916+
if (active_ospif_flash_csel_arr[i_ind] == NC) {
917+
active_ospif_flash_csel_arr[i_ind] = csel;
892918
break;
893919
}
894920
}
895921
_number_of_active_ospif_flash_csel++;
896922

897-
exit_point:
898-
_devices_mutex->unlock();
899-
return status;
923+
return 0;
900924
}
901925

902926
int OSPIFBlockDevice::remove_csel_instance(PinName csel)
903927
{
904-
int status = -1;
905-
_devices_mutex->lock();
928+
rtos::ScopedMutexLock lock(get_devices_mutex());
929+
930+
PinName *active_ospif_flash_csel_arr = get_active_ospif_csel_arr();
931+
906932
// remove the csel from existing device list
907933
for (int i_ind = 0; i_ind < OSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
908-
if (_active_ospif_flash_csel_arr[i_ind] == csel) {
909-
_active_ospif_flash_csel_arr[i_ind] = NC;
934+
if (active_ospif_flash_csel_arr[i_ind] == csel) {
935+
active_ospif_flash_csel_arr[i_ind] = NC;
910936
if (_number_of_active_ospif_flash_csel > 0) {
911937
_number_of_active_ospif_flash_csel--;
912938
}
913-
status = 0;
914-
break;
939+
return 0;
915940
}
916941
}
917-
_devices_mutex->unlock();
918-
return status;
942+
943+
return -1;
919944
}
920945

921946
/*********************************************************/

storage/blockdevice/COMPONENT_QSPIF/include/QSPIF/QSPIFBlockDevice.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,8 @@ class QSPIFBlockDevice : public mbed::BlockDevice {
343343
// QSPI Driver Object
344344
mbed::QSPI _qspi;
345345

346-
// Static List of different QSPI based Flash devices csel that already exist
347-
// Each QSPI Flash device csel can have only 1 QSPIFBlockDevice instance
348-
// _devices_mutex is used to lock csel list - only one QSPIFBlockDevice instance per csel is allowed
349-
static SingletonPtr<rtos::Mutex> _devices_mutex;
346+
// Number of active OSPIFBlockDevice chip select pins
350347
static int _number_of_active_qspif_flash_csel;
351-
static PinName *_active_qspif_flash_csel_arr;
352348

353349
int _unique_device_status;
354350
PinName _csel;

storage/blockdevice/COMPONENT_QSPIF/source/QSPIFBlockDevice.cpp

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,21 @@ using namespace mbed;
114114
// Length of data returned from RDID instruction
115115
#define QSPI_RDID_DATA_LENGTH 3
116116

117+
/*
118+
* Get the global mutex used to protect the chip select pin array (below).
119+
* It will be initialized on first use.
120+
*/
121+
static rtos::Mutex &get_devices_mutex();
122+
123+
/*
124+
* Get the global array of active chip select pins.
125+
* Each OSPI Flash device csel can have only 1 OSPIFBlockDevice instance.
126+
*
127+
* This function should be called with the devices mutex locked.
128+
*/
129+
static PinName *get_active_qspif_csel_arr();
117130

118-
/* Init function to initialize Different Devices CS static list */
119-
static PinName *generate_initialized_active_qspif_csel_arr();
120-
// Static Members for different devices csel
121-
// _devices_mutex is used to lock csel list - only one QSPIFBlockDevice instance per csel is allowed
122-
SingletonPtr<rtos::Mutex> QSPIFBlockDevice::_devices_mutex;
123131
int QSPIFBlockDevice::_number_of_active_qspif_flash_csel = 0;
124-
PinName *QSPIFBlockDevice::_active_qspif_flash_csel_arr = generate_initialized_active_qspif_csel_arr();
125132

126133
/********* Public API Functions *********/
127134
/****************************************/
@@ -555,63 +562,76 @@ int QSPIFBlockDevice::get_erase_value() const
555562
/********************************/
556563
/* Different Device Csel Mgmt */
557564
/********************************/
558-
static PinName *generate_initialized_active_qspif_csel_arr()
565+
static rtos::Mutex &get_devices_mutex()
559566
{
560-
PinName *init_arr = new PinName[QSPIF_MAX_ACTIVE_FLASH_DEVICES];
561-
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
562-
init_arr[i_ind] = NC;
567+
static rtos::Mutex devicesMutex;
568+
return devicesMutex;
569+
}
570+
571+
static PinName *get_active_qspif_csel_arr()
572+
{
573+
// Declare the active csel array info as local static variables.
574+
// This makes sure it's initialized on first use, so even if a QSPIFBlockDevice is declared
575+
// globally and constructed before the globals in this file, things will still work correctly.
576+
static bool active_csel_arr_initialized = false;
577+
static PinName active_csel_arr[QSPIF_MAX_ACTIVE_FLASH_DEVICES];
578+
579+
if (!active_csel_arr_initialized) {
580+
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
581+
active_csel_arr[i_ind] = NC;
582+
}
583+
active_csel_arr_initialized = true;
563584
}
564-
return init_arr;
585+
return active_csel_arr;
565586
}
566587

567588
int QSPIFBlockDevice::add_new_csel_instance(PinName csel)
568589
{
569-
int status = 0;
570-
_devices_mutex->lock();
590+
rtos::ScopedMutexLock lock(get_devices_mutex());
591+
592+
PinName *active_qspif_flash_csel_arr = get_active_qspif_csel_arr();
593+
571594
if (_number_of_active_qspif_flash_csel >= QSPIF_MAX_ACTIVE_FLASH_DEVICES) {
572-
status = -2;
573-
goto exit_point;
595+
return -2;
574596
}
575597

576598
// verify the device is unique(no identical csel already exists)
577599
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
578-
if (_active_qspif_flash_csel_arr[i_ind] == csel) {
579-
status = -1;
580-
goto exit_point;
600+
if (active_qspif_flash_csel_arr[i_ind] == csel) {
601+
return -1;
581602
}
582603
}
583604

584605
// Insert new csel into existing device list
585606
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
586-
if (_active_qspif_flash_csel_arr[i_ind] == NC) {
587-
_active_qspif_flash_csel_arr[i_ind] = csel;
607+
if (active_qspif_flash_csel_arr[i_ind] == NC) {
608+
active_qspif_flash_csel_arr[i_ind] = csel;
588609
break;
589610
}
590611
}
591612
_number_of_active_qspif_flash_csel++;
592613

593-
exit_point:
594-
_devices_mutex->unlock();
595-
return status;
614+
return 0;
596615
}
597616

598617
int QSPIFBlockDevice::remove_csel_instance(PinName csel)
599618
{
600-
int status = -1;
601-
_devices_mutex->lock();
619+
rtos::ScopedMutexLock lock(get_devices_mutex());
620+
621+
PinName *active_qspif_flash_csel_arr = get_active_qspif_csel_arr();
622+
602623
// remove the csel from existing device list
603624
for (int i_ind = 0; i_ind < QSPIF_MAX_ACTIVE_FLASH_DEVICES; i_ind++) {
604-
if (_active_qspif_flash_csel_arr[i_ind] == csel) {
605-
_active_qspif_flash_csel_arr[i_ind] = NC;
625+
if (active_qspif_flash_csel_arr[i_ind] == csel) {
626+
active_qspif_flash_csel_arr[i_ind] = NC;
606627
if (_number_of_active_qspif_flash_csel > 0) {
607628
_number_of_active_qspif_flash_csel--;
608629
}
609-
status = 0;
610-
break;
630+
return 0;
611631
}
612632
}
613-
_devices_mutex->unlock();
614-
return status;
633+
634+
return -1;
615635
}
616636

617637
/*********************************************************/

storage/platform/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ if("QSPIF" IN_LIST MBED_TARGET_LABELS)
2525
list(APPEND mbed-storage-libs mbed-storage-qspif)
2626
endif()
2727

28+
if("OSPIF" IN_LIST MBED_TARGET_LABELS)
29+
list(APPEND mbed-storage-libs mbed-storage-ospif)
30+
endif()
31+
2832
if("SD" IN_LIST MBED_TARGET_LABELS)
2933
list(APPEND mbed-storage-libs mbed-storage-sd)
3034
endif()

targets/targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4902,13 +4902,13 @@
49024902
"MX25LM51245G"
49034903
],
49044904
"components_add": [
4905-
"OSPIF"
4905+
"OSPIF",
4906+
"EMW3080B"
49064907
],
49074908
"device_has_add": [
49084909
"QSPI",
49094910
"OSPI"
49104911
],
4911-
"components_add": ["EMW3080B"],
49124912
"overrides": {
49134913
"network-default-interface-type": "WIFI"
49144914
},

0 commit comments

Comments
 (0)