aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/STM32F4xx
diff options
context:
space:
mode:
Diffstat (limited to 'testhal/STM32/STM32F4xx')
-rw-r--r--testhal/STM32/STM32F4xx/EICU/halconf_community.h6
-rw-r--r--testhal/STM32/STM32F4xx/FSMC_NAND/.cproject86
-rw-r--r--testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_spi.c1
-rw-r--r--testhal/STM32/STM32F4xx/FSMC_NAND/halconf.h2
-rw-r--r--testhal/STM32/STM32F4xx/FSMC_NAND/halconf_community.h6
-rw-r--r--testhal/STM32/STM32F4xx/FSMC_NAND/main.c188
-rw-r--r--testhal/STM32/STM32F4xx/FSMC_NAND/mcuconf_community.h1
-rw-r--r--testhal/STM32/STM32F4xx/FSMC_SDRAM/halconf_community.h6
-rw-r--r--testhal/STM32/STM32F4xx/FSMC_SRAM/halconf_community.h6
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/Makefile4
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c1
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/ff.c461
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/ff.h9
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/ffconf.h239
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h6
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/main.c71
-rw-r--r--testhal/STM32/STM32F4xx/USB_HOST/mcuconf_community.h24
-rw-r--r--testhal/STM32/STM32F4xx/onewire/.cproject1
-rw-r--r--testhal/STM32/STM32F4xx/onewire/.project12
-rw-r--r--testhal/STM32/STM32F4xx/onewire/Makefile6
-rw-r--r--testhal/STM32/STM32F4xx/onewire/boarddef.h (renamed from testhal/STM32/STM32F4xx/onewire/onewire_test.h)22
-rw-r--r--testhal/STM32/STM32F4xx/onewire/halconf_community.h6
-rw-r--r--testhal/STM32/STM32F4xx/onewire/main.c2
-rw-r--r--testhal/STM32/STM32F4xx/onewire/onewire_test.c257
-rw-r--r--testhal/STM32/STM32F4xx/onewire/real_roms.txt27
-rw-r--r--testhal/STM32/STM32F4xx/onewire/search_rom_synth.c370
26 files changed, 537 insertions, 1283 deletions
diff --git a/testhal/STM32/STM32F4xx/EICU/halconf_community.h b/testhal/STM32/STM32F4xx/EICU/halconf_community.h
index e967c6a..42c8c5d 100644
--- a/testhal/STM32/STM32F4xx/EICU/halconf_community.h
+++ b/testhal/STM32/STM32F4xx/EICU/halconf_community.h
@@ -14,8 +14,8 @@
limitations under the License.
*/
-#ifndef _HALCONF_COMMUNITY_H_
-#define _HALCONF_COMMUNITY_H_
+#ifndef HALCONF_COMMUNITY_H
+#define HALCONF_COMMUNITY_H
/**
* @brief Enables the community overlay.
@@ -93,6 +93,6 @@
*/
#define ONEWIRE_USE_SEARCH_ROM FALSE
-#endif /* _HALCONF_COMMUNITY_H_ */
+#endif /* HALCONF_COMMUNITY_H */
/** @} */
diff --git a/testhal/STM32/STM32F4xx/FSMC_NAND/.cproject b/testhal/STM32/STM32F4xx/FSMC_NAND/.cproject
index d5451e0..034a4fc 100644
--- a/testhal/STM32/STM32F4xx/FSMC_NAND/.cproject
+++ b/testhal/STM32/STM32F4xx/FSMC_NAND/.cproject
@@ -1,33 +1,79 @@
<?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.1641850078">
- <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1641850078" moduleId="org.eclipse.cdt.core.settings" name="Default">
+ <cconfiguration id="0.114656749">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.114656749" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
- <extension id="org.eclipse.cdt.core.GASErrorParser" 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.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<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 buildProperties="" description="" id="0.1641850078" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
- <folderInfo id="0.1641850078." name="/" resourcePath="">
- <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.380813788" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
- <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.380813788.1187386790" name=""/>
- <builder id="org.eclipse.cdt.build.core.settings.default.builder.1142711675" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
- <tool id="org.eclipse.cdt.build.core.settings.holder.libs.1750637121" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
- <tool id="org.eclipse.cdt.build.core.settings.holder.736586711" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
- <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1939618102" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
+ <configuration artifactName="${ProjName}" buildProperties="" description="" id="0.114656749" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+ <folderInfo id="0.114656749." name="/" resourcePath="">
+ <toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1182750861" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
+ <targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1182750861.169007201" name=""/>
+ <builder autoBuildTarget="all" cleanBuildTarget="clean" enableAutoBuild="false" enableCleanBuild="true" enabledIncrementalBuild="true" id="org.eclipse.cdt.build.core.settings.default.builder.579570726" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.libs.2143276802" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
+ <tool id="org.eclipse.cdt.build.core.settings.holder.1873650595" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <option id="org.eclipse.cdt.build.core.settings.holder.incpaths.535757245" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
+ <listOptionValue builtIn="false" value="/opt/arm-none-eabi/arm-none-eabi/include"/>
+ <listOptionValue builtIn="false" value="&quot;/opt/arm-none-eabi/lib/gcc/arm-none-eabi/${GCC_VERSION}/include&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;/opt/arm-none-eabi/lib/gcc/arm-none-eabi/${GCC_VERSION}/include-fixed&quot;"/>
+ </option>
+ <option id="org.eclipse.cdt.build.core.settings.holder.undef.incpaths.2028171354" name="Undefined Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.undef.incpaths" valueType="undefIncludePath">
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5"/>
+ <listOptionValue builtIn="false" value="/usr/include"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/backward"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include-fixed"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/x86_64-pc-linux-gnu"/>
+ </option>
+ <option id="org.eclipse.cdt.build.core.settings.holder.symbols.1664799820" superClass="org.eclipse.cdt.build.core.settings.holder.symbols" valueType="definedSymbols">
+ <listOptionValue builtIn="false" value="__cplusplus=201103L"/>
+ </option>
+ <option id="org.eclipse.cdt.build.core.settings.holder.undef.symbols.1757987937" superClass="org.eclipse.cdt.build.core.settings.holder.undef.symbols" valueType="undefDefinedSymbols">
+ <listOptionValue builtIn="false" value="__cplusplus"/>
+ </option>
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1337802279" 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.309923753" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
- <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1871197231" 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 id="org.eclipse.cdt.build.core.settings.holder.1707090075" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <option id="org.eclipse.cdt.build.core.settings.holder.incpaths.189144103" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
+ <listOptionValue builtIn="false" value="/opt/arm-none-eabi/arm-none-eabi/include"/>
+ <listOptionValue builtIn="false" value="&quot;/opt/arm-none-eabi/lib/gcc/arm-none-eabi/${GCC_VERSION}/include&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;/opt/arm-none-eabi/lib/gcc/arm-none-eabi/${GCC_VERSION}/include-fixed&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;/opt/arm-none-eabi/arm-none-eabi/include/c++/${GCC_VERSION}&quot;"/>
+ </option>
+ <option id="org.eclipse.cdt.build.core.settings.holder.undef.incpaths.711122711" name="Undefined Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.undef.incpaths" valueType="undefIncludePath">
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5"/>
+ <listOptionValue builtIn="false" value="/usr/include"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/backward"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include-fixed"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/x86_64-pc-linux-gnu"/>
+ </option>
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.338985256" 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.1841372361" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
- <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1747701731" 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 id="org.eclipse.cdt.build.core.settings.holder.1165165914" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
+ <option id="org.eclipse.cdt.build.core.settings.holder.incpaths.143231825" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
+ <listOptionValue builtIn="false" value="/opt/arm-none-eabi/arm-none-eabi/include"/>
+ <listOptionValue builtIn="false" value="&quot;/opt/arm-none-eabi/lib/gcc/arm-none-eabi/${GCC_VERSION}/include&quot;"/>
+ <listOptionValue builtIn="false" value="&quot;/opt/arm-none-eabi/lib/gcc/arm-none-eabi/${GCC_VERSION}/include-fixed&quot;"/>
+ </option>
+ <option id="org.eclipse.cdt.build.core.settings.holder.undef.incpaths.1282112545" name="Undefined Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.undef.incpaths" valueType="undefIncludePath">
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5"/>
+ <listOptionValue builtIn="false" value="/usr/include"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/backward"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include-fixed"/>
+ <listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/x86_64-pc-linux-gnu"/>
+ </option>
+ <inputType id="org.eclipse.cdt.build.core.settings.holder.inType.714476670" 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>
@@ -41,12 +87,10 @@
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
- <scannerConfigBuildInfo instanceId="0.1570569554">
+ <scannerConfigBuildInfo instanceId="0.114656749">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
</scannerConfigBuildInfo>
- <scannerConfigBuildInfo instanceId="0.1641850078">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
- </scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+ <storageModule moduleId="refreshScope"/>
</cproject>
diff --git a/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_spi.c b/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_spi.c
index e36fbc9..3c60484 100644
--- a/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_spi.c
+++ b/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_spi.c
@@ -53,6 +53,7 @@ static const SPIConfig spicfg = {
GPIOA,
GPIOA_SPI1_NSS,
0, //SPI_CR1_BR_1 | SPI_CR1_BR_0
+ 0
};
static uint32_t ints;
diff --git a/testhal/STM32/STM32F4xx/FSMC_NAND/halconf.h b/testhal/STM32/STM32F4xx/FSMC_NAND/halconf.h
index e690d15..dbc1950 100644
--- a/testhal/STM32/STM32F4xx/FSMC_NAND/halconf.h
+++ b/testhal/STM32/STM32F4xx/FSMC_NAND/halconf.h
@@ -62,7 +62,7 @@
* @brief Enables the EXT subsystem.
*/
#if !defined(HAL_USE_EXT) || defined(__DOXYGEN__)
-#define HAL_USE_EXT TRUE
+#define HAL_USE_EXT FALSE
#endif
/**
diff --git a/testhal/STM32/STM32F4xx/FSMC_NAND/halconf_community.h b/testhal/STM32/STM32F4xx/FSMC_NAND/halconf_community.h
index f480707..acbf837 100644
--- a/testhal/STM32/STM32F4xx/FSMC_NAND/halconf_community.h
+++ b/testhal/STM32/STM32F4xx/FSMC_NAND/halconf_community.h
@@ -14,8 +14,8 @@
limitations under the License.
*/
-#ifndef _HALCONF_COMMUNITY_H_
-#define _HALCONF_COMMUNITY_H_
+#ifndef HALCONF_COMMUNITY_H
+#define HALCONF_COMMUNITY_H
/**
* @brief Enables the community overlay.
@@ -93,6 +93,6 @@
*/
#define ONEWIRE_USE_SEARCH_ROM TRUE
-#endif /* _HALCONF_COMMUNITY_H_ */
+#endif /* HALCONF_COMMUNITY_H */
/** @} */
diff --git a/testhal/STM32/STM32F4xx/FSMC_NAND/main.c b/testhal/STM32/STM32F4xx/FSMC_NAND/main.c
index 2379a12..e75a937 100644
--- a/testhal/STM32/STM32F4xx/FSMC_NAND/main.c
+++ b/testhal/STM32/STM32F4xx/FSMC_NAND/main.c
@@ -56,8 +56,6 @@
******************************************************************************
*/
-#define USE_BAD_MAP TRUE
-
#define USE_KILL_BLOCK_TEST FALSE
#define FSMCNAND_TIME_SET ((uint32_t) 2) //(8nS)
@@ -74,7 +72,7 @@
#define NAND_COL_WRITE_CYCLES 2
#define NAND_TEST_START_BLOCK 1200
-#define NAND_TEST_END_BLOCK 1220
+#define NAND_TEST_END_BLOCK 1300
#if USE_KILL_BLOCK_TEST
#define NAND_TEST_KILL_BLOCK 8000
@@ -88,6 +86,8 @@
#error "You should enable at least one NAND interface"
#endif
+#define BAD_MAP_LEN (NAND_BLOCKS_COUNT / (sizeof(bitmap_word_t) * 8))
+
/*
******************************************************************************
* EXTERNS
@@ -99,11 +99,6 @@
* PROTOTYPES
******************************************************************************
*/
-#if STM32_NAND_USE_EXT_INT
-static void ready_isr_enable(void);
-static void ready_isr_disable(void);
-static void nand_ready_cb(EXTDriver *extp, expchannel_t channel);
-#endif
/*
******************************************************************************
@@ -126,14 +121,14 @@ static time_measurement_t tmu_read_data;
static time_measurement_t tmu_read_spare;
static time_measurement_t tmu_driver_start;
-#if USE_BAD_MAP
-#define BAD_MAP_LEN (NAND_BLOCKS_COUNT / (sizeof(bitmap_word_t) * 8))
-static bitmap_word_t badblock_map_array[BAD_MAP_LEN];
+/*
+ *
+ */
+static bitmap_word_t badblock_map_array[BAD_MAP_LEN];
static bitmap_t badblock_map = {
badblock_map_array,
BAD_MAP_LEN
};
-#endif
/*
*
@@ -147,47 +142,11 @@ static const NANDConfig nandcfg = {
NAND_COL_WRITE_CYCLES,
/* stm32 specific fields */
((FSMCNAND_TIME_HIZ << 24) | (FSMCNAND_TIME_HOLD << 16) | \
- (FSMCNAND_TIME_WAIT << 8) | FSMCNAND_TIME_SET),
-#if STM32_NAND_USE_EXT_INT
- ready_isr_enable,
- ready_isr_disable
-#endif
+ (FSMCNAND_TIME_WAIT << 8) | FSMCNAND_TIME_SET)
};
-/**
- *
- */
-#if STM32_NAND_USE_EXT_INT
-static const EXTConfig extcfg = {
- {
- {EXT_CH_MODE_DISABLED, NULL}, //0
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL}, //4
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_RISING_EDGE | EXT_MODE_GPIOD, nand_ready_cb},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL}, //8
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL}, //12
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL}, //16
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL}, //20
- {EXT_CH_MODE_DISABLED, NULL},
- {EXT_CH_MODE_DISABLED, NULL},
- }
-};
-#endif /* STM32_NAND_USE_EXT_INT */
-
static volatile uint32_t BackgroundThdCnt = 0;
+static thread_reference_t background_thd_ptr = NULL;
#if USE_KILL_BLOCK_TEST
static uint32_t KillCycle = 0;
@@ -202,25 +161,10 @@ static uint32_t KillCycle = 0;
*/
static void nand_wp_assert(void) {palClearPad(GPIOB, GPIOB_NAND_WP);}
static void nand_wp_release(void) {palSetPad(GPIOB, GPIOB_NAND_WP);}
-static void red_led_on(void) {palSetPad(GPIOI, GPIOI_LED_R);}
+//static void red_led_on(void) {palSetPad(GPIOI, GPIOI_LED_R);}
static void red_led_off(void) {palClearPad(GPIOI, GPIOI_LED_R);}
-
-#if STM32_NAND_USE_EXT_INT
-static void nand_ready_cb(EXTDriver *extp, expchannel_t channel){
- (void)extp;
- (void)channel;
-
- NAND.isr_handler(&NAND);
-}
-
-static void ready_isr_enable(void) {
- extChannelEnable(&EXTD1, GPIOD_NAND_RB_NWAIT);
-}
-
-static void ready_isr_disable(void) {
- extChannelDisable(&EXTD1, GPIOD_NAND_RB_NWAIT);
-}
-#endif /* STM32_NAND_USE_EXT_INT */
+static void red_led_toggle(void) {palTogglePad(GPIOI, GPIOI_LED_R);}
+static void green_led_toggle(void) {palTogglePad(GPIOI, GPIOI_LED_G);}
/**
*
@@ -467,8 +411,6 @@ static void general_test (NANDDriver *nandp, size_t first,
uint8_t op_status;
uint32_t recc, wecc;
- red_led_on();
-
/* initialize time measurement units */
chTMObjectInit(&tmu_erase);
chTMObjectInit(&tmu_write_data);
@@ -478,16 +420,38 @@ static void general_test (NANDDriver *nandp, size_t first,
/* perform basic checks */
for (block=first; block<last; block++){
+ red_led_toggle();
+ if (!nandIsBad(nandp, block)){
+ if (!is_erased(nandp, block)){
+ op_status = nandErase(nandp, block);
+ osalDbgCheck(0 == (op_status & 1)); /* operation failed */
+ }
+ }
+ }
+
+ /* check fail status */
+ for (block=first; block<last; block++){
if (!nandIsBad(nandp, block)){
if (!is_erased(nandp, block)){
op_status = nandErase(nandp, block);
osalDbgCheck(0 == (op_status & 1)); /* operation failed */
}
+ pattern_fill();
+ op_status = nandWritePageData(nandp, block, 0,
+ nand_buf, nandp->config->page_data_size, &wecc);
+ osalDbgCheck(0 == (op_status & 1));
+
+ pattern_fill();
+ op_status = nandWritePageData(nandp, block, 0,
+ nand_buf, nandp->config->page_data_size, &wecc);
+ /* operation must failed here because of write in unerased space */
+ osalDbgCheck(1 == (op_status & 1));
}
}
/* write block with pattern, read it back and compare */
for (block=first; block<last; block++){
+ red_led_toggle();
if (!nandIsBad(nandp, block)){
for (page=0; page<nandp->config->pages_per_block; page++){
pattern_fill();
@@ -538,17 +502,10 @@ static void general_test (NANDDriver *nandp, size_t first,
red_led_off();
}
-
/*
- ******************************************************************************
- * EXPORTED FUNCTIONS
- ******************************************************************************
- */
-
-/*
- * Application entry point.
+ *
*/
-int main(void) {
+static void nand_test(bool use_badblock_map) {
/* performance counters */
int32_t adc_ints = 0;
@@ -560,40 +517,26 @@ int main(void) {
uint32_t background_cnt = 0;
systime_t T = 0;
- /*
- * System initializations.
- * - HAL initialization, this also initializes the configured device drivers
- * and performs the board-specific initializations.
- * - Kernel initialization, the main() function becomes a thread and the
- * RTOS is active.
- */
- halInit();
- chSysInit();
-
-#if STM32_NAND_USE_EXT_INT
- extStart(&EXTD1, &extcfg);
-#endif
chTMObjectInit(&tmu_driver_start);
chTMStartMeasurementX(&tmu_driver_start);
-#if USE_BAD_MAP
- nandStart(&NAND, &nandcfg, &badblock_map);
-#else
- nandStart(&NAND, &nandcfg, NULL);
-#endif
+ if (use_badblock_map) {
+ nandStart(&NAND, &nandcfg, &badblock_map);
+ }
+ else {
+ nandStart(&NAND, &nandcfg, NULL);
+ }
chTMStopMeasurementX(&tmu_driver_start);
chThdSleepMilliseconds(4000);
- chThdCreateStatic(BackgroundThreadWA,
- sizeof(BackgroundThreadWA),
- NORMALPRIO - 20,
- BackgroundThread,
- NULL);
-
- nand_wp_release();
+ BackgroundThdCnt = 0;
+ if (NULL != background_thd_ptr) {
+ background_thd_ptr = chThdCreateStatic(BackgroundThreadWA,
+ sizeof(BackgroundThreadWA), NORMALPRIO - 10, BackgroundThread, NULL);
+ }
/*
- * run NAND test in parallel with DMA load and background thread
+ * run NAND test in parallel with DMA loads and background thread
*/
dma_storm_adc_start();
dma_storm_uart_start();
@@ -601,9 +544,9 @@ int main(void) {
T = chVTGetSystemTimeX();
general_test(&NAND, NAND_TEST_START_BLOCK, NAND_TEST_END_BLOCK, 1);
T = chVTGetSystemTimeX() - T;
- adc_ints = dma_storm_adc_stop();
+ adc_ints = dma_storm_adc_stop();
uart_ints = dma_storm_uart_stop();
- spi_ints = dma_storm_spi_stop();
+ spi_ints = dma_storm_spi_stop();
chSysLock();
background_cnt = BackgroundThdCnt;
BackgroundThdCnt = 0;
@@ -632,6 +575,35 @@ int main(void) {
* perform ECC calculation test
*/
ecc_test(&NAND, NAND_TEST_END_BLOCK);
+}
+
+/*
+ ******************************************************************************
+ * EXPORTED FUNCTIONS
+ ******************************************************************************
+ */
+
+/*
+ * Application entry point.
+ */
+int main(void) {
+
+
+
+ /*
+ * System initializations.
+ * - HAL initialization, this also initializes the configured device drivers
+ * and performs the board-specific initializations.
+ * - Kernel initialization, the main() function becomes a thread and the
+ * RTOS is active.
+ */
+ halInit();
+ chSysInit();
+
+ nand_wp_release();
+
+ nand_test(true);
+ nand_test(false);
#if USE_KILL_BLOCK_TEST
kill_block(&NAND, NAND_TEST_KILL_BLOCK);
@@ -642,7 +614,9 @@ int main(void) {
/*
* Normal main() thread activity, in this demo it does nothing.
*/
+ red_led_off();
while (true) {
+ green_led_toggle();
chThdSleepMilliseconds(500);
}
}
diff --git a/testhal/STM32/STM32F4xx/FSMC_NAND/mcuconf_community.h b/testhal/STM32/STM32F4xx/FSMC_NAND/mcuconf_community.h
index 9638dbe..dd72e66 100644
--- a/testhal/STM32/STM32F4xx/FSMC_NAND/mcuconf_community.h
+++ b/testhal/STM32/STM32F4xx/FSMC_NAND/mcuconf_community.h
@@ -26,7 +26,6 @@
*/
#define STM32_NAND_USE_FSMC_NAND1 TRUE
#define STM32_NAND_USE_FSMC_NAND2 FALSE
-#define STM32_NAND_USE_EXT_INT FALSE
#define STM32_NAND_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#define STM32_NAND_DMA_PRIORITY 0
#define STM32_NAND_DMA_ERROR_HOOK(nandp) osalSysHalt("DMA failure")
diff --git a/testhal/STM32/STM32F4xx/FSMC_SDRAM/halconf_community.h b/testhal/STM32/STM32F4xx/FSMC_SDRAM/halconf_community.h
index 606fed4..060481a 100644
--- a/testhal/STM32/STM32F4xx/FSMC_SDRAM/halconf_community.h
+++ b/testhal/STM32/STM32F4xx/FSMC_SDRAM/halconf_community.h
@@ -14,8 +14,8 @@
limitations under the License.
*/
-#ifndef _HALCONF_COMMUNITY_H_
-#define _HALCONF_COMMUNITY_H_
+#ifndef HALCONF_COMMUNITY_H
+#define HALCONF_COMMUNITY_H
/**
* @brief Enables the community overlay.
@@ -93,6 +93,6 @@
*/
#define ONEWIRE_USE_SEARCH_ROM TRUE
-#endif /* _HALCONF_COMMUNITY_H_ */
+#endif /* HALCONF_COMMUNITY_H */
/** @} */
diff --git a/testhal/STM32/STM32F4xx/FSMC_SRAM/halconf_community.h b/testhal/STM32/STM32F4xx/FSMC_SRAM/halconf_community.h
index 606fed4..060481a 100644
--- a/testhal/STM32/STM32F4xx/FSMC_SRAM/halconf_community.h
+++ b/testhal/STM32/STM32F4xx/FSMC_SRAM/halconf_community.h
@@ -14,8 +14,8 @@
limitations under the License.
*/
-#ifndef _HALCONF_COMMUNITY_H_
-#define _HALCONF_COMMUNITY_H_
+#ifndef HALCONF_COMMUNITY_H
+#define HALCONF_COMMUNITY_H
/**
* @brief Enables the community overlay.
@@ -93,6 +93,6 @@
*/
#define ONEWIRE_USE_SEARCH_ROM TRUE
-#endif /* _HALCONF_COMMUNITY_H_ */
+#endif /* HALCONF_COMMUNITY_H */
/** @} */
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/Makefile b/testhal/STM32/STM32F4xx/USB_HOST/Makefile
index 4946cba..0174baf 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/Makefile
+++ b/testhal/STM32/STM32F4xx/USB_HOST/Makefile
@@ -46,7 +46,7 @@ endif
# If enabled, this option makes the build process faster by not compiling
# modules not used in the current configuration.
ifeq ($(USE_SMART_BUILD),)
- USE_SMART_BUILD = no
+ USE_SMART_BUILD = yes
endif
#
@@ -105,7 +105,7 @@ include $(CHIBIOS)/os/various/shell/shell.mk
include $(CHIBIOS)/os/various/fatfs_bindings/fatfs.mk
# Define linker script file here
-LDSCRIPT = $(STARTUPLD)/STM32F407xG.ld
+LDSCRIPT= $(STARTUPLD)/STM32F407xG.ld
# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c b/testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c
index 98a7edf..41e3553 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c
+++ b/testhal/STM32/STM32F4xx/USB_HOST/fatfs_diskio.c
@@ -9,7 +9,6 @@
#include "ffconf.h"
#include "diskio.h"
-#include "usbh.h"
#include "usbh/dev/msd.h"
/*-----------------------------------------------------------------------*/
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/ff.c b/testhal/STM32/STM32F4xx/USB_HOST/ff.c
index 45e20ce..2edbe32 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/ff.c
+++ b/testhal/STM32/STM32F4xx/USB_HOST/ff.c
@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------/
-/ FatFs - FAT file system module R0.10c (C)ChaN, 2014
+/ FatFs - FAT file system module R0.10b (C)ChaN, 2014
/-----------------------------------------------------------------------------/
/ FatFs module is a generic FAT file system module for small embedded systems.
/ This is a free software that opened for education, research and commercial
@@ -113,10 +113,6 @@
/ Fixed creation of an entry with LFN fails on too many SFN collisions.
/ May 19,'14 R0.10b Fixed a hard error in the disk I/O layer can collapse the directory entry.
/ Fixed LFN entry is not deleted on delete/rename an object with lossy converted SFN.
-/ Nov 09,'14 R0.10c Added a configuration option for the platforms without RTC. (_FS_NORTC)
-/ Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel().
-/ Fixed a potential problem of FAT access that can appear on disk error.
-/ Fixed null pointer dereference on attempting to delete the root direcotry.
/---------------------------------------------------------------------------*/
#include "ff.h" /* Declarations of FatFs API */
@@ -131,7 +127,7 @@
---------------------------------------------------------------------------*/
-#if _FATFS != 80376 /* Revision ID */
+#if _FATFS != 8051 /* Revision ID */
#error Wrong include file (ff.h).
#endif
@@ -139,7 +135,7 @@
/* Reentrancy related */
#if _FS_REENTRANT
#if _USE_LFN == 1
-#error Static LFN work area cannot be used at thread-safe configuration
+#error Static LFN work area cannot be used at thread-safe configuration.
#endif
#define ENTER_FF(fs) { if (!lock_fs(fs)) return FR_TIMEOUT; }
#define LEAVE_FF(fs, res) { unlock_fs(fs, res); return res; }
@@ -153,7 +149,7 @@
/* Definitions of sector size */
#if (_MAX_SS < _MIN_SS) || (_MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096) || (_MIN_SS != 512 && _MIN_SS != 1024 && _MIN_SS != 2048 && _MIN_SS != 4096)
-#error Wrong sector size configuration
+#error Wrong sector size configuration.
#endif
#if _MAX_SS == _MIN_SS
#define SS(fs) ((UINT)_MAX_SS) /* Fixed sector size */
@@ -162,21 +158,10 @@
#endif
-/* Timestamp feature */
-#if _FS_NORTC == 1
-#if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31
-#error Invalid _FS_NORTC settings
-#endif
-#define GET_FATTIME() ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)
-#else
-#define GET_FATTIME() get_fattime()
-#endif
-
-
/* File access control feature */
#if _FS_LOCK
#if _FS_READONLY
-#error _FS_LOCK must be 0 at read-only configuration
+#error _FS_LOCK must be 0 at read-only cfg.
#endif
typedef struct {
FATFS *fs; /* Object ID 1, volume (NULL:blank entry) */
@@ -413,7 +398,7 @@ typedef struct {
/* Name status flags */
-#define NSFLAG 11 /* Index of name status byte in fn[] */
+#define NS 11 /* Index of name status byte in fn[] */
#define NS_LOSS 0x01 /* Out of 8.3 format */
#define NS_LFN 0x02 /* Force to create LFN entry */
#define NS_LAST 0x04 /* Last segment */
@@ -422,16 +407,16 @@ typedef struct {
#define NS_DOT 0x20 /* Dot entry */
-/* FAT sub-type boundaries (Differ from specs but correct for real DOS/Windows) */
-#define MIN_FAT16 4086U /* Minimum number of clusters as FAT16 */
-#define MIN_FAT32 65526U /* Minimum number of clusters as FAT32 */
+/* FAT sub-type boundaries */
+#define MIN_FAT16 4086U /* Minimum number of clusters for FAT16 */
+#define MIN_FAT32 65526U /* Minimum number of clusters for FAT32 */
/* FatFs refers the members in the FAT structures as byte array instead of
/ structure member because the structure is not binary compatible between
/ different platforms */
-#define BS_jmpBoot 0 /* x86 jump instruction (3) */
+#define BS_jmpBoot 0 /* Jump instruction (3) */
#define BS_OEMName 3 /* OEM name (8) */
#define BPB_BytsPerSec 11 /* Sector size [byte] (2) */
#define BPB_SecPerClus 13 /* Cluster size [sector] (1) */
@@ -497,53 +482,63 @@ typedef struct {
/*------------------------------------------------------------*/
/* Module private work area */
/*------------------------------------------------------------*/
-/* Remark: Uninitialized variables with static duration are
-/ guaranteed zero/null at start-up. If not, either the linker
-/ or start-up routine being used is out of ANSI-C standard.
+/* Note that uninitialized variables with static duration are
+/ guaranteed zero/null as initial value. If not, either the
+/ linker or start-up routine is out of ANSI-C standard.
*/
-#if _VOLUMES < 1 || _VOLUMES > 9
-#error Wrong _VOLUMES setting
+#if _VOLUMES >= 1 || _VOLUMES <= 10
+static
+FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */
+#else
+#error Number of volumes must be 1 to 10.
#endif
-static FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */
-static WORD Fsid; /* File system mount ID */
+
+static
+WORD Fsid; /* File system mount ID */
#if _FS_RPATH && _VOLUMES >= 2
-static BYTE CurrVol; /* Current drive */
+static
+BYTE CurrVol; /* Current drive */
#endif
#if _FS_LOCK
-static FILESEM Files[_FS_LOCK]; /* Open object lock semaphores */
+static
+FILESEM Files[_FS_LOCK]; /* Open object lock semaphores */
#endif
-#if _USE_LFN == 0 /* Non LFN feature */
+#if _USE_LFN == 0 /* No LFN feature */
#define DEF_NAMEBUF BYTE sfn[12]
#define INIT_BUF(dobj) (dobj).fn = sfn
#define FREE_BUF()
-#else
-#if _MAX_LFN < 12 || _MAX_LFN > 255
-#error Wrong _MAX_LFN setting
-#endif
-#if _USE_LFN == 1 /* LFN feature with static working buffer */
-static WCHAR LfnBuf[_MAX_LFN+1];
+
+#elif _USE_LFN == 1 /* LFN feature with static working buffer */
+static
+WCHAR LfnBuf[_MAX_LFN+1];
#define DEF_NAMEBUF BYTE sfn[12]
#define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; }
#define FREE_BUF()
+
#elif _USE_LFN == 2 /* LFN feature with dynamic working buffer on the stack */
#define DEF_NAMEBUF BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1]
#define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; }
#define FREE_BUF()
+
#elif _USE_LFN == 3 /* LFN feature with dynamic working buffer on the heap */
#define DEF_NAMEBUF BYTE sfn[12]; WCHAR *lfn
-#define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); (dobj).lfn = lfn; (dobj).fn = sfn; }
+#define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); \
+ if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); \
+ (dobj).lfn = lfn; (dobj).fn = sfn; }
#define FREE_BUF() ff_memfree(lfn)
+
#else
-#error Wrong _USE_LFN setting
-#endif
+#error Wrong LFN configuration.
#endif
+
#ifdef _EXCVT
-static const BYTE ExCvt[] = _EXCVT; /* Upper conversion table for extended characters */
+static
+const BYTE ExCvt[] = _EXCVT; /* Upper conversion table for extended characters */
#endif
@@ -763,24 +758,21 @@ FRESULT sync_window (
{
DWORD wsect;
UINT nf;
- FRESULT res = FR_OK;
if (fs->wflag) { /* Write back the sector if it is dirty */
wsect = fs->winsect; /* Current sector number */
- if (disk_write(fs->drv, fs->win, wsect, 1) != RES_OK) {
- res = FR_DISK_ERR;
- } else {
- fs->wflag = 0;
- if (wsect - fs->fatbase < fs->fsize) { /* Is it in the FAT area? */
- for (nf = fs->n_fats; nf >= 2; nf--) { /* Reflect the change to all FAT copies */
- wsect += fs->fsize;
- disk_write(fs->drv, fs->win, wsect, 1);
- }
+ if (disk_write(fs->drv, fs->win, wsect, 1))
+ return FR_DISK_ERR;
+ fs->wflag = 0;
+ if (wsect - fs->fatbase < fs->fsize) { /* Is it in the FAT area? */
+ for (nf = fs->n_fats; nf >= 2; nf--) { /* Reflect the change to all FAT copies */
+ wsect += fs->fsize;
+ disk_write(fs->drv, fs->win, wsect, 1);
}
}
}
- return res;
+ return FR_OK;
}
#endif
@@ -791,22 +783,17 @@ FRESULT move_window (
DWORD sector /* Sector number to make appearance in the fs->win[] */
)
{
- FRESULT res = FR_OK;
-
-
- if (sector != fs->winsect) { /* Window offset changed? */
+ if (sector != fs->winsect) { /* Changed current window */
#if !_FS_READONLY
- res = sync_window(fs); /* Write-back changes */
+ if (sync_window(fs) != FR_OK)
+ return FR_DISK_ERR;
#endif
- if (res == FR_OK) { /* Fill sector window with new data */
- if (disk_read(fs->drv, fs->win, sector, 1) != RES_OK) {
- sector = 0xFFFFFFFF; /* Invalidate window if data is not reliable */
- res = FR_DISK_ERR;
- }
- fs->winsect = sector;
- }
+ if (disk_read(fs->drv, fs->win, sector, 1))
+ return FR_DISK_ERR;
+ fs->winsect = sector;
}
- return res;
+
+ return FR_OK;
}
@@ -855,7 +842,7 @@ FRESULT sync_fs ( /* FR_OK: successful, FR_DISK_ERR: failed */
/*-----------------------------------------------------------------------*/
/* Get sector# from cluster# */
/*-----------------------------------------------------------------------*/
-/* Hidden API for hacks and disk tools */
+
DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */
FATFS* fs, /* File system object */
@@ -863,7 +850,7 @@ DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */
)
{
clst -= 2;
- if (clst >= fs->n_fatent - 2) return 0; /* Invalid cluster# */
+ if (clst >= (fs->n_fatent - 2)) return 0; /* Invalid cluster# */
return clst * fs->csize + fs->database;
}
@@ -873,52 +860,44 @@ DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */
/*-----------------------------------------------------------------------*/
/* FAT access - Read value of a FAT entry */
/*-----------------------------------------------------------------------*/
-/* Hidden API for hacks and disk tools */
-DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluster status */
+
+DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status */
FATFS* fs, /* File system object */
- DWORD clst /* FAT item index (cluster#) to get the value */
+ DWORD clst /* Cluster# to get the link information */
)
{
UINT wc, bc;
BYTE *p;
- DWORD val;
- if (clst < 2 || clst >= fs->n_fatent) { /* Check range */
- val = 1; /* Internal error */
+ if (clst < 2 || clst >= fs->n_fatent) /* Check range */
+ return 1;
- } else {
- val = 0xFFFFFFFF; /* Default value falls on disk error */
+ switch (fs->fs_type) {
+ case FS_FAT12 :
+ bc = (UINT)clst; bc += bc / 2;
+ if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break;
+ wc = fs->win[bc % SS(fs)]; bc++;
+ if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break;
+ wc |= fs->win[bc % SS(fs)] << 8;
+ return clst & 1 ? wc >> 4 : (wc & 0xFFF);
- switch (fs->fs_type) {
- case FS_FAT12 :
- bc = (UINT)clst; bc += bc / 2;
- if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;
- wc = fs->win[bc++ % SS(fs)];
- if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;
- wc |= fs->win[bc % SS(fs)] << 8;
- val = clst & 1 ? wc >> 4 : (wc & 0xFFF);
- break;
+ case FS_FAT16 :
+ if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)))) break;
+ p = &fs->win[clst * 2 % SS(fs)];
+ return LD_WORD(p);
- case FS_FAT16 :
- if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))) != FR_OK) break;
- p = &fs->win[clst * 2 % SS(fs)];
- val = LD_WORD(p);
- break;
+ case FS_FAT32 :
+ if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)))) break;
+ p = &fs->win[clst * 4 % SS(fs)];
+ return LD_DWORD(p) & 0x0FFFFFFF;
- case FS_FAT32 :
- if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break;
- p = &fs->win[clst * 4 % SS(fs)];
- val = LD_DWORD(p) & 0x0FFFFFFF;
- break;
-
- default:
- val = 1; /* Internal error */
- }
+ default:
+ return 1;
}
- return val;
+ return 0xFFFFFFFF; /* An error occurred at the disk I/O layer */
}
@@ -927,12 +906,11 @@ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x0FFFFFFF:Cluste
/*-----------------------------------------------------------------------*/
/* FAT access - Change value of a FAT entry */
/*-----------------------------------------------------------------------*/
-/* Hidden API for hacks and disk tools */
-
#if !_FS_READONLY
+
FRESULT put_fat (
FATFS* fs, /* File system object */
- DWORD clst, /* FAT item index (cluster#) to be set */
+ DWORD clst, /* Cluster# to be changed in range of 2 to fs->n_fatent - 1 */
DWORD val /* New value to mark the cluster */
)
{
@@ -950,14 +928,14 @@ FRESULT put_fat (
bc = (UINT)clst; bc += bc / 2;
res = move_window(fs, fs->fatbase + (bc / SS(fs)));
if (res != FR_OK) break;
- p = &fs->win[bc++ % SS(fs)];
+ p = &fs->win[bc % SS(fs)];
*p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
+ bc++;
fs->wflag = 1;
res = move_window(fs, fs->fatbase + (bc / SS(fs)));
if (res != FR_OK) break;
p = &fs->win[bc % SS(fs)];
*p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
- fs->wflag = 1;
break;
case FS_FAT16 :
@@ -965,7 +943,6 @@ FRESULT put_fat (
if (res != FR_OK) break;
p = &fs->win[clst * 2 % SS(fs)];
ST_WORD(p, (WORD)val);
- fs->wflag = 1;
break;
case FS_FAT32 :
@@ -974,12 +951,12 @@ FRESULT put_fat (
p = &fs->win[clst * 4 % SS(fs)];
val |= LD_DWORD(p) & 0xF0000000;
ST_DWORD(p, val);
- fs->wflag = 1;
break;
default :
res = FR_INT_ERR;
}
+ fs->wflag = 1;
}
return res;
@@ -1001,7 +978,7 @@ FRESULT remove_chain (
{
FRESULT res;
DWORD nxt;
-#if _USE_TRIM
+#if _USE_ERASE
DWORD scl = clst, ecl = clst, rt[2];
#endif
@@ -1021,13 +998,13 @@ FRESULT remove_chain (
fs->free_clust++;
fs->fsi_flag |= 1;
}
-#if _USE_TRIM
+#if _USE_ERASE
if (ecl + 1 == nxt) { /* Is next cluster contiguous? */
ecl = nxt;
} else { /* End of contiguous clusters */
rt[0] = clust2sect(fs, scl); /* Start sector */
rt[1] = clust2sect(fs, ecl) + fs->csize - 1; /* End sector */
- disk_ioctl(fs->drv, CTRL_TRIM, rt); /* Erase the block */
+ disk_ioctl(fs->drv, CTRL_ERASE_SECTOR, rt); /* Erase the block */
scl = ecl = nxt;
}
#endif
@@ -1269,8 +1246,8 @@ FRESULT dir_alloc (
do {
res = move_window(dp->fs, dp->sect);
if (res != FR_OK) break;
- if (dp->dir[0] == DDE || dp->dir[0] == 0) { /* Is it a free entry? */
- if (++n == nent) break; /* A block of contiguous free entries is found */
+ if (dp->dir[0] == DDE || dp->dir[0] == 0) { /* Is it a blank entry? */
+ if (++n == nent) break; /* A block of contiguous entries is found */
} else {
n = 0; /* Not a blank entry. Restart to search */
}
@@ -1549,7 +1526,7 @@ FRESULT dir_find (
}
} else { /* An SFN entry is found */
if (!ord && sum == sum_sfn(dir)) break; /* LFN matched? */
- if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dir, dp->fn, 11)) break; /* SFN matched? */
+ if (!(dp->fn[NS] & NS_LOSS) && !mem_cmp(dir, dp->fn, 11)) break; /* SFN matched? */
ord = 0xFF; dp->lfn_idx = 0xFFFF; /* Reset LFN sequence */
}
}
@@ -1591,7 +1568,7 @@ FRESULT dir_read (
if (c == 0) { res = FR_NO_FILE; break; } /* Reached to end of table */
a = dir[DIR_Attr] & AM_MASK;
#if _USE_LFN /* LFN configuration */
- if (c == DDE || (!_FS_RPATH && c == '.') || (int)((a & ~AM_ARC) == AM_VOL) != vol) { /* An entry without valid data */
+ if (c == DDE || (!_FS_RPATH && c == '.') || (int)(a == AM_VOL) != vol) { /* An entry without valid data */
ord = 0xFF;
} else {
if (a == AM_LFN) { /* An LFN entry is found */
@@ -1609,7 +1586,7 @@ FRESULT dir_read (
}
}
#else /* Non LFN configuration */
- if (c != DDE && (_FS_RPATH || c != '.') && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol) /* Is it a valid entry? */
+ if (c != DDE && (_FS_RPATH || c != '.') && a != AM_LFN && (int)(a == AM_VOL) == vol) /* Is it a valid entry? */
break;
#endif
res = dir_next(dp, 0); /* Next entry */
@@ -1644,11 +1621,11 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many
fn = dp->fn; lfn = dp->lfn;
mem_cpy(sn, fn, 12);
- if (_FS_RPATH && (sn[NSFLAG] & NS_DOT)) /* Cannot create dot entry */
+ if (_FS_RPATH && (sn[NS] & NS_DOT)) /* Cannot create dot entry */
return FR_INVALID_NAME;
- if (sn[NSFLAG] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */
- fn[NSFLAG] = 0; dp->lfn = 0; /* Find only SFN */
+ if (sn[NS] & NS_LOSS) { /* When LFN is out of 8.3 format, generate a numbered name */
+ fn[NS] = 0; dp->lfn = 0; /* Find only SFN */
for (n = 1; n < 100; n++) {
gen_numname(fn, sn, lfn, n); /* Generate a numbered name */
res = dir_find(dp); /* Check if the name collides with existing SFN */
@@ -1656,10 +1633,10 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many
}
if (n == 100) return FR_DENIED; /* Abort if too many collisions */
if (res != FR_NO_FILE) return res; /* Abort if the result is other than 'not collided' */
- fn[NSFLAG] = sn[NSFLAG]; dp->lfn = lfn;
+ fn[NS] = sn[NS]; dp->lfn = lfn;
}
- if (sn[NSFLAG] & NS_LFN) { /* When LFN is to be created, allocate entries for an SFN + LFNs. */
+ if (sn[NS] & NS_LFN) { /* When LFN is to be created, allocate entries for an SFN + LFNs. */
for (n = 0; lfn[n]; n++) ;
nent = (n + 25) / 13;
} else { /* Otherwise allocate an entry for an SFN */
@@ -1690,7 +1667,7 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many
mem_set(dp->dir, 0, SZ_DIR); /* Clean the entry */
mem_cpy(dp->dir, dp->fn, 11); /* Put SFN */
#if _USE_LFN
- dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT); /* Put NT flag */
+ dp->dir[DIR_NTres] = dp->fn[NS] & (NS_BODY | NS_EXT); /* Put NT flag */
#endif
dp->fs->wflag = 1;
}
@@ -1946,7 +1923,7 @@ FRESULT create_name (
if ((b & 0x0C) == 0x04) cf |= NS_BODY; /* NT flag (Filename has only small capital) */
}
- dp->fn[NSFLAG] = cf; /* SFN is created */
+ dp->fn[NS] = cf; /* SFN is created */
return FR_OK;
@@ -1970,7 +1947,7 @@ FRESULT create_name (
}
if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME;
*path = &p[si]; /* Return pointer to the next segment */
- sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of path */
+ sfn[NS] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT; /* Set last segment flag if end of path */
return FR_OK;
}
#endif
@@ -2021,7 +1998,7 @@ FRESULT create_name (
if ((b & 0x03) == 0x01) c |= NS_EXT; /* NT flag (Name extension has only small capital) */
if ((b & 0x0C) == 0x04) c |= NS_BODY; /* NT flag (Name body has only small capital) */
- sfn[NSFLAG] = c; /* Store NT flag, File name is created */
+ sfn[NS] = c; /* Store NT flag, File name is created */
return FR_OK;
#endif
@@ -2064,7 +2041,7 @@ FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */
res = create_name(dp, &path); /* Get a segment name of the path */
if (res != FR_OK) break;
res = dir_find(dp); /* Find an object with the sagment name */
- ns = dp->fn[NSFLAG];
+ ns = dp->fn[NS];
if (res != FR_OK) { /* Failed to find the object */
if (res == FR_NO_FILE) { /* Object is not found */
if (_FS_RPATH && (ns & NS_DOT)) { /* If dot entry is not exist, */
@@ -2306,7 +2283,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: any error occurred */
szbfat = (fmt == FS_FAT16) ? /* (Needed FAT size) */
fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1);
}
- if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than the size needed) */
+ if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than needed) */
return FR_NO_FILESYSTEM;
#if !_FS_READONLY
@@ -2494,7 +2471,7 @@ FRESULT f_open (
}
}
if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) { /* Truncate it if overwrite mode */
- dw = GET_FATTIME(); /* Created time */
+ dw = get_fattime(); /* Created time */
ST_DWORD(dir+DIR_CrtTime, dw);
dir[DIR_Attr] = 0; /* Reset attribute */
ST_DWORD(dir+DIR_FileSize, 0); /* size = 0 */
@@ -2620,7 +2597,7 @@ FRESULT f_read (
if (cc) { /* Read maximum contiguous sectors directly */
if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */
cc = fp->fs->csize - csect;
- if (disk_read(fp->fs->drv, rbuff, sect, cc) != RES_OK)
+ if (disk_read(fp->fs->drv, rbuff, sect, cc))
ABORT(fp->fs, FR_DISK_ERR);
#if !_FS_READONLY && _FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */
#if _FS_TINY
@@ -2638,12 +2615,12 @@ FRESULT f_read (
if (fp->dsect != sect) { /* Load data sector if not in cache */
#if !_FS_READONLY
if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
ABORT(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
#endif
- if (disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK) /* Fill sector cache */
+ if (disk_read(fp->fs->drv, fp->buf, sect, 1)) /* Fill sector cache */
ABORT(fp->fs, FR_DISK_ERR);
}
#endif
@@ -2652,7 +2629,7 @@ FRESULT f_read (
rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs)); /* Get partial sector data from sector buffer */
if (rcnt > btr) rcnt = btr;
#if _FS_TINY
- if (move_window(fp->fs, fp->dsect) != FR_OK) /* Move sector window */
+ if (move_window(fp->fs, fp->dsect)) /* Move sector window */
ABORT(fp->fs, FR_DISK_ERR);
mem_cpy(rbuff, &fp->fs->win[fp->fptr % SS(fp->fs)], rcnt); /* Pick partial sector */
#else
@@ -2723,7 +2700,7 @@ FRESULT f_write (
ABORT(fp->fs, FR_DISK_ERR);
#else
if (fp->flag & FA__DIRTY) { /* Write-back sector cache */
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
ABORT(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
@@ -2735,7 +2712,7 @@ FRESULT f_write (
if (cc) { /* Write maximum contiguous sectors directly */
if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */
cc = fp->fs->csize - csect;
- if (disk_write(fp->fs->drv, wbuff, sect, cc) != RES_OK)
+ if (disk_write(fp->fs->drv, wbuff, sect, cc))
ABORT(fp->fs, FR_DISK_ERR);
#if _FS_MINIMIZE <= 2
#if _FS_TINY
@@ -2761,7 +2738,7 @@ FRESULT f_write (
#else
if (fp->dsect != sect) { /* Fill sector cache with file data */
if (fp->fptr < fp->fsize &&
- disk_read(fp->fs->drv, fp->buf, sect, 1) != RES_OK)
+ disk_read(fp->fs->drv, fp->buf, sect, 1))
ABORT(fp->fs, FR_DISK_ERR);
}
#endif
@@ -2770,7 +2747,7 @@ FRESULT f_write (
wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */
if (wcnt > btw) wcnt = btw;
#if _FS_TINY
- if (move_window(fp->fs, fp->dsect) != FR_OK) /* Move sector window */
+ if (move_window(fp->fs, fp->dsect)) /* Move sector window */
ABORT(fp->fs, FR_DISK_ERR);
mem_cpy(&fp->fs->win[fp->fptr % SS(fp->fs)], wbuff, wcnt); /* Fit partial sector */
fp->fs->wflag = 1;
@@ -2808,7 +2785,7 @@ FRESULT f_sync (
/* Write-back dirty buffer */
#if !_FS_TINY
if (fp->flag & FA__DIRTY) {
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
LEAVE_FF(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
@@ -2820,7 +2797,7 @@ FRESULT f_sync (
dir[DIR_Attr] |= AM_ARC; /* Set archive bit */
ST_DWORD(dir+DIR_FileSize, fp->fsize); /* Update file size */
st_clust(dir, fp->sclust); /* Update start cluster */
- tm = GET_FATTIME(); /* Update updated time */
+ tm = get_fattime(); /* Update updated time */
ST_DWORD(dir+DIR_WrtTime, tm);
ST_WORD(dir+DIR_LstAccDate, 0);
fp->flag &= ~FA__WRITTEN;
@@ -3069,12 +3046,12 @@ FRESULT f_lseek (
#if !_FS_TINY
#if !_FS_READONLY
if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
ABORT(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
#endif
- if (disk_read(fp->fs->drv, fp->buf, dsc, 1) != RES_OK) /* Load current sector */
+ if (disk_read(fp->fs->drv, fp->buf, dsc, 1)) /* Load current sector */
ABORT(fp->fs, FR_DISK_ERR);
#endif
fp->dsect = dsc;
@@ -3144,12 +3121,12 @@ FRESULT f_lseek (
#if !_FS_TINY
#if !_FS_READONLY
if (fp->flag & FA__DIRTY) { /* Write-back dirty sector cache */
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
ABORT(fp->fs, FR_DISK_ERR);
fp->flag &= ~FA__DIRTY;
}
#endif
- if (disk_read(fp->fs->drv, fp->buf, nsect, 1) != RES_OK) /* Fill sector cache */
+ if (disk_read(fp->fs->drv, fp->buf, nsect, 1)) /* Fill sector cache */
ABORT(fp->fs, FR_DISK_ERR);
#endif
fp->dsect = nsect;
@@ -3440,7 +3417,7 @@ FRESULT f_truncate (
}
#if !_FS_TINY
if (res == FR_OK && (fp->flag & FA__DIRTY)) {
- if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
+ if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1))
res = FR_DISK_ERR;
else
fp->flag &= ~FA__DIRTY;
@@ -3467,7 +3444,7 @@ FRESULT f_unlink (
FRESULT res;
DIR dj, sdj;
BYTE *dir;
- DWORD dclst = 0;
+ DWORD dclst;
DEF_NAMEBUF;
@@ -3476,46 +3453,45 @@ FRESULT f_unlink (
if (res == FR_OK) {
INIT_BUF(dj);
res = follow_path(&dj, path); /* Follow the file path */
- if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+ if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
res = FR_INVALID_NAME; /* Cannot remove dot entry */
#if _FS_LOCK
- if (res == FR_OK) res = chk_lock(&dj, 2); /* Cannot remove open object */
+ if (res == FR_OK) res = chk_lock(&dj, 2); /* Cannot remove open file */
#endif
if (res == FR_OK) { /* The object is accessible */
dir = dj.dir;
if (!dir) {
- res = FR_INVALID_NAME; /* Cannot remove the origin directory */
+ res = FR_INVALID_NAME; /* Cannot remove the start directory */
} else {
if (dir[DIR_Attr] & AM_RDO)
res = FR_DENIED; /* Cannot remove R/O object */
}
- //if (res == FR_OK && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-dir? */
- if (res == FR_OK) {
- dclst = ld_clust(dj.fs, dir);
- if (dir[DIR_Attr] & AM_DIR) { /* Is it a sub-dir? */
- if (!dclst) {
- res = FR_INT_ERR;
- } else { /* Make sure the sub-directory is empty */
- mem_cpy(&sdj, &dj, sizeof (DIR));
- sdj.sclust = dclst;
- res = dir_sdi(&sdj, 2); /* Exclude dot entries */
- if (res == FR_OK) {
- res = dir_read(&sdj, 0); /* Read an item */
- if (res == FR_OK /* Not empty directory */
+ dclst = ld_clust(dj.fs, dir);
+ if (res == FR_OK && (dir[DIR_Attr] & AM_DIR)) { /* Is it a sub-dir? */
+ if (dclst < 2) {
+ res = FR_INT_ERR;
+ } else {
+ mem_cpy(&sdj, &dj, sizeof (DIR)); /* Check if the sub-directory is empty or not */
+ sdj.sclust = dclst;
+ res = dir_sdi(&sdj, 2); /* Exclude dot entries */
+ if (res == FR_OK) {
+ res = dir_read(&sdj, 0); /* Read an item */
+ if (res == FR_OK /* Not empty directory */
#if _FS_RPATH
- || dclst == dj.fs->cdir /* or current directory */
+ || dclst == dj.fs->cdir /* Current directory */
#endif
- ) res = FR_DENIED;
- if (res == FR_NO_FILE) res = FR_OK; /* It is empty */
- }
+ ) res = FR_DENIED;
+ if (res == FR_NO_FILE) res = FR_OK; /* Empty */
}
}
}
if (res == FR_OK) {
res = dir_remove(&dj); /* Remove the directory entry */
- if (res == FR_OK && dclst) /* Remove the cluster chain if exist */
- res = remove_chain(dj.fs, dclst);
- if (res == FR_OK) res = sync_fs(dj.fs);
+ if (res == FR_OK) {
+ if (dclst) /* Remove the cluster chain if exist */
+ res = remove_chain(dj.fs, dclst);
+ if (res == FR_OK) res = sync_fs(dj.fs);
+ }
}
}
FREE_BUF();
@@ -3538,7 +3514,7 @@ FRESULT f_mkdir (
FRESULT res;
DIR dj;
BYTE *dir, n;
- DWORD dsc, dcl, pcl, tm = GET_FATTIME();
+ DWORD dsc, dcl, pcl, tm = get_fattime();
DEF_NAMEBUF;
@@ -3548,7 +3524,7 @@ FRESULT f_mkdir (
INIT_BUF(dj);
res = follow_path(&dj, path); /* Follow the file path */
if (res == FR_OK) res = FR_EXIST; /* Any object with same name is already existing */
- if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT))
+ if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NS] & NS_DOT))
res = FR_INVALID_NAME;
if (res == FR_NO_FILE) { /* Can create a new directory */
dcl = create_chain(dj.fs, 0); /* Allocate a cluster for the new directory table */
@@ -3623,7 +3599,7 @@ FRESULT f_chmod (
INIT_BUF(dj);
res = follow_path(&dj, path); /* Follow the file path */
FREE_BUF();
- if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
+ if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
res = FR_INVALID_NAME;
if (res == FR_OK) {
dir = dj.dir;
@@ -3645,6 +3621,48 @@ FRESULT f_chmod (
/*-----------------------------------------------------------------------*/
+/* Change Timestamp */
+/*-----------------------------------------------------------------------*/
+
+FRESULT f_utime (
+ const TCHAR* path, /* Pointer to the file/directory name */
+ const FILINFO* fno /* Pointer to the time stamp to be set */
+)
+{
+ FRESULT res;
+ DIR dj;
+ BYTE *dir;
+ DEF_NAMEBUF;
+
+
+ /* Get logical drive number */
+ res = find_volume(&dj.fs, &path, 1);
+ if (res == FR_OK) {
+ INIT_BUF(dj);
+ res = follow_path(&dj, path); /* Follow the file path */
+ FREE_BUF();
+ if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
+ res = FR_INVALID_NAME;
+ if (res == FR_OK) {
+ dir = dj.dir;
+ if (!dir) { /* Root directory */
+ res = FR_INVALID_NAME;
+ } else { /* File or sub-directory */
+ ST_WORD(dir+DIR_WrtTime, fno->ftime);
+ ST_WORD(dir+DIR_WrtDate, fno->fdate);
+ dj.fs->wflag = 1;
+ res = sync_fs(dj.fs);
+ }
+ }
+ }
+
+ LEAVE_FF(dj.fs, res);
+}
+
+
+
+
+/*-----------------------------------------------------------------------*/
/* Rename File/Directory */
/*-----------------------------------------------------------------------*/
@@ -3666,7 +3684,7 @@ FRESULT f_rename (
djn.fs = djo.fs;
INIT_BUF(djo);
res = follow_path(&djo, path_old); /* Check old object */
- if (_FS_RPATH && res == FR_OK && (djo.fn[NSFLAG] & NS_DOT))
+ if (_FS_RPATH && res == FR_OK && (djo.fn[NS] & NS_DOT))
res = FR_INVALID_NAME;
#if _FS_LOCK
if (res == FR_OK) res = chk_lock(&djo, 2);
@@ -3678,19 +3696,19 @@ FRESULT f_rename (
mem_cpy(buf, djo.dir+DIR_Attr, 21); /* Save the object information except name */
mem_cpy(&djn, &djo, sizeof (DIR)); /* Duplicate the directory object */
if (get_ldnumber(&path_new) >= 0) /* Snip drive number off and ignore it */
- res = follow_path(&djn, path_new); /* and make sure if new object name is not conflicting */
+ res = follow_path(&djn, path_new); /* and check if new object is exist */
else
res = FR_INVALID_DRIVE;
if (res == FR_OK) res = FR_EXIST; /* The new object name is already existing */
- if (res == FR_NO_FILE) { /* It is a valid path and no name collision */
-/* Start of critical section that any interruption can cause a cross-link */
+ if (res == FR_NO_FILE) { /* Is it a valid path and no name collision? */
+/* Start critical section that any interruption can cause a cross-link */
res = dir_register(&djn); /* Register the new entry */
if (res == FR_OK) {
dir = djn.dir; /* Copy object information except name */
mem_cpy(dir+13, buf+2, 19);
dir[DIR_Attr] = buf[0] | AM_ARC;
djo.fs->wflag = 1;
- if ((dir[DIR_Attr] & AM_DIR) && djo.sclust != djn.sclust) { /* Update .. entry in the directory if needed */
+ if (djo.sclust != djn.sclust && (dir[DIR_Attr] & AM_DIR)) { /* Update .. entry in the directory if needed */
dw = clust2sect(djo.fs, ld_clust(djo.fs, dir));
if (!dw) {
res = FR_INT_ERR;
@@ -3698,7 +3716,8 @@ FRESULT f_rename (
res = move_window(djo.fs, dw);
dir = djo.fs->win+SZ_DIR; /* .. entry */
if (res == FR_OK && dir[1] == '.') {
- st_clust(dir, djn.sclust);
+ dw = (djo.fs->fs_type == FS_FAT32 && djn.sclust == djo.fs->dirbase) ? 0 : djn.sclust;
+ st_clust(dir, dw);
djo.fs->wflag = 1;
}
}
@@ -3709,7 +3728,7 @@ FRESULT f_rename (
res = sync_fs(djo.fs);
}
}
-/* End of critical section */
+/* End critical section */
}
}
}
@@ -3719,48 +3738,6 @@ FRESULT f_rename (
LEAVE_FF(djo.fs, res);
}
-
-
-
-/*-----------------------------------------------------------------------*/
-/* Change Timestamp */
-/*-----------------------------------------------------------------------*/
-
-FRESULT f_utime (
- const TCHAR* path, /* Pointer to the file/directory name */
- const FILINFO* fno /* Pointer to the time stamp to be set */
-)
-{
- FRESULT res;
- DIR dj;
- BYTE *dir;
- DEF_NAMEBUF;
-
-
- /* Get logical drive number */
- res = find_volume(&dj.fs, &path, 1);
- if (res == FR_OK) {
- INIT_BUF(dj);
- res = follow_path(&dj, path); /* Follow the file path */
- FREE_BUF();
- if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT))
- res = FR_INVALID_NAME;
- if (res == FR_OK) {
- dir = dj.dir;
- if (!dir) { /* Root directory */
- res = FR_INVALID_NAME;
- } else { /* File or sub-directory */
- ST_WORD(dir+DIR_WrtTime, fno->ftime);
- ST_WORD(dir+DIR_WrtDate, fno->fdate);
- dj.fs->wflag = 1;
- res = sync_fs(dj.fs);
- }
- }
- }
-
- LEAVE_FF(dj.fs, res);
-}
-
#endif /* !_FS_READONLY */
#endif /* _FS_MINIMIZE == 0 */
#endif /* _FS_MINIMIZE <= 1 */
@@ -3894,7 +3871,7 @@ FRESULT f_setlabel (
if (res == FR_OK) { /* A volume label is found */
if (vn[0]) {
mem_cpy(dj.dir, vn, 11); /* Change the volume label name */
- tm = GET_FATTIME();
+ tm = get_fattime();
ST_DWORD(dj.dir+DIR_WrtTime, tm);
} else {
dj.dir[0] = DDE; /* Remove the volume label */
@@ -3910,7 +3887,7 @@ FRESULT f_setlabel (
mem_set(dj.dir, 0, SZ_DIR); /* Set volume label */
mem_cpy(dj.dir, vn, 11);
dj.dir[DIR_Attr] = AM_VOL;
- tm = GET_FATTIME();
+ tm = get_fattime();
ST_DWORD(dj.dir+DIR_WrtTime, tm);
dj.fs->wflag = 1;
res = sync_fs(dj.fs);
@@ -3973,7 +3950,7 @@ FRESULT f_forward (
sect = clust2sect(fp->fs, fp->clust); /* Get current data sector */
if (!sect) ABORT(fp->fs, FR_INT_ERR);
sect += csect;
- if (move_window(fp->fs, sect) != FR_OK) /* Move sector window */
+ if (move_window(fp->fs, sect)) /* Move sector window */
ABORT(fp->fs, FR_DISK_ERR);
fp->dsect = sect;
rcnt = SS(fp->fs) - (WORD)(fp->fptr % SS(fp->fs)); /* Forward data from sector window */
@@ -3993,13 +3970,13 @@ FRESULT f_forward (
/* Create File System on the Drive */
/*-----------------------------------------------------------------------*/
#define N_ROOTDIR 512 /* Number of root directory entries for FAT12/16 */
-#define N_FATS 1 /* Number of FATs (1 or 2) */
+#define N_FATS 1 /* Number of FAT copies (1 or 2) */
FRESULT f_mkfs (
const TCHAR* path, /* Logical drive number */
BYTE sfd, /* Partitioning rule 0:FDISK, 1:SFD */
- UINT au /* Size of allocation unit in unit of byte or sector */
+ UINT au /* Allocation unit [bytes] */
)
{
static const WORD vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0};
@@ -4015,9 +3992,10 @@ FRESULT f_mkfs (
/* Check mounted drive and clear work area */
- if (sfd > 1) return FR_INVALID_PARAMETER;
vol = get_ldnumber(&path);
if (vol < 0) return FR_INVALID_DRIVE;
+ if (sfd > 1) return FR_INVALID_PARAMETER;
+ if (au & (au - 1)) return FR_INVALID_PARAMETER;
fs = FatFs[vol];
if (!fs) return FR_NOT_ENABLED;
fs->fs_type = 0;
@@ -4034,7 +4012,7 @@ FRESULT f_mkfs (
#endif
if (_MULTI_PARTITION && part) {
/* Get partition information from partition table in the MBR */
- if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR;
+ if (disk_read(pdrv, fs->win, 0, 1)) return FR_DISK_ERR;
if (LD_WORD(fs->win+BS_55AA) != 0xAA55) return FR_MKFS_ABORTED;
tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
if (!tbl[4]) return FR_MKFS_ABORTED; /* No partition? */
@@ -4048,14 +4026,13 @@ FRESULT f_mkfs (
n_vol -= b_vol; /* Volume size */
}
- if (au & (au - 1)) au = 0;
- if (!au) { /* AU auto selection */
+ if (!au) { /* AU auto selection */
vs = n_vol / (2000 / (SS(fs) / 512));
for (i = 0; vs < vst[i]; i++) ;
au = cst[i];
}
- if (au >= _MIN_SS) au /= SS(fs); /* Number of sectors per cluster */
- if (!au) au = 1;
+ au /= SS(fs); /* Number of sectors per cluster */
+ if (au == 0) au = 1;
if (au > 128) au = 128;
/* Pre-compute number of clusters and FAT sub-type */
@@ -4112,7 +4089,7 @@ FRESULT f_mkfs (
/* Update system ID in the partition table */
tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];
tbl[4] = sys;
- if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) /* Write it to teh MBR */
+ if (disk_write(pdrv, fs->win, 0, 1)) /* Write it to teh MBR */
return FR_DISK_ERR;
md = 0xF8;
} else {
@@ -4132,7 +4109,7 @@ FRESULT f_mkfs (
ST_DWORD(tbl+8, 63); /* Partition start in LBA */
ST_DWORD(tbl+12, n_vol); /* Partition size in LBA */
ST_WORD(fs->win+BS_55AA, 0xAA55); /* MBR signature */
- if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) /* Write it to the MBR */
+ if (disk_write(pdrv, fs->win, 0, 1)) /* Write it to the MBR */
return FR_DISK_ERR;
md = 0xF8;
}
@@ -4158,7 +4135,7 @@ FRESULT f_mkfs (
ST_WORD(tbl+BPB_SecPerTrk, 63); /* Number of sectors per track */
ST_WORD(tbl+BPB_NumHeads, 255); /* Number of heads */
ST_DWORD(tbl+BPB_HiddSec, b_vol); /* Hidden sectors */
- n = GET_FATTIME(); /* Use current time as VSN */
+ n = get_fattime(); /* Use current time as VSN */
if (fmt == FS_FAT32) {
ST_DWORD(tbl+BS_VolID32, n); /* VSN */
ST_DWORD(tbl+BPB_FATSz32, n_fat); /* Number of sectors per FAT */
@@ -4176,7 +4153,7 @@ FRESULT f_mkfs (
mem_cpy(tbl+BS_VolLab, "NO NAME " "FAT ", 19); /* Volume label, FAT signature */
}
ST_WORD(tbl+BS_55AA, 0xAA55); /* Signature (Offset is fixed here regardless of sector size) */
- if (disk_write(pdrv, tbl, b_vol, 1) != RES_OK) /* Write it to the VBR sector */
+ if (disk_write(pdrv, tbl, b_vol, 1)) /* Write it to the VBR sector */
return FR_DISK_ERR;
if (fmt == FS_FAT32) /* Write backup VBR if needed (VBR+6) */
disk_write(pdrv, tbl, b_vol + 6, 1);
@@ -4195,11 +4172,11 @@ FRESULT f_mkfs (
ST_DWORD(tbl+4, 0xFFFFFFFF);
ST_DWORD(tbl+8, 0x0FFFFFFF); /* Reserve cluster #2 for root directory */
}
- if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
+ if (disk_write(pdrv, tbl, wsect++, 1))
return FR_DISK_ERR;
mem_set(tbl, 0, SS(fs)); /* Fill following FAT entries with zero */
for (n = 1; n < n_fat; n++) { /* This loop may take a time on FAT32 volume due to many single sector writes */
- if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
+ if (disk_write(pdrv, tbl, wsect++, 1))
return FR_DISK_ERR;
}
}
@@ -4207,16 +4184,16 @@ FRESULT f_mkfs (
/* Initialize root directory */
i = (fmt == FS_FAT32) ? au : (UINT)n_dir;
do {
- if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK)
+ if (disk_write(pdrv, tbl, wsect++, 1))
return FR_DISK_ERR;
} while (--i);
-#if _USE_TRIM /* Erase data area if needed */
+#if _USE_ERASE /* Erase data area if needed */
{
DWORD eb[2];
eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1;
- disk_ioctl(pdrv, CTRL_TRIM, eb);
+ disk_ioctl(pdrv, CTRL_ERASE_SECTOR, eb);
}
#endif
@@ -4299,7 +4276,7 @@ FRESULT f_fdisk (
ST_WORD(p, 0xAA55);
/* Write it to the MBR */
- return (disk_write(pdrv, buf, 0, 1) != RES_OK || disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) ? FR_DISK_ERR : FR_OK;
+ return (disk_write(pdrv, buf, 0, 1) || disk_ioctl(pdrv, CTRL_SYNC, 0)) ? FR_DISK_ERR : FR_OK;
}
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/ff.h b/testhal/STM32/STM32F4xx/USB_HOST/ff.h
index 5eaad5f..9894921 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/ff.h
+++ b/testhal/STM32/STM32F4xx/USB_HOST/ff.h
@@ -1,5 +1,5 @@
/*---------------------------------------------------------------------------/
-/ FatFs - FAT file system module include file R0.10c (C)ChaN, 2014
+/ FatFs - FAT file system module include file R0.10b (C)ChaN, 2014
/----------------------------------------------------------------------------/
/ FatFs module is a generic FAT file system module for small embedded systems.
/ This is a free software that opened for education, research and commercial
@@ -15,7 +15,7 @@
/----------------------------------------------------------------------------*/
#ifndef _FATFS
-#define _FATFS 80376 /* Revision ID */
+#define _FATFS 8051 /* Revision ID */
#ifdef __cplusplus
extern "C" {
@@ -23,6 +23,7 @@ extern "C" {
#include "integer.h" /* Basic integer types */
#include "ffconf.h" /* FatFs configuration options */
+
#if _FATFS != _FFCONF
#error Wrong configuration file (ffconf.h).
#endif
@@ -235,7 +236,7 @@ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
-#define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
+#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
#define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->fsize)
@@ -251,7 +252,7 @@ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the fil
/* Additional user defined functions */
/* RTC function */
-#if !_FS_READONLY && !_FS_NORTC
+#if !_FS_READONLY
DWORD get_fattime (void);
#endif
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/ffconf.h b/testhal/STM32/STM32F4xx/USB_HOST/ffconf.h
index 0ae6f01..2af5efe 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/ffconf.h
+++ b/testhal/STM32/STM32F4xx/USB_HOST/ffconf.h
@@ -1,31 +1,33 @@
+/* CHIBIOS FIX */
+#include "ch.h"
+
/*---------------------------------------------------------------------------/
-/ FatFs - FAT file system module configuration file R0.10c (C)ChaN, 2014
+/ FatFs - FAT file system module configuration file R0.10b (C)ChaN, 2014
/---------------------------------------------------------------------------*/
-#include "ch.h"
-#define _FFCONF 80376 /* Revision ID */
+#ifndef _FFCONF
+#define _FFCONF 8051 /* Revision ID */
+
/*---------------------------------------------------------------------------/
/ Functions and Buffer Configurations
/---------------------------------------------------------------------------*/
-#define _FS_TINY 0
-/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
-/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS
-/ bytes. Instead of private sector buffer eliminated from the file object,
-/ common sector buffer in the file system object (FATFS) is used for the file
-/ data transfer. */
+#define _FS_TINY 0 /* 0:Normal or 1:Tiny */
+/* When _FS_TINY is set to 1, it reduces memory consumption _MAX_SS bytes each
+/ file object. For file data transfer, FatFs uses the common sector buffer in
+/ the file system object (FATFS) instead of private sector buffer eliminated
+/ from the file object (FIL). */
-#define _FS_READONLY 0
-/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
-/ Read-only configuration removes basic writing API functions, f_write(),
-/ f_sync(), f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(),
-/ f_getfree() and optional writing functions as well. */
+#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
+/* Setting _FS_READONLY to 1 defines read only configuration. This removes
+/ writing functions, f_write(), f_sync(), f_unlink(), f_mkdir(), f_chmod(),
+/ f_rename(), f_truncate() and useless f_getfree(). */
-#define _FS_MINIMIZE 0
-/* This option defines minimization level to remove some API functions.
+#define _FS_MINIMIZE 0 /* 0 to 3 */
+/* The _FS_MINIMIZE option defines minimization level to remove API functions.
/
/ 0: All basic functions are enabled.
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
@@ -34,40 +36,32 @@
/ 3: f_lseek() function is removed in addition to 2. */
-#define _USE_STRFUNC 0
-/* This option switches string functions, f_gets(), f_putc(), f_puts() and
-/ f_printf().
-/
-/ 0: Disable string functions.
-/ 1: Enable without LF-CRLF conversion.
-/ 2: Enable with LF-CRLF conversion. */
+#define _USE_STRFUNC 0 /* 0:Disable or 1-2:Enable */
+/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
-#define _USE_MKFS 0
-/* This option switches f_mkfs() function. (0:Disable or 1:Enable)
-/ To enable it, also _FS_READONLY need to be set to 0. */
+#define _USE_MKFS 0 /* 0:Disable or 1:Enable */
+/* To enable f_mkfs() function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
-#define _USE_FASTSEEK 0
-/* This option switches fast seek feature. (0:Disable or 1:Enable) */
+#define _USE_FASTSEEK 0 /* 0:Disable or 1:Enable */
+/* To enable fast seek feature, set _USE_FASTSEEK to 1. */
-#define _USE_LABEL 0
-/* This option switches volume label functions, f_getlabel() and f_setlabel().
-/ (0:Disable or 1:Enable) */
+#define _USE_LABEL 0 /* 0:Disable or 1:Enable */
+/* To enable volume label functions, set _USE_LAVEL to 1 */
-#define _USE_FORWARD 0
-/* This option switches f_forward() function. (0:Disable or 1:Enable) */
-/* To enable it, also _FS_TINY need to be set to 1. */
+#define _USE_FORWARD 0 /* 0:Disable or 1:Enable */
+/* To enable f_forward() function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/---------------------------------------------------------------------------*/
-#define _CODE_PAGE 437
-/* This option specifies the OEM code page to be used on the target system.
+#define _CODE_PAGE 1252
+/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
/ Incorrect setting of the code page can cause a file open failure.
/
/ 932 - Japanese Shift_JIS (DBCS, OEM, Windows)
@@ -95,11 +89,11 @@
/ 857 - Turkish (OEM)
/ 862 - Hebrew (OEM)
/ 874 - Thai (OEM, Windows)
-/ 1 - ASCII (No extended character. Valid for only non-LFN configuration.) */
+/ 1 - ASCII (Valid for only non-LFN configuration) */
-#define _USE_LFN 0
-#define _MAX_LFN 255
+#define _USE_LFN 3 /* 0 to 3 */
+#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN feature.
/
/ 0: Disable LFN feature. _MAX_LFN has no effect.
@@ -107,86 +101,77 @@
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
-/ When enable the LFN feature, Unicode handling functions (option/unicode.c) must
-/ be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes.
-/ When use stack for the working buffer, take care on stack overflow. When use heap
-/ memory for the working buffer, memory management functions, ff_memalloc() and
-/ ff_memfree(), must be added to the project. */
+/ When enable LFN feature, Unicode handling functions ff_convert() and ff_wtoupper()
+/ function must be added to the project.
+/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. When use stack for the
+/ working buffer, take care on stack overflow. When use heap memory for the working
+/ buffer, memory management functions, ff_memalloc() and ff_memfree(), must be added
+/ to the project. */
-#define _LFN_UNICODE 0
-/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
-/ To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE
-/ to 1. This option also affects behavior of string I/O functions. */
+#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
+/* To switch the character encoding on the FatFs API (TCHAR) to Unicode, enable LFN
+/ feature and set _LFN_UNICODE to 1. This option affects behavior of string I/O
+/ functions. This option must be 0 when LFN feature is not enabled. */
-#define _STRF_ENCODE 3
-/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
-/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
-/
-/ 0: ANSI/OEM
-/ 1: UTF-16LE
-/ 2: UTF-16BE
-/ 3: UTF-8
-/
-/ When _LFN_UNICODE is 0, this option has no effect. */
+#define _STRF_ENCODE 3 /* 0:ANSI/OEM, 1:UTF-16LE, 2:UTF-16BE, 3:UTF-8 */
+/* When Unicode API is enabled by _LFN_UNICODE option, this option selects the character
+/ encoding on the file to be read/written via string I/O functions, f_gets(), f_putc(),
+/ f_puts and f_printf(). This option has no effect when Unicode API is not enabled. */
-#define _FS_RPATH 0
-/* This option configures relative path feature.
+#define _FS_RPATH 0 /* 0 to 2 */
+/* The _FS_RPATH option configures relative path feature.
/
/ 0: Disable relative path feature and remove related functions.
-/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available.
+/ 1: Enable relative path. f_chdrive() and f_chdir() function are available.
/ 2: f_getcwd() function is available in addition to 1.
/
-/ Note that directory items read via f_readdir() are affected by this option. */
+/ Note that output of the f_readdir() fnction is affected by this option. */
/*---------------------------------------------------------------------------/
/ Drive/Volume Configurations
/---------------------------------------------------------------------------*/
-#define _VOLUMES 1
+#define _VOLUMES 1
/* Number of volumes (logical drives) to be used. */
-#define _STR_VOLUME_ID 0
-#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
-/* _STR_VOLUME_ID option switches string volume ID feature.
-/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
-/ number in the path name. _VOLUME_STRS defines the drive ID strings for each
-/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for
-/ the drive ID strings are: A-Z and 0-9. */
+#define _STR_VOLUME_ID 0 /* 0:Use only 0-9 for drive ID, 1:Use strings for drive ID */
+#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
+/* When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
+/ number in the path name. _VOLUME_STRS defines the drive ID strings for each logical
+/ drives. Number of items must be equal to _VOLUMES. Valid characters for the drive ID
+/ strings are: 0-9 and A-Z. */
-#define _MULTI_PARTITION 0
-/* This option switches multi-partition feature. By default (0), each logical drive
-/ number is bound to the same physical drive number and only an FAT volume found on
-/ the physical drive will be mounted. When multi-partition feature is enabled (1),
-/ each logical drive number is bound to arbitrary physical drive and partition
-/ listed in the VolToPart[]. Also f_fdisk() funciton will be enabled. */
+#define _MULTI_PARTITION 0 /* 0:Single partition, 1:Enable multiple partition */
+/* By default(0), each logical drive number is bound to the same physical drive number
+/ and only a FAT volume found on the physical drive is mounted. When it is set to 1,
+/ each logical drive number is bound to arbitrary drive/partition listed in VolToPart[].
+*/
-#define _MIN_SS 512
-#define _MAX_SS 512
-/* These options configure the range of sector size to be supported. (512, 1024,
-/ 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
-/ harddisk. But a larger value may be required for on-board flash memory and some
-/ type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
-/ to variable sector size and GET_SECTOR_SIZE command must be implemented to the
-/ disk_ioctl() function. */
+#define _MIN_SS 512
+#define _MAX_SS 512
+/* These options configure the range of sector size to be supported. (512, 1024, 2048 or
+/ 4096) Always set both 512 for most systems, all memory card and harddisk. But a larger
+/ value may be required for on-board flash memory and some type of optical media.
+/ When _MAX_SS is larger than _MIN_SS, FatFs is configured to variable sector size and
+/ GET_SECTOR_SIZE command must be implemented to the disk_ioctl() function. */
-#define _USE_TRIM 0
-/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
-/ To enable Trim feature, also CTRL_TRIM command should be implemented to the
-/ disk_ioctl() function. */
+#define _USE_ERASE 0 /* 0:Disable or 1:Enable */
+/* To enable sector erase feature, set _USE_ERASE to 1. Also CTRL_ERASE_SECTOR command
+/ should be added to the disk_ioctl() function. */
-#define _FS_NOFSINFO 0
-/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
-/ option, and f_getfree() function at first time after volume mount will force
-/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
+#define _FS_NOFSINFO 0 /* 0 to 3 */
+/* If you need to know correct free space on the FAT32 volume, set bit 0 of this option
+/ and f_getfree() function at first time after volume mount will force a full FAT scan.
+/ Bit 1 controls the last allocated cluster number as bit 0.
/
/ bit0=0: Use free cluster count in the FSINFO if available.
/ bit0=1: Do not trust free cluster count in the FSINFO.
@@ -200,72 +185,46 @@
/ System Configurations
/---------------------------------------------------------------------------*/
-#define _FS_NORTC 0
-#define _NORTC_MON 11
-#define _NORTC_MDAY 9
-#define _NORTC_YEAR 2014
-/* The _FS_NORTC option switches timestamp feature. If the system does not have
-/ an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
-/ the timestamp feature. All objects modified by FatFs will have a fixed timestamp
-/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR.
-/ When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need
-/ to be added to the project to read current time form RTC. _NORTC_MON,
-/ _NORTC_MDAY and _NORTC_YEAR have no effect.
-/ These options have no effect at read-only configuration (_FS_READONLY == 1). */
-
-
-#define _FS_LOCK 0
-/* The _FS_LOCK option switches file lock feature to control duplicated file open
-/ and illegal operation to open objects. This option must be 0 when _FS_READONLY
-/ is 1.
-/
-/ 0: Disable file lock feature. To avoid volume corruption, application program
-/ should avoid illegal open, remove and rename to the open objects.
-/ >0: Enable file lock feature. The value defines how many files/sub-directories
-/ can be opened simultaneously under file lock control. Note that the file
-/ lock feature is independent of re-entrancy. */
-
-
-#define _FS_REENTRANT 0
-#define _FS_TIMEOUT S2ST(10)
-typedef semaphore_t * _SYNC_t;
-/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
-/ module itself. Note that regardless of this option, file access to different
-/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
-/ and f_fdisk() function, are always not re-entrant. Only file/directory access
-/ to the same volume is under control of this feature.
+#define _FS_LOCK 0 /* 0:Disable or >=1:Enable */
+/* To enable file lock control feature, set _FS_LOCK to non-zero value.
+/ The value defines how many files/sub-directories can be opened simultaneously
+/ with file lock control. This feature uses bss _FS_LOCK * 12 bytes. */
+
+
+#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
+#define _FS_TIMEOUT MS2ST(1000) /* Timeout period in unit of time tick */
+#define _SYNC_t semaphore_t* /* O/S dependent sync object type. e.g. HANDLE, OS_EVENT*, ID, SemaphoreHandle_t and etc.. */
+/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs module.
/
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
-/ function, must be added to the project. Samples are available in
-/ option/syscall.c.
-/
-/ The _FS_TIMEOUT defines timeout period in unit of time tick.
-/ The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
-/ SemaphoreHandle_t and etc.. */
+/ function must be added to the project.
+*/
-#define _WORD_ACCESS 0
+#define _WORD_ACCESS 0 /* 0 or 1 */
/* The _WORD_ACCESS option is an only platform dependent option. It defines
/ which access method is used to the word data on the FAT volume.
/
/ 0: Byte-by-byte access. Always compatible with all platforms.
/ 1: Word access. Do not choose this unless under both the following conditions.
/
-/ * Address misaligned memory access is always allowed to ALL instructions.
+/ * Address misaligned memory access is always allowed for ALL instructions.
/ * Byte order on the memory is little-endian.
/
-/ If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
-/ Following table shows allowable settings of some processor types.
+/ If it is the case, _WORD_ACCESS can also be set to 1 to improve performance and
+/ reduce code size. Following table shows an example of some processor types.
/
-/ ARM7TDMI 0 ColdFire 0 V850E 0
+/ ARM7TDMI 0 ColdFire 0 V850E2 0
/ Cortex-M3 0 Z80 0/1 V850ES 0/1
-/ Cortex-M0 0 x86 0/1 TLCS-870 0/1
-/ AVR 0/1 RX600(LE) 0/1 TLCS-900 0/1
+/ Cortex-M0 0 RX600(LE) 0/1 TLCS-870 0/1
+/ AVR 0/1 RX600(BE) 0 TLCS-900 0/1
/ AVR32 0 RL78 0 R32C 0
/ PIC18 0/1 SH-2 0 M16C 0/1
/ PIC24 0 H8S 0 MSP430 0
-/ PIC32 0 H8/300H 0 8051 0/1
+/ PIC32 0 H8/300H 0 x86 0/1
*/
+
+#endif /* _FFCONF */
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h b/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
index 49db499..807d741 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
+++ b/testhal/STM32/STM32F4xx/USB_HOST/halconf_community.h
@@ -14,8 +14,8 @@
limitations under the License.
*/
-#ifndef _HALCONF_COMMUNITY_H_
-#define _HALCONF_COMMUNITY_H_
+#ifndef HALCONF_COMMUNITY_H
+#define HALCONF_COMMUNITY_H
/**
* @brief Enables the community overlay.
@@ -190,6 +190,6 @@
*/
#define ONEWIRE_USE_SEARCH_ROM TRUE
-#endif /* _HALCONF_COMMUNITY_H_ */
+#endif /* HALCONF_COMMUNITY_H */
/** @} */
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/main.c b/testhal/STM32/STM32F4xx/USB_HOST/main.c
index bfb318f..23470b8 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/main.c
+++ b/testhal/STM32/STM32F4xx/USB_HOST/main.c
@@ -17,14 +17,12 @@
#include "ch.h"
#include "hal.h"
#include "ff.h"
-#include "usbh.h"
#include <string.h>
#if HAL_USBH_USE_FTDI
#include "usbh/dev/ftdi.h"
-#include "test.h"
#include "shell.h"
#include "chprintf.h"
@@ -51,56 +49,6 @@ static uint8_t buf[] =
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
-static void cmd_mem(BaseSequentialStream *chp, int argc, char *argv[]) {
- size_t n, size;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: mem\r\n");
- return;
- }
- n = chHeapStatus(NULL, &size);
- chprintf(chp, "core free memory : %u bytes\r\n", chCoreGetStatusX());
- chprintf(chp, "heap fragments : %u\r\n", n);
- chprintf(chp, "heap free total : %u bytes\r\n", size);
-}
-
-static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) {
- static const char *states[] = {CH_STATE_NAMES};
- thread_t *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: threads\r\n");
- return;
- }
- chprintf(chp, " addr stack prio refs state\r\n");
- tp = chRegFirstThread();
- do {
- chprintf(chp, "%08lx %08lx %4lu %4lu %9s\r\n",
- (uint32_t)tp, (uint32_t)tp->p_ctx.r13,
- (uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
- states[tp->p_state]);
- tp = chRegNextThread(tp);
- } while (tp != NULL);
-}
-
-static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
- thread_t *tp;
-
- (void)argv;
- if (argc > 0) {
- chprintf(chp, "Usage: test\r\n");
- return;
- }
- tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriorityX(),
- TestThread, chp);
- if (tp == NULL) {
- chprintf(chp, "out of memory\r\n");
- return;
- }
- chThdWait(tp);
-}
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
@@ -115,15 +63,12 @@ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
}
while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) {
- chSequentialStreamWrite(&FTDIPD[0], buf, sizeof buf - 1);
+ streamWrite(&FTDIPD[0], buf, sizeof buf - 1);
}
chprintf(chp, "\r\n\nstopped\r\n");
}
static const ShellCommand commands[] = {
- {"mem", cmd_mem},
- {"threads", cmd_threads},
- {"test", cmd_test},
{"write", cmd_write},
{NULL, NULL}
};
@@ -159,12 +104,12 @@ start:
//loopback
if (0) {
for(;;) {
- msg_t m = chSequentialStreamGet(ftdipp);
+ msg_t m = streamGet(ftdipp);
if (m < MSG_OK) {
usbDbgPuts("FTDI: Disconnected");
goto start;
}
- chSequentialStreamPut(ftdipp, (uint8_t)m);
+ streamPut(ftdipp, (uint8_t)m);
if (m == 'q')
break;
}
@@ -177,7 +122,7 @@ start:
if (ftdipp->state != USBHFTDIP_STATE_READY)
goto start;
if (!shelltp) {
- shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
+ shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO, shellThread, (void *) &shell_cfg1);
} else if (chThdTerminatedX(shelltp)) {
chThdRelease(shelltp);
if (ftdipp->state != USBHFTDIP_STATE_READY)
@@ -191,7 +136,7 @@ start:
//FTDI uart RX to debug TX bridge
if (0) {
for(;;) {
- msg_t m = chSequentialStreamGet(ftdipp);
+ msg_t m = streamGet(ftdipp);
if (m < MSG_OK) {
usbDbgPuts("FTDI: Disconnected");
goto start;
@@ -215,14 +160,14 @@ start:
uint32_t times = bytes / 1024;
st = chVTGetSystemTimeX();
while (times--) {
- if (chSequentialStreamWrite(ftdipp, buf, 1024) < 1024) {
+ if (streamWrite(ftdipp, buf, 1024) < 1024) {
usbDbgPuts("FTDI: Disconnected");
goto start;
}
bytes -= 1024;
}
if (bytes) {
- if (chSequentialStreamWrite(ftdipp, buf, bytes) < bytes) {
+ if (streamWrite(ftdipp, buf, bytes) < bytes) {
usbDbgPuts("FTDI: Disconnected");
goto start;
}
@@ -235,7 +180,7 @@ start:
//single character write test (tests the timer)
if (0) {
for (;;) {
- if (chSequentialStreamPut(ftdipp, 'A') != MSG_OK) {
+ if (streamPut(ftdipp, 'A') != MSG_OK) {
usbDbgPuts("FTDI: Disconnected");
goto start;
}
diff --git a/testhal/STM32/STM32F4xx/USB_HOST/mcuconf_community.h b/testhal/STM32/STM32F4xx/USB_HOST/mcuconf_community.h
index 56775af..5cb823a 100644
--- a/testhal/STM32/STM32F4xx/USB_HOST/mcuconf_community.h
+++ b/testhal/STM32/STM32F4xx/USB_HOST/mcuconf_community.h
@@ -48,19 +48,19 @@
/*
* USBH driver system settings.
*/
-#define STM32_OTG1_CHANNELS_NUMBER 8
-#define STM32_OTG2_CHANNELS_NUMBER 12
+#define STM32_OTG1_CHANNELS_NUMBER 8
+#define STM32_OTG2_CHANNELS_NUMBER 12
-#define STM32_USBH_USE_OTG1 1
-#define STM32_OTG1_RXFIFO_SIZE 1024
-#define STM32_OTG1_PTXFIFO_SIZE 128
-#define STM32_OTG1_NPTXFIFO_SIZE 128
+#define STM32_USBH_USE_OTG1 1
+#define STM32_OTG1_RXFIFO_SIZE 1024
+#define STM32_OTG1_PTXFIFO_SIZE 128
+#define STM32_OTG1_NPTXFIFO_SIZE 128
-#define STM32_USBH_USE_OTG2 0
-#define STM32_OTG2_RXFIFO_SIZE 2048
-#define STM32_OTG2_PTXFIFO_SIZE 1024
-#define STM32_OTG2_NPTXFIFO_SIZE 1024
+#define STM32_USBH_USE_OTG2 0
+#define STM32_OTG2_RXFIFO_SIZE 2048
+#define STM32_OTG2_PTXFIFO_SIZE 1024
+#define STM32_OTG2_NPTXFIFO_SIZE 1024
-#define STM32_USBH_MIN_QSPACE 4
-#define STM32_USBH_CHANNELS_NP 4
+#define STM32_USBH_MIN_QSPACE 4
+#define STM32_USBH_CHANNELS_NP 4
diff --git a/testhal/STM32/STM32F4xx/onewire/.cproject b/testhal/STM32/STM32F4xx/onewire/.cproject
index f6e2450..d2cdbd2 100644
--- a/testhal/STM32/STM32F4xx/onewire/.cproject
+++ b/testhal/STM32/STM32F4xx/onewire/.cproject
@@ -49,4 +49,5 @@
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+ <storageModule moduleId="refreshScope"/>
</cproject>
diff --git a/testhal/STM32/STM32F4xx/onewire/.project b/testhal/STM32/STM32F4xx/onewire/.project
index 30d6ff3..a82f065 100644
--- a/testhal/STM32/STM32F4xx/onewire/.project
+++ b/testhal/STM32/STM32F4xx/onewire/.project
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>STM32F4xx-onewire</name>
+ <name>STM32F4xx-1-Wire</name>
<comment></comment>
<projects>
</projects>
@@ -80,12 +80,18 @@
<link>
<name>os-community</name>
<type>2</type>
- <locationURI>PARENT-4-PROJECT_LOC/os</locationURI>
+ <locationURI>CHIBIOS_CONTRIB/os</locationURI>
</link>
<link>
<name>os-git</name>
<type>2</type>
- <locationURI>PARENT-5-PROJECT_LOC/ChibiOS-RT/os</locationURI>
+ <locationURI>copy_PARENT/ChibiOS-RT/os</locationURI>
</link>
</linkedResources>
+ <variableList>
+ <variable>
+ <name>copy_PARENT</name>
+ <value>$%7BPARENT-1-CHIBIOS%7D</value>
+ </variable>
+ </variableList>
</projectDescription>
diff --git a/testhal/STM32/STM32F4xx/onewire/Makefile b/testhal/STM32/STM32F4xx/onewire/Makefile
index 02ab018..092b023 100644
--- a/testhal/STM32/STM32F4xx/onewire/Makefile
+++ b/testhal/STM32/STM32F4xx/onewire/Makefile
@@ -88,6 +88,7 @@ PROJECT = ch
# Imported source files and paths
CHIBIOS = ../../../../../ChibiOS-RT
CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib
+TESTHAL = $(CHIBIOS_CONTRIB)/testhal/common/onewire
# Startup files.
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk
# HAL-OSAL files (optional).
@@ -113,7 +114,7 @@ CSRC = $(STARTUPSRC) \
$(BOARDSRC) \
$(TESTSRC) \
main.c \
- onewire_test.c
+ $(TESTHAL)/testhal_onewire.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
@@ -146,7 +147,8 @@ ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
INCDIR = $(CHIBIOS)/os/license \
$(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
- $(CHIBIOS)/os/various
+ $(CHIBIOS)/os/various \
+ $(TESTHAL)
#
# Project, sources and paths
diff --git a/testhal/STM32/STM32F4xx/onewire/onewire_test.h b/testhal/STM32/STM32F4xx/onewire/boarddef.h
index 1bec2d0..a048dcb 100644
--- a/testhal/STM32/STM32F4xx/onewire/onewire_test.h
+++ b/testhal/STM32/STM32F4xx/onewire/boarddef.h
@@ -1,5 +1,5 @@
/*
- ChibiOS/RT - Copyright (C) 2014 Uladzimir Pylinsky aka barthess
+ ChibiOS/RT - Copyright (C) 2016 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.
@@ -14,15 +14,15 @@
limitations under the License.
*/
-#ifndef ONEWIRE_TEST_H_
-#define ONEWIRE_TEST_H_
+#ifndef BOARDDEF_H_
+#define BOARDDEF_H_
-#ifdef __cplusplus
-extern "C" {
-#endif
- void onewireTest(void);
-#ifdef __cplusplus
-}
-#endif
+#define ONEWIRE_PORT GPIOB
+#define ONEWIRE_PIN GPIOB_PIN0
+#define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_OPENDRAIN)
+#define search_led_off() (palClearPad(GPIOD, GPIOD_LED4))
+#define search_led_on() (palSetPad(GPIOD, GPIOD_LED4))
+#define ONEWIRE_MASTER_CHANNEL 2
+#define ONEWIRE_SAMPLE_CHANNEL 3
-#endif /* ONEWIRE_TEST_H_ */
+#endif /* BOARDDEF_H_ */
diff --git a/testhal/STM32/STM32F4xx/onewire/halconf_community.h b/testhal/STM32/STM32F4xx/onewire/halconf_community.h
index 91dbfbc..0621fdb 100644
--- a/testhal/STM32/STM32F4xx/onewire/halconf_community.h
+++ b/testhal/STM32/STM32F4xx/onewire/halconf_community.h
@@ -14,8 +14,8 @@
limitations under the License.
*/
-#ifndef _HALCONF_COMMUNITY_H_
-#define _HALCONF_COMMUNITY_H_
+#ifndef HALCONF_COMMUNITY_H
+#define HALCONF_COMMUNITY_H
/**
* @brief Enables the community overlay.
@@ -93,6 +93,6 @@
*/
#define ONEWIRE_USE_SEARCH_ROM TRUE
-#endif /* _HALCONF_COMMUNITY_H_ */
+#endif /* HALCONF_COMMUNITY_H */
/** @} */
diff --git a/testhal/STM32/STM32F4xx/onewire/main.c b/testhal/STM32/STM32F4xx/onewire/main.c
index 793bffe..5265edc 100644
--- a/testhal/STM32/STM32F4xx/onewire/main.c
+++ b/testhal/STM32/STM32F4xx/onewire/main.c
@@ -17,7 +17,7 @@
#include "ch.h"
#include "hal.h"
-#include "onewire_test.h"
+#include "testhal_onewire.h"
/*
* Application entry point.
diff --git a/testhal/STM32/STM32F4xx/onewire/onewire_test.c b/testhal/STM32/STM32F4xx/onewire/onewire_test.c
deleted file mode 100644
index be20dbc..0000000
--- a/testhal/STM32/STM32F4xx/onewire/onewire_test.c
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- ChibiOS/RT - 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.
-*/
-
-#include <string.h>
-
-#include "hal.h"
-
-/*
- ******************************************************************************
- * DEFINES
- ******************************************************************************
- */
-
-#if defined(BOARD_ST_STM32F4_DISCOVERY) || \
- defined(BOARD_ST_STM32F0_DISCOVERY) || \
- defined(BOARD_ST_STM32F0308_DISCOVERY)
- #if ONEWIRE_USE_STRONG_PULLUP
- #error "This board has not enough voltage for this feature"
- #endif
-#endif
-
-#if defined(BOARD_ST_STM32F0308_DISCOVERY)
- #define ONEWIRE_PORT GPIOB
- #define ONEWIRE_PIN GPIOB_PIN0
- #define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(1) | PAL_STM32_OTYPE_OPENDRAIN)
- #define search_led_off() (palClearPad(GPIOC, GPIOC_LED4))
- #define search_led_on() (palSetPad(GPIOC, GPIOC_LED4))
- #define ONEWIRE_MASTER_CHANNEL 2
- #define ONEWIRE_SAMPLE_CHANNEL 3
-#elif defined(BOARD_ST_STM32F4_DISCOVERY)
- #define ONEWIRE_PORT GPIOB
- #define ONEWIRE_PIN GPIOB_PIN0
- #define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_OPENDRAIN)
- #define search_led_off() (palClearPad(GPIOD, GPIOD_LED4))
- #define search_led_on() (palSetPad(GPIOD, GPIOD_LED4))
- #define ONEWIRE_MASTER_CHANNEL 2
- #define ONEWIRE_SAMPLE_CHANNEL 3
-#elif defined(BOARD_OLIMEX_STM32_103STK)
- #define ONEWIRE_PORT GPIOB
- #define ONEWIRE_PIN 0
- #define ONEWIRE_PAD_MODE_IDLE PAL_MODE_INPUT
- #define ONEWIRE_PAD_MODE_ACTIVE PAL_MODE_STM32_ALTERNATE_OPENDRAIN
- #define search_led_on() (palClearPad(GPIOC, GPIOC_LED))
- #define search_led_off() (palSetPad(GPIOC, GPIOC_LED))
- #define ONEWIRE_MASTER_CHANNEL 2
- #define ONEWIRE_SAMPLE_CHANNEL 3
-#else
- #define ONEWIRE_PORT GPIOB
- #define ONEWIRE_PIN GPIOB_TACHOMETER
- #include "pads.h"
- #define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_OPENDRAIN)
- #define search_led_on red_led_on
- #define search_led_off red_led_off
- #define ONEWIRE_MASTER_CHANNEL 2
- #define ONEWIRE_SAMPLE_CHANNEL 3
-#endif
-
-/*
- ******************************************************************************
- * EXTERNS
- ******************************************************************************
- */
-
-/*
- ******************************************************************************
- * PROTOTYPES
- ******************************************************************************
- */
-/*
- * Forward declarations
- */
-#if ONEWIRE_USE_STRONG_PULLUP
-static void strong_pullup_assert(void);
-static void strong_pullup_release(void);
-#endif
-
-/*
- ******************************************************************************
- * GLOBAL VARIABLES
- ******************************************************************************
- */
-
-static uint8_t testbuf[12];
-
-/* stores 3 temperature values in millicelsius */
-static int32_t temperature[3];
-
-/*
- * Config for underlied PWM driver.
- * Note! It is NOT constant because 1-wire driver needs to change them
- * during functioning.
- */
-static PWMConfig pwm_cfg = {
- 0,
- 0,
- NULL,
- {
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL}
- },
- 0,
-#if STM32_PWM_USE_ADVANCED
- 0,
-#endif
- 0
-};
-
-/*
- *
- */
-static const onewireConfig ow_cfg = {
- &PWMD3,
- &pwm_cfg,
- PWM_OUTPUT_ACTIVE_LOW,
- ONEWIRE_MASTER_CHANNEL,
- ONEWIRE_SAMPLE_CHANNEL,
- ONEWIRE_PORT,
- ONEWIRE_PIN,
-#if defined(STM32F1XX)
- ONEWIRE_PAD_MODE_IDLE,
-#endif
- ONEWIRE_PAD_MODE_ACTIVE,
-#if ONEWIRE_USE_STRONG_PULLUP
- strong_pullup_assert,
- strong_pullup_release
-#endif
-};
-
-/*
- ******************************************************************************
- ******************************************************************************
- * LOCAL FUNCTIONS
- ******************************************************************************
- ******************************************************************************
- */
-
-#if ONEWIRE_USE_STRONG_PULLUP
-/**
- *
- */
-static void strong_pullup_assert(void) {
- palSetPadMode(ONEWIRE_PORT, ONEWIRE_PIN, PAL_MODE_STM32_ALTERNATE_PUSHPULL);
-}
-
-/**
- *
- */
-static void strong_pullup_release(void) {
- palSetPadMode(ONEWIRE_PORT, ONEWIRE_PIN, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
-}
-#endif /* ONEWIRE_USE_STRONG_PULLUP */
-
-/*
- ******************************************************************************
- * EXPORTED FUNCTIONS
- ******************************************************************************
- */
-
-/**
- *
- */
-void onewireTest(void) {
-
- int16_t tmp;
- uint8_t rombuf[24];
- size_t devices_on_bus = 0;
- size_t i = 0;
- bool presence;
-
- onewireObjectInit(&OWD1);
- onewireStart(&OWD1, &ow_cfg);
-
-#if ONEWIRE_SYNTH_SEARCH_TEST
- synthSearchRomTest(&OWD1);
-#endif
-
- for (i=0; i<3; i++)
- temperature[i] = -666;
-
- while (true) {
- if (true == onewireReset(&OWD1)){
-
- memset(rombuf, 0x55, sizeof(rombuf));
- search_led_on();
- devices_on_bus = onewireSearchRom(&OWD1, rombuf, 3);
- search_led_off();
- osalDbgCheck(devices_on_bus <= 3);
- osalDbgCheck(devices_on_bus > 0);
-
- if (1 == devices_on_bus){
- /* test read rom command */
- presence = onewireReset(&OWD1);
- osalDbgCheck(true == presence);
- testbuf[0] = ONEWIRE_CMD_READ_ROM;
- onewireWrite(&OWD1, testbuf, 1, 0);
- onewireRead(&OWD1, testbuf, 8);
- osalDbgCheck(testbuf[7] == onewireCRC(testbuf, 7));
- osalDbgCheck(0 == memcmp(rombuf, testbuf, 8));
- }
-
- /* start temperature measurement on all connected devices at once */
- presence = onewireReset(&OWD1);
- osalDbgCheck(true == presence);
- testbuf[0] = ONEWIRE_CMD_SKIP_ROM;
- testbuf[1] = ONEWIRE_CMD_CONVERT_TEMP;
-
-#if ONEWIRE_USE_STRONG_PULLUP
- onewireWrite(&OWD1, testbuf, 2, MS2ST(750));
-#else
- onewireWrite(&OWD1, testbuf, 2, 0);
- /* poll bus waiting ready signal from all connected devices */
- testbuf[0] = 0;
- while (testbuf[0] == 0){
- osalThreadSleepMilliseconds(50);
- onewireRead(&OWD1, testbuf, 1);
- }
-#endif
-
- for (i=0; i<devices_on_bus; i++) {
- /* read temperature device by device from their scratchpads */
- presence = onewireReset(&OWD1);
- osalDbgCheck(true == presence);
-
- testbuf[0] = ONEWIRE_CMD_MATCH_ROM;
- memcpy(&testbuf[1], &rombuf[i*8], 8);
- testbuf[9] = ONEWIRE_CMD_READ_SCRATCHPAD;
- onewireWrite(&OWD1, testbuf, 10, 0);
-
- onewireRead(&OWD1, testbuf, 9);
- osalDbgCheck(testbuf[8] == onewireCRC(testbuf, 8));
- memcpy(&tmp, &testbuf, 2);
- temperature[i] = ((int32_t)tmp * 625) / 10;
- }
- }
- else {
- osalSysHalt("No devices found");
- }
- osalThreadSleep(1); /* enforce ChibiOS's stack overflow check */
- }
-
- onewireStop(&OWD1);
-}
diff --git a/testhal/STM32/STM32F4xx/onewire/real_roms.txt b/testhal/STM32/STM32F4xx/onewire/real_roms.txt
deleted file mode 100644
index ea19c1a..0000000
--- a/testhal/STM32/STM32F4xx/onewire/real_roms.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-rombuf[0] 0x28
-rombuf[1] 0xec
-rombuf[2] 0xf5
-rombuf[3] 0x67
-rombuf[4] 0x5
-rombuf[5] 0x0
-rombuf[6] 0x0
-rombuf[7] 0x1d
-
-rombuf[8] 0x28
-rombuf[9] 0xbd
-rombuf[10] 0x1a
-rombuf[11] 0x60
-rombuf[12] 0x5
-rombuf[13] 0x0
-rombuf[14] 0x0
-rombuf[15] 0x37
-
-rombuf[16] 0x28
-rombuf[17] 0x83
-rombuf[18] 0x7d
-rombuf[19] 0x67
-rombuf[20] 0x5
-rombuf[21] 0x0
-rombuf[22] 0x0
-rombuf[23] 0xf
-
diff --git a/testhal/STM32/STM32F4xx/onewire/search_rom_synth.c b/testhal/STM32/STM32F4xx/onewire/search_rom_synth.c
deleted file mode 100644
index cd2528f..0000000
--- a/testhal/STM32/STM32F4xx/onewire/search_rom_synth.c
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- ChibiOS/RT - 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.
-*/
-
-#include <stdlib.h>
-
-/*
- ******************************************************************************
- * DEFINES
- ******************************************************************************
- */
-
-/* do not set it more than 64 because of some fill_pattern functions
- * will be broken.*/
-#define SYNTH_DEVICES_MAX 64
-
-/*
- * synthetic device
- */
-typedef struct {
- bool active;
- uint64_t id;
-} OWSynthDevice;
-
-/*
- * synthetic bus
- */
-typedef struct {
- OWSynthDevice devices[SYNTH_DEVICES_MAX];
- size_t dev_present;
- bool complement_bit;
- ioline_t rom_bit;
-} OWSynthBus;
-
-/*
- ******************************************************************************
- * EXTERNS
- ******************************************************************************
- */
-
-/*
- ******************************************************************************
- * PROTOTYPES
- ******************************************************************************
- */
-
-/*
- ******************************************************************************
- * GLOBAL VARIABLES
- ******************************************************************************
- */
-
-static OWSynthBus synth_bus;
-
-/*
- * local buffer for discovered ROMs
- */
-static uint64_t detected_devices[SYNTH_DEVICES_MAX];
-
-/*
- ******************************************************************************
- ******************************************************************************
- * LOCAL FUNCTIONS
- ******************************************************************************
- ******************************************************************************
- */
-
-/*
- ******************************************************************************
- * EXPORTED FUNCTIONS
- ******************************************************************************
- */
-
-/**
- *
- */
-void _synth_ow_write_bit(onewireDriver *owp, ioline_t bit) {
- (void)owp;
- size_t i;
-
- for (i=0; i<SYNTH_DEVICES_MAX; i++) {
- if (((synth_bus.devices[i].id >> synth_bus.rom_bit) & 1U) != bit) {
- synth_bus.devices[i].active = false;
- }
- }
- synth_bus.rom_bit++;
-}
-
-/**
- *
- */
-ioline_t _synth_ow_read_bit(void) {
- ioline_t ret = 0xFF;
- size_t i;
- ioline_t bit;
-
- for (i=0; i<SYNTH_DEVICES_MAX; i++) {
- if (synth_bus.devices[i].active){
- bit = (synth_bus.devices[i].id >> synth_bus.rom_bit) & 1U;
- if (synth_bus.complement_bit){
- bit ^= 1U;
- }
- if (0xFF == ret)
- ret = bit;
- else
- ret &= bit;
- }
- }
- synth_bus.complement_bit = !synth_bus.complement_bit;
- return ret;
-}
-
-/**
- *
- */
-static void synth_reset_pulse(void){
- size_t i;
-
- for (i=0; i<synth_bus.dev_present; i++){
- synth_bus.devices[i].active = true;
- }
-}
-
-/**
- *
- */
-static size_t synth_search_rom(onewireDriver *owp, uint8_t *result, size_t max_rom_cnt) {
-
- size_t i;
-
- search_clean_start(&owp->search_rom);
-
- do {
- /* initialize buffer to store result */
- if (owp->search_rom.reg.devices_found >= max_rom_cnt)
- owp->search_rom.retbuf = result + 8*(max_rom_cnt-1);
- else
- owp->search_rom.retbuf = result + 8*owp->search_rom.reg.devices_found;
- memset(owp->search_rom.retbuf, 0, 8);
-
- /* clean iteration state */
- search_clean_iteration(&owp->search_rom);
-
- /**/
- synth_reset_pulse();
- synth_bus.rom_bit = 0;
- synth_bus.complement_bit = false;
- for (i=0; i<64*3 - 1; i++){
- ow_search_rom_cb(NULL, owp);
- }
-
- if (ONEWIRE_SEARCH_ROM_ERROR != owp->search_rom.reg.result) {
- /* store cached result for usage in next iteration */
- memcpy(owp->search_rom.prev_path, owp->search_rom.retbuf, 8);
- }
- }
- while (ONEWIRE_SEARCH_ROM_SUCCESS == owp->search_rom.reg.result);
-
- /**/
- if (ONEWIRE_SEARCH_ROM_ERROR == owp->search_rom.reg.result)
- return 0;
- else
- return owp->search_rom.reg.devices_found;
-}
-
-/**
- *
- */
-static void fill_pattern_real_devices(void) {
- size_t i;
-
- for (i=0; i<SYNTH_DEVICES_MAX; i++)
- synth_bus.devices[i].active = false;
-
- synth_bus.devices[0].active = true;
- synth_bus.devices[0].id = 0x1d00000567f5ec28;
-
- synth_bus.devices[1].active = true;
- synth_bus.devices[1].id = 0x37000005601abd28;
-
- synth_bus.devices[2].active = true;
- synth_bus.devices[2].id = 0x0f000005677d8328;
-}
-
-/**
- *
- */
-static void fill_pattern_00(size_t devices, size_t start) {
- size_t i;
-
- for (i=0; i<SYNTH_DEVICES_MAX; i++)
- synth_bus.devices[i].active = false;
-
- for (i=0; i<devices; i++){
- synth_bus.devices[i].active = true;
- synth_bus.devices[i].id = (start + i);
- }
-}
-
-/**
- *
- */
-static void fill_pattern_01(size_t devices) {
- size_t i;
-
- for (i=0; i<SYNTH_DEVICES_MAX; i++)
- synth_bus.devices[i].active = false;
-
- for (i=0; i<devices; i++){
- synth_bus.devices[i].active = true;
- synth_bus.devices[i].id = (devices - i);
- }
-}
-
-/**
- *
- */
-static void fill_pattern_02(size_t devices) {
- size_t i;
-
- for (i=0; i<SYNTH_DEVICES_MAX; i++)
- synth_bus.devices[i].active = false;
-
- for (i=0; i<devices; i++){
- synth_bus.devices[i].active = true;
- synth_bus.devices[i].id = ((uint64_t)1 << i);
- }
-}
-
-/**
- *
- */
-static void fill_pattern_03(size_t devices) {
- size_t i;
-
- for (i=0; i<SYNTH_DEVICES_MAX; i++)
- synth_bus.devices[i].active = false;
-
- for (i=0; i<devices; i++){
- synth_bus.devices[i].active = true;
- synth_bus.devices[i].id = ((uint64_t)0x8000000000000000 >> i);
- }
-}
-
-/**
- * @brief random pattern helper
- */
-static bool is_id_uniq(const OWSynthDevice *dev, size_t n, uint64_t id) {
- size_t i;
-
- for (i=0; i<n; i++) {
- if (dev[i].id == id)
- return false;
- }
- return true;
-}
-
-/**
- *
- */
-static void fill_pattern_rand(size_t devices) {
- size_t i;
- uint64_t new_id;
-
- for (i=0; i<SYNTH_DEVICES_MAX; i++){
- synth_bus.devices[i].active = false;
- synth_bus.devices[i].id = 0;
- }
-
- for (i=0; i<devices; i++) {
- do {
- new_id = rand();
- new_id = (new_id << 32) | rand();
- } while (true != is_id_uniq(synth_bus.devices, i, new_id));
-
- synth_bus.devices[i].id = new_id;
- synth_bus.devices[i].active = true;
- }
-}
-
-/**
- *
- */
-static bool check_result(size_t detected) {
-
- size_t i,j;
- bool match = false;
-
- for (i=0; i<detected; i++){
- match = false;
- for (j=0; j<detected; j++){
- if (synth_bus.devices[i].id == detected_devices[j]){
- match = true;
- break;
- }
- }
- if (false == match)
- return OSAL_FAILED;
- }
- return OSAL_SUCCESS;
-}
-
-/**
- *
- */
-void synthSearchRomTest(onewireDriver *owp) {
-
- size_t detected = 0;
- size_t i;
-
- synth_bus.dev_present = 3;
- fill_pattern_real_devices();
- detected = synth_search_rom(owp, (uint8_t *)detected_devices, SYNTH_DEVICES_MAX);
- osalDbgCheck(synth_bus.dev_present == detected);
- osalDbgCheck(OSAL_SUCCESS == check_result(detected));
-
- for (i=1; i<=SYNTH_DEVICES_MAX; i++){
- synth_bus.dev_present = i;
-
- fill_pattern_00(synth_bus.dev_present, 0);
- detected = synth_search_rom(owp, (uint8_t *)detected_devices, SYNTH_DEVICES_MAX);
- osalDbgCheck(synth_bus.dev_present == detected);
- osalDbgCheck(OSAL_SUCCESS == check_result(detected));
-
- fill_pattern_00(synth_bus.dev_present, 1);
- detected = synth_search_rom(owp, (uint8_t *)detected_devices, SYNTH_DEVICES_MAX);
- osalDbgCheck(synth_bus.dev_present == detected);
- osalDbgCheck(OSAL_SUCCESS == check_result(detected));
-
- fill_pattern_01(synth_bus.dev_present);
- detected = synth_search_rom(owp, (uint8_t *)detected_devices, SYNTH_DEVICES_MAX);
- osalDbgCheck(synth_bus.dev_present == detected);
- osalDbgCheck(OSAL_SUCCESS == check_result(detected));
-
- fill_pattern_02(synth_bus.dev_present);
- detected = synth_search_rom(owp, (uint8_t *)detected_devices, SYNTH_DEVICES_MAX);
- osalDbgCheck(synth_bus.dev_present == detected);
- osalDbgCheck(OSAL_SUCCESS == check_result(detected));
-
- fill_pattern_03(synth_bus.dev_present);
- detected = synth_search_rom(owp, (uint8_t *)detected_devices, SYNTH_DEVICES_MAX);
- osalDbgCheck(synth_bus.dev_present == detected);
- osalDbgCheck(OSAL_SUCCESS == check_result(detected));
- }
-
- i = 0;
- while (i < 1000) {
- synth_bus.dev_present = 1 + (rand() & 63);
-
- fill_pattern_rand(synth_bus.dev_present);
- detected = synth_search_rom(owp, (uint8_t *)detected_devices, SYNTH_DEVICES_MAX);
- osalDbgCheck(synth_bus.dev_present == detected);
- osalDbgCheck(OSAL_SUCCESS == check_result(detected));
- i++;
- }
-}
-
-