parent
503d79de56
commit
7b4e4b3c14
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* upstream_interface_def.h
|
||||
*
|
||||
* Created on: 24/07/2015
|
||||
* Author: Robert Fisk
|
||||
*/
|
||||
|
||||
#ifndef INC_UPSTREAM_INTERFACE_DEF_H_
|
||||
#define INC_UPSTREAM_INTERFACE_DEF_H_
|
||||
|
||||
|
||||
//***************
|
||||
// Attention!
|
||||
// Keep this file synchronised with downstream_interface_def.h
|
||||
// in the Upstream project.
|
||||
//***************
|
||||
|
||||
|
||||
|
||||
#define COMMAND_CLASS_DATA_FLAG 0x80
|
||||
#define COMMAND_CLASS_MASK ((uint8_t)(~COMMAND_CLASS_DATA_FLAG))
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COMMAND_CLASS_INTERFACE = 0,
|
||||
COMMAND_CLASS_MASS_STORAGE = 1,
|
||||
COMMAND_CLASS_MAX = 2,
|
||||
}
|
||||
InterfaceCommandClassTypeDef;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
COMMAND_MSC_TEST_UNIT_READY = 0, //Returns HAL_StatusTypeDef result
|
||||
COMMAND_MSC_GET_CAPACITY = 2, //Returns uint32_t blk_nbr, uint32_t blk_size
|
||||
COMMAND_MSC_BEGIN_READ = 3, //Returns HAL_StatusTypeDef result, then data stream
|
||||
COMMAND_MSC_BEGIN_WRITE = 4, //Returns HAL_OK, HAL_ERROR if medium not present, HAL_BUSY if write-protected result, then waits for data stream
|
||||
COMMAND_MSC_MAX = 5,
|
||||
}
|
||||
InterfaceCommandMscTypeDef;
|
||||
|
||||
|
||||
|
||||
#endif /* INC_UPSTREAM_INTERFACE_DEF_H_ */
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* upstream_spi.h
|
||||
*
|
||||
* Created on: 24/07/2015
|
||||
* Author: Robert Fisk
|
||||
*/
|
||||
|
||||
#ifndef INC_UPSTREAM_SPI_H_
|
||||
#define INC_UPSTREAM_SPI_H_
|
||||
|
||||
|
||||
#include "usbh_config.h"
|
||||
|
||||
|
||||
#define UPSTREAM_PACKET_HEADER_LEN (2) //Min length = CommandClass & Command bytes
|
||||
#define UPSTREAM_PACKET_LEN (UPSTREAM_PACKET_HEADER_LEN + USBH_MAX_DATA_BUFFER)
|
||||
#define UPSTREAM_PACKET_LEN_MIN (UPSTREAM_PACKET_HEADER_LEN)
|
||||
|
||||
|
||||
#define SPI_INTERFACE_FREAKOUT_VOID \
|
||||
do { \
|
||||
while (1); \
|
||||
/*UpstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
|
||||
/*return;*/ \
|
||||
} while (0);
|
||||
|
||||
#define SPI_INTERFACE_FREAKOUT_HAL_ERROR \
|
||||
do { \
|
||||
while (1); \
|
||||
/*UpstreamInterfaceState = INTERFACE_STATE_ERROR;*/ \
|
||||
/*return HAL_ERROR;*/ \
|
||||
} while (0);
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INTERFACE_STATE_RESET = 0,
|
||||
// INTERFACE_STATE_WAITING_CLIENT = 1,
|
||||
// INTERFACE_STATE_IDLE = 2,
|
||||
// INTERFACE_STATE_TX_SIZE_WAIT = 3,
|
||||
// INTERFACE_STATE_TX_SIZE = 4,
|
||||
// INTERFACE_STATE_TX_PACKET_WAIT = 5,
|
||||
// INTERFACE_STATE_TX_PACKET = 6,
|
||||
// INTERFACE_STATE_RX_SIZE_WAIT = 7,
|
||||
// INTERFACE_STATE_RX_SIZE = 8,
|
||||
// INTERFACE_STATE_RX_PACKET_WAIT = 9,
|
||||
// INTERFACE_STATE_RX_PACKET = 10,
|
||||
INTERFACE_STATE_ERROR = 11
|
||||
} InterfaceStateTypeDef;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
NOT_BUSY = 0,
|
||||
BUSY = 1
|
||||
} PacketBusyTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PacketBusyTypeDef Busy; //Everything after Busy should be word-aligned
|
||||
uint16_t Length __ALIGN_END; //Packet length includes CommandClass, Command, and Data
|
||||
uint8_t CommandClass;
|
||||
uint8_t Command;
|
||||
uint8_t Data[USBH_MAX_DATA_BUFFER]; //Should (must?) be word-aligned, for USB copy routine
|
||||
uint8_t RxCrc;
|
||||
}
|
||||
UpstreamPacketTypeDef;
|
||||
|
||||
|
||||
void Upstream_InitInterface(void);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* INC_UPSTREAM_SPI_H_ */
|
@ -1,157 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbh_conf_template.h
|
||||
* @author MCD Application Team
|
||||
* @version V3.2.1
|
||||
* @date 26-June-2015
|
||||
* @brief Header file for usbh_conf_template.c
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBH_CONF_TEMPLATE_H
|
||||
#define __USBH_CONF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/** @addtogroup USBH_OTG_DRIVER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CONF
|
||||
* @brief usb otg low level driver configuration file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USBH_MAX_NUM_ENDPOINTS 2
|
||||
#define USBH_MAX_NUM_INTERFACES 2
|
||||
#define USBH_MAX_NUM_CONFIGURATION 1
|
||||
#define USBH_KEEP_CFG_DESCRIPTOR 1
|
||||
#define USBH_MAX_NUM_SUPPORTED_CLASS 1
|
||||
#define USBH_MAX_SIZE_CONFIGURATION 0x200
|
||||
#define USBH_MAX_DATA_BUFFER 0x200
|
||||
#define USBH_DEBUG_LEVEL 2
|
||||
#define USBH_USE_OS 1
|
||||
|
||||
/** @defgroup USBH_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Memory management macros */
|
||||
#define USBH_malloc malloc
|
||||
#define USBH_free free
|
||||
#define USBH_memset memset
|
||||
#define USBH_memcpy memcpy
|
||||
|
||||
/* DEBUG macros */
|
||||
|
||||
|
||||
#if (USBH_DEBUG_LEVEL > 0)
|
||||
#define USBH_UsrLog(...) printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBH_UsrLog(...)
|
||||
#endif
|
||||
|
||||
|
||||
#if (USBH_DEBUG_LEVEL > 1)
|
||||
|
||||
#define USBH_ErrLog(...) printf("ERROR: ") ;\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBH_ErrLog(...)
|
||||
#endif
|
||||
|
||||
|
||||
#if (USBH_DEBUG_LEVEL > 2)
|
||||
#define USBH_DbgLog(...) printf("DEBUG : ") ;\
|
||||
printf(__VA_ARGS__);\
|
||||
printf("\n");
|
||||
#else
|
||||
#define USBH_DbgLog(...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_CONF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBH_CONF_TEMPLATE_H */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* upstream_spi.c
|
||||
*
|
||||
* Created on: 24/07/2015
|
||||
* Author: Robert Fisk
|
||||
*/
|
||||
|
||||
|
||||
#include "upstream_spi.h"
|
||||
#include "upstream_interface_def.h"
|
||||
|
||||
|
||||
SPI_HandleTypeDef Hspi1;
|
||||
|
||||
InterfaceStateTypeDef UpstreamInterfaceState;
|
||||
|
||||
|
||||
|
||||
void SPI1_Init(void);
|
||||
|
||||
|
||||
|
||||
void Upstream_InitInterface(void)
|
||||
{
|
||||
UpstreamInterfaceState = INTERFACE_STATE_RESET;
|
||||
|
||||
SPI1_Init();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SPI1_Init(void)
|
||||
{
|
||||
Hspi1.Instance = SPI1;
|
||||
Hspi1.Init.Mode = SPI_MODE_SLAVE;
|
||||
Hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
Hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
Hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
Hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
Hspi1.Init.NSS = SPI_NSS_HARD_INPUT;
|
||||
Hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
Hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
Hspi1.Init.TIMode = SPI_TIMODE_DISABLED;
|
||||
Hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_ENABLE;
|
||||
Hspi1.Init.CRCPolynomial = SPI_CRC_DEFAULTPOLYNOMIAL;
|
||||
HAL_SPI_Init(&Hspi1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in new issue