Skip to content

Commit c7cd207

Browse files
committed
Moving method 'write' up to base class since it's basically the same across all storage methods. Furthermore I'm eliminating the setUpdateLen API as from now on we only support filesystem based storage mechanisms.
1 parent 0384d9b commit c7cd207

8 files changed

+33
-90
lines changed

src/Arduino_Portenta_OTA.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121

2222
#include "Arduino_Portenta_OTA.h"
2323

24+
#include <stm32h7xx_hal_rtc_ex.h>
25+
26+
/******************************************************************************
27+
* EXTERN
28+
******************************************************************************/
29+
30+
extern RTC_HandleTypeDef RTCHandle;
31+
2432
/******************************************************************************
2533
CTOR/DTOR
2634
******************************************************************************/
@@ -48,23 +56,29 @@ Arduino_Portenta_OTA::Error Arduino_Portenta_OTA::begin()
4856
return (init() == false) ? Error::OtaStorageInit : Error::None;
4957
}
5058

51-
void Arduino_Portenta_OTA::setUpdateLen(uint32_t const program_length)
52-
{
53-
_program_length = program_length;
54-
}
55-
5659
Arduino_Portenta_OTA::Error Arduino_Portenta_OTA::update()
5760
{
5861
if(!open())
5962
return Error::OtaStorageOpen;
6063

61-
if(!write())
62-
return Error::OtaStorageWrite;
64+
write();
6365

6466
return Error::None;
6567
}
6668

6769
void Arduino_Portenta_OTA::reset()
6870
{
6971
NVIC_SystemReset();
70-
}
72+
}
73+
74+
/******************************************************************************
75+
* PRIVATE MEMBER FUNCTIONS
76+
******************************************************************************/
77+
78+
void Arduino_Portenta_OTA::write()
79+
{
80+
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0x07AA);
81+
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR1, _storage_type);
82+
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR2, _data_offset);
83+
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR3, _program_length);
84+
}

src/Arduino_Portenta_OTA.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ class Arduino_Portenta_OTA
7777
OtaHeaderLength = -4,
7878
OtaHeaderCrc = -5,
7979
OtaHeaterMagicNumber = -6,
80-
OtaStorageWrite = -7,
8180
};
8281

8382
Arduino_Portenta_OTA(StorageTypePortenta const storage_type, uint32_t const data_offset);
8483
virtual ~Arduino_Portenta_OTA();
8584

8685

8786
Error begin();
88-
void setUpdateLen(uint32_t const program_length);
8987
Error update();
9088
void reset();
9189

@@ -102,9 +100,13 @@ class Arduino_Portenta_OTA
102100
uint32_t _data_offset;
103101
uint32_t _program_length;
104102

105-
virtual bool init () = 0;
106-
virtual bool open () = 0;
107-
virtual bool write () = 0;
103+
virtual bool init() = 0;
104+
virtual bool open() = 0;
105+
106+
107+
private:
108+
109+
void write();
108110

109111
};
110112

src/Arduino_Portenta_OTA_InternalFlash.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,10 @@
2121

2222
#include "Arduino_Portenta_OTA_InternalFlash.h"
2323

24-
#include <stm32h7xx_hal_rtc_ex.h>
25-
2624
#include <assert.h>
2725

2826
using namespace arduino;
2927

30-
/******************************************************************************
31-
* EXTERN
32-
******************************************************************************/
33-
34-
extern RTC_HandleTypeDef RTCHandle;
35-
3628
/******************************************************************************
3729
CTOR/DTOR
3830
******************************************************************************/
@@ -42,7 +34,6 @@ Arduino_Portenta_OTA_InternalFlash::Arduino_Portenta_OTA_InternalFlash(StorageTy
4234
, _bd(0x8000000 + _data_offset, 2 * 1024 * 1024 - _data_offset)
4335
, _fs_flash("fs")
4436
, _littlefs_fs_flash("little_fs")
45-
, _update_size_internal_flash{0}
4637
{
4738
assert(_storage_type == INTERNAL_FLASH_FATFS ||
4839
_storage_type == INTERNAL_FLASH_LITTLEFS);
@@ -97,7 +88,7 @@ bool Arduino_Portenta_OTA_InternalFlash::open()
9788
{
9889
struct stat stat_buf;
9990
stat("/fs/UPDATE.BIN", &stat_buf);
100-
_update_size_internal_flash = stat_buf.st_size;
91+
_program_length = stat_buf.st_size;
10192
closedir(dir);
10293
return true;
10394
}
@@ -118,7 +109,7 @@ bool Arduino_Portenta_OTA_InternalFlash::open()
118109
{
119110
struct stat stat_buf;
120111
stat("/little_fs/UPDATE.BIN", &stat_buf);
121-
_update_size_internal_flash = stat_buf.st_size;
112+
_program_length = stat_buf.st_size;
122113
closedir(dir);
123114
return true;
124115
}
@@ -128,15 +119,5 @@ bool Arduino_Portenta_OTA_InternalFlash::open()
128119
return false;
129120
}
130121

131-
_update_size_internal_flash = 0;
132122
return false;
133123
}
134-
135-
bool Arduino_Portenta_OTA_InternalFlash::write()
136-
{
137-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0x07AA);
138-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR1, _storage_type);
139-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR2, _data_offset);
140-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR3, _update_size_internal_flash);
141-
return true;
142-
}

src/Arduino_Portenta_OTA_InternalFlash.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ class Arduino_Portenta_OTA_InternalFlash : public Arduino_Portenta_OTA
4242

4343
virtual bool init () override;
4444
virtual bool open () override;
45-
virtual bool write () override;
4645

4746

4847
private:
4948

5049
FlashIAPBlockDevice _bd;
5150
mbed::FATFileSystem _fs_flash;
5251
mbed::LittleFileSystem _littlefs_fs_flash;
53-
int _update_size_internal_flash;
5452

5553
};
5654

src/Arduino_Portenta_OTA_QSPI.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,10 @@
2121

2222
#include "Arduino_Portenta_OTA_QSPI.h"
2323

24-
#include <stm32h7xx_hal_rtc_ex.h>
25-
2624
#include <assert.h>
2725

2826
using namespace arduino;
2927

30-
/******************************************************************************
31-
* EXTERN
32-
******************************************************************************/
33-
34-
extern RTC_HandleTypeDef RTCHandle;
35-
3628
/******************************************************************************
3729
CTOR/DTOR
3830
******************************************************************************/
@@ -42,7 +34,6 @@ Arduino_Portenta_OTA_QSPI::Arduino_Portenta_OTA_QSPI(StorageTypePortenta const s
4234
, _bd_qspi{NULL}
4335
, _fs_qspi{NULL}
4436
, _block_device_qspi(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000)
45-
, _update_size_qspi{0}
4637
{
4738
assert(_storage_type == QSPI_FLASH_FATFS ||
4839
_storage_type == QSPI_FLASH_LITTLEFS ||
@@ -103,7 +94,7 @@ bool Arduino_Portenta_OTA_QSPI::open()
10394
{
10495
struct stat stat_buf;
10596
stat("/fs/UPDATE.BIN", &stat_buf);
106-
_update_size_qspi = stat_buf.st_size;
97+
_program_length = stat_buf.st_size;
10798
closedir(dir);
10899
return true;
109100
}
@@ -112,21 +103,5 @@ bool Arduino_Portenta_OTA_QSPI::open()
112103
}
113104
}
114105

115-
_update_size_qspi = 0;
116-
return false;
117-
}
118-
119-
bool Arduino_Portenta_OTA_QSPI::write()
120-
{
121-
if(_storage_type == QSPI_FLASH_FATFS ||
122-
_storage_type == QSPI_FLASH_FATFS_MBR)
123-
{
124-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0x07AA);
125-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR1, _storage_type);
126-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR2, _data_offset);
127-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR3, _update_size_qspi);
128-
return true;
129-
}
130-
131106
return false;
132107
}

src/Arduino_Portenta_OTA_QSPI.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ class Arduino_Portenta_OTA_QSPI : public Arduino_Portenta_OTA
4141

4242
virtual bool init () override;
4343
virtual bool open () override;
44-
virtual bool write () override;
4544

4645

4746
private:
4847

4948
mbed::BlockDevice * _bd_qspi;
5049
mbed::FATFileSystem * _fs_qspi;
5150
QSPIFBlockDevice _block_device_qspi;
52-
int _update_size_qspi;
5351

5452
};
5553

src/Arduino_Portenta_OTA_SD.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,11 @@
2323

2424
#include "BSP.h"
2525
#include "stm32h7xx_hal_sd.h"
26-
#include "stm32h7xx_hal_rtc_ex.h"
2726

2827
#include <assert.h>
2928

3029
using namespace arduino;
3130

32-
/******************************************************************************
33-
* EXTERN
34-
******************************************************************************/
35-
36-
extern RTC_HandleTypeDef RTCHandle;
37-
3831
/******************************************************************************
3932
CONSTANTS
4033
******************************************************************************/
@@ -50,7 +43,6 @@ Arduino_Portenta_OTA_SD::Arduino_Portenta_OTA_SD(StorageTypePortenta const stora
5043
, _bd{NULL}
5144
, _block_device()
5245
, _fs_sd{NULL}
53-
, _update_size_sd{0}
5446
{
5547
assert(_storage_type == SD_FATFS ||
5648
_storage_type == SD_LITTLEFS ||
@@ -111,7 +103,7 @@ bool Arduino_Portenta_OTA_SD::open()
111103
{
112104
struct stat stat_buf;
113105
stat("/fs/UPDATE.BIN", &stat_buf);
114-
_update_size_sd = stat_buf.st_size;
106+
_program_length = stat_buf.st_size;
115107
closedir(dir);
116108
return true;
117109
}
@@ -123,18 +115,3 @@ bool Arduino_Portenta_OTA_SD::open()
123115

124116
return false;
125117
}
126-
127-
bool Arduino_Portenta_OTA_SD::write()
128-
{
129-
if (_storage_type == SD_FATFS ||
130-
_storage_type == SD_FATFS_MBR)
131-
{
132-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR0, 0x07AA);
133-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR1, _storage_type);
134-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR2, _data_offset);
135-
HAL_RTCEx_BKUPWrite(&RTCHandle, RTC_BKP_DR3, _update_size_sd);
136-
return true;
137-
}
138-
139-
return false;
140-
}

src/Arduino_Portenta_OTA_SD.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ class Arduino_Portenta_OTA_SD : public Arduino_Portenta_OTA
4040

4141
virtual bool init () override;
4242
virtual bool open () override;
43-
virtual bool write () override;
4443

4544

4645
private:
4746

4847
mbed::BlockDevice * _bd;
4948
SDMMCBlockDevice _block_device;
5049
mbed::FATFileSystem * _fs_sd;
51-
int _update_size_sd;
5250

5351
};
5452

0 commit comments

Comments
 (0)