mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-03-01 13:45:25 +08:00
[add] spi loopback test case.
This commit is contained in:
parent
edd3fd2174
commit
ba7865d3f5
@ -517,17 +517,17 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
|||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {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())
|
if(IS_ENGINEERING_BOOT_MODE())
|
||||||
{
|
{
|
||||||
/** Initializes the peripherals clock
|
/** Initializes the peripherals clock
|
||||||
*/
|
*/
|
||||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI45;
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI1;
|
||||||
PeriphClkInit.Spi45ClockSelection = RCC_SPI45CLKSOURCE_PCLK2;
|
PeriphClkInit.Spi1ClockSelection = RCC_SPI1CLKSOURCE_PLL4;
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
@ -536,19 +536,20 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Peripheral clock enable */
|
/* Peripheral clock enable */
|
||||||
__HAL_RCC_SPI5_CLK_ENABLE();
|
__HAL_RCC_SPI1_CLK_ENABLE();
|
||||||
|
|
||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
__HAL_RCC_GPIOZ_CLK_ENABLE();
|
||||||
/**SPI5 GPIO Configuration
|
/**SPI1 GPIO Configuration
|
||||||
PF9 ------> SPI5_MOSI
|
PZ2 ------> SPI1_MOSI
|
||||||
PF7 ------> SPI5_SCK
|
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.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI5;
|
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||||
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOZ, &GPIO_InitStruct);
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI5_MspInit 1 */
|
/* USER CODE BEGIN SPI5_MspInit 1 */
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ CubeMX_Config/Common/System/system_stm32mp1xx.c
|
|||||||
CubeMX_Config/CM4/Src/stm32mp1xx_hal_msp.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']):
|
if GetDepend(['BSP_USING_PMIC']):
|
||||||
src += Glob('ports/drv_pmic.c')
|
src += Glob('ports/drv_pmic.c')
|
||||||
|
|
||||||
@ -55,6 +58,9 @@ if GetDepend(['BSP_USING_DFSDM']):
|
|||||||
if GetDepend(['BSP_USING_WWDG']):
|
if GetDepend(['BSP_USING_WWDG']):
|
||||||
src += Glob('ports/drv_wwdg.c')
|
src += Glob('ports/drv_wwdg.c')
|
||||||
|
|
||||||
|
if GetDepend(['BSP_USING_EXTI']):
|
||||||
|
src += Glob('ports/drv_exti.c')
|
||||||
|
|
||||||
if GetDepend(['BSP_USING_OPENAMP']):
|
if GetDepend(['BSP_USING_OPENAMP']):
|
||||||
src += Glob('CubeMX_Config/CM4/Src/ipcc.c')
|
src += Glob('CubeMX_Config/CM4/Src/ipcc.c')
|
||||||
src += Glob('CubeMX_Config/CM4/Src/openamp.c')
|
src += Glob('CubeMX_Config/CM4/Src/openamp.c')
|
||||||
|
85
bsp/stm32/stm32mp157a-st-ev1/board/ports/spi_sample.c
Normal file
85
bsp/stm32/stm32mp157a-st-ev1/board/ports/spi_sample.c
Normal file
@ -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 */
|
Loading…
x
Reference in New Issue
Block a user