← index #6605Issue #6132
Related · high · value 1.322
QUERY · 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

CANDIDATE · ISSUE

STM32L496RE firmware for custom board

closedby Maryem-archopened 2020-06-09updated 2021-07-23
port-stm32

Hello,
I have a custom board that contains the STM32L496RE microcontroller I wanted to upload the micropython firmware into my board, first

  • I created a folder named NEWBOARD for my board under micropython/ports/stm32/boards

  • Copied into it the files used in the NUCLEO_L476RG (in folder NUCLEO_L476RG under micropython/ports/stm32/boards) since I have the Nucleo and it shares the same core with my custom board , and I changed the pins according to my custom board in the mpconfigboard.h under micropython/ports/stm32/boards/NEWBOARD

  • Copied the ld file used for the Nucleo board stm32l476xg.ld found under micropython/ports/stm32/boards and then I changed the memory addresses according to my board

  • Changed the reference of the ld file (line 4) in the mpconfigboard.mk file located under micropython/ports/stm32/boards/NEWBOARD

  • Changed line 52 in the Makefile located in micropython/ports/stm32 as follows:
    OPENOCD_CONFIG ?= boards/openocd_stm32l4.cfg

Then, I ran make BOARD=NEWBOARD in micropython/ports/stm32

The firmware was built and I tried to flash it into my board using make BOARD=NEWBOARD deploy-openocd ,(I made sure the board was connected to the computer and it showed in the terminal)

It didn't work so I tried it with make BOARD=NEWBOARD deploy-stlink , it said that the memory was successfully flashed but when I opened the serial connection using picocom , none of the micropython commands worked (Ex : pyb.LED(2).on() ) knowing that they worked fine when I flashed the NUCLEO_L476RG
I assumed the firmware didn't flash at all, so I moved the binary file (firmware.bin that was created in micropython/ports/smt32/build-NEWBOARD after I built the board files) to Windows (knowing that I was using Ubuntu) and I flashed the board using st-link Utility, it worked apparently but it still didn't respond to any of the micropython commands, instead the LEDs mentioned in mpconfigboard.h kept blinking without any command from me, they start blinking whenever I power on the board, knowing that when I only put one pin in the mpconfigboard.h , only the LED mentioned will blink, when I put two, they both blink.

I couldn't know the reason behind the blinking, and I couldn't figure out why the firmware that I configured didn't work properly on my board.
I would appreciate it if someone could give me further explanation about how this firmware works or why am I having this issue.

  • Also, are there any more configurations or files that I should modify to have a working firmware for my custom board ?

Thank you very much

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