Skip to content

Commit 08730c1

Browse files
0xc0170c1728p9
authored andcommitted
flash: add get start flash region
Plus fixes in the tests to get properly end of flash (start + size)
1 parent 6bc38f9 commit 08730c1

File tree

6 files changed

+39
-16
lines changed

6 files changed

+39
-16
lines changed

TESTS/mbed_drivers/flashiap/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void flashiap_program_test()
4343
TEST_ASSERT_EQUAL_INT32(ret, 0);
4444

4545
// get the last sector size (flash size - 1)
46-
uint32_t sector_size = flash_device.get_sector_size(flash_device.get_flash_size() - 1UL);
46+
uint32_t sector_size = flash_device.get_sector_size(flash_device.get_flash_start() + flash_device.get_flash_size() - 1UL);
4747
TEST_ASSERT_NOT_EQUAL(sector_size, 0);
4848
const uint8_t test_value = 0xCE;
4949
uint8_t *data = new uint8_t[sector_size];
@@ -52,7 +52,7 @@ void flashiap_program_test()
5252
}
5353

5454
// the one before the last page in the system
55-
uint32_t address = (flash_device.get_flash_size()) - (sector_size);
55+
uint32_t address = (flash_device.get_flash_start() + flash_device.get_flash_size()) - (sector_size);
5656
TEST_ASSERT_TRUE(address != 0UL);
5757
ret = flash_device.erase(address, sector_size);
5858
TEST_ASSERT_EQUAL_INT32(ret, 0);
@@ -78,7 +78,7 @@ void flashiap_write_test()
7878
TEST_ASSERT_EQUAL_INT32(ret, 0);
7979

8080
// get the last sector size
81-
uint32_t sector_size = flash_device.get_sector_size(flash_device.get_flash_size() - 1UL);
81+
uint32_t sector_size = flash_device.get_sector_size(flash_device.get_flash_start() + flash_device.get_flash_size() - 1UL);
8282
TEST_ASSERT_NOT_EQUAL(sector_size, 0);
8383
const uint8_t test_value = 0xCE;
8484
uint8_t *data = new uint8_t[sector_size];
@@ -87,7 +87,7 @@ void flashiap_write_test()
8787
}
8888

8989
// the one before the last page in the system
90-
uint32_t address = (flash_device.get_flash_size()) - (sector_size);
90+
uint32_t address = (flash_device.get_flash_start() + flash_device.get_flash_size()) - (sector_size);
9191
TEST_ASSERT_TRUE(address != 0UL);
9292
ret = flash_device.write(data, address, sector_size);
9393
TEST_ASSERT_EQUAL_INT32(ret, 0);
@@ -110,7 +110,7 @@ void flashiap_program_error_test()
110110
TEST_ASSERT_EQUAL_INT32(ret, 0);
111111

112112
// get the last sector size (flash size - 1)
113-
uint32_t sector_size = flash_device.get_sector_size(flash_device.get_flash_size() - 1UL);
113+
uint32_t sector_size = flash_device.get_sector_size(flash_device.get_flash_start() + flash_device.get_flash_size() - 1UL);
114114
TEST_ASSERT_NOT_EQUAL(sector_size, 0);
115115
const uint8_t test_value = 0xCE;
116116
uint8_t *data = new uint8_t[sector_size];
@@ -119,7 +119,7 @@ void flashiap_program_error_test()
119119
}
120120

121121
// the one before the last page in the system
122-
uint32_t address = (flash_device.get_flash_size()) - (sector_size);
122+
uint32_t address = (flash_device.get_flash_start() + flash_device.get_flash_size()) - (sector_size);
123123
TEST_ASSERT_TRUE(address != 0UL);
124124

125125
// unaligned address
@@ -147,7 +147,7 @@ void flashiap_write_error_test()
147147
TEST_ASSERT_EQUAL_INT32(ret, 0);
148148

149149
// get the last sector size
150-
uint32_t sector_size = flash_device.get_sector_size(flash_device.get_flash_size() - 1UL);
150+
uint32_t sector_size = flash_device.get_sector_size(flash_device.get_flash_start() + flash_device.get_flash_size() - 1UL);
151151
TEST_ASSERT_NOT_EQUAL(sector_size, 0);
152152
const uint8_t test_value = 0xCE;
153153
uint8_t *data = new uint8_t[sector_size];
@@ -156,7 +156,7 @@ void flashiap_write_error_test()
156156
}
157157

158158
// the one before the last page in the system
159-
uint32_t address = (flash_device.get_flash_size()) - (sector_size);
159+
uint32_t address = (flash_device.get_flash_start() + flash_device.get_flash_size()) - (sector_size);
160160
TEST_ASSERT_TRUE(address != 0UL);
161161

