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

merge dev #503

Merged
merged 3 commits into from
Dec 26, 2024
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
23 changes: 23 additions & 0 deletions picosim/libs/stdio_msc_usb/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
This library allows USB mass storage access together with USB CDC
stdio. Intended to be used together with
https://github.com/carlk3/no-OS-FatFS-SD-SDIO-SPI-RPi-Pico .

Based on pico-sdk/src/rp2_common/pico_stdio_usb and
pico-sdk/lib/tinyusb/examples/device/cdc_msc .

See CMakeLists.txt, picosim.c, and simcfg.c in srcsim to see how to
use this.

Basically:

Add with "add_subdirectory" and "target_link_libraries(tinyusb_device
stdio_msc_usb)" to CMakeLists.txt. Remove "pico_enable_stdio_usb".

Call "tusb_init()" and "stdio_msc_usb_init()" in "main()". Activate
the mass storage access with "stdio_msc_usb_do_msc()". This will wait
until the medium is ejected by the host OS.

This is done this way, because the FatFS library needs exclusive
access to the storage medium. So USB access can only be activated in
the configuration menu to allow copying of files and disk images
to/from the host OS.
16 changes: 8 additions & 8 deletions picosim/srcsim/disks.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void mount_disk(int drive, const char *name)
/*
* prepare I/O for sector read and write routines
*/
static BYTE prep_io(int drive, int track, int sector, WORD addr)
static BYTE prep_io(int drive, int track, int sector, WORD addr, bool rdwr)
{
FSIZE_t pos;

Expand All @@ -262,8 +262,10 @@ static BYTE prep_io(int drive, int track, int sector, WORD addr)
return FDC_STAT_NODISK;
}

put_pixel(rdwr ? 0x004400 : 0x440000); /* LED red/green */

/* open file with the disk image */
sd_res = f_open(&sd_file, disks[drive], FA_READ | FA_WRITE);
sd_res = f_open(&sd_file, disks[drive], rdwr ? FA_WRITE : FA_READ);
if (sd_res != FR_OK)
return FDC_STAT_NODISK;

Expand All @@ -285,10 +287,9 @@ BYTE read_sec(int drive, int track, int sector, WORD addr)
unsigned int br;
register int i;

put_pixel(0x440000); /* LED green */

/* prepare for sector read */
if ((stat = prep_io(drive, track, sector, addr)) == FDC_STAT_OK) {
stat = prep_io(drive, track, sector, addr, false);
if (stat == FDC_STAT_OK) {

/* read sector into memory */
sd_res = f_read(&sd_file, &dsk_buf[0], SEC_SZ, &br);
Expand Down Expand Up @@ -321,10 +322,9 @@ BYTE write_sec(int drive, int track, int sector, WORD addr)
unsigned int br;
register int i;

put_pixel(0x004400); /* LED red */

/* prepare for sector write */
if ((stat = prep_io(drive, track, sector, addr)) == FDC_STAT_OK) {
stat = prep_io(drive, track, sector, addr, true);
if (stat == FDC_STAT_OK) {

/* write sector to disk image */
for (i = 0; i < SEC_SZ; i++)
Expand Down
Loading