summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bsp/stm32/stm32mp157a-st-ev1/board/CubeMX_Config/CM4/Src/stm32mp1xx_hal_msp.c27
-rw-r--r--bsp/stm32/stm32mp157a-st-ev1/board/SConscript6
-rw-r--r--bsp/stm32/stm32mp157a-st-ev1/board/ports/spi_sample.c85
3 files changed, 105 insertions, 13 deletions
diff --git a/bsp/stm32/stm32mp157a-st-ev1/board/CubeMX_Config/CM4/Src/stm32mp1xx_hal_msp.c b/bsp/stm32/stm32mp157a-st-ev1/board/CubeMX_Config/CM4/Src/stm32mp1xx_hal_msp.c
index ebab8fc422..27d7a2daa2 100644
--- a/bsp/stm32/stm32mp157a-st-ev1/board/CubeMX_Config/CM4/Src/stm32mp1xx_hal_msp.c
+++ b/bsp/stm32/stm32mp157a-st-ev1/board/CubeMX_Config/CM4/Src/stm32mp1xx_hal_msp.c
@@ -517,17 +517,17 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
- if(hspi->Instance==SPI5)
+ if(hspi->Instance==SPI1)
{
- /* USER CODE BEGIN SPI5_MspInit 0 */
+ /* USER CODE BEGIN SPI1_MspInit 0 */
- /* USER CODE END SPI5_MspInit 0 */
+ /* USER CODE END SPI1_MspInit 0 */
if(IS_ENGINEERING_BOOT_MODE())
{
/** Initializes the peripherals clock
*/
- PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI45;
- PeriphClkInit.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PCLK2;
+ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI1;
+ PeriphClkInit.Spi1ClockSelection = RCC_SPI1CLKSOURCE_PLL4;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
@@ -536,19 +536,20 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
}
/* Peripheral clock enable */
- __HAL_RCC_SPI5_CLK_ENABLE();
+ __HAL_RCC_SPI1_CLK_ENABLE();
- __HAL_RCC_GPIOF_CLK_ENABLE();
- /**SPI5 GPIO Configuration
- PF9 ------> SPI5_MOSI
- PF7 ------> SPI5_SCK
+ __HAL_RCC_GPIOZ_CLK_ENABLE();
+ /**SPI1 GPIO Configuration
+ PZ2 ------> SPI1_MOSI
+ PZ1 ------> SPI1_MISO
+ PZ0 ------> SPI1_SCK
*/
- GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_7;
+ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
- GPIO_InitStruct.Alternate = GPIO_AF5_SPI5;
- HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
+ HAL_GPIO_Init(GPIOZ, &GPIO_InitStruct);
/* USER CODE BEGIN SPI5_MspInit 1 */
diff --git a/bsp/stm32/stm32mp157a-st-ev1/board/SConscript b/bsp/stm32/stm32mp157a-st-ev1/board/SConscript
index de477832e0..bf0b6388d4 100644
--- a/bsp/stm32/stm32mp157a-st-ev1/board/SConscript
+++ b/bsp/stm32/stm32mp157a-st-ev1/board/SConscript
@@ -13,6 +13,9 @@ CubeMX_Config/Common/System/system_stm32mp1xx.c
CubeMX_Config/CM4/Src/stm32mp1xx_hal_msp.c
''')
+if GetDepend(['BSP_USING_SPI1']):
+ src += Glob('ports/spi_sample.c')
+
if GetDepend(['BSP_USING_PMIC']):
src += Glob('ports/drv_pmic.c')
@@ -55,6 +58,9 @@ if GetDepend(['BSP_USING_DFSDM']):
if GetDepend(['BSP_USING_WWDG']):
src += Glob('ports/drv_wwdg.c')
+if GetDepend(['BSP_USING_EXTI']):
+ src += Glob('ports/drv_exti.c')
+
if GetDepend(['BSP_USING_OPENAMP']):
src += Glob('CubeMX_Config/CM4/Src/ipcc.c')
src += Glob('CubeMX_Config/CM4/Src/openamp.c')
diff --git a/bsp/stm32/stm32mp157a-st-ev1/board/ports/spi_sample.c b/bsp/stm32/stm32mp157a-st-ev1/board/ports/spi_sample.c
new file mode 100644
index 0000000000..ca31b0aa47
--- /dev/null
+++ b/bsp/stm32/stm32mp157a-st-ev1/board/ports/spi_sample.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2006-2022, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-09-15 thread-liu first version
+ */
+
+#include "board.h"
+
+#if defined(BSP_USING_SPI1)
+#include <drv_spi.h>
+
+#define SPI_NAME "spi1"
+#define SPI_DEVICE_NAME "spi10"
+static struct rt_spi_device *spi_dev = RT_NULL;
+
+/* attach spi1 device */
+static int rt_spi_device_init(void)
+{
+ struct rt_spi_configuration cfg;
+
+ rt_hw_spi_device_attach(SPI_NAME, SPI_DEVICE_NAME, NULL, NULL);
+
+ cfg.data_width = 8;
+ cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB | RT_SPI_NO_CS;
+ cfg.max_hz = 1 *1000 *1000;
+
+ spi_dev = (struct rt_spi_device *)rt_device_find(SPI_DEVICE_NAME);
+
+ if (RT_NULL == spi_dev)
+ {
+ rt_kprintf("spi sample run failed! can't find %s device!\n", SPI_NAME);
+ return RT_ERROR;
+ }
+
+ rt_spi_configure(spi_dev, &cfg);
+
+ return RT_EOK;
+}
+INIT_APP_EXPORT(rt_spi_device_init);
+
+/* spi5 loopback mode test case */
+static int spi_sample(int argc, char **argv)
+{
+ rt_uint8_t t_buf[8], r_buf[8];
+ int i = 0;
+ static struct rt_spi_message msg1;
+
+ if (argc != 9)
+ {
+ rt_kprintf("Usage:\n");
+ rt_kprintf("spi_sample 1 2 3 4 5 6 7 8\n");
+ return -RT_ERROR;
+ }
+
+ for (i = 0; i < 8; i++)
+ {
+ t_buf[i] = atoi(argv[i+1]);
+ }
+
+ msg1.send_buf = &t_buf;
+ msg1.recv_buf = &r_buf;
+ msg1.length = sizeof(t_buf);
+ msg1.cs_take = 1;
+ msg1.cs_release = 0;
+ msg1.next = RT_NULL;
+
+ rt_spi_transfer_message(spi_dev, &msg1);
+
+ rt_kprintf("spi rbuf : ");
+ for (i = 0; i < sizeof(t_buf); i++)
+ {
+ rt_kprintf("%x ", r_buf[i]);
+ }
+
+ rt_kprintf("\nspi loopback mode test over!\n");
+
+ return RT_EOK;
+}
+MSH_CMD_EXPORT(spi_sample, spi loopback test);
+
+#endif /* BSP_USING_SPI5 */