|
45 | 45 | #include "pendsv.h"
|
46 | 46 | #include "pybthread.h"
|
47 | 47 | #include "gccollect.h"
|
| 48 | +#include "factoryreset.h" |
48 | 49 | #include "modmachine.h"
|
49 | 50 | #include "i2c.h"
|
50 | 51 | #include "spi.h"
|
@@ -148,42 +149,6 @@ STATIC mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
148 | 149 | MP_DEFINE_CONST_FUN_OBJ_KW(pyb_main_obj, 1, pyb_main);
|
149 | 150 |
|
150 | 151 | #if MICROPY_HW_ENABLE_STORAGE
|
151 |
| -static const char fresh_boot_py[] = |
152 |
| -"# boot.py -- run on boot-up\r\n" |
153 |
| -"# can run arbitrary Python, but best to keep it minimal\r\n" |
154 |
| -"\r\n" |
155 |
| -"import machine\r\n" |
156 |
| -"import pyb\r\n" |
157 |
| -"#pyb.main('main.py') # main script to run after this one\r\n" |
158 |
| -#if MICROPY_HW_ENABLE_USB |
159 |
| -"#pyb.usb_mode('VCP+MSC') # act as a serial and a storage device\r\n" |
160 |
| -"#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse\r\n" |
161 |
| -#endif |
162 |
| -; |
163 |
| - |
164 |
| -static const char fresh_main_py[] = |
165 |
| -"# main.py -- put your code here!\r\n" |
166 |
| -; |
167 |
| - |
168 |
| -static const char fresh_pybcdc_inf[] = |
169 |
| -#include "genhdr/pybcdc_inf.h" |
170 |
| -; |
171 |
| - |
172 |
| -static const char fresh_readme_txt[] = |
173 |
| -"This is a MicroPython board\r\n" |
174 |
| -"\r\n" |
175 |
| -"You can get started right away by writing your Python code in 'main.py'.\r\n" |
176 |
| -"\r\n" |
177 |
| -"For a serial prompt:\r\n" |
178 |
| -" - Windows: you need to go to 'Device manager', right click on the unknown device,\r\n" |
179 |
| -" then update the driver software, using the 'pybcdc.inf' file found on this drive.\r\n" |
180 |
| -" Then use a terminal program like Hyperterminal or putty.\r\n" |
181 |
| -" - Mac OS X: use the command: screen /dev/tty.usbmodem*\r\n" |
182 |
| -" - Linux: use the command: screen /dev/ttyACM0\r\n" |
183 |
| -"\r\n" |
184 |
| -"Please visit http://micropython.org/help/ for further help.\r\n" |
185 |
| -; |
186 |
| - |
187 | 152 | // avoid inlining to avoid stack usage within main()
|
188 | 153 | MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
|
189 | 154 | // init the vfs object
|
@@ -213,23 +178,8 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
|
213 | 178 | // set label
|
214 | 179 | f_setlabel(&vfs_fat->fatfs, MICROPY_HW_FLASH_FS_LABEL);
|
215 | 180 |
|
216 |
| - // create empty main.py |
217 |
| - FIL fp; |
218 |
| - f_open(&vfs_fat->fatfs, &fp, "/main.py", FA_WRITE | FA_CREATE_ALWAYS); |
219 |
| - UINT n; |
220 |
| - f_write(&fp, fresh_main_py, sizeof(fresh_main_py) - 1 /* don't count null terminator */, &n); |
221 |
| - // TODO check we could write n bytes |
222 |
| - f_close(&fp); |
223 |
| - |
224 |
| - // create .inf driver file |
225 |
| - f_open(&vfs_fat->fatfs, &fp, "/pybcdc.inf", FA_WRITE | FA_CREATE_ALWAYS); |
226 |
| - f_write(&fp, fresh_pybcdc_inf, sizeof(fresh_pybcdc_inf) - 1 /* don't count null terminator */, &n); |
227 |
| - f_close(&fp); |
228 |
| - |
229 |
| - // create readme file |
230 |
| - f_open(&vfs_fat->fatfs, &fp, "/README.txt", FA_WRITE | FA_CREATE_ALWAYS); |
231 |
| - f_write(&fp, fresh_readme_txt, sizeof(fresh_readme_txt) - 1 /* don't count null terminator */, &n); |
232 |
| - f_close(&fp); |
| 181 | + // populate the filesystem with factory files |
| 182 | + factory_reset_make_files(&vfs_fat->fatfs); |
233 | 183 |
|
234 | 184 | // keep LED on for at least 200ms
|
235 | 185 | systick_wait_at_least(start_tick, 200);
|
@@ -258,28 +208,6 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
|
258 | 208 | // It is set to the internal flash filesystem by default.
|
259 | 209 | MP_STATE_PORT(vfs_cur) = vfs;
|
260 | 210 |
|
261 |
| - // Make sure we have a /flash/boot.py. Create it if needed. |
262 |
| - FILINFO fno; |
263 |
| - res = f_stat(&vfs_fat->fatfs, "/boot.py", &fno); |
264 |
| - if (res != FR_OK) { |
265 |
| - // doesn't exist, create fresh file |
266 |
| - |
267 |
| - // LED on to indicate creation of boot.py |
268 |
| - led_state(PYB_LED_GREEN, 1); |
269 |
| - uint32_t start_tick = HAL_GetTick(); |
270 |
| - |
271 |
| - FIL fp; |
272 |
| - f_open(&vfs_fat->fatfs, &fp, "/boot.py", FA_WRITE | FA_CREATE_ALWAYS); |
273 |
| - UINT n; |
274 |
| - f_write(&fp, fresh_boot_py, sizeof(fresh_boot_py) - 1 /* don't count null terminator */, &n); |
275 |
| - // TODO check we could write n bytes |
276 |
| - f_close(&fp); |
277 |
| - |
278 |
| - // keep LED on for at least 200ms |
279 |
| - systick_wait_at_least(start_tick, 200); |
280 |
| - led_state(PYB_LED_GREEN, 0); |
281 |
| - } |
282 |
| - |
283 | 211 | return true;
|
284 | 212 | }
|
285 | 213 | #endif
|
|
0 commit comments