Performance improvements to the STM32 OTG driver.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4562 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
gdisirio 2012-08-13 10:14:45 +00:00
parent 28e7808798
commit b6b473a6a1
7 changed files with 204 additions and 32 deletions

View File

@ -364,13 +364,14 @@ static const USBEndpointConfig ep1config = {
0x0000,
&ep1instate,
NULL,
2,
NULL
};
/**
* @brief OUT EP2 state.
* @brief IN EP2 state.
*/
USBOutEndpointState ep2outstate;
USBInEndpointState ep2instate;
/**
* @brief EP2 initialization structure (IN only).
@ -382,8 +383,9 @@ static const USBEndpointConfig ep2config = {
NULL,
0x0010,
0x0000,
&ep2instate,
NULL,
&ep2outstate,
1,
NULL
};
@ -404,6 +406,7 @@ static const USBEndpointConfig ep3config = {
0x0040,
NULL,
&ep3outstate,
0,
NULL
};

View File

@ -47,11 +47,11 @@
* @brief Serial over USB buffers size.
* @details Configuration parameter, the buffer size must be a multiple of
* the USB data endpoint maximum packet size.
* @note The default is 64 bytes for both the transmission and receive
* @note The default is 256 bytes for both the transmission and receive
* buffers.
*/
#if !defined(SERIAL_USB_BUFFERS_SIZE) || defined(__DOXYGEN__)
#define SERIAL_USB_BUFFERS_SIZE 64
#define SERIAL_USB_BUFFERS_SIZE 256
#endif
/** @} */

View File

@ -85,6 +85,7 @@ static const USBEndpointConfig ep0config = {
0x40,
&ep0_state.in,
&ep0_state.out,
1,
ep0setup_buffer
};
@ -448,31 +449,43 @@ static void otg_rxfifo_handler(USBDriver *usbp) {
* @notapi
*/
static void otg_txfifo_handler(USBDriver *usbp, usbep_t ep) {
uint32_t n;
/* Number of bytes remaining in current transaction.*/
n = usbp->epc[ep]->in_state->txsize - usbp->epc[ep]->in_state->txcnt;
if (n > usbp->epc[ep]->in_maxsize)
n = usbp->epc[ep]->in_maxsize;
/* The TXFIFO is filled until there is space and data to be transmitted.*/
while (TRUE) {
uint32_t n;
if (usbp->epc[ep]->in_state->txqueued) {
/* Queue associated.*/
otg_fifo_write_from_queue(ep,
usbp->epc[ep]->in_state->mode.queue.txqueue,
n);
/* Number of bytes remaining in current transaction.*/
n = usbp->epc[ep]->in_state->txsize - usbp->epc[ep]->in_state->txcnt;
if (n > usbp->epc[ep]->in_maxsize)
n = usbp->epc[ep]->in_maxsize;
/* Checks if in the TXFIFO there is enough space to accommodate the
next packet.*/
if (((OTG->ie[ep].DTXFSTS & DTXFSTS_INEPTFSAV_MASK) * 4) < n)
return;
/* Handles the two cases: linear buffer or queue.*/
if (usbp->epc[ep]->in_state->txqueued) {
/* Queue associated.*/
otg_fifo_write_from_queue(ep,
usbp->epc[ep]->in_state->mode.queue.txqueue,
n);
}
else {
/* Linear buffer associated.*/
otg_fifo_write_from_buffer(ep,
usbp->epc[ep]->in_state->mode.linear.txbuf,
n);
usbp->epc[ep]->in_state->mode.linear.txbuf += n;
}
usbp->epc[ep]->in_state->txcnt += n;
/* Interrupt disabled on transaction end.*/
if (usbp->epc[ep]->in_state->txcnt >= usbp->epc[ep]->in_state->txsize) {
OTG->DIEPEMPMSK &= ~DIEPEMPMSK_INEPTXFEM(ep);
return;
}
}
else {
/* Linear buffer associated.*/
otg_fifo_write_from_buffer(ep,
usbp->epc[ep]->in_state->mode.linear.txbuf,
n);
usbp->epc[ep]->in_state->mode.linear.txbuf += n;
}
usbp->epc[ep]->in_state->txcnt += n;
/* Interrupt disabled on transaction end.*/
if (usbp->epc[ep]->in_state->txcnt >= usbp->epc[ep]->in_state->txsize)
OTG->DIEPEMPMSK &= ~DIEPEMPMSK_INEPTXFEM(ep);
}
/**
@ -650,8 +663,8 @@ void usb_lld_start(USBDriver *usbp) {
- Full Speed 1.1 PHY.*/
OTG->GUSBCFG = GUSBCFG_FDMOD | GUSBCFG_TRDT(TRDT_VALUE) | GUSBCFG_PHYSEL;
/* Interrupt on TXFIFOs empty.*/
OTG->GAHBCFG = GAHBCFG_PTXFELVL | GAHBCFG_TXFELVL;
/* Interrupts on TXFIFOs half empty.*/
OTG->GAHBCFG = 0;
/* 48MHz 1.1 PHY.*/
OTG->DCFG = 0x02200000 | DCFG_PFIVL(0) | DCFG_DSPD_FS11;
@ -806,6 +819,8 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
if (usbp->epc[ep]->in_cb != NULL) {
/* FIFO allocation for the IN endpoint.*/
fsize = usbp->epc[ep]->in_maxsize / 4;
if (usbp->epc[ep]->in_multiplier > 1)
fsize *= usbp->epc[ep]->in_multiplier;
OTG->DIEPTXF[ep - 1] = DIEPTXF_INEPTXFD(fsize) |
DIEPTXF_INEPTXSA(otg_ram_alloc(usbp, fsize));
otg_txfifo_flush(ep);

View File

@ -231,6 +231,12 @@ typedef struct {
*/
USBOutEndpointState *out_state;
/* End of the mandatory fields.*/
/**
* @brief Determines the space allocated for the TXFIFO as multiples of
* the packet size (@p in_maxsize). Note that zero is interpreted
* as one for simplicity and robustness.
*/
uint16_t in_multiplier;
/**
* @brief Pointer to a buffer for setup packets.
* @details Setup packets require a dedicated 8-bytes buffer, set this

View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.361380083">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.361380083" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="0.361380083" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.361380083." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.160941430" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.160941430.1631463308" name=""/>
<builder id="org.eclipse.cdt.build.core.settings.default.builder.1478532740" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="-1" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.1991278458" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.956893421" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1769512652" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.2005293608" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1482746932" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1342101194" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.395629362" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="TEST-STM32F4xx-USB_CDC.null.519619434" name="TEST-STM32F4xx-USB_CDC"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.361380083">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
</scannerConfigBuildInfo>
</storageModule>
</cproject>

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TEST-STM32F4xx-USB_CDC</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>?name?</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
<value>all</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value>-j</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>make</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
<value>clean</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
<value>all</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>true</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>board</name>
<type>2</type>
<locationURI>CHIBIOS/boards/ST_STM32F4_DISCOVERY</locationURI>
</link>
<link>
<name>os</name>
<type>2</type>
<locationURI>CHIBIOS/os</locationURI>
</link>
<link>
<name>test</name>
<type>2</type>
<locationURI>CHIBIOS/test</locationURI>
</link>
</linkedResources>
</projectDescription>

View File

@ -242,13 +242,14 @@ static const USBEndpointConfig ep1config = {
0x0000,
&ep1instate,
NULL,
2,
NULL
};
/**
* @brief OUT EP2 state.
* @brief IN EP2 state.
*/
USBOutEndpointState ep2outstate;
USBInEndpointState ep2instate;
/**
* @brief EP2 initialization structure (IN only).
@ -260,8 +261,9 @@ static const USBEndpointConfig ep2config = {
NULL,
0x0010,
0x0000,
&ep2instate,
NULL,
&ep2outstate,
1,
NULL
};
@ -282,6 +284,7 @@ static const USBEndpointConfig ep3config = {
0x0040,
NULL,
&ep3outstate,
0,
NULL
};