forked from xuos/xiuos
remove adc string
This commit is contained in:
parent
efd8999988
commit
f942af6c43
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
|
@ -37,14 +37,6 @@
|
|||
|
||||
#define adc_print KPrintf
|
||||
|
||||
#define ADC1_BUS_NAME "adc1"
|
||||
#define ADC1_DRV_NAME "adc1_drv"
|
||||
#define ADC1_DEV_NAME "adc1_dev"
|
||||
|
||||
#define ADC2_BUS_NAME "adc2"
|
||||
#define ADC2_DRV_NAME "adc2_drv"
|
||||
#define ADC2_DEV_NAME "adc2_dev"
|
||||
|
||||
volatile bool adc1_flag;
|
||||
volatile uint32_t adc1_val;
|
||||
volatile uint32_t adc1_irq_cnt;
|
||||
|
@ -92,7 +84,7 @@ uint32 Imrt1052AdcOpen(void *dev)
|
|||
adc_config_t adc_cfg;
|
||||
|
||||
#ifdef BSP_USING_ADC1
|
||||
if (0 == strncmp(adc_dev->haldev.dev_name, ADC1_DEV_NAME, NAME_NUM_MAX)) {
|
||||
if (0 == strncmp(adc_dev->haldev.dev_name, ADC_1_DEVICE_NAME_0, NAME_NUM_MAX)) {
|
||||
EnableIRQ(ADC1_IRQn);
|
||||
ADC_GetDefaultConfig(&adc_cfg);
|
||||
ADC_Init(ADC1, &adc_cfg);
|
||||
|
@ -112,7 +104,7 @@ uint32 Imrt1052AdcOpen(void *dev)
|
|||
#endif
|
||||
|
||||
#ifdef BSP_USING_ADC2
|
||||
if (0 == strncmp(adc_dev->haldev.dev_name, ADC2_DEV_NAME, NAME_NUM_MAX)) {
|
||||
if (0 == strncmp(adc_dev->haldev.dev_name, ADC_2_DEVICE_NAME_0, NAME_NUM_MAX)) {
|
||||
EnableIRQ(ADC2_IRQn);
|
||||
ADC_GetDefaultConfig(&adc_cfg);
|
||||
ADC_Init(ADC2, &adc_cfg);
|
||||
|
@ -145,7 +137,7 @@ uint32 Imrt1052AdcRead(void *dev, struct BusBlockReadParam *read_param)
|
|||
adc_channel_config_t ch_cfg;
|
||||
|
||||
#ifdef BSP_USING_ADC1
|
||||
if (0 == strncmp(adc_dev->haldev.dev_name, ADC1_DEV_NAME, NAME_NUM_MAX)) {
|
||||
if (0 == strncmp(adc_dev->haldev.dev_name, ADC_1_DEVICE_NAME_0, NAME_NUM_MAX)) {
|
||||
/* Configure the user channel and interrupt. */
|
||||
ch_cfg.channelNumber = ADC1_USER_CHANNEL;
|
||||
ch_cfg.enableInterruptOnConversionCompleted = true;
|
||||
|
@ -160,7 +152,7 @@ uint32 Imrt1052AdcRead(void *dev, struct BusBlockReadParam *read_param)
|
|||
#endif
|
||||
|
||||
#ifdef BSP_USING_ADC2
|
||||
if (0 == strncmp(adc_dev->haldev.dev_name, ADC2_DEV_NAME, NAME_NUM_MAX)) {
|
||||
if (0 == strncmp(adc_dev->haldev.dev_name, ADC_2_DEVICE_NAME_0, NAME_NUM_MAX)) {
|
||||
/* Configure the user channel and interrupt. */
|
||||
ch_cfg.channelNumber = ADC2_USER_CHANNEL;
|
||||
ch_cfg.enableInterruptOnConversionCompleted = true;
|
||||
|
@ -226,18 +218,18 @@ int Imrt1052HwAdcInit(void)
|
|||
|
||||
adc1_drv.configure = Imrt1052AdcDrvConfigure;
|
||||
|
||||
ret = AdcBusInit(&adc1_bus, ADC1_BUS_NAME);
|
||||
ret = AdcBusInit(&adc1_bus, ADC_BUS_NAME_1);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC1 bus init error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = AdcDriverInit(&adc1_drv, ADC1_DRV_NAME);
|
||||
ret = AdcDriverInit(&adc1_drv, ADC_DRV_NAME_1);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC1 driver init error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
ret = AdcDriverAttachToBus(ADC1_DRV_NAME, ADC1_BUS_NAME);
|
||||
ret = AdcDriverAttachToBus(ADC_DRV_NAME_1, ADC_BUS_NAME_1);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC1 driver attach error %d\n", ret);
|
||||
return ERROR;
|
||||
|
@ -245,13 +237,13 @@ int Imrt1052HwAdcInit(void)
|
|||
|
||||
adc1_dev.adc_dev_done = &dev_done;
|
||||
|
||||
ret = AdcDeviceRegister(&adc1_dev, (void *)&adc1_cfg, ADC1_DEV_NAME);
|
||||
ret = AdcDeviceRegister(&adc1_dev, (void *)&adc1_cfg, ADC_1_DEVICE_NAME_0);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC1 device register error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = AdcDeviceAttachToBus(ADC1_DEV_NAME, ADC1_BUS_NAME);
|
||||
ret = AdcDeviceAttachToBus(ADC_1_DEVICE_NAME_0, ADC_BUS_NAME_1);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC1 device register error %d\n", ret);
|
||||
return ERROR;
|
||||
|
@ -266,18 +258,18 @@ int Imrt1052HwAdcInit(void)
|
|||
|
||||
adc2_drv.configure = Imrt1052AdcDrvConfigure;
|
||||
|
||||
ret = AdcBusInit(&adc2_bus, ADC2_BUS_NAME);
|
||||
ret = AdcBusInit(&adc2_bus, ADC_BUS_NAME_2);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC2 bus init error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = AdcDriverInit(&adc2_drv, ADC2_DRV_NAME);
|
||||
ret = AdcDriverInit(&adc2_drv, ADC_DRV_NAME_2);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC2 driver init error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
ret = AdcDriverAttachToBus(ADC2_DRV_NAME, ADC2_BUS_NAME);
|
||||
ret = AdcDriverAttachToBus(ADC_DRV_NAME_2, ADC_BUS_NAME_2);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC2 driver attach error %d\n", ret);
|
||||
return ERROR;
|
||||
|
@ -285,13 +277,13 @@ int Imrt1052HwAdcInit(void)
|
|||
|
||||
adc2_dev.adc_dev_done = &dev_done;
|
||||
|
||||
ret = AdcDeviceRegister(&adc2_dev, (void *)&adc2_cfg, ADC2_DEV_NAME);
|
||||
ret = AdcDeviceRegister(&adc2_dev, (void *)&adc2_cfg, ADC_2_DEVICE_NAME_0);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC2 device register error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
ret = AdcDeviceAttachToBus(ADC2_DEV_NAME, ADC2_BUS_NAME);
|
||||
ret = AdcDeviceAttachToBus(ADC_2_DEVICE_NAME_0, ADC_BUS_NAME_2);
|
||||
if (ret != EOK) {
|
||||
KPrintf("ADC2 device register error %d\n", ret);
|
||||
return ERROR;
|
||||
|
|
|
@ -6,7 +6,6 @@ if BSP_USING_I2C
|
|||
string "i2c bus 1 driver name"
|
||||
default "i2c1_drv"
|
||||
config I2C_1_DEVICE_NAME_0
|
||||
string "i2c bus 1 device 0 name"
|
||||
default "i2c1_dev0"
|
||||
string "i2c bus 1 device 0 name"
|
||||
default "i2c1_dev0"
|
||||
endif
|
||||
|
||||
|
|
|
@ -1,32 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2020 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-04-25 weety first version
|
||||
*/
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file connect_i2c.c
|
||||
* @brief support stm32f407-st-discovery-board i2c function and register to bus framework
|
||||
* @brief support ok1052-c-board i2c function and register to bus framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
* @date 2022-1-25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: connect_i2c.c
|
||||
Description: support stm32f407-st-discovery-board i2c configure and i2c bus register function
|
||||
Description: support ok1052-c-board i2c configure and i2c bus register function
|
||||
Others: take RT-Thread v4.0.2/components/drivers/i2c/i2c-bit-ops.c for references
|
||||
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
|
||||
History:
|
||||
1. Date: 2021-04-25
|
||||
1. Date: 2022-1-25
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. support stm32f407-st-discovery-board i2c bit configure, write and read
|
||||
2. support stm32f407-st-discovery-board i2c bus device and driver register
|
||||
1. support ok1052-c-board i2c bit configure, write and read
|
||||
2. support ok1052-c-board i2c bus device and driver register
|
||||
*************************************************/
|
||||
|
||||
#include <board.h>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
/**
|
||||
* @file connect_flash_spi.c
|
||||
* @brief support stm32f407-st-discovery-board spi flash function and register to bus framework
|
||||
* @brief support ok1052-c-board spi flash function and register to bus framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
|
@ -18,15 +18,15 @@
|
|||
|
||||
/*************************************************
|
||||
File name: connect_flash_spi.c
|
||||
Description: support stm32f407-st-discovery-board spi flash bus register function
|
||||
Description: support ok1052-c-board spi flash bus register function
|
||||
Others: take RT-Thread v4.0.2/bsp/stm32/stm32f407-atk-explorer/board/ports/spi-flash-init.c
|
||||
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
|
||||
History:
|
||||
1. Date: 2021-04-25
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. support stm32f407-st-discovery-board spi flash register to spi bus
|
||||
2. support stm32f407-st-discovery-board spi flash init
|
||||
1. support ok1052-c-board spi flash register to spi bus
|
||||
2. support ok1052-c-board spi flash init
|
||||
*************************************************/
|
||||
|
||||
//#include "connect_spi.h"
|
||||
|
|
|
@ -1,38 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2020 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-11-5 SummerGift first version
|
||||
* 2018-12-11 greedyhao Porting for stm32f7xx
|
||||
* 2019-01-03 zylx modify DMA initialization and spixfer function
|
||||
* 2020-01-15 whj4674672 Porting for stm32h7xx
|
||||
* 2020-06-18 thread-liu Porting for stm32mp1xx
|
||||
* 2020-10-14 Dozingfiretruck Porting for stm32wbxx
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file connect_spi.c
|
||||
* @brief support stm32f407-st-discovery-board spi function and register to bus framework
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: connect_spi.c
|
||||
Description: support stm32f407-st-discovery-board spi configure and spi bus register function
|
||||
Others: take RT-Thread v4.0.2/bsp/stm32/libraries/HAL_Drivers/drv_spi.c for references
|
||||
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
|
||||
History:
|
||||
1. Date: 2021-04-25
|
||||
Author: AIIT XUOS Lab
|
||||
Modification:
|
||||
1. support stm32f407-st-discovery-board spi configure, write and read
|
||||
2. support stm32f407-st-discovery-board spi bus device and driver register
|
||||
*************************************************/
|
||||
/**
|
||||
* @file connect_adc.c
|
||||
* @brief Demo for ADC function
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.1.18
|
||||
*/
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
#include "connect_spi.h"
|
||||
|
@ -97,9 +81,9 @@ Modification:
|
|||
* This function SPI device initialization
|
||||
*
|
||||
* @param spi_drv SPI device structure pointer
|
||||
*
|
||||
*
|
||||
* @param cfg SPI device operating mode configuration structure pointer
|
||||
*
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
|
||||
|
@ -204,7 +188,7 @@ static x_err_t Stm32SpiInit(struct Stm32Spi *spi_drv, struct SpiMasterParam *cfg
|
|||
/* DMA configuration */
|
||||
if (spi_drv->spi_dma_flag & SPI_USING_RX_DMA_FLAG){
|
||||
DMA_Init(spi_drv->dma.dma_rx.instance, &spi_drv->dma.dma_rx.init);
|
||||
|
||||
|
||||
prioritygroup = NVIC_GetPriorityGrouping();
|
||||
|
||||
NVIC_SetPriority(spi_drv->dma.dma_rx.dma_irq, NVIC_EncodePriority(prioritygroup, 0, 0));
|
||||
|
@ -236,7 +220,7 @@ static void DmaSpiConfig(struct SpiBus *spi_bus, uint32_t setting_len, void *rx_
|
|||
if(spi->spi_dma_flag & SPI_USING_RX_DMA_FLAG)
|
||||
{
|
||||
spi->dma.dma_rx.setting_len = setting_len;
|
||||
DMA_DeInit(spi->dma.dma_rx.instance);
|
||||
DMA_DeInit(spi->dma.dma_rx.instance);
|
||||
while(DMA_GetCmdStatus(spi->dma.dma_rx.instance) != DISABLE);
|
||||
spi->dma.dma_rx.init.DMA_Channel = spi->dma.dma_rx.channel;
|
||||
spi->dma.dma_rx.init.DMA_PeripheralBaseAddr = (uint32_t)&(spi->instance->DR);
|
||||
|
@ -276,7 +260,7 @@ static void DmaSpiConfig(struct SpiBus *spi_bus, uint32_t setting_len, void *rx_
|
|||
if(spi->spi_dma_flag & SPI_USING_TX_DMA_FLAG)
|
||||
{
|
||||
spi->dma.dma_tx.setting_len = setting_len;
|
||||
DMA_DeInit(spi->dma.dma_tx.instance);
|
||||
DMA_DeInit(spi->dma.dma_tx.instance);
|
||||
while(DMA_GetCmdStatus(spi->dma.dma_tx.instance) != DISABLE);
|
||||
spi->dma.dma_tx.init.DMA_PeripheralBaseAddr = (uint32_t)&(spi->instance->DR);
|
||||
spi->dma.dma_tx.init.DMA_Memory0BaseAddr = (uint32_t)tx_base_addr;
|
||||
|
@ -374,18 +358,18 @@ static int SpiWaitUntilTimeout(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instan
|
|||
/**
|
||||
* This function SPI sends data through DMA
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_instance SPI control handle
|
||||
*
|
||||
*
|
||||
* @param dma_init DMA Init structure
|
||||
*
|
||||
*
|
||||
* @param dma_instance DMA Controller
|
||||
*
|
||||
*
|
||||
* @param p_data Send data buffer address
|
||||
*
|
||||
*
|
||||
* @param size Amount of data sent
|
||||
*
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
int SpiTransmitDma(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, DMA_InitTypeDef dma_init, DMA_Stream_TypeDef *dma_instance, uint8_t *p_data, uint16_t size)
|
||||
|
@ -457,24 +441,24 @@ error :
|
|||
/**
|
||||
* This function SPI carries out duplex communication through DMA
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_instance SPI control handle
|
||||
*
|
||||
*
|
||||
* @param dmarx_init DMA Init structure---Rx
|
||||
*
|
||||
*
|
||||
* @param dmarx_instance DMA Controller
|
||||
*
|
||||
*
|
||||
* @param dmatx_init DMA Init structure---Tx
|
||||
*
|
||||
*
|
||||
* @param dmatx_instance DMA Controller
|
||||
*
|
||||
*
|
||||
* @param p_txdata Send data buffer address
|
||||
*
|
||||
*
|
||||
* @param p_rxdata Receive data buffer address
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
int SpiTransmitreceiveDma(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, DMA_InitTypeDef dmarx_init, DMA_Stream_TypeDef *dmarx_instance, DMA_InitTypeDef dmatx_init, DMA_Stream_TypeDef *dmatx_instance, uint8_t *p_txdata, uint8_t *p_rxdata, uint16_t size)
|
||||
|
@ -588,22 +572,22 @@ error :
|
|||
/**
|
||||
* This function SPI receives data through DMA
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_instance SPI control handle
|
||||
*
|
||||
*
|
||||
* @param dmarx_init DMA Init structure---Rx
|
||||
*
|
||||
*
|
||||
* @param dmarx_instance DMA Controller
|
||||
*
|
||||
*
|
||||
* @param dmatx_init DMA Init structure---Tx
|
||||
*
|
||||
*
|
||||
* @param dmatx_instance DMA Controller
|
||||
*
|
||||
*
|
||||
* @param p_data Receive data buffer address
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
int SpiReceiveDma(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, DMA_InitTypeDef dmarx_init, DMA_Stream_TypeDef *dmarx_instance, DMA_InitTypeDef dmatx_init, DMA_Stream_TypeDef *dmatx_instance, uint8_t *p_data, uint16_t size)
|
||||
|
@ -676,18 +660,18 @@ error:
|
|||
return errorcode;
|
||||
}
|
||||
/**
|
||||
* This function SPI receives data
|
||||
* This function SPI receives data
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_instance SPI control handle
|
||||
*
|
||||
*
|
||||
* @param p_data Transmit data buffer address
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
* @param Timeout waiting time
|
||||
*
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
int SpiTransmit(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint8_t *p_data, uint16_t size, uint32_t Timeout)
|
||||
|
@ -784,7 +768,7 @@ int SpiTransmit(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint8_t *p_
|
|||
errorcode = 3;
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
/* Check Busy flag */
|
||||
if(SpiWaitUntilTimeout(spi_init, spi_instance, SPI_FLAG_BSY, RESET, Timeout, tickstart) != 0){
|
||||
errorcode = 1;
|
||||
|
@ -797,18 +781,18 @@ error:
|
|||
/**
|
||||
* This function SPI Transmit and receive
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_instance SPI control handle
|
||||
*
|
||||
*
|
||||
* @param p_txdata Transmit data buffer address
|
||||
*
|
||||
*
|
||||
* @param p_rxdata receive data buffer address
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
* @param Timeout waiting time
|
||||
*
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
int SpiTransmitreceive(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint8_t *p_txdata, uint8_t *p_rxdata, uint16_t size, uint32_t Timeout)
|
||||
|
@ -824,9 +808,9 @@ int SpiTransmitreceive(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint
|
|||
|
||||
/* Init tickstart for timeout management*/
|
||||
tickstart = CurrentTicksGain() * 1000 / TICK_PER_SECOND;
|
||||
|
||||
|
||||
tmp = spi_init.SPI_Mode;
|
||||
|
||||
|
||||
if(!((tmp == SPI_Mode_Master) && (spi_init.SPI_Direction == SPI_Direction_2Lines_FullDuplex))){
|
||||
errorcode = 2;
|
||||
goto error;
|
||||
|
@ -864,7 +848,7 @@ int SpiTransmitreceive(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint
|
|||
spi_instance->DR = *((uint16_t *)p_txdata);
|
||||
p_txdata += sizeof(uint16_t);
|
||||
tx_xfer_count--;
|
||||
/* Next Data is a reception (Rx). Tx not allowed */
|
||||
/* Next Data is a reception (Rx). Tx not allowed */
|
||||
txallowed = 0U;
|
||||
}
|
||||
|
||||
|
@ -874,7 +858,7 @@ int SpiTransmitreceive(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint
|
|||
*((uint16_t *)p_rxdata) = spi_instance->DR;
|
||||
p_rxdata += sizeof(uint16_t);
|
||||
rx_xfer_count--;
|
||||
/* Next Data is a Transmission (Tx). Tx is allowed */
|
||||
/* Next Data is a Transmission (Tx). Tx is allowed */
|
||||
txallowed = 1U;
|
||||
}
|
||||
if((Timeout != 0xFFFFFFFFU) && ((CurrentTicksGain() * 1000 / TICK_PER_SECOND-tickstart) >= Timeout)){
|
||||
|
@ -934,23 +918,23 @@ int SpiTransmitreceive(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint
|
|||
errorcode = 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
error :
|
||||
return errorcode;
|
||||
}
|
||||
/**
|
||||
* This function SPI receive data
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_init SPI Init structure
|
||||
*
|
||||
* @param spi_instance SPI control handle
|
||||
*
|
||||
*
|
||||
* @param p_data data buffer address
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
*
|
||||
* @param size Amount of data
|
||||
*
|
||||
* @param Timeout waiting time
|
||||
*
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
int SpiReceive(SPI_InitTypeDef spi_init, SPI_TypeDef *spi_instance, uint8_t *p_data, uint16_t size, uint32_t Timeout)
|
||||
|
@ -1047,9 +1031,9 @@ error :
|
|||
* This function SPI write data
|
||||
*
|
||||
* @param spi_dev SPI device structure handle
|
||||
*
|
||||
*
|
||||
* @param spi_datacfg SPI device information structure handle
|
||||
*
|
||||
*
|
||||
* @return datacfg length
|
||||
*/
|
||||
static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
|
||||
|
@ -1067,7 +1051,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
|
|||
SPI_InitTypeDef *spi_init = &StmSpi->init;
|
||||
struct Stm32HwSpiCs *cs = (struct Stm32HwSpiCs *)spi_dev->private_data;
|
||||
|
||||
while(NONE != spi_datacfg) {
|
||||
while(NONE != spi_datacfg) {
|
||||
if(spi_datacfg->spi_chip_select) {
|
||||
GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_RESET);
|
||||
}
|
||||
|
@ -1086,7 +1070,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
|
|||
/* calculate the start address */
|
||||
already_send_length = spi_datacfg->length - send_length - message_length;
|
||||
WriteBuf = (uint8 *)spi_datacfg->tx_buff + already_send_length;
|
||||
|
||||
|
||||
/* start once data exchange in DMA mode */
|
||||
if (spi_datacfg->tx_buff) {
|
||||
if (StmSpi->spi_dma_flag & SPI_USING_TX_DMA_FLAG) {
|
||||
|
@ -1105,7 +1089,7 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
|
|||
if (spi_datacfg->spi_cs_release) {
|
||||
GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_SET);
|
||||
}
|
||||
|
||||
|
||||
spi_datacfg = spi_datacfg->next;
|
||||
}
|
||||
|
||||
|
@ -1116,9 +1100,9 @@ static uint32 Stm32SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDat
|
|||
* This function SPI read data
|
||||
*
|
||||
* @param spi_dev SPI device structure handle
|
||||
*
|
||||
*
|
||||
* @param spi_datacfg SPI device information structure handle
|
||||
*
|
||||
*
|
||||
* @return datacfg length
|
||||
*/
|
||||
static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
|
||||
|
@ -1136,7 +1120,7 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
|
|||
SPI_InitTypeDef *spi_init = &StmSpi->init;
|
||||
struct Stm32HwSpiCs *cs = (struct Stm32HwSpiCs *)spi_dev->private_data;
|
||||
|
||||
while (NONE != spi_datacfg) {
|
||||
while (NONE != spi_datacfg) {
|
||||
if (spi_datacfg->spi_chip_select) {
|
||||
GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_RESET);
|
||||
}
|
||||
|
@ -1155,7 +1139,7 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
|
|||
/* calculate the start address */
|
||||
already_send_length = spi_datacfg->length - read_length - message_length;
|
||||
ReadBuf = (uint8 *)spi_datacfg->rx_buff + already_send_length;
|
||||
|
||||
|
||||
/* start once data exchange in DMA mode */
|
||||
if (spi_datacfg->rx_buff) {
|
||||
//memset((uint8_t *)ReadBuf, 0xff, read_length);
|
||||
|
@ -1175,7 +1159,7 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
|
|||
if (spi_datacfg->spi_cs_release) {
|
||||
GPIO_WriteBit(cs->GPIOx, cs->GPIO_Pin, Bit_SET);
|
||||
}
|
||||
|
||||
|
||||
spi_read_length += spi_datacfg->length;
|
||||
spi_datacfg = spi_datacfg->next;
|
||||
}
|
||||
|
@ -1187,7 +1171,7 @@ static uint32 Stm32SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiData
|
|||
* This function SPI driver initialization function
|
||||
*
|
||||
* @param spi_drv SPI driver structure handle
|
||||
*
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
static uint32 SpiDrvInit(struct SpiDriver *spi_drv)
|
||||
|
@ -1205,9 +1189,9 @@ static uint32 SpiDrvInit(struct SpiDriver *spi_drv)
|
|||
* This function SPI driver configuration param
|
||||
*
|
||||
* @param spi_drv SPI driver structure handle
|
||||
*
|
||||
*
|
||||
* @param spi_param SPI master param structure handle
|
||||
*
|
||||
*
|
||||
* @return if successful return EOK
|
||||
*/
|
||||
static uint32 SpiDrvConfigure(struct SpiDriver *spi_drv, struct SpiMasterParam *spi_param)
|
||||
|
@ -1218,7 +1202,7 @@ static uint32 SpiDrvConfigure(struct SpiDriver *spi_drv, struct SpiMasterParam *
|
|||
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_drv->driver.private_data);
|
||||
|
||||
dev_param->spi_master_param = spi_param;
|
||||
dev_param->spi_master_param->spi_work_mode = dev_param->spi_master_param->spi_work_mode & SPI_MODE_MASK;
|
||||
dev_param->spi_master_param->spi_work_mode = dev_param->spi_master_param->spi_work_mode & SPI_MODE_MASK;
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
@ -1321,7 +1305,7 @@ DECLARE_HW_IRQ(DMA1_Stream2_IRQn, DMA1_Stream2_IRQHandler, NONE);
|
|||
#endif
|
||||
|
||||
/**
|
||||
* This function RCC clock configuration function
|
||||
* This function RCC clock configuration function
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
|
@ -1329,25 +1313,25 @@ static void RCCConfiguration(void)
|
|||
{
|
||||
#ifdef BSP_USING_SPI1
|
||||
RCC_AHB1PeriphClockCmd(SPI1_GPIO_RCC, ENABLE);
|
||||
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APBPeriph_SPI1, ENABLE);
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI2
|
||||
RCC_AHB1PeriphClockCmd(SPI2_GPIO_RCC | SPI2_GPIO_RCC_SCK, ENABLE);
|
||||
|
||||
|
||||
RCC_APB1PeriphClockCmd(RCC_APBPeriph_SPI2, ENABLE);
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI3
|
||||
RCC_AHB1PeriphClockCmd(SPI3_GPIO_RCC | SPI3_GPIO_RCC_NSS, ENABLE);
|
||||
|
||||
|
||||
RCC_APB2PeriphClockCmd(RCC_APBPeriph_SPI3, ENABLE);
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
* This function GPIO Configuration function
|
||||
*
|
||||
* This function GPIO Configuration function
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void GPIOConfiguration(void)
|
||||
|
@ -1366,7 +1350,7 @@ static void GPIOConfiguration(void)
|
|||
GPIO_PinAFConfig(SPI1_GPIO, SPI1_SCK_PIN_SOURCE, GPIO_AF_SPI1);
|
||||
GPIO_PinAFConfig(SPI1_GPIO, SPI1_MISO_PIN_SOURCE, GPIO_AF_SPI1);
|
||||
GPIO_PinAFConfig(SPI1_GPIO, SPI1_MOSI_PIN_SOURCE, GPIO_AF_SPI1);
|
||||
|
||||
|
||||
GPIO_Init(SPI1_GPIO, &gpio_initstructure); /*SPI pin initialization*/
|
||||
#endif
|
||||
|
||||
|
@ -1382,7 +1366,7 @@ static void GPIOConfiguration(void)
|
|||
GPIO_PinAFConfig(SPI2_GPIO, SPI2_NSS_PIN_SOURCE, GPIO_AF_SPI2);
|
||||
GPIO_PinAFConfig(SPI2_GPIO, SPI2_MISO_PIN_SOURCE, GPIO_AF_SPI2);
|
||||
GPIO_PinAFConfig(SPI2_GPIO, SPI2_MOSI_PIN_SOURCE, GPIO_AF_SPI2);
|
||||
|
||||
|
||||
GPIO_Init(SPI2_GPIO, &gpio_initstructure);
|
||||
#endif
|
||||
|
||||
|
@ -1397,18 +1381,18 @@ static void GPIOConfiguration(void)
|
|||
GPIO_PinAFConfig(SPI3_GPIO, SPI3_SCK_PIN_SOURCE, GPIO_AF_SPI3);
|
||||
GPIO_PinAFConfig(SPI3_GPIO, SPI3_MISO_PIN_SOURCE, GPIO_AF_SPI3);
|
||||
GPIO_PinAFConfig(SPI3_GPIO, SPI3_MOSI_PIN_SOURCE, GPIO_AF_SPI3);
|
||||
|
||||
|
||||
GPIO_Init(SPI3_GPIO, &gpio_initstructure);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* This function Init the spi bus 、spi driver and attach to the bus
|
||||
* This function Init the spi bus 、spi driver and attach to the bus
|
||||
*
|
||||
* @param spi_bus Spi bus info pointer
|
||||
*
|
||||
*
|
||||
* @param spi_driver Spi driver info pointer
|
||||
*
|
||||
*
|
||||
* @return EOK
|
||||
*/
|
||||
static int BoardSpiBusInit(struct Stm32Spi *stm32spi_bus, struct SpiDriver *spi_driver, char* drv_name)
|
||||
|
@ -1434,14 +1418,14 @@ static int BoardSpiBusInit(struct Stm32Spi *stm32spi_bus, struct SpiDriver *spi_
|
|||
if (EOK != ret) {
|
||||
KPrintf("Board_Spi_init SpiDriverAttachToBus error %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function SPI bus initialization
|
||||
* This function SPI bus initialization
|
||||
*
|
||||
* @return EOK
|
||||
*/
|
||||
|
@ -1513,16 +1497,16 @@ static int Stm32HwSpiBusInit(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* This function Mount the spi device to the bus
|
||||
* This function Mount the spi device to the bus
|
||||
*
|
||||
* @param bus_name Bus Name
|
||||
*
|
||||
*
|
||||
* @param device_name spi device name
|
||||
*
|
||||
*
|
||||
* @param cs_gpiox GPIO pin configuration handle
|
||||
*
|
||||
*
|
||||
* @param cs_gpio_pin GPIO number
|
||||
*
|
||||
*
|
||||
* @return EOK
|
||||
*/
|
||||
x_err_t HwSpiDeviceAttach(const char *bus_name, const char *device_name, GPIO_TypeDef *cs_gpiox, uint16_t cs_gpio_pin)
|
||||
|
@ -1575,8 +1559,8 @@ x_err_t HwSpiDeviceAttach(const char *bus_name, const char *device_name, GPIO_Ty
|
|||
}
|
||||
|
||||
/**
|
||||
* This function Get DMA information
|
||||
*
|
||||
* This function Get DMA information
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void Stm32GetDmaInfo(void)
|
||||
|
@ -1588,7 +1572,7 @@ static void Stm32GetDmaInfo(void)
|
|||
spi1.dma.dma_rx.channel = DMA_Channel_3;
|
||||
spi1.dma.dma_rx.dma_irq = DMA2_Stream0_IRQn;
|
||||
#endif
|
||||
#ifdef BSP_SPI1_TX_USING_DMA /*SPI1 uses DMA send enable*/
|
||||
#ifdef BSP_SPI1_TX_USING_DMA /*SPI1 uses DMA send enable*/
|
||||
spi1.spi_dma_flag |= SPI_USING_TX_DMA_FLAG;
|
||||
spi1.dma.dma_tx.instance = DMA2_Stream3;
|
||||
spi1.dma.dma_tx.dma_rcc = RCC_AHB1ENR_DMA2EN;
|
||||
|
@ -1628,7 +1612,7 @@ static void Stm32GetDmaInfo(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* This function hardware spi initialization
|
||||
* This function hardware spi initialization
|
||||
*
|
||||
* @return EOK
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue