Adding ChibiOS Contrib module for a proper mass storage driver.
Adding missing board files.
This commit is contained in:
parent
2cd048495f
commit
db8d16a47a
|
@ -2,3 +2,6 @@
|
|||
path = firmware/ChibiOS
|
||||
url = https://github.com/rusefi/ChibiOS.git
|
||||
branch = stable_rusefi
|
||||
[submodule "firmware/ChibiOS-Contrib"]
|
||||
path = firmware/ChibiOS-Contrib
|
||||
url = https://github.com/ChibiOS/ChibiOS-Contrib.git
|
||||
|
|
|
@ -88,6 +88,7 @@ PROJECT_DIR = .
|
|||
|
||||
# Imported source files and paths
|
||||
CHIBIOS = ChibiOS
|
||||
CHIBIOS_CONTRIB = ChibiOS-Contrib
|
||||
|
||||
ifneq ($(PROJECT_BOARD),OLIMEX_STM32_E407)
|
||||
PROJECT_BOARD = ST_STM32F4_DISCOVERY
|
||||
|
@ -97,8 +98,8 @@ DDEFS += -D$(PROJECT_BOARD)
|
|||
# Startup files.
|
||||
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
|
||||
# HAL-OSAL files (optional).
|
||||
include $(CHIBIOS)/os/hal/hal.mk
|
||||
include $(CHIBIOS)/os/hal/ports/STM32/STM32F4xx/platform.mk
|
||||
include $(CHIBIOS_CONTRIB)/os/hal/hal.mk
|
||||
include $(CHIBIOS_CONTRIB)/os/hal/ports/STM32/STM32F4xx/platform.mk
|
||||
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
|
||||
# RTOS files (optional).
|
||||
include $(CHIBIOS)/os/rt/rt.mk
|
||||
|
@ -212,6 +213,7 @@ INCDIR = $(PORTINC) \
|
|||
$(CHIBIOS)/os/hal/lib/streams \
|
||||
$(CHIBIOS)/os/various \
|
||||
$(CHIBIOS)/os/various/devices_lib/accel \
|
||||
$(CHIBIOS_CONTRIB)/os/various \
|
||||
config/stm32f4ems \
|
||||
config/engines \
|
||||
config \
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
||||
|
||||
Licensed 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file has been automatically generated using ChibiStudio board
|
||||
* generator plugin. Do not edit manually.
|
||||
*/
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
#if HAL_USE_PAL || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief PAL setup.
|
||||
* @details Digital I/O ports static configuration as defined in @p board.h.
|
||||
* This variable is used by the HAL when initializing the PAL driver.
|
||||
*/
|
||||
const PALConfig pal_default_config = {
|
||||
#if STM32_HAS_GPIOA
|
||||
{VAL_GPIOA_MODER, VAL_GPIOA_OTYPER, VAL_GPIOA_OSPEEDR, VAL_GPIOA_PUPDR,
|
||||
VAL_GPIOA_ODR, VAL_GPIOA_AFRL, VAL_GPIOA_AFRH},
|
||||
#endif
|
||||
#if STM32_HAS_GPIOB
|
||||
{VAL_GPIOB_MODER, VAL_GPIOB_OTYPER, VAL_GPIOB_OSPEEDR, VAL_GPIOB_PUPDR,
|
||||
VAL_GPIOB_ODR, VAL_GPIOB_AFRL, VAL_GPIOB_AFRH},
|
||||
#endif
|
||||
#if STM32_HAS_GPIOC
|
||||
{VAL_GPIOC_MODER, VAL_GPIOC_OTYPER, VAL_GPIOC_OSPEEDR, VAL_GPIOC_PUPDR,
|
||||
VAL_GPIOC_ODR, VAL_GPIOC_AFRL, VAL_GPIOC_AFRH},
|
||||
#endif
|
||||
#if STM32_HAS_GPIOD
|
||||
{VAL_GPIOD_MODER, VAL_GPIOD_OTYPER, VAL_GPIOD_OSPEEDR, VAL_GPIOD_PUPDR,
|
||||
VAL_GPIOD_ODR, VAL_GPIOD_AFRL, VAL_GPIOD_AFRH},
|
||||
#endif
|
||||
#if STM32_HAS_GPIOE
|
||||
{VAL_GPIOE_MODER, VAL_GPIOE_OTYPER, VAL_GPIOE_OSPEEDR, VAL_GPIOE_PUPDR,
|
||||
VAL_GPIOE_ODR, VAL_GPIOE_AFRL, VAL_GPIOE_AFRH},
|
||||
#endif
|
||||
#if STM32_HAS_GPIOF
|
||||
{VAL_GPIOF_MODER, VAL_GPIOF_OTYPER, VAL_GPIOF_OSPEEDR, VAL_GPIOF_PUPDR,
|
||||
VAL_GPIOF_ODR, VAL_GPIOF_AFRL, VAL_GPIOF_AFRH},
|
||||
#endif
|
||||
#if STM32_HAS_GPIOG
|
||||
{VAL_GPIOG_MODER, VAL_GPIOG_OTYPER, VAL_GPIOG_OSPEEDR, VAL_GPIOG_PUPDR,
|
||||
VAL_GPIOG_ODR, VAL_GPIOG_AFRL, VAL_GPIOG_AFRH},
|
||||
#endif
|
||||
#if STM32_HAS_GPIOH
|
||||
{VAL_GPIOH_MODER, VAL_GPIOH_OTYPER, VAL_GPIOH_OSPEEDR, VAL_GPIOH_PUPDR,
|
||||
VAL_GPIOH_ODR, VAL_GPIOH_AFRL, VAL_GPIOH_AFRH},
|
||||
#endif
|
||||
#if STM32_HAS_GPIOI
|
||||
{VAL_GPIOI_MODER, VAL_GPIOI_OTYPER, VAL_GPIOI_OSPEEDR, VAL_GPIOI_PUPDR,
|
||||
VAL_GPIOI_ODR, VAL_GPIOI_AFRL, VAL_GPIOI_AFRH}
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Early initialization code.
|
||||
* @details This initialization must be performed just after stack setup
|
||||
* and before any other initialization.
|
||||
*/
|
||||
void __early_init(void) {
|
||||
|
||||
stm32_clock_init();
|
||||
}
|
||||
|
||||
#if HAL_USE_SDC || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief SDC card detection.
|
||||
*/
|
||||
bool sdc_lld_is_card_inserted(SDCDriver *sdcp) {
|
||||
|
||||
(void)sdcp;
|
||||
/* TODO: Fill the implementation.*/
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SDC card write protection detection.
|
||||
*/
|
||||
bool sdc_lld_is_write_protected(SDCDriver *sdcp) {
|
||||
|
||||
(void)sdcp;
|
||||
/* TODO: Fill the implementation.*/
|
||||
return false;
|
||||
}
|
||||
#endif /* HAL_USE_SDC */
|
||||
|
||||
#if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief MMC_SPI card detection.
|
||||
*/
|
||||
bool mmc_lld_is_card_inserted(MMCDriver *mmcp) {
|
||||
|
||||
(void)mmcp;
|
||||
/* TODO: Fill the implementation.*/
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MMC_SPI card write protection detection.
|
||||
*/
|
||||
bool mmc_lld_is_write_protected(MMCDriver *mmcp) {
|
||||
|
||||
(void)mmcp;
|
||||
/* TODO: Fill the implementation.*/
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Board-specific initialization code.
|
||||
* @todo Add your board-specific code, if any.
|
||||
*/
|
||||
void boardInit(void) {
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,5 @@
|
|||
# List of all the board related files.
|
||||
BOARDSRC = $(PROJECT_DIR)/boards/ST_STM32F4_DISCOVERY/board.c
|
||||
|
||||
# Required include directories
|
||||
BOARDINC = $(PROJECT_DIR)/boards/ST_STM32F4_DISCOVERY
|
|
@ -373,9 +373,11 @@
|
|||
* @note Disabling this option saves both code and data space.
|
||||
*/
|
||||
#if !defined(USB_USE_WAIT) || defined(__DOXYGEN__)
|
||||
#define USB_USE_WAIT FALSE
|
||||
#define USB_USE_WAIT TRUE
|
||||
#endif
|
||||
|
||||
#include "halconf_community.h"
|
||||
|
||||
#endif /* _HALCONF_H_ */
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
ChibiOS - Copyright (C) 2014 Uladzimir Pylinsky aka barthess
|
||||
|
||||
Licensed 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.
|
||||
*/
|
||||
|
||||
#ifndef _HALCONF_COMMUNITY_H_
|
||||
#define _HALCONF_COMMUNITY_H_
|
||||
|
||||
/**
|
||||
* @brief Enables the community overlay.
|
||||
*/
|
||||
#if !defined(HAL_USE_COMMUNITY) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_COMMUNITY TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the FSMC subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_FSMC) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_FSMC FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the NAND subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_NAND) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_NAND FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the 1-wire subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_ONEWIRE) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_ONEWIRE FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the EICU subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_EICU) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_EICU FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the CRC subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_CRC) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_CRC FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the USBH subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_USBH) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_USBH FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the EEPROM subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_EEPROM) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_EEPROM FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the TIMCAP subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_TIMCAP) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_TIMCAP FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the RNG subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_RNG) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_RNG FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the USB_MSD subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_USB_MSD) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_USB_MSD TRUE
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* FSMCNAND driver related settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Enables the @p nandAcquireBus() and @p nanReleaseBus() APIs.
|
||||
* @note Disabling this option saves both code and data space.
|
||||
*/
|
||||
#if !defined(NAND_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
|
||||
#define NAND_USE_MUTUAL_EXCLUSION TRUE
|
||||
#endif
|
||||
|
||||
/*===========================================================================*/
|
||||
/* 1-wire driver related settings. */
|
||||
/*===========================================================================*/
|
||||
/**
|
||||
* @brief Enables strong pull up feature.
|
||||
* @note Disabling this option saves both code and data space.
|
||||
*/
|
||||
#define ONEWIRE_USE_STRONG_PULLUP FALSE
|
||||
|
||||
/**
|
||||
* @brief Enables search ROM feature.
|
||||
* @note Disabling this option saves both code and data space.
|
||||
*/
|
||||
#define ONEWIRE_USE_SEARCH_ROM FALSE
|
||||
|
||||
|
||||
/*===========================================================================*/
|
||||
/* EEProm driver related settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
#define EEPROM_USE_EE24XX FALSE
|
||||
#define EEPROM_USE_EE25XX TRUE
|
||||
|
||||
|
||||
#define rccEnableCRC(lp) rccEnableAHB(RCC_AHBENR_CRCEN, lp)
|
||||
#define rccDisableCRC(lp) rccDisableAHB(RCC_AHBENR_CRCEN, lp)
|
||||
|
||||
/*===========================================================================*/
|
||||
/* CRC driver settings. */
|
||||
/*===========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Enables DMA engine when performing CRC transactions.
|
||||
* @note Enabling this option also enables asynchronous API.
|
||||
*/
|
||||
#if !defined(CRC_USE_DMA) || defined(__DOXYGEN__)
|
||||
#define CRC_USE_DMA FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enables the @p crcAcquireUnit() and @p crcReleaseUnit() APIs.
|
||||
* @note Disabling this option saves both code and data space.
|
||||
*/
|
||||
#if !defined(CRC_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
|
||||
#define CRC_USE_MUTUAL_EXCLUSION TRUE
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* _HALCONF_COMMUNITY_H_ */
|
||||
|
||||
/** @} */
|
|
@ -1,2 +1,2 @@
|
|||
|
||||
HW_MASS_STORAGE_SRC_C = $(PROJECT_DIR)/hw_layer/mass_storage/usb_msd.c
|
||||
HW_MASS_STORAGE_SRC_C = $(PROJECT_DIR)/hw_layer/mass_storage/usb_msd_cfg.c
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,311 +0,0 @@
|
|||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _USB_MSD_H_
|
||||
#define _USB_MSD_H_
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
/* Default to disabled for USB Mass Storage */
|
||||
#if !defined(HAL_USE_MASS_STORAGE_USB)
|
||||
# define HAL_USE_MASS_STORAGE_USB TRUE
|
||||
#endif
|
||||
|
||||
#if HAL_USE_MASS_STORAGE_USB || defined(__DOXYGEN__)
|
||||
|
||||
#ifndef PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#endif
|
||||
|
||||
#ifndef PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#endif
|
||||
|
||||
#ifndef PACK_STRUCT_END
|
||||
#define PACK_STRUCT_END
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define MSD_RW_LED_ON() palSetPad(GPIOI, GPIOI_TRI_LED_BLUE)
|
||||
#define MSD_RW_LED_OFF() palClearPad(GPIOI, GPIOI_TRI_LED_BLUE)
|
||||
#define MSD_R_LED_ON() palSetPad(GPIOI, GPIOI_TRI_LED_BLUE)
|
||||
#define MSD_R_LED_OFF() palClearPad(GPIOI, GPIOI_TRI_LED_BLUE)
|
||||
#define MSD_W_LED_ON() palSetPad(GPIOH, GPIOI_TRI_LED_BLUE)
|
||||
#define MSD_W_LED_OFF() palClearPad(GPIOH, GPIOI_TRI_LED_BLUE)
|
||||
#else
|
||||
#define MSD_RW_LED_ON()
|
||||
#define MSD_RW_LED_OFF()
|
||||
#define MSD_R_LED_ON()
|
||||
#define MSD_R_LED_OFF()
|
||||
#define MSD_W_LED_ON()
|
||||
#define MSD_W_LED_OFF()
|
||||
#endif
|
||||
|
||||
|
||||
#if STM32_USB_USE_OTG2 && STM32_USE_USB_OTG2_HS
|
||||
# define USB_MS_EP_SIZE 512
|
||||
#else
|
||||
# define USB_MS_EP_SIZE 64
|
||||
#endif
|
||||
|
||||
#define MSD_THREAD_STACK_SIZE 1024
|
||||
|
||||
#define MSD_REQ_RESET 0xFF
|
||||
#define MSD_GET_MAX_LUN 0xFE
|
||||
#define MSD_CBW_SIGNATURE 0x43425355
|
||||
#define MSD_CSW_SIGNATURE 0x53425355
|
||||
#define MSD_COMMAND_DIR_DATA_OUT (0 << 7)
|
||||
#define MSD_COMMAND_DIR_DATA_IN (1 << 7)
|
||||
|
||||
#define MSD_SETUP_WORD(setup, index) (uint16_t)(((uint16_t)setup[index+1] << 8) | (setup[index] & 0x00FF))
|
||||
|
||||
#define MSD_SETUP_VALUE(setup) MSD_SETUP_WORD(setup, 2)
|
||||
#define MSD_SETUP_INDEX(setup) MSD_SETUP_WORD(setup, 4)
|
||||
#define MSD_SETUP_LENGTH(setup) MSD_SETUP_WORD(setup, 6)
|
||||
|
||||
typedef enum {
|
||||
SCSI_CMD_TEST_UNIT_READY = 0x00,
|
||||
SCSI_CMD_REQUEST_SENSE_6 = 0x03,
|
||||
SCSI_CMD_INQUIRY = 0x12,
|
||||
SCSI_CMD_MODE_SENSE_6 = 0x1A,
|
||||
SCSI_CMD_START_STOP_UNIT = 0x1B,
|
||||
SCSI_CMD_SEND_DIAGNOSTIC = 0x1D,
|
||||
SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
|
||||
SCSI_CMD_READ_FORMAT_CAPACITY = 0x23,
|
||||
SCSI_CMD_READ_CAPACITY_10 = 0x25,
|
||||
SCSI_CMD_READ_10 = 0x28,
|
||||
SCSI_CMD_WRITE_10 = 0x2A,
|
||||
SCSI_CMD_VERIFY_10 = 0x2F,
|
||||
SCSI_CMD_SYNCHRONIZE_CACHE_10 = 0x35,
|
||||
} msd_scsi_command_t;
|
||||
|
||||
|
||||
|
||||
#define MSD_COMMAND_PASSED 0x00
|
||||
#define MSD_COMMAND_FAILED 0x01
|
||||
#define MSD_COMMAND_PHASE_ERROR 0x02
|
||||
|
||||
#define SCSI_SENSE_KEY_GOOD 0x00
|
||||
#define SCSI_SENSE_KEY_RECOVERED_ERROR 0x01
|
||||
#define SCSI_SENSE_KEY_NOT_READY 0x02
|
||||
#define SCSI_SENSE_KEY_MEDIUM_ERROR 0x03
|
||||
#define SCSI_SENSE_KEY_HARDWARE_ERROR 0x04
|
||||
#define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05
|
||||
#define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06
|
||||
#define SCSI_SENSE_KEY_DATA_PROTECT 0x07
|
||||
#define SCSI_SENSE_KEY_BLANK_CHECK 0x08
|
||||
#define SCSI_SENSE_KEY_VENDOR_SPECIFIC 0x09
|
||||
#define SCSI_SENSE_KEY_COPY_ABORTED 0x0A
|
||||
#define SCSI_SENSE_KEY_ABORTED_COMMAND 0x0B
|
||||
#define SCSI_SENSE_KEY_VOLUME_OVERFLOW 0x0D
|
||||
#define SCSI_SENSE_KEY_MISCOMPARE 0x0E
|
||||
|
||||
#define SCSI_ASENSE_NO_ADDITIONAL_INFORMATION 0x00
|
||||
#define SCSI_ASENSE_PEREPHERIAL_DEVICE_WRITE_FAULT 0x03
|
||||
#define SCSI_ASENSE_LOGICAL_UNIT_NOT_READY 0x04
|
||||
#define SCSI_ASENSE_UNRECOVERED_READ_ERROR 0x11
|
||||
#define SCSI_ASENSE_INVALID_COMMAND 0x20
|
||||
#define SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x21
|
||||
#define SCSI_ASENSE_INVALID_FIELD_IN_CDB 0x24
|
||||
#define SCSI_ASENSE_WRITE_PROTECTED 0x27
|
||||
#define SCSI_ASENSE_NOT_READY_TO_READY_CHANGE 0x28
|
||||
#define SCSI_ASENSE_FORMAT_ERROR 0x31
|
||||
#define SCSI_ASENSE_MEDIUM_NOT_PRESENT 0x3A
|
||||
|
||||
#define SCSI_ASENSEQ_NO_QUALIFIER 0x00
|
||||
#define SCSI_ASENSEQ_PEREPHERIAL_DEVICE_WRITE_FAULT 0x00
|
||||
#define SCSI_ASENSEQ_FORMAT_COMMAND_FAILED 0x01
|
||||
#define SCSI_ASENSEQ_INITIALIZING_COMMAND_REQUIRED 0x02
|
||||
#define SCSI_ASENSEQ_OPERATION_IN_PROGRESS 0x07
|
||||
|
||||
|
||||
PACK_STRUCT_BEGIN typedef struct {
|
||||
uint32_t signature;
|
||||
uint32_t tag;
|
||||
uint32_t data_len;
|
||||
uint8_t flags;
|
||||
uint8_t lun;
|
||||
uint8_t scsi_cmd_len;
|
||||
uint8_t scsi_cmd_data[16];
|
||||
} PACK_STRUCT_STRUCT msd_cbw_t PACK_STRUCT_END;
|
||||
|
||||
PACK_STRUCT_BEGIN typedef struct {
|
||||
uint32_t signature;
|
||||
uint32_t tag;
|
||||
uint32_t data_residue;
|
||||
uint8_t status;
|
||||
} PACK_STRUCT_STRUCT msd_csw_t PACK_STRUCT_END;
|
||||
|
||||
typedef struct {
|
||||
uint8_t byte[18];
|
||||
} PACK_STRUCT_STRUCT scsi_sense_response_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t mode_data_length; //Number of bytes that follow
|
||||
uint8_t medium_type; //0x00 for SBC devices
|
||||
uint8_t device_specifc_paramters; //bit 7 is the write protect bit
|
||||
uint8_t block_descriptor_length; //Length in bytes of all block descriptors in the mode parameter list.
|
||||
} PACK_STRUCT_STRUCT scsi_mode_sense6_response_t;
|
||||
|
||||
PACK_STRUCT_BEGIN typedef struct
|
||||
{
|
||||
uint8_t peripheral;
|
||||
uint8_t removable;
|
||||
uint8_t version;
|
||||
uint8_t response_data_format;
|
||||
uint8_t additional_length;
|
||||
uint8_t sccstp;
|
||||
uint8_t bqueetc;
|
||||
uint8_t cmdque;
|
||||
uint8_t vendorID[8];
|
||||
uint8_t productID[16];
|
||||
uint8_t productRev[4];
|
||||
} PACK_STRUCT_STRUCT scsi_inquiry_response_t PACK_STRUCT_END;
|
||||
|
||||
PACK_STRUCT_BEGIN typedef struct {
|
||||
uint8_t payload_byte_length[4];
|
||||
uint32_t last_block_addr;
|
||||
uint32_t block_size;
|
||||
} PACK_STRUCT_STRUCT scsi_read_format_capacity_response_t PACK_STRUCT_END;
|
||||
|
||||
PACK_STRUCT_BEGIN typedef struct {
|
||||
uint32_t last_block_addr;
|
||||
uint32_t block_size;
|
||||
} PACK_STRUCT_STRUCT scsi_read_capacity10_response_t PACK_STRUCT_END;
|
||||
|
||||
PACK_STRUCT_BEGIN typedef struct {
|
||||
uint8_t op_code;
|
||||
uint8_t lun_immed;
|
||||
uint8_t res1;
|
||||
uint8_t res2;
|
||||
uint8_t loej_start;
|
||||
uint8_t control;
|
||||
} PACK_STRUCT_STRUCT scsi_start_stop_unit_request_t;
|
||||
|
||||
|
||||
|
||||
typedef enum {
|
||||
MSD_WAIT_MODE_NONE = 0,
|
||||
MSD_WAIT_MODE_BULK_IN,
|
||||
MSD_WAIT_MODE_BULK_OUT
|
||||
} msd_wait_mode_t;
|
||||
|
||||
typedef enum {
|
||||
MSD_STATE_IDLE = 0,
|
||||
MSD_STATE_READ_CMD_BLOCK,
|
||||
MSD_STATE_EJECTED
|
||||
} msd_state_t;
|
||||
|
||||
typedef enum {
|
||||
USB_MSD_DRIVER_UNINITIALIZED = 0,
|
||||
USB_MSD_DRIVER_ERROR,
|
||||
USB_MSD_DRIVER_OK,
|
||||
USB_MSD_DRIVER_STOPPED,
|
||||
USB_MSD_DRIVER_ERROR_BLK_DEV_NOT_READY,
|
||||
} usb_msd_driver_state_t;
|
||||
|
||||
typedef struct USBMassStorageDriver USBMassStorageDriver;
|
||||
|
||||
struct USBMassStorageDriver {
|
||||
/* Driver Setup Data */
|
||||
USBDriver *usbp;
|
||||
BaseBlockDevice *bbdp;
|
||||
event_source_t evt_connected;
|
||||
event_source_t evt_ejected;
|
||||
BlockDeviceInfo block_dev_info;
|
||||
bool block_dev_info_valid_flag;
|
||||
usb_msd_driver_state_t driver_state;
|
||||
usbep_t ms_ep_number;
|
||||
uint16_t msd_interface_number;
|
||||
bool (*enable_msd_callback)(void);
|
||||
bool (*suspend_threads_callback)(void);
|
||||
|
||||
/* Externally modifiable settings */
|
||||
bool enable_media_removial;
|
||||
bool disable_usb_bus_disconnect_on_eject;
|
||||
BaseSequentialStream *chp; /*For debug logging*/
|
||||
|
||||
/*Internal data for operation of the driver */
|
||||
binary_semaphore_t bsem;
|
||||
binary_semaphore_t usb_transfer_thread_bsem;
|
||||
binary_semaphore_t mass_sorage_thd_bsem;
|
||||
volatile uint32_t trigger_transfer_index;
|
||||
|
||||
volatile bool bulk_in_interupt_flag;
|
||||
volatile bool bulk_out_interupt_flag;
|
||||
|
||||
struct {
|
||||
scsi_read_format_capacity_response_t format_capacity_response;
|
||||
scsi_read_capacity10_response_t read_capacity10_response;
|
||||
scsi_mode_sense6_response_t mode_sense6_response;
|
||||
uint8_t max_lun_len_buf[1];
|
||||
scsi_inquiry_response_t scsi_inquiry_response;
|
||||
} data;
|
||||
|
||||
msd_state_t state;
|
||||
msd_cbw_t cbw;
|
||||
msd_csw_t csw;
|
||||
scsi_sense_response_t sense;
|
||||
|
||||
volatile bool reconfigured_or_reset_event;
|
||||
|
||||
bool command_succeeded_flag;
|
||||
bool stall_in_endpoint;
|
||||
bool stall_out_endpoint;
|
||||
|
||||
|
||||
/*Debugging Information*/
|
||||
volatile uint32_t read_error_count;
|
||||
volatile uint32_t write_error_count;
|
||||
volatile uint32_t read_success_count;
|
||||
volatile uint32_t write_success_count;
|
||||
char *msd_thread_state;
|
||||
char *transfer_thread_state;
|
||||
char *scsi_command_state;
|
||||
volatile uint8_t last_bad_scsi_command;
|
||||
|
||||
/* Externally readable values */
|
||||
volatile bool debug_enable_msd;
|
||||
volatile msd_wait_mode_t debug_wait_for_isr;
|
||||
|
||||
THD_WORKING_AREA(waMassStorage, MSD_THREAD_STACK_SIZE);
|
||||
THD_WORKING_AREA(waMassStorageUSBTransfer, MSD_THREAD_STACK_SIZE);
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
usb_msd_driver_state_t msdInit(USBDriver *usbp, BaseBlockDevice *bbdp, USBMassStorageDriver *msdp, const usbep_t ms_ep_number, const uint16_t msd_interface_number);
|
||||
usb_msd_driver_state_t msdStart(USBMassStorageDriver *msdp);
|
||||
usb_msd_driver_state_t msdStop(USBMassStorageDriver *msdp);
|
||||
void msdBulkInCallbackComplete(USBDriver *usbp, usbep_t ep);
|
||||
void msdBulkOutCallbackComplete(USBDriver *usbp, usbep_t ep);
|
||||
bool msdRequestsHook(USBDriver *usbp);
|
||||
bool msdRequestsHook2(USBDriver *usbp, USBMassStorageDriver *msdp);
|
||||
const char* usb_msd_driver_state_t_to_str(const usb_msd_driver_state_t driver_state);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* HAL_USE_MASS_STORAGE_USB */
|
||||
|
||||
#endif /* _USB_MSD_H_ */
|
|
@ -1,43 +1,41 @@
|
|||
/*
|
||||
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
||||
2011,2012,2013 Giovanni Di Sirio.
|
||||
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
||||
|
||||
This file is part of ChibiOS/RT.
|
||||
Licensed 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
|
||||
|
||||
ChibiOS/RT is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
ChibiOS/RT is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "ch.h"
|
||||
#include "hal.h"
|
||||
|
||||
#include "hal_usb_msd.h"
|
||||
#include "usb_msd_cfg.h"
|
||||
#include "usb_msd.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* must be 64 for full speed and 512 for high speed
|
||||
*/
|
||||
#define USB_MSD_EP_SIZE 64U
|
||||
|
||||
/*
|
||||
* USB Device Descriptor.
|
||||
*/
|
||||
static const uint8_t msd_device_descriptor_data[18] = {
|
||||
USB_DESC_DEVICE (0x0200, /* bcdUSB (2.0). */
|
||||
0x00, /* bDeviceClass (None). */
|
||||
0x02, /* bDeviceClass (CDC). */
|
||||
0x00, /* bDeviceSubClass. */
|
||||
0x00, /* bDeviceProtocol. */
|
||||
0x40, /* Control Endpoint Size. */
|
||||
0x40, /* bMaxPacketSize. */
|
||||
0x0483, /* idVendor (ST). */
|
||||
0x5742, /* idProduct. */
|
||||
0x0100, /* bcdDevice. */
|
||||
0x0200, /* bcdDevice. */
|
||||
1, /* iManufacturer. */
|
||||
2, /* iProduct. */
|
||||
3, /* iSerialNumber. */
|
||||
|
@ -52,34 +50,34 @@ static const USBDescriptor msd_device_descriptor = {
|
|||
msd_device_descriptor_data
|
||||
};
|
||||
|
||||
/* Configuration Descriptor tree*/
|
||||
static const uint8_t msd_configuration_descriptor_data[] = {
|
||||
/* Configuration Descriptor.*/
|
||||
USB_DESC_CONFIGURATION(0x0020, /* wTotalLength. */
|
||||
0x01, /* bNumInterfaces. */
|
||||
0x01, /* bConfigurationValue. */
|
||||
0, /* iConfiguration. */
|
||||
0xC0, /* bmAttributes (self powered). */
|
||||
0x32), /* bMaxPower (100mA). */
|
||||
/* Interface Descriptor.*/
|
||||
USB_DESC_INTERFACE (USB_MSD_INTERFACE_NUMBER, /* bInterfaceNumber. */
|
||||
0x00, /* bAlternateSetting. */
|
||||
0x02, /* bNumEndpoints. */
|
||||
0x08, /* bInterfaceClass (Mass Storage) */
|
||||
0x06, /* bInterfaceSubClass (SCSI
|
||||
Transparent storage class) */
|
||||
0x50, /* bInterfaceProtocol (Bulk Only) */
|
||||
0), /* iInterface. (none) */
|
||||
/* Mass Storage Data In Endpoint Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_MS_DATA_EP|0x80,
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
USB_MS_EP_SIZE,/* wMaxPacketSize. */
|
||||
0x05), /* bInterval. 1ms */
|
||||
/* Mass Storage Data In Endpoint Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_MS_DATA_EP,
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
USB_MS_EP_SIZE,/* wMaxPacketSize. */
|
||||
0x05) /* bInterval. 1ms */
|
||||
/* Configuration Descriptor tree for a CDC.*/
|
||||
static const uint8_t msd_configuration_descriptor_data[67] = {
|
||||
/* Configuration Descriptor.*/
|
||||
USB_DESC_CONFIGURATION(0x0020, /* wTotalLength. */
|
||||
0x01, /* bNumInterfaces. */
|
||||
0x01, /* bConfigurationValue. */
|
||||
0, /* iConfiguration. */
|
||||
0xC0, /* bmAttributes (self powered). */
|
||||
0x32), /* bMaxPower (100mA). */
|
||||
/* Interface Descriptor.*/
|
||||
USB_DESC_INTERFACE (0x00, /* bInterfaceNumber. */
|
||||
0x00, /* bAlternateSetting. */
|
||||
0x02, /* bNumEndpoints. */
|
||||
0x08, /* bInterfaceClass (Mass Storage) */
|
||||
0x06, /* bInterfaceSubClass (SCSI
|
||||
Transparent storage class) */
|
||||
0x50, /* bInterfaceProtocol (Bulk Only) */
|
||||
0), /* iInterface. (none) */
|
||||
/* Mass Storage Data In Endpoint Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_MSD_DATA_EP | 0x80,
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
USB_MSD_EP_SIZE, /* wMaxPacketSize. */
|
||||
0x00), /* bInterval. 1ms */
|
||||
/* Mass Storage Data Out Endpoint Descriptor.*/
|
||||
USB_DESC_ENDPOINT (USB_MSD_DATA_EP,
|
||||
0x02, /* bmAttributes (Bulk). */
|
||||
USB_MSD_EP_SIZE, /* wMaxPacketSize. */
|
||||
0x00) /* bInterval. 1ms */
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -114,17 +112,17 @@ static const uint8_t msd_string1[] = {
|
|||
* Device Description string.
|
||||
*/
|
||||
static const uint8_t msd_string2[] = {
|
||||
USB_DESC_BYTE(58), /* bLength. */
|
||||
USB_DESC_BYTE(62), /* bLength. */
|
||||
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
|
||||
'r', 0, 'u', 0, 's', 0, 'E', 0, 'f', 0, 'i', 0,
|
||||
' ', 0, 'M', 0, 'a', 0, 's', 0, 's', 0, ' ', 0,
|
||||
'C', 0, 'h', 0, 'i', 0, 'b', 0, 'i', 0, 'O', 0, 'S', 0, '/', 0,
|
||||
'R', 0, 'T', 0, ' ', 0, 'M', 0, 'a', 0, 's', 0, 's', 0, ' ', 0,
|
||||
'S', 0, 't', 0, 'o', 0, 'r', 0, 'a', 0, 'g', 0, 'e', 0, ' ', 0,
|
||||
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0
|
||||
};
|
||||
|
||||
static const uint8_t msd_string3[] = {
|
||||
USB_DESC_BYTE(26), /* bLength. */
|
||||
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
|
||||
USB_DESC_BYTE(26), /* bLength. */
|
||||
USB_DESC_BYTE(USB_DESCRIPTOR_STRING), /* bDescriptorType. */
|
||||
'A', 0, 'E', 0, 'C', 0, 'C', 0, 'E', 0, 'C', 0, 'C', 0, 'C', 0, 'C', 0,
|
||||
'0' + CH_KERNEL_MAJOR, 0,
|
||||
'0' + CH_KERNEL_MINOR, 0,
|
||||
|
@ -164,53 +162,51 @@ static const USBDescriptor *get_descriptor(USBDriver *usbp,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief IN EP1 state.
|
||||
*/
|
||||
static USBInEndpointState ep1InState;
|
||||
static USBOutEndpointState ep1OutState;
|
||||
static USBInEndpointState ep1instate;
|
||||
|
||||
/**
|
||||
* @brief EP1 initialization structure (IN only).
|
||||
* @brief OUT EP1 state.
|
||||
*/
|
||||
static const USBEndpointConfig epDataConfig = {
|
||||
static USBOutEndpointState ep1outstate;
|
||||
|
||||
/**
|
||||
* @brief EP1 initialization structure (both IN and OUT).
|
||||
*/
|
||||
static const USBEndpointConfig ep1config = {
|
||||
USB_EP_MODE_TYPE_BULK,
|
||||
NULL,
|
||||
msdBulkInCallbackComplete,
|
||||
msdBulkOutCallbackComplete,
|
||||
USB_MS_EP_SIZE,
|
||||
USB_MS_EP_SIZE,
|
||||
&ep1InState,
|
||||
&ep1OutState,
|
||||
1,
|
||||
NULL,
|
||||
NULL,
|
||||
USB_MSD_EP_SIZE,
|
||||
USB_MSD_EP_SIZE,
|
||||
&ep1instate,
|
||||
&ep1outstate,
|
||||
4,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Handles the USB driver global events.
|
||||
*/
|
||||
static void usb_event(USBDriver *usbp, usbevent_t event) {
|
||||
USBMassStorageDriver *msdp = (USBMassStorageDriver *)usbp->in_params[USB_MS_DATA_EP - 1];
|
||||
|
||||
switch (event) {
|
||||
case USB_EVENT_RESET:
|
||||
msdp->reconfigured_or_reset_event = TRUE;
|
||||
return;
|
||||
case USB_EVENT_ADDRESS:
|
||||
return;
|
||||
case USB_EVENT_CONFIGURED:
|
||||
chSysLockFromISR();
|
||||
msdp->reconfigured_or_reset_event = TRUE;
|
||||
usbInitEndpointI(usbp, msdp->ms_ep_number, &epDataConfig);
|
||||
/* Kick-start the thread */
|
||||
chBSemSignalI(&msdp->bsem);
|
||||
|
||||
/* signal that the device is connected */
|
||||
chEvtBroadcastI(&msdp->evt_connected);
|
||||
/* Enables the endpoints specified into the configuration.
|
||||
Note, this callback is invoked from an ISR so I-Class functions
|
||||
must be used.*/
|
||||
usbInitEndpointI(usbp, USBD1_DATA_REQUEST_EP, &ep1config);
|
||||
chSysUnlockFromISR();
|
||||
|
||||
return;
|
||||
case USB_EVENT_UNCONFIGURED:
|
||||
return;
|
||||
case USB_EVENT_SUSPEND:
|
||||
return;
|
||||
|
@ -222,10 +218,13 @@ static void usb_event(USBDriver *usbp, usbevent_t event) {
|
|||
return;
|
||||
}
|
||||
|
||||
const USBConfig msd_usb_config = {
|
||||
usb_event,
|
||||
get_descriptor,
|
||||
msdRequestsHook,
|
||||
NULL
|
||||
/*
|
||||
* USB driver configuration.
|
||||
*/
|
||||
const USBConfig msdusbcfg = {
|
||||
usb_event,
|
||||
get_descriptor,
|
||||
msd_request_hook,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
|
@ -22,8 +22,9 @@
|
|||
#define USB_MSD_CFG_H_
|
||||
|
||||
|
||||
#define USB_MS_DATA_EP 1
|
||||
#define USB_MSD_INTERFACE_NUMBER 0x00
|
||||
#define USBD1_DATA_REQUEST_EP 1
|
||||
#define USBD1_DATA_AVAILABLE_EP 1
|
||||
#define USBD1_INTERRUPT_REQUEST_EP 2
|
||||
|
||||
|
||||
#endif /* USB_MSD_CFG_H_ */
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "hardware.h"
|
||||
#include "engine_configuration.h"
|
||||
#include "status_loop.h"
|
||||
#include "usb_msd.h"
|
||||
#include "hal_usb_msd.h"
|
||||
#include "usb_msd_cfg.h"
|
||||
|
||||
#include "rtc_helper.h"
|
||||
|
@ -56,7 +56,7 @@ extern board_configuration_s *boardConfiguration;
|
|||
|
||||
//static USBDriver *ms_usb_driver = &USBD1;
|
||||
//static USBMassStorageDriver UMSD1;
|
||||
//extern const USBConfig msd_usb_config;
|
||||
extern const USBConfig msdusbcfg;
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue