Skip to content

usb/tinyusb: Add msc_flash package to expose flash over USB #3480

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

Merged
merged 1 commit into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions hw/usb/tinyusb/msc_flash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->

## MSC_FLASH

Package adds functionality to expose whole flash or one flash area as block device over USB MSC interface.
This allows to read and write to flash from host computer directly to flash. Device will not have file system provided by package so it's up to the system to utilize it.

### Configuration
Add package to **application** or **target** `pkg.deps:` list.

For example following configuration will present content of slot 1 flash as RAW disk.
```yaml
syscfg.vals:
MSC_FLASH_FLASH_AREA_ID: FLASH_AREA_IMAGE_1
```

To expose entire flash (not single flash area) following configuration could be used:
```yaml
syscfg.vals:
MSC_FLASH_FLASH_ID: 0
```
If some starting flash sector should not be exposed (used by bootloader), starting offset can be provided. In following example first 16kB of flash will not be visible.
```yaml
syscfg.vals:
MSC_FLASH_FLASH_ID: 0
MSC_FLASH_FLASH_OFFSET: 0x4000
```

Complete target settings to expose flash could look like this

**syscfg.yml**:
```yaml
syscfg.vals:
USBD_VID: 0xABCD
USBD_PID: 0x1234
USBD_VENDOR_STRING: '"Vendor"'
USBD_PRODUCT_STRING: '"FlashDisk"'
MSC_FLASH_FLASH_AREA_ID: FLASH_AREA_IMAGE_1
```

**pkg.yml**:
```yaml
pkg.deps:
- "@apache-mynewt-core/hw/usb/tinyusb/msc_flash"
```
34 changes: 34 additions & 0 deletions hw/usb/tinyusb/msc_flash/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

pkg.name: hw/usb/tinyusb/msc_flash
pkg.description:
pkg.author: "Apache Mynewt <[email protected]>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
- msc
- usb

pkg.deps:
- "@apache-mynewt-core/hw/hal"
- "@apache-mynewt-core/kernel/os"
- "@apache-mynewt-core/hw/usb/tinyusb"

pkg.init:
msc_flash_init: $before:tinyusb_start
Loading
Loading