Skip to content

mimxrt: Add MSC support for the mimxrt port. #8820

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

Closed
wants to merge 14 commits into from

Conversation

robert-hh
Copy link
Contributor

@robert-hh robert-hh commented Jun 25, 2022

Using the good implementation by @iabdalkader for RP2 and some of @alphaFred's work for the bootloader.
This is a build option. The PR consists of two major parts:

  • Adding basic MSC support in the commits up to the commit mimxrt: Change the MSC enable/disable setting
  • Adding the work of PR MSC exclusive access support. #8814 for mimxrt in the following commits.

MSC support is not possible for device with hyperflash memory. FAT does not match with the 256k sector size of these devices. For all other devices, MSC is enabled by default.

@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2022

Codecov Report

Merging #8820 (db726ec) into master (fb94ae4) will decrease coverage by 0.02%.
The diff coverage is 69.23%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #8820      +/-   ##
==========================================
- Coverage   98.50%   98.48%   -0.02%     
==========================================
  Files         155      155              
  Lines       20540    20549       +9     
==========================================
+ Hits        20232    20237       +5     
- Misses        308      312       +4     
Impacted Files Coverage Δ
extmod/vfs_fat_diskio.c 88.23% <69.23%> (-7.01%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@robert-hh robert-hh force-pushed the mimxrt_msc branch 6 times, most recently from 43f8bae to f24a814 Compare June 26, 2022 20:14
@robert-hh robert-hh force-pushed the mimxrt_msc branch 3 times, most recently from 8c607f7 to 48d46bb Compare July 7, 2022 13:00
@robert-hh robert-hh force-pushed the mimxrt_msc branch 4 times, most recently from 7491747 to 66f458a Compare July 20, 2022 13:14
@robert-hh robert-hh requested a review from jimmo September 16, 2022 08:54
@robert-hh robert-hh marked this pull request as draft November 17, 2022 07:24
@robert-hh robert-hh marked this pull request as ready for review November 17, 2022 13:47
@robert-hh robert-hh requested review from dpgeorge and removed request for jimmo November 17, 2022 13:49
@github-actions
Copy link

github-actions bot commented Dec 15, 2022

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:   +64 +0.008% standard
      stm32:   +28 +0.007% PYBV10
        rp2:   +56 +0.017% PICO

These will be needed for MSC support. The change matches the changes
for the bootloader.
The DTCM section got too large.
This attribute is present on builds with MSC support, allowing _boot.py
to decide about creating if and which file system.
As a benefit, it will not destroy an existing FAT partition.
Using the good implementation by @iabdalkader for RP2 and some of
@alphaFred's work for the bootlaoder.

Open topics:

- In the descriptor the blocksize was set to 64. MIMXRT requires 512
- Adding a lock preventing local write as long as the disk is mounted.
- Hyperflash has a sector size of 256k. Here, the
  BLOCK_SIZE == SECTOR_SIZE_BYTES is 4096, which by good luck meets the
  size required for SD Cards.
Enable MSC unless defined different for a board.
Disable MSC for MIMXRT1050_EVK because of it's hyperflash chip.
Porting PR micropython#8814 of @iabdalkader to the mimxrt platform.
- When the board is mounted to a PC, local write access is blocked.
- Local write access will be re-enabled again if the disk is ejected.
- If the board is not connected to a PC on start-up, local write access
  is enabled.
- The status of the write access can be determined by bdev.ioctl(7, 0).
  If the device is mounted to a PAC and thus local write access is
  blocked, it return 1, otherwise 0.
- low level write/erase using the block device calls are still possible.
  It is up to the user to check the device status ahead.
That way it is guaranteed, that a new file system is created before
an MSC mount attempt can be made.
Also: Check for readonly mode before trying mkfs.
Since remount after MSC eject does not update the file system's data
in memory, keep file the system readonly until after a soft reset, which
has to be done deliberately.
That's neither comfortable nor elegant, but safe.

Disabled MSC as default option.
Disabled MSC for MIMXRT1050_EVK deliberately.
Enabled MSC for MIMXRT1020_EVK, Teensy 4.1 and OLIMEX_RT1010 for testing.
To enble/disable MSC at boot time. The calls are a simplified version
if pyb.usb_mode():

mimxrt.usb_mode(modestr)

with modestr being either "vcp" or "vcp+msc".

The call has to be placed in boot.py and requires a hard reset to get
effective, since tusb_init() is executed only once after reset.

As a side effect, USB is not active in boot.py. So there is not USB
I/O possible in boot.py, and code running in boot.py cannot by stopped
with Ctrl-C.
1. USB will be enabled BEFORE boot.py is executed, avoiding deadlocks
   by user written code.
2. MSC support is enabled in _boot.py according to the following rules:
   a) For a FAT file system, MSC will be enabled by default.
   b) For a LFS file system, MSC will be disabled by default.
   c) The setting can be overriden by a file with the name
      set_usb_mode.py, which can define usb_mode with the lines:

      usb_mode = "vcp+msc"  # enable MSC

      or

      usb_mode = "vcp" # do not enable MSC

    If that file does not exist or is faulty, the default is used.
Including some notes about littlfs file system and MSC access.

When the board is formatted with littlfs, the FS access method by the
PC is different.
@robert-hh
Copy link
Contributor Author

Assuming that with PR #9497 it will be possible to have MSC support using a Python coded driver, which can be the same for all ports using TinyUSB, I close this PR. I will keep the branch in my repository and maintain it.

@robert-hh robert-hh closed this May 4, 2023
@iabdalkader
Copy link
Contributor

Thank you for this, I will cherry-pick it in my fork too until we see if the other PR is merged. @robert-hh I wanted to mention a storage related issue, with the port in general, so the VFS offset is fixed without checking if firmware overflows, if the firmware grows more than 0x100000, it gets overwritten and weird bugs happen, at least for the 1062... I've been debugging this issue for few days, the VFS should be in its own section.

vfs_start           = flash_start + 0x00100000;

@robert-hh
Copy link
Contributor Author

Yes I know hat there is no automatic check. When starting 1Mbyte for code seemed huge. And the actual Teensy 4.1 build is as 580k. So you must have added a lot.

@iabdalkader
Copy link
Contributor

When starting 1Mbyte for code seemed huge

Not really if you add WiFi driver and firmware (which is ~400K alone) LWIP, nimble etc

tannewt pushed a commit to tannewt/circuitpython that referenced this pull request Feb 29, 2024
…ices

New methods to get list of associated stations in access point mode and get maximum number of stations that can be associated
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.

4 participants