porting to STM32L5 series

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
Kris Suuuu
Posts: 2
Joined: Wed Aug 24, 2022 8:27 am

porting to STM32L5 series

Post by Kris Suuuu » Thu Aug 25, 2022 12:58 am

Hi there,

I want to porting MicroPython on STM32L552, is it possible?
I know this series doesn't supported by MicroPython, so I try to download the MicroPython source code and modify some files.
In addition, I have added a new STM32L5 HAL Driver, but when compiling, there are a lot of problems, so I don't know if this is the right way, do you have any suggestions, thanks!

board.json

Code: Select all

{
    "deploy": [
        "../deploy.md"
    ],
    "docs": "",
    "features": [],
    "images": [
        "nucleo_l552rc.jpg"
    ],
    "mcu": "stm32l5",
    "product": "Nucleo L552VE",
    "thumbnail": "",
    "url": "",
    "vendor": "ST Microelectronics"
}
mpconfigboard.h

Code: Select all

#define MICROPY_HW_BOARD_NAME       "NUCLEO-L552VE"
#define MICROPY_HW_MCU_NAME         "STM32L552VE"
mpconfigboard.mk

Code: Select all

MCU_SERIES = l5
CMSIS_MCU = STM32L552xx
AF_FILE = boards/stm32l552_af.csv
LD_FILES = boards/stm32l552.ld boards/common_basic.ld
# OPENOCD_CONFIG = boards/openocd_stm32l4.cfg

# MicroPython settings
# MICROPY_VFS_FAT = 0
# MICROPY_VFS_LFS1 ?= 1
MICROPY_VFS_FAT = 1

# Don't include default frozen modules because MCU is tight on flash space
FROZEN_MANIFEST ?=  

# LTO reduces final binary size, may be slower to build depending on gcc version and hardware
LTO ?= 1
stm32l5xx_hal_conf.h

Code: Select all

#ifndef MICROPY_INCLUDED_STM32L5XX_HAL_CONF_H
#define MICROPY_INCLUDED_STM32L5XX_HAL_CONF_H

#include "boards/stm32l5xx_hal_conf_base.h"

// Oscillator values in Hz
#define HSE_VALUE (8000000)
#define LSE_VALUE (32768)
#define EXTERNAL_SAI1_CLOCK_VALUE (48000)
#define EXTERNAL_SAI2_CLOCK_VALUE (48000)

// Oscillator timeouts in ms
#define HSE_STARTUP_TIMEOUT (100)
#define LSE_STARTUP_TIMEOUT (5000)

#endif // MICROPY_INCLUDED_STM32L4XX_HAL_CONF_H

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: porting to STM32L5 series

Post by jimmo » Thu Aug 25, 2022 2:55 am

Kris Suuuu wrote:
Thu Aug 25, 2022 12:58 am
I want to porting MicroPython on STM32L552, is it possible?
Yes, this is the right approach. Assume you added the HAL to github.com/micropython/stm32lib and updated the submodule.

The compile errors are likely because the HALs for the different families are slightly different, and so you need to adjust the various drivers to use the correct HAL functions. You'll see a lot of e.g. "#if defined(STM32G0)" in the various files in the stm32 port.

Kris Suuuu
Posts: 2
Joined: Wed Aug 24, 2022 8:27 am

Re: porting to STM32L5 series

Post by Kris Suuuu » Thu Aug 25, 2022 3:04 am

jimmo wrote:
Thu Aug 25, 2022 2:55 am
Kris Suuuu wrote:
Thu Aug 25, 2022 12:58 am
I want to porting MicroPython on STM32L552, is it possible?
Yes, this is the right approach. Assume you added the HAL to github.com/micropython/stm32lib and updated the submodule.

The compile errors are likely because the HALs for the different families are slightly different, and so you need to adjust the various drivers to use the correct HAL functions. You'll see a lot of e.g. "#if defined(STM32G0)" in the various files in the stm32 port.
Yes, I noticed that I originally thought that STM32L4 and STM32L5 would not be very different, so I changed it to defined(STM32L4) || defined(STM32L5), but it doesn't seem to be the case, any suggestions, thank you!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: porting to STM32L5 series

Post by jimmo » Thu Aug 25, 2022 3:17 am

Kris Suuuu wrote:
Thu Aug 25, 2022 3:04 am
Yes, I noticed that I originally thought that STM32L4 and STM32L5 would not be very different, so I changed it to defined(STM32L4) || defined(STM32L5), but it doesn't seem to be the case, any suggestions, thank you!
That hasn't really been my experience. The families can be quite different.

Post Reply