← index #7929Issue #6605
Likely Duplicate · medium · value 2.902
QUERY · ISSUE

[NUCLEO-L432KC] MPY: can't mount flash

openby B-Laurentopened 2021-10-25updated 2026-03-24
port-stm32proposed-close

Hello,

With a nucleo board L432KC and the micropython v1.17 the message following
is prompt at boot time.

>>> MPY: can't mount flash

Micropython and board :
MicroPython v1.17 on 2021-10-21; NUCLEO-L432KC with STM32L432KC

From repl prompt :

>>> import os
>>> os.listdir()
[]
>>> import sys
>>> sys.path
['']

From rshell prompt:

>ls /flash
Cannot access '/flash': No such file or directory
> ls /pyboard
> 
> cp main.py /flash
Copying '/---/main.py' to '/flash' ...
Unable to copy '/---/main.py' to '/flash'
> cp main.py /pyboard
Copying '/---/Microcode/main.py' to '/pyboard/main.py' ...
timed out or error in transfer to remote: b'F'

For comparison, on an other nucleoboard NUCLEO-F401RE:

MicroPython v1.13-103-gb137d064e on 2020-10-09; NUCLEO-F401RE with STM32F401xE

From repl prompt :

>>> import os
>>> os.listdir()
['boot.py', 'contact.py', 'mcp23017.py', 'EMCP23017.py', 'main.py', 'conf.py']
>>> import sys
>>> sys.path
['', '/flash', '/flash/lib']

From rshell prompt:

>ls /flash
EMCP23017.py boot.py conf.py contact.py main.py mcp23017.py
>ls /pyboard
flash/

I'm confused by this problem and do really know how to investigate in order solve it.
Could someone help me to understand what's wrong ?
Thanks in advance for help

CANDIDATE · ISSUE

STM32L432KC "can't" create flash filesystem

openby ZSorcereropened 2020-11-08updated 2024-09-08
port-stm32

I have designed a custom pyboard used STM32L432KC as the controller and downloaded both V1.12 and V1.13 NUCLEO_L432KC as the firmare. Neither of them works,the file system can not be loaded. I can not mount the flash.

I already set the following parameters:

#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (1)  //   in file mpconfigboard.h
#define MICROPY_HW_ENABLE_USB       (1)   //   in file mpconfigboard.h
#define MICROPY_HW_USB_MSC          (1)    //   in file mpconfigboard.h
#define MICROPY_HW_USB_HID          (1)    //   in file mpconfigboard.h

And

MEMORY    //   in file stm32l432.ld
{
    FLASH (rx)      : ORIGIN = 0x08000000, LENGTH = 246K /* sectors 0-114 */    
    FLASH_FS (rx)    : ORIGIN = 0x0803D800, LENGTH = 10K /* sectors 115-127 */          I want 10k file system, therefore  ORIGIN = 0x0803D800
    RAM (xrw)       : ORIGIN = 0x20000000, LENGTH = 64K /* SRAM1, 48K + SRAM2, 16K */
}

And

MICROPY_VFS_FAT = 1         //   in file mpconfigboard.mk

I have successfully compiled the code and downloaded it into my L432 board. After I reset the board, I got the following output:

mpy

The REPL works fine.
But, there are 2 ERRORS:
(1)Can't create flash system.
(2)Can't mount flash.

I know the flash size for STM32L432KC is only 256kb which is tiny, but 5kb~10kb file system is enough for me. I only need to implement some basic GPIO operations.

I also used the printf function to check where the program went wrong.

in main.c , the following function gives nonzero value of ret which is -5.

int vfs_mount_and_chdir(mp_obj_t bdev, mp_obj_t mount_point)

because the expression

 (nlr_push(&nlr)  ≠ 0

Here is the complete function:

#if MICROPY_HW_ENABLE_STORAGE
STATIC int vfs_mount_and_chdir(mp_obj_t bdev, mp_obj_t mount_point) {
    nlr_buf_t nlr;
    mp_int_t ret = -MP_EIO;
    nlr_push_test();
    if (nlr_push(&nlr) == 0) {
        mp_obj_t args[] = { bdev, mount_point };
        mp_vfs_mount(2, args, (mp_map_t*)&mp_const_empty_map);
        mp_vfs_chdir(mount_point);
        ret = 0; // success
        nlr_pop();
    } else {
        mp_obj_base_t *exc = nlr.ret_val;
        if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(exc->type), MP_OBJ_FROM_PTR(&mp_type_OSError))) {
            mp_obj_t v = mp_obj_exception_get_value(MP_OBJ_FROM_PTR(exc));
            mp_obj_get_int_maybe(v, &ret); // get errno value
            ret = -ret;
        }
    }
    return ret;
}

Why this expression (nlr_push(&nlr) ≠ 0 , how to slove this problem? I think this caused the failure of the flash FS.

Another error came from factoryreset.c . in the following function:

MP_WEAK int factory_reset_create_filesystem(void) {
    // LED on to indicate creation of local filesystem
    led_state(PYB_LED_GREEN, 1);
    uint32_t start_tick = HAL_GetTick();

    fs_user_mount_t vfs;
    pyb_flash_init_vfs(&vfs);
    uint8_t working_buf[FF_MAX_SS];
    FRESULT res = f_mkfs(&vfs.fatfs, FM_FAT, 0, working_buf, sizeof(working_buf));
    if (res != FR_OK) {
        mp_printf(&mp_plat_print, "MPY: can't create flash filesystem\n");    // **This is the ERROR message**
        return -MP_ENODEV;
    }

    // Set label
    f_setlabel(&vfs.fatfs, MICROPY_HW_FLASH_FS_LABEL);

    // Populate the filesystem with factory files
    factory_reset_make_files(&vfs.fatfs);

    // Keep LED on for at least 200ms
    systick_wait_at_least(start_tick, 200);
    led_state(PYB_LED_GREEN, 0);

    return 0; // success
}

#endif // MICROPY_HW_ENABLE_STORAGE

it means the condition (res != FR_OK) is not satisfied.

Can anyone tell me how to revise the code to creat the file system for this L432 board, thanks.

@dpgeorge @boochow @chrismas9 @davehylands

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied