mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
F7 performance improvements
This commit is contained in:
parent
c1ed72644f
commit
8d76579c9e
5 changed files with 32 additions and 20 deletions
|
@ -231,7 +231,14 @@ void i2cInit(I2CDevice device)
|
||||||
|
|
||||||
i2cHandle[device].Handle.Instance = i2cHardwareMap[device].dev;
|
i2cHandle[device].Handle.Instance = i2cHardwareMap[device].dev;
|
||||||
/// TODO: HAL check if I2C timing is correct
|
/// TODO: HAL check if I2C timing is correct
|
||||||
i2cHandle[device].Handle.Init.Timing = 0x00B01B59;
|
|
||||||
|
if (i2c->overClock) {
|
||||||
|
// 800khz Maximum speed tested on various boards without issues
|
||||||
|
i2cHandle[device].Handle.Init.Timing = 0x00500D1D;
|
||||||
|
} else {
|
||||||
|
//i2cHandle[device].Handle.Init.Timing = 0x00500B6A;
|
||||||
|
i2cHandle[device].Handle.Init.Timing = 0x00500C6F;
|
||||||
|
}
|
||||||
//i2cHandle[device].Handle.Init.Timing = 0x00D00E28; /* (Rise time = 120ns, Fall time = 25ns) */
|
//i2cHandle[device].Handle.Init.Timing = 0x00D00E28; /* (Rise time = 120ns, Fall time = 25ns) */
|
||||||
i2cHandle[device].Handle.Init.OwnAddress1 = 0x0;
|
i2cHandle[device].Handle.Init.OwnAddress1 = 0x0;
|
||||||
i2cHandle[device].Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
i2cHandle[device].Handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||||
|
|
|
@ -126,10 +126,8 @@ void SPI4_IRQHandler(void)
|
||||||
|
|
||||||
void spiInitDevice(SPIDevice device)
|
void spiInitDevice(SPIDevice device)
|
||||||
{
|
{
|
||||||
static SPI_InitTypeDef spiInit;
|
|
||||||
spiDevice_t *spi = &(spiHardwareMap[device]);
|
spiDevice_t *spi = &(spiHardwareMap[device]);
|
||||||
|
|
||||||
|
|
||||||
#ifdef SDCARD_SPI_INSTANCE
|
#ifdef SDCARD_SPI_INSTANCE
|
||||||
if (spi->dev == SDCARD_SPI_INSTANCE) {
|
if (spi->dev == SDCARD_SPI_INSTANCE) {
|
||||||
spi->leadingEdge = true;
|
spi->leadingEdge = true;
|
||||||
|
@ -173,27 +171,25 @@ void spiInitDevice(SPIDevice device)
|
||||||
// Init SPI hardware
|
// Init SPI hardware
|
||||||
HAL_SPI_DeInit(&spiHardwareMap[device].hspi);
|
HAL_SPI_DeInit(&spiHardwareMap[device].hspi);
|
||||||
|
|
||||||
spiInit.Mode = SPI_MODE_MASTER;
|
spiHardwareMap[device].hspi.Init.Mode = SPI_MODE_MASTER;
|
||||||
spiInit.Direction = SPI_DIRECTION_2LINES;
|
spiHardwareMap[device].hspi.Init.Direction = SPI_DIRECTION_2LINES;
|
||||||
spiInit.DataSize = SPI_DATASIZE_8BIT;
|
spiHardwareMap[device].hspi.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||||
spiInit.NSS = SPI_NSS_SOFT;
|
spiHardwareMap[device].hspi.Init.NSS = SPI_NSS_SOFT;
|
||||||
spiInit.FirstBit = SPI_FIRSTBIT_MSB;
|
spiHardwareMap[device].hspi.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||||
spiInit.CRCPolynomial = 7;
|
spiHardwareMap[device].hspi.Init.CRCPolynomial = 7;
|
||||||
spiInit.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
|
spiHardwareMap[device].hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
|
||||||
spiInit.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
spiHardwareMap[device].hspi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||||
spiInit.TIMode = SPI_TIMODE_DISABLED;
|
spiHardwareMap[device].hspi.Init.TIMode = SPI_TIMODE_DISABLED;
|
||||||
|
|
||||||
if (spi->leadingEdge) {
|
if (spi->leadingEdge) {
|
||||||
spiInit.CLKPolarity = SPI_POLARITY_LOW;
|
spiHardwareMap[device].hspi.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||||
spiInit.CLKPhase = SPI_PHASE_1EDGE;
|
spiHardwareMap[device].hspi.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
spiInit.CLKPolarity = SPI_POLARITY_HIGH;
|
spiHardwareMap[device].hspi.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||||
spiInit.CLKPhase = SPI_PHASE_2EDGE;
|
spiHardwareMap[device].hspi.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
spiHardwareMap[device].hspi.Init = spiInit;
|
|
||||||
|
|
||||||
if (HAL_SPI_Init(&spiHardwareMap[device].hspi) == HAL_OK)
|
if (HAL_SPI_Init(&spiHardwareMap[device].hspi) == HAL_OK)
|
||||||
{
|
{
|
||||||
if (spi->nss) {
|
if (spi->nss) {
|
||||||
|
@ -394,6 +390,7 @@ DMA_HandleTypeDef* spiSetDMATransmit(DMA_Stream_TypeDef *Stream, uint32_t Channe
|
||||||
// DMA TX Interrupt
|
// DMA TX Interrupt
|
||||||
dmaSetHandler(spiHardwareMap[device].dmaIrqHandler, dmaSPIIRQHandler, NVIC_BUILD_PRIORITY(3, 0), (uint32_t)device);
|
dmaSetHandler(spiHardwareMap[device].dmaIrqHandler, dmaSPIIRQHandler, NVIC_BUILD_PRIORITY(3, 0), (uint32_t)device);
|
||||||
|
|
||||||
|
HAL_CLEANCACHE(pData,Size);
|
||||||
// And Transmit
|
// And Transmit
|
||||||
HAL_SPI_Transmit_DMA(&spiHardwareMap[device].hspi, pData, Size);
|
HAL_SPI_Transmit_DMA(&spiHardwareMap[device].hspi, pData, Size);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ typedef struct dmaChannelDescriptor_s {
|
||||||
|
|
||||||
#if defined(STM32F4) || defined(STM32F7)
|
#if defined(STM32F4) || defined(STM32F7)
|
||||||
|
|
||||||
|
#define HAL_CLEANINVALIDATECACHE(addr, size) (SCB_CleanInvalidateDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
|
||||||
|
#define HAL_CLEANCACHE(addr, size) (SCB_CleanDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f)))
|
||||||
|
|
||||||
uint32_t dmaFlag_IT_TCIF(const DMA_Stream_TypeDef *stream);
|
uint32_t dmaFlag_IT_TCIF(const DMA_Stream_TypeDef *stream);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "nvic.h"
|
#include "nvic.h"
|
||||||
#include "inverter.h"
|
#include "inverter.h"
|
||||||
|
#include "dma.h"
|
||||||
|
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "serial_uart.h"
|
#include "serial_uart.h"
|
||||||
|
@ -265,6 +266,7 @@ void uartStartTxDMA(uartPort_t *s)
|
||||||
s->port.txBufferTail = 0;
|
s->port.txBufferTail = 0;
|
||||||
}
|
}
|
||||||
s->txDMAEmpty = false;
|
s->txDMAEmpty = false;
|
||||||
|
HAL_CLEANCACHE((uint8_t *)&s->port.txBuffer[fromwhere],size);
|
||||||
HAL_UART_Transmit_DMA(&s->Handle, (uint8_t *)&s->port.txBuffer[fromwhere], size);
|
HAL_UART_Transmit_DMA(&s->Handle, (uint8_t *)&s->port.txBuffer[fromwhere], size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -197,6 +197,7 @@
|
||||||
|RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_USART6
|
|RCC_PERIPHCLK_USART3|RCC_PERIPHCLK_USART6
|
||||||
|RCC_PERIPHCLK_UART4|RCC_PERIPHCLK_UART5
|
|RCC_PERIPHCLK_UART4|RCC_PERIPHCLK_UART5
|
||||||
|RCC_PERIPHCLK_UART7|RCC_PERIPHCLK_UART8
|
|RCC_PERIPHCLK_UART7|RCC_PERIPHCLK_UART8
|
||||||
|
|RCC_PERIPHCLK_I2C1|RCC_PERIPHCLK_I2C3
|
||||||
|RCC_PERIPHCLK_I2C2|RCC_PERIPHCLK_I2C4;
|
|RCC_PERIPHCLK_I2C2|RCC_PERIPHCLK_I2C4;
|
||||||
PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
|
PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
|
||||||
PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
PeriphClkInitStruct.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
||||||
|
@ -206,7 +207,9 @@
|
||||||
PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_PCLK2;
|
PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_PCLK2;
|
||||||
PeriphClkInitStruct.Uart7ClockSelection = RCC_UART7CLKSOURCE_PCLK1;
|
PeriphClkInitStruct.Uart7ClockSelection = RCC_UART7CLKSOURCE_PCLK1;
|
||||||
PeriphClkInitStruct.Uart8ClockSelection = RCC_UART8CLKSOURCE_PCLK1;
|
PeriphClkInitStruct.Uart8ClockSelection = RCC_UART8CLKSOURCE_PCLK1;
|
||||||
|
PeriphClkInitStruct.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
|
||||||
PeriphClkInitStruct.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1;
|
PeriphClkInitStruct.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1;
|
||||||
|
PeriphClkInitStruct.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;
|
||||||
PeriphClkInitStruct.I2c4ClockSelection = RCC_I2C4CLKSOURCE_PCLK1;
|
PeriphClkInitStruct.I2c4ClockSelection = RCC_I2C4CLKSOURCE_PCLK1;
|
||||||
ret = HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
ret = HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
||||||
if (ret != HAL_OK)
|
if (ret != HAL_OK)
|
||||||
|
@ -268,10 +271,10 @@ void SystemInit(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Enable I-Cache */
|
/* Enable I-Cache */
|
||||||
//SCB_EnableICache();
|
SCB_EnableICache();
|
||||||
|
|
||||||
/* Enable D-Cache */
|
/* Enable D-Cache */
|
||||||
//SCB_EnableDCache();
|
SCB_EnableDCache();
|
||||||
|
|
||||||
/* Configure the system clock to 216 MHz */
|
/* Configure the system clock to 216 MHz */
|
||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue