Commit of Downstream before diving into USB MSC class driver

modifications.

Also correct project settings to compile for Cortex M4 architecture.
pull/7/head
Robert Fisk 9 years ago
parent 674cb621a7
commit b9b6123642

@ -15,7 +15,7 @@
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.110983800" name="Debug" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug"> <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.110983800" name="Debug" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug">
<folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.110983800." name="/" resourcePath=""> <folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.110983800." name="/" resourcePath="">
<toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug.1271795031" name="Cross ARM GCC" nonInternalBuilderId="ilg.gnuarmeclipse.managedbuild.cross.builder" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug"> <toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug.1271795031" name="Cross ARM GCC" nonInternalBuilderId="ilg.gnuarmeclipse.managedbuild.cross.builder" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug">
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.2140590766" name="Optimization Level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level" value="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.none" valueType="enumerated"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.2140590766" name="Optimization Level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level" value="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.debug" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.messagelength.1655246483" name="Message length (-fmessage-length=0)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.messagelength" value="true" valueType="boolean"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.messagelength.1655246483" name="Message length (-fmessage-length=0)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.messagelength" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.signedchar.1912399695" name="'char' is signed (-fsigned-char)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.signedchar" value="true" valueType="boolean"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.signedchar.1912399695" name="'char' is signed (-fsigned-char)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.signedchar" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.functionsections.2097677227" name="Function sections (-ffunction-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.functionsections" value="true" valueType="boolean"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.functionsections.2097677227" name="Function sections (-ffunction-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.functionsections" value="true" valueType="boolean"/>
@ -24,7 +24,7 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format.973313256" name="Debug format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format.973313256" name="Debug format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name.859574207" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name" value="GNU Tools for ARM Embedded Processors" valueType="string"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name.859574207" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name" value="GNU Tools for ARM Embedded Processors" valueType="string"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.1378373916" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture" value="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.arm" valueType="enumerated"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.1378373916" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture" value="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.arm" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.1657788080" name="ARM family" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.mcpu.cortex-m3" valueType="enumerated"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.1657788080" name="ARM family" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.mcpu.cortex-m4" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.21974397" name="Instruction set" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.thumb" valueType="enumerated"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.21974397" name="Instruction set" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.thumb" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix.195914210" name="Prefix" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix" value="arm-none-eabi-" valueType="string"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix.195914210" name="Prefix" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix" value="arm-none-eabi-" valueType="string"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.c.1353241937" name="C compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.c" value="gcc" valueType="string"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.c.1353241937" name="C compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.c" value="gcc" valueType="string"/>
@ -91,7 +91,7 @@
</tool> </tool>
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.printsize.2134899522" name="Cross ARM GNU Print Size" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.printsize"> <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.printsize.2134899522" name="Cross ARM GNU Print Size" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.printsize">
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.format.596374317" name="Size format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.format"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.format.596374317" name="Size format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.format"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.totals.878347212" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.totals" value="true" valueType="boolean"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.totals.878347212" name="Show totals" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.totals" value="true" valueType="boolean"/>
</tool> </tool>
</toolChain> </toolChain>
</folderInfo> </folderInfo>

@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1737264941266578779" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1699849300025239643" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

@ -25,6 +25,8 @@ typedef enum
{ {
COMMAND_CLASS_INTERFACE, COMMAND_CLASS_INTERFACE,
COMMAND_CLASS_MASS_STORAGE, COMMAND_CLASS_MASS_STORAGE,
//...
COMMAND_CLASS_ERROR
} }
InterfaceCommandClassTypeDef; InterfaceCommandClassTypeDef;

@ -0,0 +1,20 @@
/*
* downstream_msc.h
*
* Created on: 8/08/2015
* Author: Robert Fisk
*/
#ifndef INC_DOWNSTREAM_MSC_H_
#define INC_DOWNSTREAM_MSC_H_
#include "downstream_spi.h"
HAL_StatusTypeDef Downstream_MSC_ApproveConnectedDevice(void);
void Downstream_MSC_PacketProcessor(DownstreamPacketTypeDef* receivedPacket);
#endif /* INC_DOWNSTREAM_MSC_H_ */

@ -10,13 +10,15 @@
#include "usbh_def.h" #include "usbh_def.h"
#include "downstream_spi.h"
typedef enum typedef enum
{ {
STATE_NOT_READY, STATE_DEVICE_NOT_READY,
STATE_WAIT_DEVICE_READY_CALLBACK, STATE_DEVICE_READY, //HOST_USER_CLASS_ACTIVE callback arrives first
STATE_DEVICE_READY, STATE_WAIT_DEVICE_READY, //COMMAND_INTERFACE_NOTIFY_DEVICE message arrives first
STATE_ACTIVE,
STATE_ERROR STATE_ERROR
} DownstreamStateTypeDef; } DownstreamStateTypeDef;
@ -24,7 +26,8 @@ typedef enum
void Downstream_InitStateMachine(void); void Downstream_InitStateMachine(void);
void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id); void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id);
void Downstream_PacketProcessor_ErrorReply(DownstreamPacketTypeDef* replyPacket);
void Downstream_PacketProcessor_ClassReply(DownstreamPacketTypeDef* replyPacket);
#endif /* INC_DOWNSTREAM_STATEMACHINE_H_ */ #endif /* INC_DOWNSTREAM_STATEMACHINE_H_ */

