stm32: rework spi, based on PR #740 and #742.

split spi stuff in three part:
 - v1 : basic spi peripheral
 - v1_frf : v1 spi with frf mode additional bit in spi_cr2 / spi_sr
 - v2 : spi with variable datasize, fifo and other fancy stuff.

v1 maps to f1 chips
v1_frf to f2, f4 and l0,l1
v2 to f0, f3 and l4

This breaks spi_master_init API for v2 devices : function prototype from
common spi header used to be abused, with DFF bit reused for CRCL bit.
New v2 spi_master_init does not handle anymore CRCL bits, as it does not
usually mess with other crc configuration.
This commit is contained in:
Guillaume Revaillot
2018-04-04 16:27:59 +02:00
committed by Karl Palsson
parent 0deb58c73c
commit bf125e91f9
24 changed files with 205 additions and 83 deletions

View File

@@ -345,8 +345,6 @@ specific memorymap.h header before including this header file.*/
BEGIN_DECLS
void spi_reset(uint32_t spi_peripheral);
int spi_init_master(uint32_t spi, uint32_t br, uint32_t cpol, uint32_t cpha,
uint32_t dff, uint32_t lsbfirst);
void spi_enable(uint32_t spi);
void spi_disable(uint32_t spi);
uint16_t spi_clean_disable(uint32_t spi);
@@ -362,8 +360,6 @@ void spi_enable_crc(uint32_t spi);
void spi_disable_crc(uint32_t spi);
void spi_set_next_tx_from_buffer(uint32_t spi);
void spi_set_next_tx_from_crc(uint32_t spi);
void spi_set_dff_8bit(uint32_t spi);
void spi_set_dff_16bit(uint32_t spi);
void spi_set_full_duplex_mode(uint32_t spi);
void spi_set_receive_only_mode(uint32_t spi);
void spi_disable_software_slave_management(uint32_t spi);

View File

