Skip to content

Commit

Permalink
Merge pull request #8222 from tannewt/fat_window_align
Browse files Browse the repository at this point in the history
Align fatfs window buffer for tinyusb
  • Loading branch information
dhalbert authored Jul 28, 2023
2 parents 5ccf36d + e45a61f commit f466a43
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/oofatfs/ff.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ typedef struct {
DWORD bitbase; /* Allocation bitmap base sector */
#endif
DWORD winsect; /* Current sector appearing in the win[] */
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
__attribute__((aligned(FF_WINDOW_ALIGNMENT),)) BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg). */
} FATFS;


Expand Down
6 changes: 6 additions & 0 deletions lib/oofatfs/ffconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@
/ for variable sector size mode and disk_ioctl() function needs to implement
/ GET_SECTOR_SIZE command. */

#ifdef MICROPY_FATFS_WINDOW_ALIGNMENT
#define FF_WINDOW_ALIGNMENT (MICROPY_FATFS_WINDOW_ALIGNMENT)
#else
#define FF_WINDOW_ALIGNMENT 1
#endif


#define FF_USE_TRIM 0
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
Expand Down
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 63 files
+1 −1 .github/workflows/cmake_arm.yml
+1 −0 .idea/cmake.xml
+10 −0 .idea/runConfigurations/lpc4088.xml
+1 −0 examples/dual/host_hid_to_device_cdc/only.txt
+61 −59 hw/bsp/imxrt/family.cmake
+165 −0 hw/bsp/lpc40/FreeRTOSConfig/FreeRTOSConfig.h
+9 −0 hw/bsp/lpc40/boards/ea4088_quickstart/board.cmake
+74 −0 hw/bsp/lpc40/boards/ea4088_quickstart/board.h
+8 −0 hw/bsp/lpc40/boards/ea4088_quickstart/board.mk
+0 −0 hw/bsp/lpc40/boards/ea4088_quickstart/lpc4088.ld
+238 −0 hw/bsp/lpc40/boards/ea4088_quickstart/ozone/ea4088_quickstart.jdebug
+41 −74 hw/bsp/lpc40/family.c
+102 −0 hw/bsp/lpc40/family.cmake
+8 −22 hw/bsp/lpc40/family.mk
+6 −6 hw/bsp/rp2040/board.h
+1 −1 hw/bsp/xmc4000/boards/xmc4500_relax/board.mk
+81 −0 hw/bsp/xmc4000/boards/xmc4700_relax/board.h
+12 −0 hw/bsp/xmc4000/boards/xmc4700_relax/board.mk
+22 −4 hw/bsp/xmc4000/family.c
+4 −1 hw/bsp/xmc4000/family.mk
+1 −1 lib/networking/rndis_reports.c
+1 −0 src/CMakeLists.txt
+22 −22 src/class/audio/audio_device.c
+1 −1 src/class/bth/bth_device.c
+1 −1 src/class/cdc/cdc_device.c
+1 −1 src/class/dfu/dfu_device.c
+1 −1 src/class/hid/hid_device.c
+1 −1 src/class/midi/midi_device.c
+25 −22 src/class/msc/msc_device.c
+6 −6 src/class/net/ecm_rndis_device.c
+3 −3 src/class/net/ncm_device.c
+1 −1 src/class/usbtmc/usbtmc_device.c
+1 −1 src/class/vendor/vendor_device.c
+2 −2 src/class/video/video_device.c
+9 −6 src/common/tusb_common.h
+45 −48 src/device/usbd.c
+4 −7 src/device/usbd_control.c
+8 −1 src/device/usbd_pvt.h
+8 −4 src/host/hcd.h
+1 −1 src/host/hub.c
+69 −55 src/host/usbh.c
+6 −2 src/host/usbh.h
+1 −1 src/portable/bridgetek/ft9xx/dcd_ft9xx.c
+1 −1 src/portable/chipidea/ci_fs/dcd_ci_fs.c
+9 −6 src/portable/chipidea/ci_hs/ci_hs_imxrt.h
+1 −1 src/portable/chipidea/ci_hs/dcd_ci_hs.c
+6 −6 src/portable/chipidea/ci_hs/hcd_ci_hs.c
+274 −318 src/portable/ehci/ehci.c
+13 −12 src/portable/ehci/ehci.h
+10 −2 src/portable/mentor/musb/hcd_musb.c
+1 −1 src/portable/microchip/pic/dcd_pic.c
+1 −1 src/portable/microchip/samx7x/dcd_samx7x.c
+1 −1 src/portable/mindmotion/mm32/dcd_mm32f327x_otg.c
+1 −1 src/portable/nxp/khci/dcd_khci.c
+10 −2 src/portable/nxp/khci/hcd_khci.c
+1 −1 src/portable/nxp/lpc17_40/dcd_lpc17_40.c
+3 −3 src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c
+25 −12 src/portable/ohci/ohci.c
+7 −2 src/portable/raspberrypi/pio_usb/hcd_pio_usb.c
+10 −2 src/portable/raspberrypi/rp2040/hcd_rp2040.c
+10 −2 src/portable/renesas/rusb2/hcd_rusb2.c
+11 −31 src/tusb_option.h
+1 −1 tools/get_deps.py
9 changes: 7 additions & 2 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,10 @@ msgstr ""
msgid "Pins must share PWM slice"
msgstr ""