@ -0,0 +1,132 @@
/*
* downstream_msc.c
*
* Created on: 8/08/2015
* Author: Robert Fisk
*/
#include "downstream_msc.h"
#include "downstream_interface_def.h"
#include "downstream_statemachine.h"
#include "usbh_msc.h"
extern USBH_HandleTypeDef hUsbHostFS; //Hard-link ourselves to usb_host.c
void Downstream_MSC_PacketProcessor_TestUnitReady(DownstreamPacketTypeDef* receivedPacket);
void Downstream_MSC_PacketProcessor_GetCapacity(DownstreamPacketTypeDef* receivedPacket);
void Downstream_MSC_PacketProcessor_BeginRead(DownstreamPacketTypeDef* receivedPacket);
//High-level checks on the connected device. We don't want some weirdly
//configured device to bomb our USB stack, accidentally or otherwise.
HAL_StatusTypeDef Downstream_MSC_ApproveConnectedDevice(void)
{
MSC_HandleTypeDef* MSC_Handle = (MSC_HandleTypeDef*)hUsbHostFS.pActiveClass->pData;
if ((MSC_Handle->unit[0].capacity.block_nbr == 0) ||
(MSC_Handle->unit[0].capacity.block_nbr == UINT32_MAX))
{
return HAL_ERROR;
}
if (MSC_Handle->unit[0].capacity.block_size != 512)
{
return HAL_ERROR;
}
return HAL_OK;
}
void Downstream_MSC_PacketProcessor(DownstreamPacketTypeDef* receivedPacket)
{
switch (receivedPacket->Command)
{
case COMMAND_MSC_TEST_UNIT_READY:
Downstream_MSC_PacketProcessor_TestUnitReady(receivedPacket);
break;
case COMMAND_MSC_GET_CAPACITY:
Downstream_MSC_PacketProcessor_GetCapacity(receivedPacket);
break;
case COMMAND_MSC_BEGIN_READ:
Downstream_MSC_PacketProcessor_BeginRead(receivedPacket);
break;
default:
Downstream_PacketProcessor_ErrorReply(receivedPacket);
}
}
void Downstream_MSC_PacketProcessor_TestUnitReady(DownstreamPacketTypeDef* receivedPacket)
{
if (USBH_MSC_UnitIsReady(&hUsbHostFS, 0))
{
receivedPacket->Data[0] = HAL_OK;
}
else
{
receivedPacket->Data[0] = HAL_ERROR;
}
receivedPacket->Length = DOWNSTREAM_PACKET_HEADER_LEN + 1;
Downstream_PacketProcessor_ClassReply(receivedPacket);
}
void Downstream_MSC_PacketProcessor_GetCapacity(DownstreamPacketTypeDef* receivedPacket)
{
MSC_HandleTypeDef* MSC_Handle = (MSC_HandleTypeDef*)hUsbHostFS.pActiveClass->pData;
receivedPacket->Length = DOWNSTREAM_PACKET_HEADER_LEN + 8;
*(uint32_t*)&(receivedPacket->Data[0]) = MSC_Handle->unit[0].capacity.block_nbr;
*(uint32_t*)&(receivedPacket->Data[4]) = (uint32_t)MSC_Handle->unit[0].capacity.block_size;
Downstream_PacketProcessor_ClassReply(receivedPacket);
}
void Downstream_MSC_PacketProcessor_BeginRead(DownstreamPacketTypeDef* receivedPacket)
{
uint64_t address;
uint32_t count;
MSC_HandleTypeDef* MSC_Handle = (MSC_HandleTypeDef*)hUsbHostFS.pActiveClass->pData;
if (receivedPacket->Length != (DOWNSTREAM_PACKET_HEADER_LEN + (4 * 3)))
{
Downstream_PacketProcessor_ErrorReply(receivedPacket);
return;
}
address = *(uint64_t*)&(receivedPacket->Data[0]);
count = *(uint32_t*)&(receivedPacket->Data[8]);
if ((address >= (uint64_t)MSC_Handle->unit[0].capacity.block_nbr) ||
((address + count - 1) >= (uint64_t)MSC_Handle->unit[0].capacity.block_nbr))
{
Downstream_PacketProcessor_ErrorReply(receivedPacket);
return;
}
if (USBH_MSC_UnitIsReady(&hUsbHostFS, 0))
{
receivedPacket->Data[0] = HAL_OK;
}
else
{
receivedPacket->Data[0] = HAL_ERROR;
}
receivedPacket->Length = DOWNSTREAM_PACKET_HEADER_LEN + 1;
Downstream_TransmitPacket(receivedPacket);
USBH_MSC_Read(&hUsbHostFS,
0,
(uint32_t)address,
count);
}