@@ -29,18 +29,12 @@ specific memorymap.h header before including this header file.*/
/** @cond */
#ifdef LIBOPENCM3_SPI_H
/** @endcond */
#ifndef LIBOPENCM3_SPI_COMMON_L1F124_H
#define LIBOPENCM3_SPI_COMMON_L1F124_H
#pragma once
/**@{*/
#include <libopencm3/stm32/common/spi_common_all.h>
/*
* This file extends the common STM32 version with definitions only
* applicable to the STM32L1/F1/2/4 series of devices.
*/
/* DFF: Data frame format */
/****************************************************************************/
/** @defgroup spi_dff SPI data frame format
@@ -48,17 +42,27 @@ specific memorymap.h header before including this header file.*/
@{*/
#define SPI_CR1_DFF_8BIT (0 << 11)
#define SPI_CR1_DFF_16BIT (1 << 11)
#define SPI_CR1_DFF_8BIT (0 << 11)
#define SPI_CR1_DFF_16BIT (1 << 11)
/**@}*/
#define SPI_CR1_DFF (1 << 11)
#define SPI_CR1_DFF (1 << 11)
/* --- Function prototypes ------------------------------------------------- */
BEGIN_DECLS
int spi_init_master(uint32_t spi, uint32_t br, uint32_t cpol, uint32_t cpha,
uint32_t dff, uint32_t lsbfirst);
void spi_set_dff_8bit(uint32_t spi);
void spi_set_dff_16bit(uint32_t spi);
END_DECLS
#endif
/** @cond */
#else
#warning "spi_common_l1f124.h should not be included explicitly, only via spi.h"
#warning "spi_common_v1.h should not be included explicitly, only via spi.h"
#endif
/** @endcond */
/**@}*/

View File

@@ -29,37 +29,38 @@ specific memorymap.h header before including this header file.*/
/** @cond */
#ifdef LIBOPENCM3_SPI_H
/** @endcond */
#ifndef LIBOPENCM3_SPI_COMMON_F24_H
#define LIBOPENCM3_SPI_COMMON_F24_H
#pragma once
/**@{*/
#include <libopencm3/stm32/common/spi_common_l1f124.h>
/*
* This file extends the common STM32 version with definitions only
* applicable to the STM32F2/4 series of devices.
*/
/* Note, these values are also on the F0, but other parts are _not_ */
#include <libopencm3/stm32/common/spi_common_v1.h>
/* --- SPI_CR2 values ------------------------------------------------------ */
/* FRF: Frame format */
/* Note: Not used in I2S mode. */
#define SPI_CR2_FRF (1 << 4)
#define SPI_CR2_FRF (1 << 4)
#define SPI_CR2_FRF_MOTOROLA_MODE (0 << 4)
#define SPI_CR2_FRF_TI_MODE (1 << 4)
/* --- SPI_SR values ------------------------------------------------------- */
/* TIFRFE: TI frame format error */
#define SPI_SR_TIFRFE (1 << 8)
/* FRE / TIFRFE: TI frame format error */
#define SPI_SR_TIFRFE (1 << 8) //F2
#define SPI_SR_FRE (1 << 8) //others
/* --- Function prototypes ------------------------------------------------- */
BEGIN_DECLS
void spi_set_frf_ti(uint32_t spi);
void spi_set_frf_motorola(uint32_t spi);
END_DECLS
#endif
/** @cond */
#else
#warning "spi_common_f24.h should not be included explicitly, only via spi.h"
#warning "spi_common_v1_frf.h should not be included explicitly, only via spi.h"
#endif
/** @endcond */
/**@}*/

View File

@@ -19,32 +19,26 @@
*/
/* THIS FILE SHOULD NOT BE INCLUDED DIRECTLY, BUT ONLY VIA SPI.H
* The order of header inclusion is important. spi.h includes the device
* specific memorymap.h header before including this header file.*/
The order of header inclusion is important. spi.h includes the device
specific memorymap.h header before including this header file.*/
/** @cond */
#ifdef LIBOPENCM3_SPI_H
/** @endcond */
#ifndef LIBOPENCM3_SPI_COMMON_F03_H
#define LIBOPENCM3_SPI_COMMON_F03_H
#pragma once
/**@{*/
#include <libopencm3/stm32/common/spi_common_all.h>
/*
* This file extends the common stm32 version with defintions only
* applicable to the STM32F0/F3 series of devices
*/
#define SPI_DR8(spi_base) MMIO8((spi_base) + 0x0c)
#define SPI1_DR8 SPI_DR8(SPI1_BASE)
#define SPI2_DR8 SPI_DR8(SPI2_BASE)
#define SPI3_DR8 SPI_DR8(SPI3_BASE)
/* DFF: Data frame format */
/* CRCL: CRC Length */
/****************************************************************************/
/** @defgroup spi_dff SPI data frame format
/** @defgroup spi_crcl SPI crc length
* @ingroup spi_defines
*
* @{*/
@@ -65,8 +59,12 @@
/* FRXTH: FIFO reception threshold */
#define SPI_CR2_FRXTH (1 << 12)
/* DS [3:0]: Data size */
/* 0x0 - 0x2 NOT USED */
/* DS: Data size */
/****************************************************************************/
/** @defgroup spi_ds SPI data size
* @ingroup spi_defines
*
* @{*/
#define SPI_CR2_DS_4BIT (0x3 << 8)
#define SPI_CR2_DS_5BIT (0x4 << 8)
#define SPI_CR2_DS_6BIT (0x5 << 8)
@@ -80,6 +78,7 @@
#define SPI_CR2_DS_14BIT (0xD << 8)
#define SPI_CR2_DS_15BIT (0xE << 8)
#define SPI_CR2_DS_16BIT (0xF << 8)
/**@}*/
#define SPI_CR2_DS_MASK (0xF << 8)
/* NSSP: NSS pulse management */
@@ -102,7 +101,8 @@
/* --- Function prototypes ------------------------------------------------- */
BEGIN_DECLS
int spi_init_master(uint32_t spi, uint32_t br, uint32_t cpol, uint32_t cpha,
uint32_t lsbfirst);
void spi_set_crcl_8bit(uint32_t spi);
void spi_set_crcl_16bit(uint32_t spi);
void spi_set_data_size(uint32_t spi, uint16_t data_s);
@@ -114,10 +114,9 @@ uint8_t spi_read8(uint32_t spi);
END_DECLS
#endif
/** @cond */
#else
#warning "spi_common_f03.h should not be included explicitly, only via spi.h"
#warning "spi_common_v2.h should not be included explicitly, only via spi.h"
#endif
/** @endcond */
/**@}*/

View File

@@ -31,6 +31,6 @@
#ifndef LIBOPENCM3_SPI_H
#define LIBOPENCM3_SPI_H
#include <libopencm3/stm32/common/spi_common_f03.h>
#include <libopencm3/stm32/common/spi_common_v2.h>
#endif

View File

@@ -31,7 +31,7 @@ LGPL License Terms @ref lgpl_license
#ifndef LIBOPENCM3_SPI_H
#define LIBOPENCM3_SPI_H
#include <libopencm3/stm32/common/spi_common_l1f124.h>
#include <libopencm3/stm32/common/spi_common_v1.h>
#endif

View File

@@ -31,7 +31,7 @@ LGPL License Terms @ref lgpl_license
#ifndef LIBOPENCM3_SPI_H
#define LIBOPENCM3_SPI_H
#include <libopencm3/stm32/common/spi_common_f24.h>
#include <libopencm3/stm32/common/spi_common_v1_frf.h>
#endif

View File

@@ -31,6 +31,6 @@
#ifndef LIBOPENCM3_SPI_H
#define LIBOPENCM3_SPI_H
#include <libopencm3/stm32/common/spi_common_f03.h>
#include <libopencm3/stm32/common/spi_common_v2.h>
#endif

View File

@@ -31,7 +31,7 @@ LGPL License Terms @ref lgpl_license
#ifndef LIBOPENCM3_SPI_H
#define LIBOPENCM3_SPI_H
#include <libopencm3/stm32/common/spi_common_f24.h>
#include <libopencm3/stm32/common/spi_common_v1_frf.h>
#endif

View File

@@ -0,0 +1,37 @@
/** @defgroup spi_defines SPI Defines
@brief <b>Defined Constants and Types for the STM32L0xx SPI</b>
@ingroup STM32L0xx_defines
@version 1.0.0
@date 20 January 2017
LGPL License Terms @ref lgpl_license
*/
/*
* This file is part of the libopencm3 project.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBOPENCM3_SPI_H
#define LIBOPENCM3_SPI_H
#include <libopencm3/stm32/common/spi_common_v1_frf.h>
#endif

View File

@@ -31,7 +31,7 @@ LGPL License Terms @ref lgpl_license
#ifndef LIBOPENCM3_SPI_H
#define LIBOPENCM3_SPI_H
#include <libopencm3/stm32/common/spi_common_l1f124.h>
#include <libopencm3/stm32/common/spi_common_v1_frf.h>
#endif

View File

@@ -31,6 +31,6 @@
#ifndef LIBOPENCM3_SPI_H
#define LIBOPENCM3_SPI_H
#include <libopencm3/stm32/common/spi_common_f03.h>
#include <libopencm3/stm32/common/spi_common_v2.h>
#endif

View File

@@ -30,6 +30,8 @@
# include <libopencm3/stm32/f3/spi.h>
#elif defined(STM32F4)
# include <libopencm3/stm32/f4/spi.h>
#elif defined(STM32L0)
# include <libopencm3/stm32/l0/spi.h>
#elif defined(STM32L1)
# include <libopencm3/stm32/l1/spi.h>
#elif defined(STM32L4)