add peripheral definitions

This commit is contained in:
Hierophect 2019-09-25 11:37:27 -04:00
parent 7f1bc48a88
commit f286737868
4 changed files with 148 additions and 18 deletions

View File

@ -31,10 +31,28 @@
#include "boards/board.h"
#include "common-hal/microcontroller/Pin.h"
//mp_raise_NotImplementedError(translate("SPI not yet supported"));
void common_hal_busio_spi_construct(busio_spi_obj_t *self,
const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi,
const mcu_pin_obj_t * miso) {
mp_raise_NotImplementedError(translate("SPI not yet supported"));
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}
void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {

View File

@ -33,17 +33,17 @@
#include "stm32f4xx_hal.h"
#include "stm32f4/pins.h"
// Address Version
// I2C
typedef struct {
uint8_t i2c_index:4; // Index of the I2C unit (1 to 3)
uint8_t altfn_index:4; //Index of the altfn for this pin (0 to 15)
const mcu_pin_obj_t * pin;
} mcu_i2c_sda_obj_t;
// Address Version
typedef struct {
uint8_t i2c_index:4; // Index of the I2C unit (1 to 3)
uint8_t altfn_index:4; //Index of the altfn for this pin (0 to 15)
uint8_t i2c_index:4;
uint8_t altfn_index:4;
const mcu_pin_obj_t * pin;
} mcu_i2c_scl_obj_t;
@ -62,6 +62,39 @@ typedef struct {
.pin = scl_pin, \
}
// SPI
typedef struct {
uint8_t spi_index:4; //Up to 6 SPI units
uint8_t altfn_index:4; //Up to 15 alt channels
const mcu_pin_obj_t * pin;
} mcu_spi_sck_obj_t;
typedef struct {
uint8_t spi_index:4;
uint8_t altfn_index:4;
const mcu_pin_obj_t * pin;
} mcu_spi_miso_obj_t;
typedef struct {
uint8_t spi_index:4;
uint8_t altfn_index:4;
const mcu_pin_obj_t * pin;
} mcu_spi_mosi_obj_t;
typedef struct {
uint8_t i2c_index:4;
uint8_t altfn_index:4;
const mcu_pin_obj_t * pin;
} mcu_spi_nss_obj_t;
#define SPI(index, alt, spi_pin) \
{ \
.i2c_index = index, \
.altfn_index = alt, \
.pin = spi_pin, \
}
// TODO: SPI, UART, etc
// Choose based on chip

View File

@ -34,20 +34,91 @@
I2C_TypeDef * mcu_i2c_banks[3] = {I2C1, I2C2, I2C3};
const mcu_i2c_sda_obj_t mcu_i2c_sda_list[8] = {
I2C_SDA(1, 4, &pin_PB07),
I2C_SDA(1, 4, &pin_PB09),
I2C_SDA(2, 4, &pin_PB11), //not on LQFP100
I2C_SDA(2, 9, &pin_PB09),
I2C_SDA(2, 9, &pin_PB03),
I2C_SDA(3, 4, &pin_PC09),
I2C_SDA(3, 9, &pin_PB04),
I2C_SDA(3, 9, &pin_PB08)
I2C_SDA(1, 4, &pin_PB07),
I2C_SDA(1, 4, &pin_PB09),
I2C_SDA(2, 4, &pin_PB11), //not on LQFP100
I2C_SDA(2, 9, &pin_PB09),
I2C_SDA(2, 9, &pin_PB03),
I2C_SDA(3, 4, &pin_PC09),
I2C_SDA(3, 9, &pin_PB04),
I2C_SDA(3, 9, &pin_PB08)
};
const mcu_i2c_scl_obj_t mcu_i2c_scl_list[4] = {
I2C_SCL(1, 4, &pin_PB06),
I2C_SCL(1, 4, &pin_PB08),
I2C_SCL(2, 4, &pin_PB10),
I2C_SCL(3, 4, &pin_PA08)
I2C_SCL(1, 4, &pin_PB06),
I2C_SCL(1, 4, &pin_PB08),
I2C_SCL(2, 4, &pin_PB10),
I2C_SCL(3, 4, &pin_PA08)
};
//SPI, UART, Etc
// SPI
SPI_TypeDef * mcu_i2c_banks[3] = {SPI1, SPI2, SPI3, SPI4, SPI5};
const mcu_spi_sck_obj_t mcu_spi_sck_list[16] = {
SPI(1, 5, &pin_PA05),
SPI(5, 6, &pin_PB00),
SPI(1, 5, &pin_PB03),
SPI(3, 6, &pin_PB03),
SPI(2, 5, &pin_PB10),
SPI(5, 6, &pin_PB00),
SPI(3, 7, &pin_PB12),
SPI(2, 5, &pin_PB13),
SPI(4, 6, &pin_PB13),
SPI(2, 5, &pin_PC07),
SPI(3, 6, &pin_PC10),
SPI(2, 5, &pin_PD03),
SPI(4, 5, &pin_PE02),
SPI(5, 6, &pin_PE02),
SPI(4, 5, &pin_PE12),
SPI(5, 6, &pin_PE12),
};
const mcu_spi_mosi_obj_t mcu_spi_mosi_list[14] = {
SPI(4, 5, &pin_PA01),
SPI(1, 5, &pin_PA07),
SPI(5, 6, &pin_PA10),
SPI(1, 5, &pin_PB05),
SPI(3, 6, &pin_PB05),
SPI(5, 6, &pin_PB08),
SPI(2, 5, &pin_PB15),
SPI(2, 5, &pin_PC03),
SPI(3, 6, &pin_PC12),
SPI(3, 5, &pin_PD06),
SPI(4, 5, &pin_PE06),
SPI(5, 6, &pin_PE06),
SPI(4, 5, &pin_PE14),
SPI(5, 6, &pin_PE14),
};
const mcu_spi_miso_obj_t mcu_spi_miso_list[12] = {
SPI(1, 5, &pin_PA06),
SPI(4, 6, &pin_PA11),
SPI(5, 6, &pin_PA12),
SPI(1, 5, &pin_PB04),
SPI(3, 6, &pin_PB04),
SPI(2, 5, &pin_PB14),
SPI(2, 5, &pin_PC02),
SPI(3, 6, &pin_PC11),
SPI(4, 5, &pin_PE05),
SPI(5, 6, &pin_PE05),
SPI(4, 5, &pin_PE13),
SPI(5, 6, &pin_PE13),
};
const mcu_spi_nss_obj_t mcu_spi_nss_list[12] = {
SPI(1, 5, &pin_PA04),
SPI(3, 6, &pin_PA04),
SPI(1, 5, &pin_PA15),
SPI(3, 6, &pin_PA15),
SPI(5, 6, &pin_PB01),
SPI(2, 5, &pin_PB09),
SPI(2, 5, &pin_PB12),
SPI(4, 6, &pin_PB12),
SPI(4, 5, &pin_PE04),
SPI(5, 6, &pin_PE04),
SPI(4, 5, &pin_PE11),
SPI(5, 6, &pin_PE11),
};
//UART, Etc

View File

@ -34,4 +34,12 @@ extern const mcu_i2c_sda_obj_t mcu_i2c_sda_list[8];
extern const mcu_i2c_scl_obj_t mcu_i2c_scl_list[4];
//SPI
extern SPI_TypeDef * mcu_spi_banks[5];
extern const mcu_spi_sck_obj_t mcu_spi_sck_list[8];
extern const mcu_spi_mosi_obj_t mcu_spi_mosi_list[4];
extern const mcu_spi_miso_obj_t mcu_spi_miso_list[4];
extern const mcu_spi_nss_obj_t mcu_spi_nss_list[4];
#endif // MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F411VE_PERIPH_H