Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32L4: Support all STM32L4 MCUs with all features. Add NUCLEO boards. #7123

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chrismas9
Copy link
Contributor

This corrects errors and omissions in the STM32L4 ports.
In particular it adds:

  • USB for STM32L45x family.
  • STM32L433/443 support.
  • An easier way to fine tune memory allocation per board which is
    necessary on 256KB parts.
  • Adds all series members instead of just one, eg L451, L452, L462
    instead of just L452.
  • NUCLEO_L432KC with 28KB LFS1 file system.
  • NUCLEO_L433-P board.
  • NUCLEO_L433-P board with 28KB LFS1 file system.
  • NUCLEO_L433-P board with USB and 16KB LFS1 file system.
    Requires custom USB connection.
  • NUCLEO_L452-P board.

Note: The -P boards have a low power mode using on board SMPS.
Low power mode is not supported. MCU runs from 3.3V.

Add support for all STM32L4 MCUs with at least 256KB Flash,
  except L4+ series.
Add missing features to already supported MCUs.

adc.c: VBAT_DIV add all STM32L4.
boards/stm32l432.ld: Fix error in ORIGIN(FLASH_FS).
boards/stm32l452_af.csv: Fix missing EVENTOUT on PH3.
flashbdev.c: Add all STM32L4.
mpconfigboard_common.h: Add support for all MCUs with only USB_FS.
stm32_it.c: Add support for all MCUs with only USB_FS.
usbd_conf.c: Add support for all MCUs with only USB_FS.
boards/stm32l433_af.csv: Added.

Signed-off-by: Chris Mason <c.mason@inchipdesign.com.au>
boards/stm32l4*.ld: Add all MCU names and sizes to linker scripts.
                   Calculate ORIGIN(FLASH_FS) to simplify changing FS size.
                   no need for duplicate values or hex entries.

The STM32L43x series with 256KB Flash have limited space for a file system.
  Depending on options (FRAMEBUF 4KB, CANbus 6KB, USB 10KB, etc) the file
  system space using LittleFS1 is typically between 14KB and 28KB.
  This needs to be tuned on a board by board basis. The linker script is
  split into a generic stm32l4xx.ld and board specific stm32l43x.ld.
  The stack / heap trade-off can also be tuned in the board linker script.

boards/stm32l4xx.ld: Generic STM32L4 linker script for RAM,
                     except L47x which does not have contiguous RAM.
boards/NUCLEO_L432KC/stm32l43x.ld: Define FLASH and stack for board.
boards/NUCLEO_L432KC/mpconfigboard.mk: Use new linker scripts.
boards/NUCLEO_L432KC/mpconfigboard.h: Cleanup and add comments on memory
    usage of modules to help optimise file system size.

Signed-off-by: Chris Mason <c.mason@inchipdesign.com.au>
NUCLEO_L432KC_LFS1: With 28KB LFS1 file system.
NUCLEO_L433RC-P: No file system. Does not support low power SMPS.
NUCLEO_L433RC-P_LFS1: With 28KB LFS1 file system.
NUCLEO_L433RC-P_USB_LFS1: With USB and 16KB LFS1 file system.
NUCLEO_L452RE-P: Does not support low power SMPS.

The L433 ports show how to fine tune the file system size
  depending on options.
The -P boards have a low power mode with SMPS,
  but low mode power is not supported.

Signed-off-by: Chris Mason <c.mason@inchipdesign.com.au>
@chrismas9
Copy link
Contributor Author

Motivation for this was to support USB on L452 and add L433, but I decided to do a complete review of the L4 series. I haven't added L4+ series (STM32L4P5, etc) yet because they need and ST32 HAL submodule update.

These changes have been tested for REPL, USB and file system on NUCLEO_L432KC, NUCLEO_L433RC-P with USB cable, NUCLEO_L452-P and custom boards with USB connectors. Also verified PYBV3 not broken.

Other changes have only been verified by code inspection.

@chrismas9
Copy link
Contributor Author

@dpgeorge, please review the changes I made to the linker scripts. On L4 the end of FLASH is always the beginning of FLASH_FS and the current linker scripts require entry in decimal for LENGTH(FLASH) and hex for ORIGIN(FLASH_FS). I have found this error prone and effectively requires entering the same value twice.

The first change I made is to calculate ORIGIN(FLASH_FS) so you only have to enter two decimal values to define the lenth of the two regions.

The second change is currently only on the L43x boards where it is necessary to fine tune the small file system space depending on board options (eg USB uses 10KB, so needs a smaller FLASH_FS). I split the linker script so MEMORY is defined per board. Since you can't use symbols in the MEMORY section I created two dummy regions to define constants and use them to calculate FLASH and FLASH_FS. This way you only need to edit one decimal value (eg 16K or 28K) to tune the file system size.

Is this legal and acceptable? It works with gnu LD, but using arithmetic expressions in the MEMORY section isn't discussed in the docs.

@chrismas9
Copy link
Contributor Author

Test scripts for the LFS1 file system. When reprogramming the boards with different FLASH_FS sizes it is necessary to erase all flash first. On the NUCLEO_L432KC board I found it necessary to hold reset when connecting to STLINK in STM32CubeProgrammer and release it when the software starts searching. I am not sure why as PA13 and PA14 are not used by MicroPython.

Lfs1-mk.py

import pyb, uos try: uos.umount('/flash') except Exception: pass print('Creating new filesystem') uos.VfsLfs1.mkfs(pyb.Flash(start=0)) uos.mount(pyb.Flash(start=0), '/flash') uos.chdir('/flash') f=open('main.py', 'w') f.write('# main.py -- put your code here!\r\n') f.close() print(uos.statvfs('/flash')) print(uos.listdir())

Lfs1-rd.py

import pyb, uos print(uos.statvfs('/flash')) print(uos.listdir()) f=open('main.py') print(f.read()) f.close()

@dpgeorge
Copy link
Member

Sorry I never got to this. Does it need to be fixed now that the linker script can set the extents of the flash filesystem?

@chrismas9
Copy link
Contributor Author

I am working on an update to this now. I have removed the filesystem size stuff and am using your approach for L432KC after rebase. I have added L4plus support. I have added NUCLEO-L496ZG-P board and tested L4plus on NUCLEO-L4R5ZI and custom L4R5 board. I have an issue with timers. The L4 HAL does not seem to support ETR or BKIN af on some pins. There are also discrepancies between the ST documents and HAL. I have built an STMCUBEMX project and I'm working through the sample code to see how they do it. I would wait until I push the update before reviewing it. I have several products that are dependant on this branch, eg for USB on L452, so It would be good to see it merged.

Two things are holding me up:

Timer callbacks seem to be broken on L4 since last HAL update. It would be good to get that fixed before a major L4 update, I can't figure it out. See:
https://github.com/micropython/micropython/issues/8732

I can't work out how to connect a pin to a Timer BKIN. The Pin class only supports af change for outputs. See my comment in:
https://github.com/micropython/micropython/pull/6535

tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Nov 16, 2022
…espif

Raise error with positive code in recv_into for espressif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants