aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/STM32F3xx/SPI-N25Q128
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-05-09 10:23:42 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-05-09 10:23:42 +0000
commitf0d90404d995f4a023be047e7d431c81ff56ed5a (patch)
tree3ae25718cad5cdc8a081bfc3e739cc39a2156bed /testhal/STM32/STM32F3xx/SPI-N25Q128
parent0e5cd3594e812de478ba88b184cb462a7f2d1f55 (diff)
downloadChibiOS-f0d90404d995f4a023be047e7d431c81ff56ed5a.tar.gz
ChibiOS-f0d90404d995f4a023be047e7d431c81ff56ed5a.tar.bz2
ChibiOS-f0d90404d995f4a023be047e7d431c81ff56ed5a.zip
Flash driver works.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9454 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32/STM32F3xx/SPI-N25Q128')
-rw-r--r--testhal/STM32/STM32F3xx/SPI-N25Q128/debug/STM32F3xx-SPI-N25Q128 (OpenOCD, Flash and Run).launch2
-rw-r--r--testhal/STM32/STM32F3xx/SPI-N25Q128/main.c86
-rw-r--r--testhal/STM32/STM32F3xx/SPI-N25Q128/mcuconf.h4
3 files changed, 89 insertions, 3 deletions
diff --git a/testhal/STM32/STM32F3xx/SPI-N25Q128/debug/STM32F3xx-SPI-N25Q128 (OpenOCD, Flash and Run).launch b/testhal/STM32/STM32F3xx/SPI-N25Q128/debug/STM32F3xx-SPI-N25Q128 (OpenOCD, Flash and Run).launch
index 3d2ffb322..f8a5dd2d5 100644
--- a/testhal/STM32/STM32F3xx/SPI-N25Q128/debug/STM32F3xx-SPI-N25Q128 (OpenOCD, Flash and Run).launch
+++ b/testhal/STM32/STM32F3xx/SPI-N25Q128/debug/STM32F3xx-SPI-N25Q128 (OpenOCD, Flash and Run).launch
@@ -33,7 +33,7 @@
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
-<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList/&gt;"/>
+<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&lt;contentList&gt;&lt;content id=&quot;cmd-flash_send_cmd-(format)&quot; val=&quot;4&quot;/&gt;&lt;content id=&quot;null-main-(format)&quot; val=&quot;0&quot;/&gt;&lt;content id=&quot;buffer[0]-null-main-(format)&quot; val=&quot;0&quot;/&gt;&lt;/contentList&gt;"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
diff --git a/testhal/STM32/STM32F3xx/SPI-N25Q128/main.c b/testhal/STM32/STM32F3xx/SPI-N25Q128/main.c
index 7df94b53f..c8ca4aaa4 100644
--- a/testhal/STM32/STM32F3xx/SPI-N25Q128/main.c
+++ b/testhal/STM32/STM32F3xx/SPI-N25Q128/main.c
@@ -20,6 +20,46 @@
#include "n25q128.h"
/*
+ * Maximum speed SPI configuration (18MHz, CPHA=0, CPOL=0, MSb first).
+ */
+static const SPIConfig hs_spicfg = {
+ NULL,
+ GPIOB,
+ 12,
+ 0,
+ SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
+};
+
+/*
+ * Flash driver configuration.
+ */
+static const N25Q128Config flashcfg = {
+ &SPID2,
+ &hs_spicfg
+};
+
+/*
+ * Flash driver object.
+ */
+static N25Q128Driver flash;
+
+/*
+ * Generic buffer.
+ */
+uint8_t buffer[2048];
+
+const uint8_t pattern[128] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
+};
+
+/*
* LED blinker thread, times are in milliseconds.
*/
static THD_WORKING_AREA(waThread1, 128);
@@ -37,6 +77,7 @@ static THD_FUNCTION(Thread1, arg) {
* Application entry point.
*/
int main(void) {
+ flash_error_t err;
/*
* System initializations.
@@ -53,6 +94,51 @@ int main(void) {
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL);
+
+ /*
+ * SPI2 I/O pins setup.
+ */
+ palSetPad(GPIOB, 12);
+ palSetPadMode(GPIOB, 12, PAL_MODE_OUTPUT_PUSHPULL |
+ PAL_STM32_OSPEED_HIGHEST); /* New CS. */
+ palSetPadMode(GPIOB, 13, PAL_MODE_ALTERNATE(5) |
+ PAL_STM32_OSPEED_HIGHEST); /* New SCK. */
+ palSetPadMode(GPIOB, 14, PAL_MODE_ALTERNATE(5) |
+ PAL_STM32_OSPEED_HIGHEST); /* New MISO. */
+ palSetPadMode(GPIOB, 15, PAL_MODE_ALTERNATE(5) |
+ PAL_STM32_OSPEED_HIGHEST); /* New MOSI. */
+
+ /*
+ * Initializing and starting flash driver.
+ */
+ n25q128ObjectInit(&flash);
+ n25q128Start(&flash, &flashcfg);
+
+ /*
+ * Reading flash identifier.
+ */
+ n25q128ReadId(&flash, buffer, 17);
+
+ /*
+ * Writing then reading a pattern on a single page with final erase and
+ * verify.
+ */
+ err = flashProgram(&flash, 0, pattern, 128);
+ if (err != FLASH_NO_ERROR)
+ chSysHalt("program error");
+ err = flashRead(&flash, 0, buffer, 128);
+ if (err != FLASH_NO_ERROR)
+ chSysHalt("read error");
+ err = flashEraseSectors(&flash, 0, 1);
+ if (err != FLASH_NO_ERROR)
+ chSysHalt("erase error");
+ err = flashVerifyErase(&flash, 0, 1);
+ if (err != FLASH_NO_ERROR)
+ chSysHalt("verify erase error");
+ err = flashRead(&flash, 0, buffer, 128);
+ if (err != FLASH_NO_ERROR)
+ chSysHalt("read error");
+
while (true) {
chThdSleepMilliseconds(500);
}
diff --git a/testhal/STM32/STM32F3xx/SPI-N25Q128/mcuconf.h b/testhal/STM32/STM32F3xx/SPI-N25Q128/mcuconf.h
index 09de76c82..8d7a8d2ef 100644
--- a/testhal/STM32/STM32F3xx/SPI-N25Q128/mcuconf.h
+++ b/testhal/STM32/STM32F3xx/SPI-N25Q128/mcuconf.h
@@ -206,8 +206,8 @@
/*
* SPI driver system settings.
*/
-#define STM32_SPI_USE_SPI1 TRUE
-#define STM32_SPI_USE_SPI2 FALSE
+#define STM32_SPI_USE_SPI1 FALSE
+#define STM32_SPI_USE_SPI2 TRUE
#define STM32_SPI_USE_SPI3 FALSE
#define STM32_SPI_SPI1_DMA_PRIORITY 1
#define STM32_SPI_SPI2_DMA_PRIORITY 1