#: shared-module/usb/core/Device.c
msgid "Pipe error"
msgstr ""

#: py/builtinhelp.c
msgid "Plus any modules on the filesystem\n"
msgstr ""
Expand Down Expand Up @@ -1825,7 +1829,8 @@ msgstr ""

#: shared-bindings/_bleio/__init__.c
#: shared-bindings/memorymonitor/AllocationSize.c
#: shared-bindings/pulseio/PulseIn.c shared-module/displayio/Bitmap.c
#: shared-bindings/pulseio/PulseIn.c shared-module/bitmaptools/__init__.c
#: shared-module/displayio/Bitmap.c
msgid "Read-only"
msgstr ""

Expand Down Expand Up @@ -4021,7 +4026,7 @@ msgstr ""
msgid "sosfilt requires iterable arguments"
msgstr ""

#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
#: shared-bindings/bitmaptools/__init__.c
msgid "source palette too large"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion ports/raspberrypi/lib/Pico-PIO-USB
6 changes: 6 additions & 0 deletions py/circuitpy_mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ void background_callback_run_all(void);
#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (0)
#endif

// Align the internal sector buffer. Useful when it is passed into TinyUSB for
// loads.
#ifndef MICROPY_FATFS_WINDOW_ALIGNMENT
#define MICROPY_FATFS_WINDOW_ALIGNMENT CIRCUITPY_TUSB_MEM_ALIGN
#endif

#define FF_FS_CASE_INSENSITIVE_COMPARISON_ASCII_ONLY (1)

#define FF_FS_MAKE_VOLID (1)
Expand Down
21 changes: 17 additions & 4 deletions shared-module/usb/core/Device.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void tuh_umount_cb(uint8_t dev_addr) {
}

STATIC xfer_result_t _xfer_result;
STATIC size_t _actual_len;
bool common_hal_usb_core_device_construct(usb_core_device_obj_t *self, uint8_t device_number) {
if (device_number == 0 || device_number > CFG_TUH_DEVICE_MAX + CFG_TUH_HUB) {
return false;
Expand Down Expand Up @@ -78,6 +79,9 @@ uint16_t common_hal_usb_core_device_get_idProduct(usb_core_device_obj_t *self) {
STATIC void _transfer_done_cb(tuh_xfer_t *xfer) {
// Store the result so we stop waiting for the transfer.
_xfer_result = xfer->result;
// The passed in xfer is not the original one we passed in, so we need to
// copy any info out that we want (like actual_len.)
_actual_len = xfer->actual_len;
}

STATIC bool _wait_for_callback(void) {
Expand Down Expand Up @@ -159,11 +163,14 @@ STATIC size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) {
}
xfer_result_t result = _xfer_result;
_xfer_result = 0xff;
if (result == XFER_RESULT_STALLED || result == 0xff) {
if (result == XFER_RESULT_STALLED) {
mp_raise_usb_core_USBError(translate("Pipe error"));
}
if (result == 0xff) {
mp_raise_usb_core_USBTimeoutError();
}
if (result == XFER_RESULT_SUCCESS) {
return xfer->actual_len;
return _actual_len;
}

return 0;
Expand Down Expand Up @@ -192,7 +199,10 @@ STATIC bool _open_endpoint(usb_core_device_obj_t *self, mp_int_t endpoint) {
}
tusb_desc_configuration_t *desc_cfg = (tusb_desc_configuration_t *)desc_buf;

uint8_t const *desc_end = ((uint8_t const *)desc_cfg) + tu_le16toh(desc_cfg->wTotalLength);
uint32_t total_length = tu_le16toh(desc_cfg->wTotalLength);
// Cap to the buffer size we requested.
total_length = MIN(total_length, sizeof(desc_buf));
uint8_t const *desc_end = ((uint8_t const *)desc_cfg) + total_length;
uint8_t const *p_desc = tu_desc_next(desc_cfg);

// parse each interfaces
Expand Down Expand Up @@ -281,7 +291,10 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
}
xfer_result_t result = _xfer_result;
_xfer_result = 0xff;
if (result == XFER_RESULT_STALLED || result == 0xff) {
if (result == XFER_RESULT_STALLED) {
mp_raise_usb_core_USBError(translate("Pipe error"));
}
if (result == 0xff) {
mp_raise_usb_core_USBTimeoutError();
}
if (result == XFER_RESULT_SUCCESS) {
Expand Down

0 comments on commit f466a43

Please sign in to comment.