Skip to content

Commit

Permalink
stm32: WIP getting filesystem working on NUCLEO_L432KC.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgeorge committed May 2, 2019
1 parent a974f2d commit c855a6f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
8 changes: 5 additions & 3 deletions ports/stm32/boards/NUCLEO_L432KC/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@

#define MICROPY_EMIT_THUMB (0)
#define MICROPY_EMIT_INLINE_THUMB (0)
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_TERSE)
#define MICROPY_PY_BUILTINS_COMPLEX (0)
#define MICROPY_PY_USOCKET (0)
#define MICROPY_PY_NETWORK (0)
#define MICROPY_PY_STM (0)
#define MICROPY_PY_PYB_LEGACY (0)
#define MICROPY_VFS_FAT (0)
//#define MICROPY_VFS_FAT (0)

#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)
#define MICROPY_HW_ENABLE_RTC (1)
#define MICROPY_HW_ENABLE_ADC (1)
#define MICROPY_HW_ENABLE_DAC (1)
#define MICROPY_HW_ENABLE_DAC (0)
#define MICROPY_HW_ENABLE_TIMER (1)
#define MICROPY_HW_HAS_SWITCH (0)
#define MICROPY_HW_HAS_FLASH (1)

// MSI is used and is 4MHz
#define MICROPY_HW_CLK_PLLM (1)
Expand Down
17 changes: 12 additions & 5 deletions ports/stm32/boards/stm32l432.ld
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
/* Specify the memory areas */
MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K
FLASH_TEXT (rx) : ORIGIN = 0x08000000, LENGTH = 256K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
SRAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 16K
/*FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 256K*/
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 230K
FLASH_FS (r) : ORIGIN = 0x08039800, LENGTH = 26K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 62K
FS_CACHE (xrw) : ORIGIN = 0x2000f800, LENGTH = 2K
}

/* produce a link error if there is not this amount of RAM for these sections */
Expand All @@ -24,4 +25,10 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);
_ram_start = ORIGIN(RAM);
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_start = _ebss; /* heap starts just after statically allocated memory */
_heap_end = 0x2000A800; /* room for a 6k stack */
_heap_end = 0x2000e000; /* room for a 6k stack */

/* RAM and flash for the internal filesystem */
_ram_fs_cache_start = ORIGIN(FS_CACHE);
_ram_fs_cache_end = ORIGIN(FS_CACHE) + LENGTH(FS_CACHE);
_flash_fs_start = ORIGIN(FLASH_FS);
_flash_fs_end = ORIGIN(FLASH_FS) + LENGTH(FLASH_FS);
8 changes: 8 additions & 0 deletions ports/stm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ STATIC mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
MP_DEFINE_CONST_FUN_OBJ_KW(pyb_main_obj, 1, pyb_main);

#if MICROPY_HW_ENABLE_STORAGE
#if 0
static const char fresh_boot_py[] =
"# boot.py -- run on boot-up\r\n"
"# can run arbitrary Python, but best to keep it minimal\r\n"
Expand All @@ -160,11 +161,13 @@ static const char fresh_boot_py[] =
"#pyb.usb_mode('VCP+HID') # act as a serial device and a mouse\r\n"
#endif
;
#endif

static const char fresh_main_py[] =
"# main.py -- put your code here!\r\n"
;

#if 0
static const char fresh_pybcdc_inf[] =
#include "genhdr/pybcdc_inf.h"
;
Expand All @@ -183,6 +186,7 @@ static const char fresh_readme_txt[] =
"\r\n"
"Please visit http://micropython.org/help/ for further help.\r\n"
;
#endif

// avoid inlining to avoid stack usage within main()
MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
Expand Down Expand Up @@ -221,6 +225,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
// TODO check we could write n bytes
f_close(&fp);

#if 0
// create .inf driver file
f_open(&vfs_fat->fatfs, &fp, "/pybcdc.inf", FA_WRITE | FA_CREATE_ALWAYS);
f_write(&fp, fresh_pybcdc_inf, sizeof(fresh_pybcdc_inf) - 1 /* don't count null terminator */, &n);
Expand All @@ -230,6 +235,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
f_open(&vfs_fat->fatfs, &fp, "/README.txt", FA_WRITE | FA_CREATE_ALWAYS);
f_write(&fp, fresh_readme_txt, sizeof(fresh_readme_txt) - 1 /* don't count null terminator */, &n);
f_close(&fp);
#endif

// keep LED on for at least 200ms
systick_wait_at_least(start_tick, 200);
Expand Down Expand Up @@ -258,6 +264,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
// It is set to the internal flash filesystem by default.
MP_STATE_PORT(vfs_cur) = vfs;

#if 0
// Make sure we have a /flash/boot.py. Create it if needed.
FILINFO fno;
res = f_stat(&vfs_fat->fatfs, "/boot.py", &fno);
Expand All @@ -279,6 +286,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) {
systick_wait_at_least(start_tick, 200);
led_state(PYB_LED_GREEN, 0);
}
#endif

return true;
}
Expand Down

0 comments on commit c855a6f

Please sign in to comment.