diff options
author | Joel Challis <git@zvecr.com> | 2021-11-19 18:41:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 10:41:02 -0800 |
commit | 2728603fe6d73e805a539d337fd01051c46ca806 (patch) | |
tree | 5c83ffc7efa112da870bd5d8502a9d91d4792f35 /platforms/test | |
parent | 43b9e23bae12916d5161f03700c9bfe46737324b (diff) | |
download | qmk_firmware-2728603fe6d73e805a539d337fd01051c46ca806.tar.gz qmk_firmware-2728603fe6d73e805a539d337fd01051c46ca806.zip |
Move tmk_core/common/<plat> (#13918)
Diffstat (limited to 'platforms/test')
-rw-r--r-- | platforms/test/_wait.h | 22 | ||||
-rw-r--r-- | platforms/test/bootloader.c | 19 | ||||
-rw-r--r-- | platforms/test/eeprom.c | 95 | ||||
-rw-r--r-- | platforms/test/eeprom_stm32_tests.cpp | 438 | ||||
-rw-r--r-- | platforms/test/flash_stm32_mock.c | 49 | ||||
-rw-r--r-- | platforms/test/hal.h | 18 | ||||
-rw-r--r-- | platforms/test/platform.c | 21 | ||||
-rw-r--r-- | platforms/test/platform.h | 18 | ||||
-rw-r--r-- | platforms/test/platform.mk | 34 | ||||
-rw-r--r-- | platforms/test/platform_deps.h | 18 | ||||
-rw-r--r-- | platforms/test/rules.mk | 24 | ||||
-rw-r--r-- | platforms/test/suspend.c | 15 | ||||
-rw-r--r-- | platforms/test/testlist.mk | 1 | ||||
-rw-r--r-- | platforms/test/timer.c | 33 |
14 files changed, 805 insertions, 0 deletions
diff --git a/platforms/test/_wait.h b/platforms/test/_wait.h new file mode 100644 index 000000000..4e22f593b --- /dev/null +++ b/platforms/test/_wait.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* Copyright 2021 QMK | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #pragma once | ||
17 | |||
18 | #include <inttypes.h> | ||
19 | |||
20 | void wait_ms(uint32_t ms); | ||
21 | #define wait_us(us) wait_ms(us / 1000) | ||
22 | #define waitInputPinDelay() | ||
diff --git a/platforms/test/bootloader.c b/platforms/test/bootloader.c new file mode 100644 index 000000000..5155d9ff0 --- /dev/null +++ b/platforms/test/bootloader.c | |||
@@ -0,0 +1,19 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "bootloader.h" | ||
18 | |||
19 | void bootloader_jump(void) {} | ||
diff --git a/platforms/test/eeprom.c b/platforms/test/eeprom.c new file mode 100644 index 000000000..5c8e69dae --- /dev/null +++ b/platforms/test/eeprom.c | |||
@@ -0,0 +1,95 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "eeprom.h" | ||
18 | |||
19 | #define EEPROM_SIZE 32 | ||
20 | |||
21 | static uint8_t buffer[EEPROM_SIZE]; | ||
22 | |||
23 | uint8_t eeprom_read_byte(const uint8_t *addr) { | ||
24 | uintptr_t offset = (uintptr_t)addr; | ||
25 | return buffer[offset]; | ||
26 | } | ||
27 | |||
28 | void eeprom_write_byte(uint8_t *addr, uint8_t value) { | ||
29 | uintptr_t offset = (uintptr_t)addr; | ||
30 | buffer[offset] = value; | ||
31 | } | ||
32 | |||
33 | uint16_t eeprom_read_word(const uint16_t *addr) { | ||
34 | const uint8_t *p = (const uint8_t *)addr; | ||
35 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8); | ||
36 | } | ||
37 | |||
38 | uint32_t eeprom_read_dword(const uint32_t *addr) { | ||
39 | const uint8_t *p = (const uint8_t *)addr; | ||
40 | return eeprom_read_byte(p) | (eeprom_read_byte(p + 1) << 8) | (eeprom_read_byte(p + 2) << 16) | (eeprom_read_byte(p + 3) << 24); | ||
41 | } | ||
42 | |||
43 | void eeprom_read_block(void *buf, const void *addr, size_t len) { | ||
44 | const uint8_t *p = (const uint8_t *)addr; | ||
45 | uint8_t * dest = (uint8_t *)buf; | ||
46 | while (len--) { | ||
47 | *dest++ = eeprom_read_byte(p++); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | void eeprom_write_word(uint16_t *addr, uint16_t value) { | ||
52 | uint8_t *p = (uint8_t *)addr; | ||
53 | eeprom_write_byte(p++, value); | ||
54 | eeprom_write_byte(p, value >> 8); | ||
55 | } | ||
56 | |||
57 | void eeprom_write_dword(uint32_t *addr, uint32_t value) { | ||
58 | uint8_t *p = (uint8_t *)addr; | ||
59 | eeprom_write_byte(p++, value); | ||
60 | eeprom_write_byte(p++, value >> 8); | ||
61 | eeprom_write_byte(p++, value >> 16); | ||
62 | eeprom_write_byte(p, value >> 24); | ||
63 | } | ||
64 | |||
65 | void eeprom_write_block(const void *buf, void *addr, size_t len) { | ||
66 | uint8_t * p = (uint8_t *)addr; | ||
67 | const uint8_t *src = (const uint8_t *)buf; | ||
68 | while (len--) { | ||
69 | eeprom_write_byte(p++, *src++); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | void eeprom_update_byte(uint8_t *addr, uint8_t value) { eeprom_write_byte(addr, value); } | ||
74 | |||
75 | void eeprom_update_word(uint16_t *addr, uint16_t value) { | ||
76 | uint8_t *p = (uint8_t *)addr; | ||
77 | eeprom_write_byte(p++, value); | ||
78 | eeprom_write_byte(p, value >> 8); | ||
79 | } | ||
80 | |||
81 | void eeprom_update_dword(uint32_t *addr, uint32_t value) { | ||
82 | uint8_t *p = (uint8_t *)addr; | ||
83 | eeprom_write_byte(p++, value); | ||
84 | eeprom_write_byte(p++, value >> 8); | ||
85 | eeprom_write_byte(p++, value >> 16); | ||
86 | eeprom_write_byte(p, value >> 24); | ||
87 | } | ||
88 | |||
89 | void eeprom_update_block(const void *buf, void *addr, size_t len) { | ||
90 | uint8_t * p = (uint8_t *)addr; | ||
91 | const uint8_t *src = (const uint8_t *)buf; | ||
92 | while (len--) { | ||
93 | eeprom_write_byte(p++, *src++); | ||
94 | } | ||
95 | } | ||
diff --git a/platforms/test/eeprom_stm32_tests.cpp b/platforms/test/eeprom_stm32_tests.cpp new file mode 100644 index 000000000..5bc8d8790 --- /dev/null +++ b/platforms/test/eeprom_stm32_tests.cpp | |||
@@ -0,0 +1,438 @@ | |||
1 | /* Copyright 2021 by Don Kjer | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "gtest/gtest.h" | ||
18 | |||
19 | extern "C" { | ||
20 | #include "flash_stm32.h" | ||
21 | #include "eeprom_stm32.h" | ||
22 | #include "eeprom.h" | ||
23 | } | ||
24 | |||
25 | /* Mock Flash Parameters: | ||
26 | * | ||
27 | * === Large Layout === | ||
28 | * flash size: 65536 | ||
29 | * page size: 2048 | ||
30 | * density pages: 16 | ||
31 | * Simulated EEPROM size: 16384 | ||
32 | * | ||
33 | * FlashBuf Layout: | ||
34 | * [Unused | Compact | Write Log ] | ||
35 | * [0......|32768......|49152......65535] | ||
36 | * | ||
37 | * === Tiny Layout === | ||
38 | * flash size: 1024 | ||
39 | * page size: 512 | ||
40 | * density pages: 1 | ||
41 | * Simulated EEPROM size: 256 | ||
42 | * | ||
43 | * FlashBuf Layout: | ||
44 | * [Unused | Compact | Write Log ] | ||
45 | * [0......|512......|768......1023] | ||
46 | * | ||
47 | */ | ||
48 | |||
49 | #define EEPROM_SIZE (FEE_PAGE_SIZE * FEE_PAGE_COUNT / 2) | ||
50 | #define LOG_SIZE EEPROM_SIZE | ||
51 | #define LOG_BASE (MOCK_FLASH_SIZE - LOG_SIZE) | ||
52 | #define EEPROM_BASE (LOG_BASE - EEPROM_SIZE) | ||
53 | |||
54 | /* Log encoding helpers */ | ||
55 | #define BYTE_VALUE(addr, value) (((addr) << 8) | (value)) | ||
56 | #define WORD_ZERO(addr) (0x8000 | ((addr) >> 1)) | ||
57 | #define WORD_ONE(addr) (0xA000 | ((addr) >> 1)) | ||
58 | #define WORD_NEXT(addr) (0xE000 | (((addr)-0x80) >> 1)) | ||
59 | |||
60 | class EepromStm32Test : public testing::Test { | ||
61 | public: | ||
62 | EepromStm32Test() {} | ||
63 | ~EepromStm32Test() {} | ||
64 | |||
65 | protected: | ||
66 | void SetUp() override { EEPROM_Erase(); } | ||
67 | |||
68 | void TearDown() override { | ||
69 | #ifdef EEPROM_DEBUG | ||
70 | dumpEepromDataBuf(); | ||
71 | #endif | ||
72 | } | ||
73 | }; | ||
74 | |||
75 | TEST_F(EepromStm32Test, TestErase) { | ||
76 | EEPROM_WriteDataByte(0, 0x42); | ||
77 | EEPROM_Erase(); | ||
78 | EXPECT_EQ(EEPROM_ReadDataByte(0), 0); | ||
79 | EXPECT_EQ(EEPROM_ReadDataByte(1), 0); | ||
80 | } | ||
81 | |||
82 | TEST_F(EepromStm32Test, TestReadGarbage) { | ||
83 | uint8_t garbage = 0x3c; | ||
84 | for (int i = 0; i < MOCK_FLASH_SIZE; ++i) { | ||
85 | garbage ^= 0xa3; | ||
86 | garbage += i; | ||
87 | FlashBuf[i] = garbage; | ||
88 | } | ||
89 | EEPROM_Init(); // Just verify we don't crash | ||
90 | } | ||
91 | |||
92 | TEST_F(EepromStm32Test, TestWriteBadAddress) { | ||
93 | EXPECT_EQ(EEPROM_WriteDataByte(EEPROM_SIZE, 0x42), FLASH_BAD_ADDRESS); | ||
94 | EXPECT_EQ(EEPROM_WriteDataWord(EEPROM_SIZE - 1, 0xbeef), FLASH_BAD_ADDRESS); | ||
95 | EXPECT_EQ(EEPROM_WriteDataWord(EEPROM_SIZE, 0xbeef), FLASH_BAD_ADDRESS); | ||
96 | } | ||
97 | |||
98 | TEST_F(EepromStm32Test, TestReadBadAddress) { | ||
99 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE), 0xFF); | ||
100 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 1), 0xFFFF); | ||
101 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE), 0xFFFF); | ||
102 | EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 4)), 0); | ||
103 | EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 3)), 0xFF000000); | ||
104 | EXPECT_EQ(eeprom_read_dword((uint32_t*)EEPROM_SIZE), 0xFFFFFFFF); | ||
105 | } | ||
106 | |||
107 | TEST_F(EepromStm32Test, TestReadByte) { | ||
108 | /* Direct compacted-area baseline: Address < 0x80 */ | ||
109 | FlashBuf[EEPROM_BASE + 2] = ~0xef; | ||
110 | FlashBuf[EEPROM_BASE + 3] = ~0xbe; | ||
111 | /* Direct compacted-area baseline: Address >= 0x80 */ | ||
112 | FlashBuf[EEPROM_BASE + EEPROM_SIZE - 2] = ~0x78; | ||
113 | FlashBuf[EEPROM_BASE + EEPROM_SIZE - 1] = ~0x56; | ||
114 | /* Check values */ | ||
115 | EEPROM_Init(); | ||
116 | EXPECT_EQ(EEPROM_ReadDataByte(2), 0xef); | ||
117 | EXPECT_EQ(EEPROM_ReadDataByte(3), 0xbe); | ||
118 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE - 2), 0x78); | ||
119 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE - 1), 0x56); | ||
120 | /* Write Log byte value */ | ||
121 | FlashBuf[LOG_BASE] = 0x65; | ||
122 | FlashBuf[LOG_BASE + 1] = 3; | ||
123 | /* Write Log word value */ | ||
124 | *(uint16_t*)&FlashBuf[LOG_BASE + 2] = WORD_NEXT(EEPROM_SIZE - 2); | ||
125 | *(uint16_t*)&FlashBuf[LOG_BASE + 4] = ~0x9abc; | ||
126 | /* Check values */ | ||
127 | EEPROM_Init(); | ||
128 | EXPECT_EQ(EEPROM_ReadDataByte(2), 0xef); | ||
129 | EXPECT_EQ(EEPROM_ReadDataByte(3), 0x65); | ||
130 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE - 2), 0xbc); | ||
131 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE - 1), 0x9a); | ||
132 | } | ||
133 | |||
134 | TEST_F(EepromStm32Test, TestWriteByte) { | ||
135 | /* Direct compacted-area baseline: Address < 0x80 */ | ||
136 | EEPROM_WriteDataByte(2, 0xef); | ||
137 | EEPROM_WriteDataByte(3, 0xbe); | ||
138 | /* Direct compacted-area baseline: Address >= 0x80 */ | ||
139 | EEPROM_WriteDataByte(EEPROM_SIZE - 2, 0x78); | ||
140 | EEPROM_WriteDataByte(EEPROM_SIZE - 1, 0x56); | ||
141 | /* Check values */ | ||
142 | /* First write in each aligned word should have been direct */ | ||
143 | EXPECT_EQ(FlashBuf[EEPROM_BASE + 2], (uint8_t)~0xef); | ||
144 | EXPECT_EQ(FlashBuf[EEPROM_BASE + EEPROM_SIZE - 2], (uint8_t)~0x78); | ||
145 | |||
146 | /* Second write per aligned word requires a log entry */ | ||
147 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE], BYTE_VALUE(3, 0xbe)); | ||
148 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 2], WORD_NEXT(EEPROM_SIZE - 1)); | ||
149 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 4], (uint16_t)~0x5678); | ||
150 | } | ||
151 | |||
152 | TEST_F(EepromStm32Test, TestByteRoundTrip) { | ||
153 | /* Direct compacted-area: Address < 0x80 */ | ||
154 | EEPROM_WriteDataWord(0, 0xdead); | ||
155 | EEPROM_WriteDataByte(2, 0xef); | ||
156 | EEPROM_WriteDataByte(3, 0xbe); | ||
157 | /* Direct compacted-area: Address >= 0x80 */ | ||
158 | EEPROM_WriteDataByte(EEPROM_SIZE - 2, 0x78); | ||
159 | EEPROM_WriteDataByte(EEPROM_SIZE - 1, 0x56); | ||
160 | /* Check values */ | ||
161 | EEPROM_Init(); | ||
162 | EXPECT_EQ(EEPROM_ReadDataByte(0), 0xad); | ||
163 | EXPECT_EQ(EEPROM_ReadDataByte(1), 0xde); | ||
164 | EXPECT_EQ(EEPROM_ReadDataByte(2), 0xef); | ||
165 | EXPECT_EQ(EEPROM_ReadDataByte(3), 0xbe); | ||
166 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE - 2), 0x78); | ||
167 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE - 1), 0x56); | ||
168 | /* Write log entries */ | ||
169 | EEPROM_WriteDataByte(2, 0x80); | ||
170 | EEPROM_WriteDataByte(EEPROM_SIZE - 2, 0x3c); | ||
171 | /* Check values */ | ||
172 | EEPROM_Init(); | ||
173 | EXPECT_EQ(EEPROM_ReadDataByte(2), 0x80); | ||
174 | EXPECT_EQ(EEPROM_ReadDataByte(3), 0xbe); | ||
175 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE - 2), 0x3c); | ||
176 | EXPECT_EQ(EEPROM_ReadDataByte(EEPROM_SIZE - 1), 0x56); | ||
177 | } | ||
178 | |||
179 | TEST_F(EepromStm32Test, TestReadWord) { | ||
180 | /* Direct compacted-area baseline: Address < 0x80 */ | ||
181 | FlashBuf[EEPROM_BASE + 0] = ~0xad; | ||
182 | FlashBuf[EEPROM_BASE + 1] = ~0xde; | ||
183 | /* Direct compacted-area baseline: Address >= 0x80 */ | ||
184 | FlashBuf[EEPROM_BASE + 200] = ~0xcd; | ||
185 | FlashBuf[EEPROM_BASE + 201] = ~0xab; | ||
186 | FlashBuf[EEPROM_BASE + EEPROM_SIZE - 4] = ~0x34; | ||
187 | FlashBuf[EEPROM_BASE + EEPROM_SIZE - 3] = ~0x12; | ||
188 | FlashBuf[EEPROM_BASE + EEPROM_SIZE - 2] = ~0x78; | ||
189 | FlashBuf[EEPROM_BASE + EEPROM_SIZE - 1] = ~0x56; | ||
190 | /* Check values */ | ||
191 | EEPROM_Init(); | ||
192 | EXPECT_EQ(EEPROM_ReadDataWord(0), 0xdead); | ||
193 | EXPECT_EQ(EEPROM_ReadDataWord(200), 0xabcd); | ||
194 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 4), 0x1234); | ||
195 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 2), 0x5678); | ||
196 | /* Write Log word zero-encoded */ | ||
197 | *(uint16_t*)&FlashBuf[LOG_BASE] = WORD_ZERO(200); | ||
198 | /* Write Log word one-encoded */ | ||
199 | *(uint16_t*)&FlashBuf[LOG_BASE + 2] = WORD_ONE(EEPROM_SIZE - 4); | ||
200 | /* Write Log word value */ | ||
201 | *(uint16_t*)&FlashBuf[LOG_BASE + 4] = WORD_NEXT(EEPROM_SIZE - 2); | ||
202 | *(uint16_t*)&FlashBuf[LOG_BASE + 6] = ~0x9abc; | ||
203 | /* Check values */ | ||
204 | EEPROM_Init(); | ||
205 | EXPECT_EQ(EEPROM_ReadDataWord(200), 0); | ||
206 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 4), 1); | ||
207 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 2), 0x9abc); | ||
208 | } | ||
209 | |||
210 | TEST_F(EepromStm32Test, TestWriteWord) { | ||
211 | /* Direct compacted-area: Address < 0x80 */ | ||
212 | EEPROM_WriteDataWord(0, 0xdead); // Aligned | ||
213 | EEPROM_WriteDataWord(3, 0xbeef); // Unaligned | ||
214 | /* Direct compacted-area: Address >= 0x80 */ | ||
215 | EEPROM_WriteDataWord(200, 0xabcd); // Aligned | ||
216 | EEPROM_WriteDataWord(203, 0x9876); // Unaligned | ||
217 | EEPROM_WriteDataWord(EEPROM_SIZE - 4, 0x1234); | ||
218 | EEPROM_WriteDataWord(EEPROM_SIZE - 2, 0x5678); | ||
219 | /* Write Log word zero-encoded */ | ||
220 | EEPROM_WriteDataWord(EEPROM_SIZE - 4, 0); | ||
221 | /* Write Log word one-encoded */ | ||
222 | EEPROM_WriteDataWord(EEPROM_SIZE - 2, 1); | ||
223 | /* Write Log word value aligned */ | ||
224 | EEPROM_WriteDataWord(200, 0x4321); // Aligned | ||
225 | /* Write Log word value unaligned */ | ||
226 | EEPROM_WriteDataByte(202, 0x3c); // Set neighboring byte | ||
227 | EEPROM_WriteDataWord(203, 0xcdef); // Unaligned | ||
228 | /* Check values */ | ||
229 | /* Direct compacted-area */ | ||
230 | EXPECT_EQ(*(uint16_t*)&FlashBuf[EEPROM_BASE], (uint16_t)~0xdead); | ||
231 | EXPECT_EQ(*(uint16_t*)&FlashBuf[EEPROM_BASE + 3], (uint16_t)~0xbeef); | ||
232 | EXPECT_EQ(*(uint16_t*)&FlashBuf[EEPROM_BASE + 200], (uint16_t)~0xabcd); | ||
233 | EXPECT_EQ(FlashBuf[EEPROM_BASE + 203], (uint8_t)~0x76); | ||
234 | EXPECT_EQ(FlashBuf[EEPROM_BASE + 204], (uint8_t)~0x98); | ||
235 | EXPECT_EQ(*(uint16_t*)&FlashBuf[EEPROM_BASE + EEPROM_SIZE - 4], (uint16_t)~0x1234); | ||
236 | EXPECT_EQ(*(uint16_t*)&FlashBuf[EEPROM_BASE + EEPROM_SIZE - 2], (uint16_t)~0x5678); | ||
237 | /* Write Log word zero-encoded */ | ||
238 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE], WORD_ZERO(EEPROM_SIZE - 4)); | ||
239 | /* Write Log word one-encoded */ | ||
240 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 2], WORD_ONE(EEPROM_SIZE - 2)); | ||
241 | /* Write Log word value aligned */ | ||
242 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 4], WORD_NEXT(200)); | ||
243 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 6], (uint16_t)~0x4321); | ||
244 | /* Write Log word value unaligned */ | ||
245 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 8], WORD_NEXT(202)); | ||
246 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 10], (uint16_t)~0x763c); | ||
247 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 12], WORD_NEXT(202)); | ||
248 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 14], (uint16_t)~0xef3c); | ||
249 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 16], WORD_NEXT(204)); | ||
250 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 18], (uint16_t)~0x00cd); | ||
251 | } | ||
252 | |||
253 | TEST_F(EepromStm32Test, TestWordRoundTrip) { | ||
254 | /* Direct compacted-area: Address < 0x80 */ | ||
255 | EEPROM_WriteDataWord(0, 0xdead); // Aligned | ||
256 | EEPROM_WriteDataWord(3, 0xbeef); // Unaligned | ||
257 | /* Direct compacted-area: Address >= 0x80 */ | ||
258 | EEPROM_WriteDataWord(200, 0xabcd); // Aligned | ||
259 | EEPROM_WriteDataWord(203, 0x9876); // Unaligned | ||
260 | EEPROM_WriteDataWord(EEPROM_SIZE - 4, 0x1234); | ||
261 | EEPROM_WriteDataWord(EEPROM_SIZE - 2, 0x5678); | ||
262 | /* Check values */ | ||
263 | EEPROM_Init(); | ||
264 | EXPECT_EQ(EEPROM_ReadDataWord(0), 0xdead); | ||
265 | EXPECT_EQ(EEPROM_ReadDataWord(3), 0xbeef); | ||
266 | EXPECT_EQ(EEPROM_ReadDataWord(200), 0xabcd); | ||
267 | EXPECT_EQ(EEPROM_ReadDataWord(203), 0x9876); | ||
268 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 4), 0x1234); | ||
269 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 2), 0x5678); | ||
270 | |||
271 | /* Write Log word zero-encoded */ | ||
272 | EEPROM_WriteDataWord(EEPROM_SIZE - 4, 0); | ||
273 | /* Write Log word one-encoded */ | ||
274 | EEPROM_WriteDataWord(EEPROM_SIZE - 2, 1); | ||
275 | /* Write Log word value aligned */ | ||
276 | EEPROM_WriteDataWord(200, 0x4321); // Aligned | ||
277 | /* Write Log word value unaligned */ | ||
278 | EEPROM_WriteDataByte(202, 0x3c); // Set neighboring byte | ||
279 | EEPROM_WriteDataWord(203, 0xcdef); // Unaligned | ||
280 | /* Check values */ | ||
281 | EEPROM_Init(); | ||
282 | EXPECT_EQ(EEPROM_ReadDataWord(200), 0x4321); | ||
283 | EXPECT_EQ(EEPROM_ReadDataByte(202), 0x3c); | ||
284 | EXPECT_EQ(EEPROM_ReadDataWord(203), 0xcdef); | ||
285 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 4), 0); | ||
286 | EXPECT_EQ(EEPROM_ReadDataWord(EEPROM_SIZE - 2), 1); | ||
287 | } | ||
288 | |||
289 | TEST_F(EepromStm32Test, TestByteWordBoundary) { | ||
290 | /* Direct compacted-area write */ | ||
291 | EEPROM_WriteDataWord(0x7e, 0xdead); | ||
292 | EEPROM_WriteDataWord(0x80, 0xbeef); | ||
293 | /* Byte log entry */ | ||
294 | EEPROM_WriteDataByte(0x7f, 0x3c); | ||
295 | /* Word log entry */ | ||
296 | EEPROM_WriteDataByte(0x80, 0x18); | ||
297 | /* Check values */ | ||
298 | EEPROM_Init(); | ||
299 | EXPECT_EQ(EEPROM_ReadDataWord(0x7e), 0x3cad); | ||
300 | EXPECT_EQ(EEPROM_ReadDataWord(0x80), 0xbe18); | ||
301 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE], BYTE_VALUE(0x7f, 0x3c)); | ||
302 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 2], WORD_NEXT(0x80)); | ||
303 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 4], (uint16_t)~0xbe18); | ||
304 | /* Byte log entries */ | ||
305 | EEPROM_WriteDataWord(0x7e, 0xcafe); | ||
306 | /* Check values */ | ||
307 | EEPROM_Init(); | ||
308 | EXPECT_EQ(EEPROM_ReadDataWord(0x7e), 0xcafe); | ||
309 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 6], BYTE_VALUE(0x7e, 0xfe)); | ||
310 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 8], BYTE_VALUE(0x7f, 0xca)); | ||
311 | /* Byte and Word log entries */ | ||
312 | EEPROM_WriteDataWord(0x7f, 0xba5e); | ||
313 | /* Check values */ | ||
314 | EEPROM_Init(); | ||
315 | EXPECT_EQ(EEPROM_ReadDataWord(0x7f), 0xba5e); | ||
316 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 10], BYTE_VALUE(0x7f, 0x5e)); | ||
317 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 12], WORD_NEXT(0x80)); | ||
318 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 14], (uint16_t)~0xbeba); | ||
319 | /* Word log entry */ | ||
320 | EEPROM_WriteDataWord(0x80, 0xf00d); | ||
321 | /* Check values */ | ||
322 | EEPROM_Init(); | ||
323 | EXPECT_EQ(EEPROM_ReadDataWord(0x80), 0xf00d); | ||
324 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 16], WORD_NEXT(0x80)); | ||
325 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + 18], (uint16_t)~0xf00d); | ||
326 | } | ||
327 | |||
328 | TEST_F(EepromStm32Test, TestDWordRoundTrip) { | ||
329 | /* Direct compacted-area: Address < 0x80 */ | ||
330 | eeprom_write_dword((uint32_t*)0, 0xdeadbeef); // Aligned | ||
331 | eeprom_write_dword((uint32_t*)9, 0x12345678); // Unaligned | ||
332 | /* Direct compacted-area: Address >= 0x80 */ | ||
333 | eeprom_write_dword((uint32_t*)200, 0xfacef00d); | ||
334 | eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 4), 0xba5eba11); // Aligned | ||
335 | eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 9), 0xcafed00d); // Unaligned | ||
336 | /* Check direct values */ | ||
337 | EEPROM_Init(); | ||
338 | EXPECT_EQ(eeprom_read_dword((uint32_t*)0), 0xdeadbeef); | ||
339 | EXPECT_EQ(eeprom_read_dword((uint32_t*)9), 0x12345678); | ||
340 | EXPECT_EQ(eeprom_read_dword((uint32_t*)200), 0xfacef00d); | ||
341 | EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 4)), 0xba5eba11); // Aligned | ||
342 | EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 9)), 0xcafed00d); // Unaligned | ||
343 | /* Write Log byte encoded */ | ||
344 | eeprom_write_dword((uint32_t*)0, 0xdecafbad); | ||
345 | eeprom_write_dword((uint32_t*)9, 0x87654321); | ||
346 | /* Write Log word encoded */ | ||
347 | eeprom_write_dword((uint32_t*)200, 1); | ||
348 | /* Write Log word value aligned */ | ||
349 | eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 4), 0xdeadc0de); // Aligned | ||
350 | eeprom_write_dword((uint32_t*)(EEPROM_SIZE - 9), 0x6789abcd); // Unaligned | ||
351 | /* Check log values */ | ||
352 | EEPROM_Init(); | ||
353 | EXPECT_EQ(eeprom_read_dword((uint32_t*)0), 0xdecafbad); | ||
354 | EXPECT_EQ(eeprom_read_dword((uint32_t*)9), 0x87654321); | ||
355 | EXPECT_EQ(eeprom_read_dword((uint32_t*)200), 1); | ||
356 | EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 4)), 0xdeadc0de); // Aligned | ||
357 | EXPECT_EQ(eeprom_read_dword((uint32_t*)(EEPROM_SIZE - 9)), 0x6789abcd); // Unaligned | ||
358 | } | ||
359 | |||
360 | TEST_F(EepromStm32Test, TestBlockRoundTrip) { | ||
361 | char src0[] = "0123456789abcdef"; | ||
362 | void* src1 = (void*)&src0[1]; | ||
363 | /* Various alignments of src & dst, Address < 0x80 */ | ||
364 | eeprom_write_block(src0, (void*)0, sizeof(src0)); | ||
365 | eeprom_write_block(src0, (void*)21, sizeof(src0)); | ||
366 | eeprom_write_block(src1, (void*)40, sizeof(src0) - 1); | ||
367 | eeprom_write_block(src1, (void*)61, sizeof(src0) - 1); | ||
368 | /* Various alignments of src & dst, Address >= 0x80 */ | ||
369 | eeprom_write_block(src0, (void*)140, sizeof(src0)); | ||
370 | eeprom_write_block(src0, (void*)161, sizeof(src0)); | ||
371 | eeprom_write_block(src1, (void*)180, sizeof(src0) - 1); | ||
372 | eeprom_write_block(src1, (void*)201, sizeof(src0) - 1); | ||
373 | |||
374 | /* Check values */ | ||
375 | EEPROM_Init(); | ||
376 | |||
377 | char dstBuf[256] = {0}; | ||
378 | char* dst0a = (char*)dstBuf; | ||
379 | char* dst0b = (char*)&dstBuf[20]; | ||
380 | char* dst1a = (char*)&dstBuf[41]; | ||
381 | char* dst1b = (char*)&dstBuf[61]; | ||
382 | char* dst0c = (char*)&dstBuf[80]; | ||
383 | char* dst0d = (char*)&dstBuf[100]; | ||
384 | char* dst1c = (char*)&dstBuf[121]; | ||
385 | char* dst1d = (char*)&dstBuf[141]; | ||
386 | eeprom_read_block((void*)dst0a, (void*)0, sizeof(src0)); | ||
387 | eeprom_read_block((void*)dst0b, (void*)21, sizeof(src0)); | ||
388 | eeprom_read_block((void*)dst1a, (void*)40, sizeof(src0) - 1); | ||
389 | eeprom_read_block((void*)dst1b, (void*)61, sizeof(src0) - 1); | ||
390 | eeprom_read_block((void*)dst0c, (void*)140, sizeof(src0)); | ||
391 | eeprom_read_block((void*)dst0d, (void*)161, sizeof(src0)); | ||
392 | eeprom_read_block((void*)dst1c, (void*)180, sizeof(src0) - 1); | ||
393 | eeprom_read_block((void*)dst1d, (void*)201, sizeof(src0) - 1); | ||
394 | EXPECT_EQ(strcmp((char*)src0, dst0a), 0); | ||
395 | EXPECT_EQ(strcmp((char*)src0, dst0b), 0); | ||
396 | EXPECT_EQ(strcmp((char*)src0, dst0c), 0); | ||
397 | EXPECT_EQ(strcmp((char*)src0, dst0d), 0); | ||
398 | EXPECT_EQ(strcmp((char*)src1, dst1a), 0); | ||
399 | EXPECT_EQ(strcmp((char*)src1, dst1b), 0); | ||
400 | EXPECT_EQ(strcmp((char*)src1, dst1c), 0); | ||
401 | EXPECT_EQ(strcmp((char*)src1, dst1d), 0); | ||
402 | } | ||
403 | |||
404 | TEST_F(EepromStm32Test, TestCompaction) { | ||
405 | /* Direct writes */ | ||
406 | eeprom_write_dword((uint32_t*)0, 0xdeadbeef); | ||
407 | eeprom_write_byte((uint8_t*)4, 0x3c); | ||
408 | eeprom_write_word((uint16_t*)6, 0xd00d); | ||
409 | eeprom_write_dword((uint32_t*)150, 0xcafef00d); | ||
410 | eeprom_write_dword((uint32_t*)200, 0x12345678); | ||
411 | /* Fill write log entries */ | ||
412 | uint32_t i; | ||
413 | uint32_t val = 0xd8453c6b; | ||
414 | for (i = 0; i < (LOG_SIZE / (sizeof(uint32_t) * 2)); i++) { | ||
415 | val ^= 0x593ca5b3; | ||
416 | val += i; | ||
417 | eeprom_write_dword((uint32_t*)200, val); | ||
418 | } | ||
419 | /* Check values pre-compaction */ | ||
420 | EEPROM_Init(); | ||
421 | EXPECT_EQ(eeprom_read_dword((uint32_t*)0), 0xdeadbeef); | ||
422 | EXPECT_EQ(eeprom_read_byte((uint8_t*)4), 0x3c); | ||
423 | EXPECT_EQ(eeprom_read_word((uint16_t*)6), 0xd00d); | ||
424 | EXPECT_EQ(eeprom_read_dword((uint32_t*)150), 0xcafef00d); | ||
425 | EXPECT_EQ(eeprom_read_dword((uint32_t*)200), val); | ||
426 | EXPECT_NE(*(uint16_t*)&FlashBuf[LOG_BASE], 0xFFFF); | ||
427 | EXPECT_NE(*(uint16_t*)&FlashBuf[LOG_BASE + LOG_SIZE - 2], 0xFFFF); | ||
428 | /* Run compaction */ | ||
429 | eeprom_write_byte((uint8_t*)4, 0x1f); | ||
430 | EEPROM_Init(); | ||
431 | EXPECT_EQ(eeprom_read_dword((uint32_t*)0), 0xdeadbeef); | ||
432 | EXPECT_EQ(eeprom_read_byte((uint8_t*)4), 0x1f); | ||
433 | EXPECT_EQ(eeprom_read_word((uint16_t*)6), 0xd00d); | ||
434 | EXPECT_EQ(eeprom_read_dword((uint32_t*)150), 0xcafef00d); | ||
435 | EXPECT_EQ(eeprom_read_dword((uint32_t*)200), val); | ||
436 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE], 0xFFFF); | ||
437 | EXPECT_EQ(*(uint16_t*)&FlashBuf[LOG_BASE + LOG_SIZE - 2], 0xFFFF); | ||
438 | } | ||
diff --git a/platforms/test/flash_stm32_mock.c b/platforms/test/flash_stm32_mock.c new file mode 100644 index 000000000..222a004bc --- /dev/null +++ b/platforms/test/flash_stm32_mock.c | |||
@@ -0,0 +1,49 @@ | |||
1 | /* Copyright 2021 by Don Kjer | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include <string.h> | ||
18 | #include <stdbool.h> | ||
19 | #include "flash_stm32.h" | ||
20 | |||
21 | uint8_t FlashBuf[MOCK_FLASH_SIZE] = {0}; | ||
22 | |||
23 | static bool flash_locked = true; | ||
24 | |||
25 | FLASH_Status FLASH_ErasePage(uint32_t Page_Address) { | ||
26 | if (flash_locked) return FLASH_ERROR_WRP; | ||
27 | Page_Address -= (uintptr_t)FlashBuf; | ||
28 | Page_Address -= (Page_Address % FEE_PAGE_SIZE); | ||
29 | if (Page_Address >= MOCK_FLASH_SIZE) return FLASH_BAD_ADDRESS; | ||
30 | memset(&FlashBuf[Page_Address], '\xff', FEE_PAGE_SIZE); | ||
31 | return FLASH_COMPLETE; | ||
32 | } | ||
33 | |||
34 | FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data) { | ||
35 | if (flash_locked) return FLASH_ERROR_WRP; | ||
36 | Address -= (uintptr_t)FlashBuf; | ||
37 | if (Address >= MOCK_FLASH_SIZE) return FLASH_BAD_ADDRESS; | ||
38 | uint16_t oldData = *(uint16_t*)&FlashBuf[Address]; | ||
39 | if (oldData == 0xFFFF || Data == 0) { | ||
40 | *(uint16_t*)&FlashBuf[Address] = Data; | ||
41 | return FLASH_COMPLETE; | ||
42 | } else { | ||
43 | return FLASH_ERROR_PG; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout) { return FLASH_COMPLETE; } | ||
48 | void FLASH_Unlock(void) { flash_locked = false; } | ||
49 | void FLASH_Lock(void) { flash_locked = true; } | ||
diff --git a/platforms/test/hal.h b/platforms/test/hal.h new file mode 100644 index 000000000..2d268ad54 --- /dev/null +++ b/platforms/test/hal.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* Copyright 2021 QMK | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #pragma once | ||
17 | |||
18 | // Just here to please eeprom tests | ||
diff --git a/platforms/test/platform.c b/platforms/test/platform.c new file mode 100644 index 000000000..8ddceeda8 --- /dev/null +++ b/platforms/test/platform.c | |||
@@ -0,0 +1,21 @@ | |||
1 | /* Copyright 2021 QMK | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "platform_deps.h" | ||
18 | |||
19 | void platform_setup(void) { | ||
20 | // do nothing | ||
21 | } \ No newline at end of file | ||
diff --git a/platforms/test/platform.h b/platforms/test/platform.h new file mode 100644 index 000000000..f296d1d53 --- /dev/null +++ b/platforms/test/platform.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* Copyright 2021 QMK | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #pragma once | ||
17 | |||
18 | // here just to please the build | ||
diff --git a/platforms/test/platform.mk b/platforms/test/platform.mk new file mode 100644 index 000000000..eb2424ec5 --- /dev/null +++ b/platforms/test/platform.mk | |||
@@ -0,0 +1,34 @@ | |||
1 | SYSTEM_TYPE := $(shell gcc -dumpmachine) | ||
2 | GCC_VERSION := $(shell gcc --version 2>/dev/null) | ||
3 | |||
4 | CC = $(CC_PREFIX) gcc | ||
5 | OBJCOPY = | ||
6 | OBJDUMP = | ||
7 | SIZE = | ||
8 | AR = | ||
9 | NM = | ||
10 | HEX = | ||
11 | EEP = | ||
12 | BIN = | ||
13 | |||
14 | |||
15 | COMPILEFLAGS += -funsigned-char | ||
16 | ifeq ($(findstring clang, ${GCC_VERSION}),) | ||
17 | COMPILEFLAGS += -funsigned-bitfields | ||
18 | endif | ||
19 | COMPILEFLAGS += -ffunction-sections | ||
20 | COMPILEFLAGS += -fdata-sections | ||
21 | COMPILEFLAGS += -fshort-enums | ||
22 | ifneq ($(findstring mingw, ${SYSTEM_TYPE}),) | ||
23 | COMPILEFLAGS += -mno-ms-bitfields | ||
24 | endif | ||
25 | |||
26 | CFLAGS += $(COMPILEFLAGS) | ||
27 | ifeq ($(findstring clang, ${GCC_VERSION}),) | ||
28 | CFLAGS += -fno-inline-small-functions | ||
29 | endif | ||
30 | CFLAGS += -fno-strict-aliasing | ||
31 | |||
32 | CXXFLAGS += $(COMPILEFLAGS) | ||
33 | CXXFLAGS += -fno-exceptions | ||
34 | CXXFLAGS += -std=gnu++11 | ||
diff --git a/platforms/test/platform_deps.h b/platforms/test/platform_deps.h new file mode 100644 index 000000000..f296d1d53 --- /dev/null +++ b/platforms/test/platform_deps.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* Copyright 2021 QMK | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 3 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | #pragma once | ||
17 | |||
18 | // here just to please the build | ||
diff --git a/platforms/test/rules.mk b/platforms/test/rules.mk new file mode 100644 index 000000000..66b853d8e --- /dev/null +++ b/platforms/test/rules.mk | |||
@@ -0,0 +1,24 @@ | |||
1 | eeprom_stm32_DEFS := -DFLASH_STM32_MOCKED -DNO_PRINT -DFEE_FLASH_BASE=FlashBuf | ||
2 | eeprom_stm32_tiny_DEFS := $(eeprom_stm32_DEFS) \ | ||
3 | -DFEE_MCU_FLASH_SIZE=1 \ | ||
4 | -DMOCK_FLASH_SIZE=1024 \ | ||
5 | -DFEE_PAGE_SIZE=512 \ | ||
6 | -DFEE_PAGE_COUNT=1 | ||
7 | eeprom_stm32_large_DEFS := $(eeprom_stm32_DEFS) \ | ||
8 | -DFEE_MCU_FLASH_SIZE=64 \ | ||
9 | -DMOCK_FLASH_SIZE=65536 \ | ||
10 | -DFEE_PAGE_SIZE=2048 \ | ||
11 | -DFEE_PAGE_COUNT=16 | ||
12 | |||
13 | eeprom_stm32_INC := \ | ||
14 | $(PLATFORM_PATH)/chibios/ | ||
15 | eeprom_stm32_tiny_INC := $(eeprom_stm32_INC) | ||
16 | eeprom_stm32_large_INC := $(eeprom_stm32_INC) | ||
17 | |||
18 | eeprom_stm32_SRC := \ | ||
19 | $(TOP_DIR)/drivers/eeprom/eeprom_driver.c \ | ||
20 | $(PLATFORM_PATH)/$(PLATFORM_KEY)/eeprom_stm32_tests.cpp \ | ||
21 | $(PLATFORM_PATH)/$(PLATFORM_KEY)/flash_stm32_mock.c \ | ||
22 | $(PLATFORM_PATH)/chibios/eeprom_stm32.c | ||
23 | eeprom_stm32_tiny_SRC := $(eeprom_stm32_SRC) | ||
24 | eeprom_stm32_large_SRC := $(eeprom_stm32_SRC) | ||
diff --git a/platforms/test/suspend.c b/platforms/test/suspend.c new file mode 100644 index 000000000..76b705967 --- /dev/null +++ b/platforms/test/suspend.c | |||
@@ -0,0 +1,15 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
diff --git a/platforms/test/testlist.mk b/platforms/test/testlist.mk new file mode 100644 index 000000000..51a9638bb --- /dev/null +++ b/platforms/test/testlist.mk | |||
@@ -0,0 +1 @@ | |||
TEST_LIST += eeprom_stm32_tiny eeprom_stm32_large | |||
diff --git a/platforms/test/timer.c b/platforms/test/timer.c new file mode 100644 index 000000000..61c3a0020 --- /dev/null +++ b/platforms/test/timer.c | |||
@@ -0,0 +1,33 @@ | |||
1 | /* Copyright 2017 Fred Sundvik | ||
2 | * | ||
3 | * This program is free software: you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License as published by | ||
5 | * the Free Software Foundation, either version 2 of the License, or | ||
6 | * (at your option) any later version. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
15 | */ | ||
16 | |||
17 | #include "timer.h" | ||
18 | |||
19 | static uint32_t current_time = 0; | ||
20 | |||
21 | void timer_init(void) { current_time = 0; } | ||
22 | |||
23 | void timer_clear(void) { current_time = 0; } | ||
24 | |||
25 | uint16_t timer_read(void) { return current_time & 0xFFFF; } | ||
26 | uint32_t timer_read32(void) { return current_time; } | ||
27 | uint16_t timer_elapsed(uint16_t last) { return TIMER_DIFF_16(timer_read(), last); } | ||
28 | uint32_t timer_elapsed32(uint32_t last) { return TIMER_DIFF_32(timer_read32(), last); } | ||
29 | |||
30 | void set_time(uint32_t t) { current_time = t; } | ||
31 | void advance_time(uint32_t ms) { current_time += ms; } | ||
32 | |||
33 | void wait_ms(uint32_t ms) { advance_time(ms); } | ||