From 7e46dc94aa5d6bad9ff7e449878f64938b2437f1 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 9 Jan 2018 15:39:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11242 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- .../multi/SPI/cfg-stm32h743_nucleo144/portab.c | 20 +++++++- .../multi/SPI/cfg-stm32h743_nucleo144/portab.h | 1 + testhal/STM32/multi/SPI/main.c | 54 ++++++++++++++++++---- 3 files changed, 63 insertions(+), 12 deletions(-) (limited to 'testhal/STM32') 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. @@ -107,6 +130,11 @@ int main(void) { */ portab_setup(); + /* + * Creates the blinker thread. + */ + chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); + /* * Prepare transmit pattern. */ @@ -114,6 +142,19 @@ int main(void) { 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. */ -- cgit v1.2.3