Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spi_init_master should be more generic. #68

Open
rewolff opened this issue May 18, 2014 · 1 comment
Open

spi_init_master should be more generic. #68

rewolff opened this issue May 18, 2014 · 1 comment

Comments

@rewolff
Copy link

rewolff commented May 18, 2014

I manged to issue a "pull request" for the libopencm3.
But somehow my git is now messed up, so I'm getting push/pull/merge errors when I try to clean up the patch. So... here is the patch:

diff --git a/examples/stm32/f1/lisa-m-1/usb_hid/usbhid.c b/examples/stm32/f1/lisa-m-1/usb_hid/usbhid.c
index dd84f80..17765c5 100644
--- a/examples/stm32/f1/lisa-m-1/usb_hid/usbhid.c
+++ b/examples/stm32/f1/lisa-m-1/usb_hid/usbhid.c
@@ -345,11 +345,11 @@ int main(void)
        /* Force to SPI mode. This should be default after reset! */
        SPI2_I2SCFGR = 0;
        spi_init_master(SPI2,
-                       SPI_CR1_BAUDRATE_FPCLK_DIV_256,
-                       SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE,
-                       SPI_CR1_CPHA_CLK_TRANSITION_2,
-                       SPI_CR1_DFF_8BIT,
-                       SPI_CR1_MSBFIRST);
+                       SPI_BAUDRATE_CLK_DIV_256,
+                       SPI_CLK_TO_1_WHEN_IDLE,
+                       SPI_LATCH_RISING,
+                       SPI_FORMAT_8BIT,
+                       SPI_MSBFIRST);
        /* Ignore the stupid NSS pin. */
        spi_enable_software_slave_management(SPI2);
        spi_set_nss_high(SPI2);
diff --git a/examples/stm32/f1/lisa-m-2/spi/spi.c b/examples/stm32/f1/lisa-m-2/spi/spi.c
index f94aaeb..b1f0c0a 100644
--- a/examples/stm32/f1/lisa-m-2/spi/spi.c
+++ b/examples/stm32/f1/lisa-m-2/spi/spi.c
@@ -68,8 +68,8 @@ static void spi_setup(void) {
    * Data frame format: 8-bit
    * Frame format: MSB First
    */
-  spi_init_master(SPI1, SPI_CR1_BAUDRATE_FPCLK_DIV_64, SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE,
-                  SPI_CR1_CPHA_CLK_TRANSITION_2, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
+  spi_init_master(SPI1, SPI_BAUDRATE_CLK_DIV_64, SPI_CLK_TO_1_WHEN_IDLE,
+                  SPI_LATCH_RISING, SPI_FORMAT_8BIT, SPI_MSBFIRST);

   /*
    * Set NSS management to software.
diff --git a/examples/stm32/f1/lisa-m-2/spi_dma/spi_dma.c b/examples/stm32/f1/lisa-m-2/spi_dma/spi_dma.c
index bf948ba..b460244 100644
--- a/examples/stm32/f1/lisa-m-2/spi_dma/spi_dma.c
+++ b/examples/stm32/f1/lisa-m-2/spi_dma/spi_dma.c
@@ -97,12 +97,12 @@ static void spi_setup(void) {
         * Frame format: MSB First
         */
 #if USE_16BIT_TRANSFERS
-       spi_init_master(SPI1, SPI_CR1_BAUDRATE_FPCLK_DIV_64, SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE,
-                       SPI_CR1_CPHA_CLK_TRANSITION_2, SPI_CR1_DFF_16BIT, SPI_CR1_MSBFIRST);
+#define MY_FORMAT SPI_FORMAT_16BIT
 #else
-       spi_init_master(SPI1, SPI_CR1_BAUDRATE_FPCLK_DIV_64, SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE,
-                       SPI_CR1_CPHA_CLK_TRANSITION_2, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
+#define MY_FORMAT SPI_FORMAT_8BIT
 #endif
+       spi_init_master(SPI1, SPI_BAUDRATE_CLK_DIV_64, SPI_CLK_TO_1_WHEN_IDLE,
+                       SPI_LATCH_RISING, MY_FORMAT, SPI_MSBFIRST);

        /*
         * Set NSS management to software.
diff --git a/examples/stm32/f1/lisa-m-2/spi_dma_adv/spi_dma_adv.c b/examples/stm32/f1/lisa-m-2/spi_dma_adv/spi_dma_adv.c
index 2182865..5947fb6 100644
--- a/examples/stm32/f1/lisa-m-2/spi_dma_adv/spi_dma_adv.c
+++ b/examples/stm32/f1/lisa-m-2/spi_dma_adv/spi_dma_adv.c
@@ -107,13 +107,14 @@ static void spi_setup(void) {
         * Frame format: MSB First
         */
 #if USE_16BIT_TRANSFERS
-       spi_init_master(SPI1, SPI_CR1_BAUDRATE_FPCLK_DIV_64, SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE,
-                       SPI_CR1_CPHA_CLK_TRANSITION_2, SPI_CR1_DFF_16BIT, SPI_CR1_MSBFIRST);
-#else
-       spi_init_master(SPI1, SPI_CR1_BAUDRATE_FPCLK_DIV_64, SPI_CR1_CPOL_CLK_TO_1_WHEN_IDLE,
-                       SPI_CR1_CPHA_CLK_TRANSITION_2, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
+#define MY_BIT_FORMAT SPI_FORMAT_16BIT
+#else 
+#define MY_BIT_FORMAT SPI_FORMAT_8BIT
 #endif

+       spi_init_master(SPI1, SPI_BAUDRATE_CLK_DIV_64, SPI_CLK_TO_1_WHEN_IDLE,
+                       SPI_LATCH_RISING, MY_BIT_FORMAT, SPI_MSBFIRST);
+
        /*
         * Set NSS management to software.
         *
diff --git a/examples/stm32/f2/jobygps/spi_test/spi_test.c b/examples/stm32/f2/jobygps/spi_test/spi_test.c
index bb570c2..10d6f65 100644
--- a/examples/stm32/f2/jobygps/spi_test/spi_test.c
+++ b/examples/stm32/f2/jobygps/spi_test/spi_test.c
@@ -45,8 +45,8 @@ static void spi_setup(void)
        gpio_set_af(GPIOB, GPIO_AF5, GPIO13 | GPIO14 | GPIO15);

        /* Setup SPI parameters. */
-       spi_init_master(SPI2, SPI_CR1_BAUDRATE_FPCLK_DIV_256, SPI_CR1_CPOL,
-                       SPI_CR1_CPHA, SPI_CR1_DFF_8BIT, SPI_CR1_MSBFIRST);
+       spi_init_master(SPI2, SPI_BAUDRATE_CLK_DIV_256, SPI_CLK_TO_1_WHEN_IDLE,
+                       SPI_LATCH_RISING, SPI_FORMAT_8BIT, SPI_MSBFIRST);
        spi_enable_ss_output(SPI2); /* Required, see NSS, 25.3.1 section. */

        /* Finally enable the SPI. */
@rewolff
Copy link
Author

rewolff commented May 18, 2014

This depends on the defines I added to libopencm3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant