aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/multi
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-01-09 15:39:54 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-01-09 15:39:54 +0000
commit7e46dc94aa5d6bad9ff7e449878f64938b2437f1 (patch)
tree70cdbe952a24ebdae5f6ab406d7faa3ba72608c3 /testhal/STM32/multi
parentcafec08d95c1428645e3b2efa59d11a3a5c1d432 (diff)
downloadChibiOS-7e46dc94aa5d6bad9ff7e449878f64938b2437f1.tar.gz
ChibiOS-7e46dc94aa5d6bad9ff7e449878f64938b2437f1.tar.bz2
ChibiOS-7e46dc94aa5d6bad9ff7e449878f64938b2437f1.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11242 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32/multi')
-rw-r--r--testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.c20
-rw-r--r--testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.h1
-rwxr-xr-xtesthal/STM32/multi/SPI/main.c54
3 files changed, 63 insertions, 12 deletions
diff --git a/testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.c b/testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.c
index 152b669e8..42caab502 100644
--- a/testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.c
+++ b/testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.c
@@ -34,10 +34,25 @@
/* Module exported variables. */
/*===========================================================================*/
+void spi_circular_cb(SPIDriver *spip);
+
+/*
+ * Circular SPI configuration (25MHz, CPHA=0, CPOL=0, MSb first).
+ */
+const SPIConfig c_spicfg = {
+ true,
+ spi_circular_cb,
+ GPIOD,
+ GPIOD_SPI1_NSS,
+ SPI_CFG1_MBR_DIV8 | SPI_CFG1_DSIZE_VALUE(7),
+ 0
+};
+
/*
- * Maximum speed SPI configuration (21MHz, CPHA=0, CPOL=0, MSb first).
+ * Maximum speed SPI configuration (25MHz, CPHA=0, CPOL=0, MSb first).
*/
const SPIConfig hs_spicfg = {
+ false,
NULL,
GPIOD,
GPIOD_SPI1_NSS,
@@ -46,9 +61,10 @@ const SPIConfig hs_spicfg = {
};
/*
- * Low speed SPI configuration (328.125kHz, CPHA=0, CPOL=0, MSb first).
+ * Low speed SPI configuration (1.5625MHz, CPHA=0, CPOL=0, MSb first).
*/
const SPIConfig ls_spicfg = {
+ false,
NULL,
GPIOD,
GPIOD_SPI1_NSS,
diff --git a/testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.h b/testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.h
index 901638a7f..b36241ad9 100644
--- a/testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.h
+++ b/testhal/STM32/multi/SPI/cfg-stm32h743_nucleo144/portab.h
@@ -57,6 +57,7 @@
/* External declarations. */
/*===========================================================================*/
+extern const SPIConfig c_spicfg;
extern const SPIConfig hs_spicfg;
extern const SPIConfig ls_spicfg;
diff --git a/testhal/STM32/multi/SPI/main.c b/testhal/STM32/multi/SPI/main.c
index 85328a6a3..d4e5e3e80 100755
--- a/testhal/STM32/multi/SPI/main.c
+++ b/testhal/STM32/multi/SPI/main.c
@@ -26,6 +26,23 @@
CC_ALIGN(32) static uint8_t txbuf[512];
CC_ALIGN(32) static uint8_t rxbuf[512];
+#if SPI_SUPPORTS_CIRCULAR == TRUE
+/*
+ * SPI callback for circular operations.
+ */
+void spi_circular_cb(SPIDriver *spip) {
+
+ if(spip->state == SPI_COMPLETE) {
+ /* 2nd half.*/
+ palWriteLine(PORTAB_LINE_LED1, PORTAB_LED_OFF);
+ }
+ else {
+ /* 1st half.*/
+ palWriteLine(PORTAB_LINE_LED1, PORTAB_LED_ON);
+ }
+}
+#endif
+
/*
* SPI bus contender 1.
*/
@@ -70,7 +87,6 @@ static THD_FUNCTION(spi_thread_2, p) {
}
}
-#if defined(PORTAB_LINE_LED2)
/*
* LED blinker thread, times are in milliseconds.
*/
@@ -79,12 +95,19 @@ static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("blinker");
while (true) {
- systime_t time = palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED ? 250 : 500;
+ bool key_pressed = palReadLine(PORTAB_LINE_BUTTON) == PORTAB_BUTTON_PRESSED;
+ systime_t time = key_pressed ? 250 : 500;
+#if SPI_SUPPORTS_CIRCULAR == TRUE
+ if (key_pressed) {
+ spiAbort(&PORTAB_SPI1);
+ }
+#endif
+#if defined(PORTAB_LINE_LED2)
palToggleLine(PORTAB_LINE_LED2);
+#endif
chThdSleepMilliseconds(time);
}
}
-#endif
/*
* Application entry point.
@@ -108,12 +131,30 @@ int main(void) {
portab_setup();
/*
+ * Creates the blinker thread.
+ */
+ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
+
+ /*
* Prepare transmit pattern.
*/
for (i = 0; i < sizeof(txbuf); i++)
txbuf[i] = (uint8_t)i;
cacheBufferFlush(&txbuf[0], sizeof txbuf);
+#if SPI_SUPPORTS_CIRCULAR == TRUE
+ /*
+ * Starting a continous operation for test.
+ */
+ spiStart(&PORTAB_SPI1, &c_spicfg); /* Setup transfer parameters. */
+ spiSelect(&PORTAB_SPI1); /* Slave Select assertion. */
+ spiExchange(&PORTAB_SPI1, 512,
+ txbuf, rxbuf); /* Atomic transfer operations. */
+ spiUnselect(&PORTAB_SPI1); /* Slave Select de-assertion. */
+ cacheBufferInvalidate(&txbuf[0], /* Cache invalidation over the */
+ sizeof txbuf);/* buffer. */
+#endif
+
/*
* Starting the transmitter and receiver threads.
*/
@@ -122,13 +163,6 @@ int main(void) {
chThdCreateStatic(spi_thread_2_wa, sizeof(spi_thread_2_wa),
NORMALPRIO + 1, spi_thread_2, NULL);
-#if defined(PORTAB_LINE_LED2)
- /*
- * Creates the blinker thread.
- */
- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
-#endif
-
/*
* Normal main() thread activity, in this demo it does nothing.
*/