summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Palsson <karlp@tweak.net.au>2018-04-17 22:53:25 +0000
committerKarl Palsson <karlp@tweak.net.au>2018-04-17 22:53:25 +0000
commit90ce052d82daa86e1e86ab4dac7fbba0cdda8680 (patch)
tree15e5d715d0b01fba81e785cf2b2650a523313368
parent3ee8c6f8b9fa35ccd91b74ecb349e635463104c1 (diff)
downloadolsndot-90ce052d82daa86e1e86ab4dac7fbba0cdda8680.tar.gz
olsndot-90ce052d82daa86e1e86ab4dac7fbba0cdda8680.tar.bz2
olsndot-90ce052d82daa86e1e86ab4dac7fbba0cdda8680.zip
spi-master: functional spi slave on l1 host
Doesn't do much other than reply with an increasing pattern, but at least the basic wiring is now in place.
-rw-r--r--tests/spi-master/Makefile.host-stm32l1-generic (renamed from tests/spi-master/Makefile.stm32l1-generic)4
-rw-r--r--tests/spi-master/main-dut-stm32l073rz.c7
-rw-r--r--tests/spi-master/main-host-stm32l1-generic.c (renamed from tests/spi-master/main-stm32l1-generic.c)47
3 files changed, 29 insertions, 29 deletions
diff --git a/tests/spi-master/Makefile.stm32l1-generic b/tests/spi-master/Makefile.host-stm32l1-generic
index 52ad2ec..8996ff7 100644
--- a/tests/spi-master/Makefile.stm32l1-generic
+++ b/tests/spi-master/Makefile.host-stm32l1-generic
@@ -1,5 +1,5 @@
-BOARD = stm32l1-generic
-PROJECT = spi-master-$(BOARD)
+BOARD = host-stm32l1-generic
+PROJECT = spi-slave-$(BOARD)
BUILD_DIR = bin-$(BOARD)
SHARED_DIR = ../../shared
diff --git a/tests/spi-master/main-dut-stm32l073rz.c b/tests/spi-master/main-dut-stm32l073rz.c
index 63898d5..058d841 100644
--- a/tests/spi-master/main-dut-stm32l073rz.c
+++ b/tests/spi-master/main-dut-stm32l073rz.c
@@ -52,7 +52,7 @@ static void test_init(void)
{
/* Setup SPI parameters. */
rcc_periph_clock_enable(hw_details.periph_rcc);
- spi_init_master(hw_details.periph, SPI_CR1_BAUDRATE_FPCLK_DIV_64, SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE,
+ spi_init_master(hw_details.periph, SPI_CR1_BAUDRATE_FPCLK_DIV_32, SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE,
SPI_CR1_CPHA_CLK_TRANSITION_1, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
/* Ignore the stupid NSS pin. */
spi_enable_software_slave_management(hw_details.periph);
@@ -64,12 +64,13 @@ static void test_init(void)
static void test_task(void) {
static int i = 0;
+ printf("DUT iter %d\n", i++);
gpio_set(hw_details.trigger_port, hw_details.trigger_pin);
- printf("Test iteration %d\n", i++);
+ gpio_clear(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN);
spi_xfer(hw_details.periph, 0xaa);
spi_xfer(hw_details.periph, 0x42);
spi_xfer(hw_details.periph, 0x69);
-
+ gpio_set(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN);
gpio_clear(hw_details.trigger_port, hw_details.trigger_pin);
}
diff --git a/tests/spi-master/main-stm32l1-generic.c b/tests/spi-master/main-host-stm32l1-generic.c
index 38d3525..fa40ba1 100644
--- a/tests/spi-master/main-stm32l1-generic.c
+++ b/tests/spi-master/main-host-stm32l1-generic.c
@@ -14,10 +14,6 @@
#include "hw.h"
-#define LED_DISCO_GREEN_PORT GPIOB
-#define LED_DISCO_GREEN_PIN GPIO8
-
-
struct hw_detail hw_details = {
.periph = SPI2,
.periph_rcc = RCC_SPI2,
@@ -53,26 +49,37 @@ static void test_init(void)
{
/* Setup SPI parameters. */
rcc_periph_clock_enable(hw_details.periph_rcc);
- spi_init_master(hw_details.periph, SPI_CR1_BAUDRATE_FPCLK_DIV_16, SPI_CR1_CPOL_CLK_TO_0_WHEN_IDLE,
- SPI_CR1_CPHA_CLK_TRANSITION_1, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
- /* Ignore the stupid NSS pin. */
- spi_enable_software_slave_management(hw_details.periph);
- //spi_enable_ss_output(MRF_SPI);
- spi_set_nss_high(hw_details.periph);
+ /* mostly, this is just "write 0 to cr1" */
+ spi_set_slave_mode(hw_details.periph);
+ spi_send_msb_first(hw_details.periph);
+ spi_set_dff_8bit(hw_details.periph);
+ spi_set_clock_phase_0(hw_details.periph);
+ spi_set_clock_polarity_0(hw_details.periph);
+ spi_set_frf_motorola(hw_details.periph);
+
+ /* we're a spi slave, use a CS pin */
+ spi_disable_software_slave_management(hw_details.periph);
+ SPI_CR2(hw_details.periph) &= ~SPI_CR2_SSOE;
+
/* Finally enable the SPI. */
spi_enable(hw_details.periph);
}
static void test_task(void) {
static int i = 0;
- printf("Test iteration %d\n", i++);
- gpio_set(hw_details.trigger_port, hw_details.trigger_pin);
- spi_xfer(hw_details.periph, 0xaa);
- spi_xfer(hw_details.periph, 0x42);
- spi_xfer(hw_details.periph, 0x69);
- gpio_clear(hw_details.trigger_port, hw_details.trigger_pin);
+ uint32_t spi = hw_details.periph;
+ if (SPI_SR(spi) & SPI_SR_TXE) {
+ /* ready to load next data in */
+ SPI_DR(spi) = i++;
+ }
+
+ if (SPI_SR(spi) & SPI_SR_RXNE) {
+ uint8_t data = SPI_DR(spi);
+ trace_send8(2, data);
+ }
}
+
static void setup(void)
{
printf("hi guys!\n");
@@ -98,18 +105,10 @@ int main(void)
};
int i, j;
rcc_clock_setup_pll(&myclock);
- /* green led for ticking */
- rcc_periph_clock_enable(RCC_GPIOB);
- gpio_mode_setup(LED_DISCO_GREEN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,
- LED_DISCO_GREEN_PIN);
setup();
while (1) {
test_task();
- gpio_toggle(LED_DISCO_GREEN_PORT, LED_DISCO_GREEN_PIN);
- for (i = 0; i < 0x800000; i++) { /* Wait a bit. */
- __asm__("NOP");
- }
}
return 0;
}