162162
// unaligned address

TESTS/mbed_hal/flash/functional_tests/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void flash_program_page_test()
6060
}
6161

6262
// the one before the last page in the system
63-
uint32_t address = (test_flash.target_config->flash_start + test_flash.target_config->flash_size) - (2*test_size);
63+
uint32_t address = flash_get_start_address(&test_flash) + flash_get_size(&test_flash) - (2*test_size);
6464

6565
// sector size might not be same as page size
6666
uint32_t erase_sector_boundary = ALIGN_DOWN(address, flash_get_sector_size(&test_flash, address));
@@ -97,7 +97,7 @@ void flash_erase_sector_test()
9797
TEST_ASSERT_EQUAL_INT32(ret, 0);
9898

9999
uint32_t sector_size = 0x1000;
100-
uint32_t address = (test_flash.target_config->flash_start + test_flash.target_config->flash_size) - (4*sector_size);
100+
uint32_t address = flash_get_start_address(&test_flash) + flash_get_size(&test_flash) - (4*sector_size);
101101
// sector size might not be same as page size
102102
uint32_t erase_sector_boundary = ALIGN_DOWN(address, flash_get_sector_size(&test_flash, address));
103103
ret = flash_erase_sector(&test_flash, erase_sector_boundary);
@@ -115,7 +115,7 @@ void flash_erase_sector_error_test()
115115

116116
// most common sector size to get an sector address
117117
uint32_t sector_size = 0x1000;
118-
uint32_t address = (test_flash.target_config->flash_start + test_flash.target_config->flash_size) - (4*sector_size);
118+
uint32_t address = flash_get_start_address(&test_flash) + flash_get_size(&test_flash) - (4*sector_size);
119119
uint32_t erase_sector_boundary = ALIGN_DOWN(address, flash_get_sector_size(&test_flash, address));
120120

121121
// unaligned address
@@ -136,7 +136,7 @@ void flash_program_page_error_test()
136136

137137
uint32_t test_size = flash_get_page_size(&test_flash);
138138
// the one before the last page in the system
139-
uint32_t address = (test_flash.target_config->flash_start + test_flash.target_config->flash_size) - (2*test_size);
139+
uint32_t address = flash_get_start_address(&test_flash) + flash_get_size(&test_flash) - (2*test_size);
140140

141141
// sector size might not be same as page size
142142
uint32_t erase_sector_boundary = ALIGN_DOWN(address, flash_get_sector_size(&test_flash, address));

drivers/FlashIAP.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ uint32_t FlashIAP::get_sector_size(uint32_t addr) const
165165
return flash_get_sector_size(&_flash, addr);
166166
}
167167

168+
uint32_t FlashIAP::get_flash_start() const
169+
{
170+
return flash_get_start_address(&_flash);
171+
}
172+
168173
uint32_t FlashIAP::get_flash_size() const
169174
{
170175
return flash_get_size(&_flash);

drivers/FlashIAP.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,15 @@ class FlashIAP {
107107
*/
108108
uint32_t get_sector_size(uint32_t addr) const;
109109

110-
/** Get the total size of the underlying device
110+
/** Get the flash start address
111111
*
112-
* @return Size of the underlying device in bytes
112+
* @return Flash start address
113+
*/
114+
uint32_t get_flash_start() const;
115+
116+
/** Get the flash size
117+
*
118+
* @return Flash size
113119
*/
114120
uint32_t get_flash_size() const;
115121

hal/TARGET_FLASH_CMSIS_ALGO/flash_common_algo.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ uint32_t flash_get_page_size(const flash_t *obj)
161161
return obj->target_config->page_size;
162162
}
163163

164+
uint32_t flash_get_start_address(const flash_t *obj)
165+
{
166+
return obj->target_config->flash_start;
167+
}
168+
164169
uint32_t flash_get_size(const flash_t *obj)
165170
{
166171
return obj->target_config->flash_size;

hal/flash_api.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address);
9090
*/
9191
uint32_t flash_get_page_size(const flash_t *obj);
9292

93-
/** Get flash size
93+
/** Get start address for the flash region
9494
*
9595
* @param obj The flash objects
96-
* @return The size of the flash available
96+
* @return The start address for the flash region
97+
*/
98+
uint32_t flash_get_start_address(const flash_t *obj);
99+
100+
/** Get the flash region size
101+
*
102+
* @param obj The flash objects
103+
* @return The flash region size
97104
*/
98105
uint32_t flash_get_size(const flash_t *obj);
99106

0 commit comments

Comments
 (0)