@ -9,6 +9,7 @@
#include "downstream_statemachine.h" #include "downstream_statemachine.h"
#include "downstream_interface_def.h" #include "downstream_interface_def.h"
#include "downstream_spi.h" #include "downstream_spi.h"
#include "downstream_msc.h"
#include "usbh_core.h" #include "usbh_core.h"
#include "usbh_msc.h" #include "usbh_msc.h"
@ -21,13 +22,12 @@ InterfaceCommandClassTypeDef ConfiguredDeviceClass;
void Downstream_PacketProcessor(DownstreamPacketTypeDef* receivedPacket); void Downstream_PacketProcessor(DownstreamPacketTypeDef* receivedPacket);
void Downstream_PacketProcessor_Interface(DownstreamPacketTypeDef* receivedPacket); void Downstream_PacketProcessor_Interface(DownstreamPacketTypeDef* receivedPacket);
void Downstream_PacketProcessor_Interface_ReplyNotifyDevice(DownstreamPacketTypeDef* replyPacket); void Downstream_PacketProcessor_Interface_ReplyNotifyDevice(DownstreamPacketTypeDef* replyPacket);
void Downstream_PacketProcessor_EmptyReply(DownstreamPacketTypeDef* replyPacket);
void Downstream_InitStateMachine(void) void Downstream_InitStateMachine(void)
{ {
DownstreamState = STATE_NOT_READY; DownstreamState = STATE_DEVICE_NOT_READY;
ConfiguredDeviceClass = COMMAND_CLASS_INTERFACE; ConfiguredDeviceClass = COMMAND_CLASS_INTERFACE;
Downstream_InitSPI(); Downstream_InitSPI();
@ -41,7 +41,7 @@ void Downstream_PacketProcessor(DownstreamPacketTypeDef* receivedPacket)
switch (receivedPacket->CommandClass) switch (receivedPacket->CommandClass)
{ {
case COMMAND_CLASS_INTERFACE: case COMMAND_CLASS_INTERFACE:
if (DownstreamState != STATE_NOT_READY) if (DownstreamState > STATE_DEVICE_READY)
{ {
SPI_INTERFACE_FREAKOUT_RETURN_VOID; SPI_INTERFACE_FREAKOUT_RETURN_VOID;
} }
@ -49,17 +49,18 @@ void Downstream_PacketProcessor(DownstreamPacketTypeDef* receivedPacket)
break; break;
case COMMAND_CLASS_MASS_STORAGE: case COMMAND_CLASS_MASS_STORAGE:
if (DownstreamState != STATE_DEVICE_READY) if (DownstreamState != STATE_ACTIVE)
{ {
Downstream_PacketProcessor_EmptyReply(receivedPacket); Downstream_PacketProcessor_ErrorReply(receivedPacket);
return;
} }
//Mass storage packet processor... Downstream_MSC_PacketProcessor(receivedPacket);
break; break;
//Add other classes here... //Add other classes here...
default: default:
SPI_INTERFACE_FREAKOUT_RETURN_VOID; Downstream_PacketProcessor_ErrorReply(receivedPacket);
} }
} }
@ -72,22 +73,27 @@ void Downstream_PacketProcessor_Interface(DownstreamPacketTypeDef* receivedPacke
case COMMAND_INTERFACE_ECHO: case COMMAND_INTERFACE_ECHO:
Downstream_TransmitPacket(receivedPacket); Downstream_TransmitPacket(receivedPacket);
Downstream_ReceivePacket(Downstream_PacketProcessor); Downstream_ReceivePacket(Downstream_PacketProcessor);
break; return;
case COMMAND_INTERFACE_NOTIFY_DEVICE: case COMMAND_INTERFACE_NOTIFY_DEVICE:
if (ConfiguredDeviceClass != COMMAND_CLASS_INTERFACE) if (DownstreamState == STATE_DEVICE_READY)
{ {
Downstream_PacketProcessor_Interface_ReplyNotifyDevice(receivedPacket); Downstream_PacketProcessor_Interface_ReplyNotifyDevice(receivedPacket);
return;
} }
else
if (DownstreamState == STATE_DEVICE_NOT_READY)
{ {
DownstreamState = STATE_WAIT_DEVICE_READY;
Downstream_ReleasePacket(receivedPacket); Downstream_ReleasePacket(receivedPacket);
DownstreamState = STATE_WAIT_DEVICE_READY_CALLBACK; return;
} }
break; Downstream_PacketProcessor_ErrorReply(receivedPacket);
return;
default: default:
SPI_INTERFACE_FREAKOUT_RETURN_VOID; Downstream_PacketProcessor_ErrorReply(receivedPacket);
} }
} }
@ -100,60 +106,85 @@ void Downstream_PacketProcessor_Interface_ReplyNotifyDevice(DownstreamPacketType
replyPacket->Data[0] = ConfiguredDeviceClass; replyPacket->Data[0] = ConfiguredDeviceClass;
Downstream_TransmitPacket(replyPacket); Downstream_TransmitPacket(replyPacket);
DownstreamState = STATE_DEVICE_READY; DownstreamState = STATE_ACTIVE;
Downstream_ReceivePacket(Downstream_PacketProcessor); Downstream_ReceivePacket(Downstream_PacketProcessor);
} }
//An empty reply implies and error processing class-specific requests. void Downstream_PacketProcessor_ErrorReply(DownstreamPacketTypeDef* replyPacket)
void Downstream_PacketProcessor_EmptyReply(DownstreamPacketTypeDef* replyPacket)
{ {
replyPacket->Length = DOWNSTREAM_PACKET_HEADER_LEN; replyPacket->Length = DOWNSTREAM_PACKET_HEADER_LEN;
replyPacket->CommandClass = COMMAND_CLASS_ERROR;
Downstream_TransmitPacket(replyPacket);
Downstream_ReceivePacket(Downstream_PacketProcessor);
}
void Downstream_PacketProcessor_ClassReply(DownstreamPacketTypeDef* replyPacket)
{
Downstream_TransmitPacket(replyPacket); Downstream_TransmitPacket(replyPacket);
Downstream_ReceivePacket(Downstream_PacketProcessor); Downstream_ReceivePacket(Downstream_PacketProcessor);
} }
//This callback receives various event ids from the host stack, either
//at INT_PRIORITY_OTG_FS or from main(). We should therefore be prepared
//for pre-emption by USB or SPI/DMA interrupts.
void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id) void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id)
{ {
InterfaceCommandClassTypeDef newActiveClass; InterfaceCommandClassTypeDef newActiveClass = COMMAND_CLASS_INTERFACE;
//Called from USB interrupt
if (id == HOST_USER_DISCONNECTION) if (id == HOST_USER_DISCONNECTION)
{ {
DownstreamState = STATE_NOT_READY; DownstreamState = STATE_DEVICE_NOT_READY;
return; return;
} }
//Called from main(). Beware pre-emption!
if (id == HOST_USER_CLASS_ACTIVE) if (id == HOST_USER_CLASS_ACTIVE)
{ {
if (DownstreamState > STATE_WAIT_DEVICE_READY_CALLBACK)
{
SPI_INTERFACE_FREAKOUT_RETURN_VOID;
}
switch (phost->pActiveClass->ClassCode) switch (phost->pActiveClass->ClassCode)
{ {
case USB_MSC_CLASS: case USB_MSC_CLASS:
newActiveClass = COMMAND_CLASS_MASS_STORAGE; if (Downstream_MSC_ApproveConnectedDevice() == HAL_OK)
{
newActiveClass = COMMAND_CLASS_MASS_STORAGE;
}
break; break;
//Add other classes here... //Add other classes here...
default:
newActiveClass = COMMAND_CLASS_INTERFACE;
} }
//To change device class, we must reboot.
if ((ConfiguredDeviceClass != COMMAND_CLASS_INTERFACE) && if ((ConfiguredDeviceClass != COMMAND_CLASS_INTERFACE) &&
(ConfiguredDeviceClass != newActiveClass)) //To change device class, we must reboot. (ConfiguredDeviceClass != newActiveClass))
{ {
SPI_INTERFACE_FREAKOUT_RETURN_VOID; SPI_INTERFACE_FREAKOUT_NO_RETURN;
DownstreamState = STATE_ERROR;
return;
} }
if (newActiveClass == COMMAND_CLASS_INTERFACE)
{
return;
}
ConfiguredDeviceClass = newActiveClass; ConfiguredDeviceClass = newActiveClass;
if (DownstreamState == STATE_WAIT_DEVICE_READY_CALLBACK) if (DownstreamState == STATE_WAIT_DEVICE_READY)
{ {
Downstream_GetFreePacket(Downstream_PacketProcessor_Interface_ReplyNotifyDevice); Downstream_GetFreePacket(Downstream_PacketProcessor_Interface_ReplyNotifyDevice);
return;
}
if (DownstreamState == STATE_DEVICE_NOT_READY)
{
DownstreamState = STATE_DEVICE_READY;
return;
} }
SPI_INTERFACE_FREAKOUT_NO_RETURN;
DownstreamState = STATE_ERROR;
return; return;
} }
} }

@ -153,7 +153,7 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format.1144510040" name="Debug format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format.1144510040" name="Debug format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name.1181802609" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name" value="GNU Tools for ARM Embedded Processors" valueType="string"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name.1181802609" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name" value="GNU Tools for ARM Embedded Processors" valueType="string"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.2106535829" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture" value="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.arm" valueType="enumerated"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.2106535829" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture" value="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.arm" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.947696750" name="ARM family" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.mcpu.cortex-m3" valueType="enumerated"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.947696750" name="ARM family" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.mcpu.cortex-m4" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.1004778404" name="Instruction set" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.thumb" valueType="enumerated"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.1004778404" name="Instruction set" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.thumb" valueType="enumerated"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix.545759084" name="Prefix" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix" value="arm-none-eabi-" valueType="string"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix.545759084" name="Prefix" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix" value="arm-none-eabi-" valueType="string"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.c.1467106052" name="C compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.c" value="gcc" valueType="string"/> <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.c.1467106052" name="C compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.c" value="gcc" valueType="string"/>
@ -239,7 +239,21 @@
</configuration> </configuration>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="ilg.gnuarmeclipse.managedbuild.packs"/> <storageModule moduleId="ilg.gnuarmeclipse.managedbuild.packs">
<option id="cmsis.device.name" value="STM32F405RG"/>
<option id="cmsis.subfamily.name" value="STM32F405"/>
<option id="cmsis.family.name" value="STM32F4 Series"/>
<option id="cmsis.device.vendor.name" value="STMicroelectronics"/>
<option id="cmsis.device.vendor.id" value="13"/>
<option id="cmsis.device.pack.vendor" value="Keil"/>
<option id="cmsis.device.pack.name" value="STM32F4xx_DFP"/>
<option id="cmsis.device.pack.version" value="2.4.0"/>
<option id="cmsis.core.name" value="Cortex-M4"/>
<option id="cmsis.compiler.define" value="STM32F405xx"/>
<memory section="IRAM1" size="0x20000" start="0x20000000" startup="0"/>
<memory section="IRAM2" size="0x10000" start="0x10000000" startup="0"/>
<memory section="IROM1" size="0x100000" start="0x08000000" startup="1"/>
</storageModule>
</cconfiguration> </cconfiguration>
</storageModule> </storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0"> <storageModule moduleId="cdtBuildSystem" version="4.0.0">

@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1669631317434636379" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1738966398791227387" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

@ -26,7 +26,9 @@
typedef enum typedef enum
{ {
COMMAND_CLASS_INTERFACE, COMMAND_CLASS_INTERFACE,
COMMAND_CLASS_MASS_STORAGE COMMAND_CLASS_MASS_STORAGE,
//...
COMMAND_CLASS_ERROR
} }
InterfaceCommandClassTypeDef; InterfaceCommandClassTypeDef;

Loading…
Cancel
Save