Prusa MINI Firmware overview
usbh_diskio.c File Reference

USB Host Disk I/O driver. More...

#include "ff_gen_drv.h"
#include "usbh_diskio.h"

Macros

#define USB_DEFAULT_BLOCK_SIZE   512
 

Functions

DSTATUS USBH_initialize (BYTE lun)
 Initializes a Drive. More...
 
DSTATUS USBH_status (BYTE lun)
 Gets Disk Status. More...
 
DRESULT USBH_read (BYTE lun, BYTE *buff, DWORD sector, UINT count)
 Reads Sector(s) More...
 

Variables

USBH_HandleTypeDef hUSB_Host
 
const Diskio_drvTypeDef USBH_Driver
 

Detailed Description

USB Host Disk I/O driver.

(based on usbh_diskio_template.c v2.0.2) This notice applies to any and all portions of this file that are not between comment pairs USER CODE BEGIN and USER CODE END. Other portions of this file, whether inserted by the user or by software development tools are owned by their respective copyright owners.

Copyright (c) 2019 STMicroelectronics International N.V. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted, provided that the following conditions are met:

  1. Redistribution of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of STMicroelectronics nor the names of other contributors to this software may be used to endorse or promote products derived from this software without specific written permission.
  4. This software, including modifications and/or derivative works of this software, must execute solely and exclusively on microcontroller or microprocessor devices manufactured by or for STMicroelectronics.
  5. Redistribution and use of this software other than as permitted under this license is void and will automatically terminate your rights under this license.

THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ USB_DEFAULT_BLOCK_SIZE

#define USB_DEFAULT_BLOCK_SIZE   512

Function Documentation

◆ USBH_initialize()

DSTATUS USBH_initialize ( BYTE  lun)

Initializes a Drive.

Parameters
lun: lun id
Return values
DSTATUSOperation status
100  {
101  /* CAUTION : USB Host library has to be initialized in the application */
102 
103  return RES_OK;
104 }

◆ USBH_status()

DSTATUS USBH_status ( BYTE  lun)

Gets Disk Status.

Parameters
lun: lun id
Return values
DSTATUSOperation status
111  {
112  DRESULT res = RES_ERROR;
113 
114  if (USBH_MSC_UnitIsReady(&hUSB_Host, lun)) {
115  res = RES_OK;
116  } else {
117  res = RES_ERROR;
118  }
119 
120  return res;
121 }
Here is the call graph for this function:

◆ USBH_read()

DRESULT USBH_read ( BYTE  lun,
BYTE buff,
DWORD  sector,
UINT  count 
)

Reads Sector(s)

Parameters
lun: lun id
*buffData buffer to store read data
sectorSector address (LBA)
countNumber of sectors to read (1..128)
Return values
DRESULTOperation result
135  {
136  DRESULT res = RES_ERROR;
138 
139  if (USBH_MSC_Read(&hUSB_Host, lun, sector, buff, count) == USBH_OK) {
140  res = RES_OK;
141  } else {
143 
144  switch (info.sense.asc) {
148  USBH_ErrLog("USB Disk is not ready!");
149  res = RES_NOTRDY;
150  break;
151 
152  default:
153  res = RES_ERROR;
154  break;
155  }
156  }
157 
158  return res;
159 }
Here is the call graph for this function:

Variable Documentation

◆ hUSB_Host

USBH_HandleTypeDef hUSB_Host

◆ USBH_Driver

const Diskio_drvTypeDef USBH_Driver
Initial value:
USBH_read
DRESULT USBH_read(BYTE, BYTE *, DWORD, UINT)
Reads Sector(s)
Definition: usbh_diskio.c:135
MSC_LUNTypeDef
Definition: usbh_msc.h:102
hUSB_Host
USBH_HandleTypeDef hUSB_Host
RES_ERROR
Definition: onboard_sd.h:24
USBH_ErrLog
#define USBH_ErrLog(...)
Definition: usbh_conf.h:176
USBH_MSC_Read
USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost, uint8_t lun, uint32_t address, uint8_t *pbuf, uint32_t length)
USBH_MSC_Read The function performs a Read operation.
Definition: usbh_msc.c:700
USBH_MSC_GetLUNInfo
USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info)
USBH_MSC_GetLUNInfo The function return a LUN information.
Definition: usbh_msc.c:676
USBH_OK
Definition: usbh_def.h:304
USBH_MSC_UnitIsReady
uint8_t USBH_MSC_UnitIsReady(USBH_HandleTypeDef *phost, uint8_t lun)
USBH_MSC_UnitIsReady The function check whether a LUN is ready.
Definition: usbh_msc.c:655
RES_OK
Definition: onboard_sd.h:23
USBH_status
DSTATUS USBH_status(BYTE)
Gets Disk Status.
Definition: usbh_diskio.c:111
SCSI_ASC_LOGICAL_UNIT_NOT_READY
#define SCSI_ASC_LOGICAL_UNIT_NOT_READY
Definition: usbh_msc_scsi.h:129
USBH_initialize
DSTATUS USBH_initialize(BYTE)
Initializes a Drive.
Definition: usbh_diskio.c:100
SCSI_ASC_NOT_READY_TO_READY_CHANGE
#define SCSI_ASC_NOT_READY_TO_READY_CHANGE
Definition: usbh_msc_scsi.h:134
DRESULT
DRESULT
Definition: onboard_sd.h:22
SCSI_ASC_MEDIUM_NOT_PRESENT
#define SCSI_ASC_MEDIUM_NOT_PRESENT
Definition: masstorage.h:155
RES_NOTRDY
Definition: onboard_sd.h:26
info
uint8_t info[12]
Definition: masstorage.h:54