Add peripheral definitions
This commit is contained in:
parent
f4922a530a
commit
51901f7de0
@ -41,7 +41,28 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
|
|||||||
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate,
|
const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, uint32_t baudrate,
|
||||||
uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout,
|
uint8_t bits, uart_parity_t parity, uint8_t stop, mp_float_t timeout,
|
||||||
uint16_t receiver_buffer_size) {
|
uint16_t receiver_buffer_size) {
|
||||||
mp_raise_NotImplementedError(translate("UART not yet supported"));
|
|
||||||
|
GPIO_InitStruct.Pin = pin_mask(10)|pin_mask(11);
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
|
||||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
__HAL_RCC_USART2_CLK_ENABLE();
|
||||||
|
|
||||||
|
huart2.Instance = USART2;
|
||||||
|
huart2.Init.BaudRate = 115200;
|
||||||
|
huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
|
huart2.Init.StopBits = UART_STOPBITS_1;
|
||||||
|
huart2.Init.Parity = UART_PARITY_NONE;
|
||||||
|
huart2.Init.Mode = UART_MODE_TX_RX;
|
||||||
|
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
|
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
|
if (HAL_UART_Init(&huart2) != HAL_OK)
|
||||||
|
{
|
||||||
|
mp_raise_NotImplementedError(translate("UART explode"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
|
bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
|
||||||
|
@ -33,8 +33,8 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
uint8_t rx_pin;
|
const mcu_uart_tx_obj_t *tx;
|
||||||
uint8_t tx_pin;
|
const mcu_uart_rx_obj_t *rx;
|
||||||
uint8_t character_bits;
|
uint8_t character_bits;
|
||||||
bool rx_error;
|
bool rx_error;
|
||||||
uint32_t baudrate;
|
uint32_t baudrate;
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
#include "stm32f4/pins.h"
|
#include "stm32f4/pins.h"
|
||||||
|
|
||||||
// I2C
|
// I2C
|
||||||
//TODO: these objects should be condensed into a single 'periph_pin' unless we
|
// TODO: these objects should be condensed into a single 'periph_pin' unless we
|
||||||
//find a compelling reason to store more unique data in them.
|
// find a compelling reason to store more unique data in them.
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t i2c_index:4; // Index of the I2C unit (1 to 3)
|
uint8_t i2c_index:4; // Index of the I2C unit (1 to 3)
|
||||||
@ -65,8 +65,8 @@ typedef struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
//TODO: these objects should be condensed into a single 'periph_pin' unless we
|
// TODO: these objects should be condensed into a single 'periph_pin' unless we
|
||||||
//find a compelling reason to store more unique data in them.
|
// find a compelling reason to store more unique data in them.
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t spi_index:4; //Up to 6 SPI units
|
uint8_t spi_index:4; //Up to 6 SPI units
|
||||||
@ -99,7 +99,28 @@ typedef struct {
|
|||||||
.pin = spi_pin, \
|
.pin = spi_pin, \
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: SPI, UART, etc
|
// UART
|
||||||
|
// TODO: these objects should be condensed into a single 'periph_pin' unless we
|
||||||
|
// find a compelling reason to store more unique data in them.
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t uart_index:4;
|
||||||
|
uint8_t altfn_index:4;
|
||||||
|
const mcu_pin_obj_t * pin;
|
||||||
|
} mcu_uart_tx_obj_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t uart_index:4;
|
||||||
|
uint8_t altfn_index:4;
|
||||||
|
const mcu_pin_obj_t * pin;
|
||||||
|
} mcu_uart_rx_obj_t;
|
||||||
|
|
||||||
|
#define UART(index, alt, uart_pin) \
|
||||||
|
{ \
|
||||||
|
.uart_index = index, \
|
||||||
|
.altfn_index = alt, \
|
||||||
|
.pin = uart_pin, \
|
||||||
|
}
|
||||||
|
|
||||||
// Choose based on chip
|
// Choose based on chip
|
||||||
#ifdef STM32F412Zx
|
#ifdef STM32F412Zx
|
||||||
|
@ -85,4 +85,38 @@ const mcu_spi_nss_obj_t mcu_spi_nss_list[6] = {
|
|||||||
SPI(3, 6, &pin_PA04),
|
SPI(3, 6, &pin_PA04),
|
||||||
SPI(3, 6, &pin_PA15),
|
SPI(3, 6, &pin_PA15),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
USART_TypeDef * mcu_uart_banks[6] = {USART1, USART2, USART3, UART4, UART5, USART6};
|
||||||
|
bool mcu_uart_has_usart[6] = {true, true, true, false, false, true};
|
||||||
|
|
||||||
|
const mcu_uart_tx_obj_t mcu_uart_tx_list[12] = {
|
||||||
|
UART(4, 8, &pin_PA00),
|
||||||
|
UART(2, 7, &pin_PA02),
|
||||||
|
UART(1, 7, &pin_PA09),
|
||||||
|
UART(1, 7, &pin_PB06),
|
||||||
|
UART(3, 7, &pin_PB10),
|
||||||
|
UART(6, 8, &pin_PC06),
|
||||||
|
UART(3, 7, &pin_PC10),
|
||||||
|
UART(4, 8, &pin_PC10),
|
||||||
|
UART(5, 8, &pin_PC12),
|
||||||
|
UART(2, 7, &pin_PD05),
|
||||||
|
UART(3, 7, &pin_PD08),
|
||||||
|
UART(6, 8, &pin_PG14),
|
||||||
|
};
|
||||||
|
|
||||||
|
const mcu_uart_rx_obj_t mcu_uart_rx_list[12] = {
|
||||||
|
UART(4, 8, &pin_PA01),
|
||||||
|
UART(2, 7, &pin_PA03),
|
||||||
|
UART(1, 7, &pin_PA10),
|
||||||
|
UART(1, 7, &pin_PB07),
|
||||||
|
UART(3, 7, &pin_PB11),
|
||||||
|
UART(6, 8, &pin_PC07),
|
||||||
|
UART(3, 7, &pin_PC11),
|
||||||
|
UART(4, 8, &pin_PC11),
|
||||||
|
UART(5, 8, &pin_PD02),
|
||||||
|
UART(2, 7, &pin_PD06),
|
||||||
|
UART(3, 7, &pin_PD09),
|
||||||
|
UART(6, 8, &pin_PG09),
|
||||||
|
};
|
||||||
|
|
||||||
//UART, Etc
|
//UART, Etc
|
||||||
|
@ -41,5 +41,12 @@ extern const mcu_spi_mosi_obj_t mcu_spi_mosi_list[6];
|
|||||||
extern const mcu_spi_miso_obj_t mcu_spi_miso_list[6];
|
extern const mcu_spi_miso_obj_t mcu_spi_miso_list[6];
|
||||||
extern const mcu_spi_nss_obj_t mcu_spi_nss_list[6];
|
extern const mcu_spi_nss_obj_t mcu_spi_nss_list[6];
|
||||||
|
|
||||||
|
//UART
|
||||||
|
extern USART_TypeDef * mcu_uart_banks[6];
|
||||||
|
bool mcu_uart_has_usart[6]
|
||||||
|
|
||||||
|
extern const mcu_uart_tx_obj_t mcu_uart_tx_list[12];
|
||||||
|
extern const mcu_uart_rx_obj_t mcu_uart_rx_list[12];
|
||||||
|
|
||||||
|
|
||||||
#endif // MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F405XX_PERIPH_H
|
#endif // MICROPY_INCLUDED_STM32F4_PERIPHERALS_STM32F405XX_PERIPH_H
|
Loading…
Reference in New Issue
Block a user