2013-02-21 18:52:17 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <board.h>
|
|
|
|
|
|
|
|
#ifdef RT_USING_LWIP
|
|
|
|
#include "stm32_eth.h"
|
|
|
|
#endif /* RT_USING_LWIP */
|
|
|
|
|
2013-02-21 20:10:54 +08:00
|
|
|
#ifdef RT_USING_SPI
|
|
|
|
#include "rt_stm32f10x_spi.h"
|
|
|
|
|
2018-02-06 20:26:49 +08:00
|
|
|
#if defined(RT_USING_DFS) && defined(RT_USING_SPI_MSD)
|
|
|
|
#include "spi_msd.h"
|
2013-02-21 20:10:54 +08:00
|
|
|
#endif /* RT_USING_DFS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SPI1_MOSI: PA7
|
|
|
|
* SPI1_MISO: PA6
|
|
|
|
* SPI1_SCK : PA5
|
|
|
|
*
|
|
|
|
* CS0: PA4 SD card.
|
|
|
|
*/
|
|
|
|
static void rt_hw_spi_init(void)
|
|
|
|
{
|
|
|
|
#ifdef RT_USING_SPI1
|
|
|
|
/* register spi bus */
|
|
|
|
{
|
|
|
|
static struct stm32_spi_bus stm32_spi;
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
/* Enable GPIO clock */
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,
|
|
|
|
ENABLE);
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
|
|
|
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
stm32_spi_register(SPI1, &stm32_spi, "spi1");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* attach cs */
|
|
|
|
{
|
|
|
|
static struct rt_spi_device spi_device;
|
|
|
|
static struct stm32_spi_cs spi_cs;
|
|
|
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
|
|
|
|
/* spi21: PG10 */
|
|
|
|
spi_cs.GPIOx = GPIOA;
|
|
|
|
spi_cs.GPIO_Pin = GPIO_Pin_4;
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = spi_cs.GPIO_Pin;
|
|
|
|
GPIO_SetBits(spi_cs.GPIOx, spi_cs.GPIO_Pin);
|
|
|
|
GPIO_Init(spi_cs.GPIOx, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
rt_spi_bus_attach_device(&spi_device, "spi10", "spi1", (void*)&spi_cs);
|
|
|
|
}
|
|
|
|
#endif /* RT_USING_SPI1 */
|
|
|
|
}
|
|
|
|
#endif /* RT_USING_SPI */
|
|
|
|
|
|
|
|
|
2013-02-21 18:52:17 +08:00
|
|
|
void rt_platform_init(void)
|
|
|
|
{
|
2013-02-21 20:10:54 +08:00
|
|
|
#ifdef RT_USING_SPI
|
|
|
|
rt_hw_spi_init();
|
2013-02-21 18:52:17 +08:00
|
|
|
|
2018-02-06 20:26:49 +08:00
|
|
|
#if defined(RT_USING_DFS) && defined(RT_USING_SPI_MSD)
|
2013-02-21 18:52:17 +08:00
|
|
|
/* init sdcard driver */
|
|
|
|
{
|
|
|
|
extern void rt_hw_msd_init(void);
|
2013-02-21 20:10:54 +08:00
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
|
|
|
/* PC4 : SD Power */
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
|
|
|
|
|
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
|
|
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
|
|
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
|
|
GPIO_Init(GPIOC, &GPIO_InitStructure);
|
|
|
|
|
|
|
|
/* SD card power on. */
|
|
|
|
GPIO_ResetBits(GPIOC, GPIO_Pin_4);
|
|
|
|
rt_thread_delay(2);
|
|
|
|
|
|
|
|
msd_init("sd0", "spi10");
|
2013-02-21 18:52:17 +08:00
|
|
|
}
|
2018-02-06 20:26:49 +08:00
|
|
|
#endif /* RT_USING_DFS && RT_USING_SPI_MSD */
|
2013-02-21 20:10:54 +08:00
|
|
|
|
|
|
|
#endif // RT_USING_SPI
|
|
|
|
|
|
|
|
#ifdef RT_USING_LWIP
|
|
|
|
/* initialize eth interface */
|
|
|
|
rt_hw_stm32_eth_init();
|
|
|
|
#endif /* RT_USING_LWIP */
|
|
|
|
|
2013-02-21 18:52:17 +08:00
|
|
|
}
|