chore(hal): remove StdPeriph (#5023)
Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com> Co-authored-by: Malte Langermann <malte@langermann.net> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: Richard Li <richard.li@ces.hk>
This commit is contained in:
co-authored by
raphaelcoeffic
Malte Langermann
3djc
Richard Li
parent
fea402a6e3
commit
6579905088
@@ -91,6 +91,7 @@ if(NOT NATIVE_BUILD)
|
||||
${STM32_DRIVER_DIR}/stm32_i2c_driver.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_timer.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_dma.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_gpio.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_spi.cpp
|
||||
${STM32_DRIVER_DIR}/stm32_adc.cpp
|
||||
)
|
||||
|
||||
@@ -19,6 +19,11 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "hal/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_timer.h"
|
||||
#include "stm32_dma.h"
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if !defined(SIMU)
|
||||
@@ -27,7 +32,6 @@ const AudioBuffer * nextBuffer = nullptr;
|
||||
void setSampleRate(uint32_t frequency)
|
||||
{
|
||||
uint32_t timer = (PERI1_FREQUENCY * TIMER_MULT_APB1) / frequency - 1 ; // MCK/8 and 100 000 Hz
|
||||
|
||||
AUDIO_TIMER->CR1 &= ~TIM_CR1_CEN ;
|
||||
AUDIO_TIMER->CNT = 0 ;
|
||||
AUDIO_TIMER->ARR = limit<uint32_t>(2, timer, 65535) ;
|
||||
@@ -37,38 +41,30 @@ void setSampleRate(uint32_t frequency)
|
||||
// Start TIMER6 at 100000Hz, used for DAC trigger
|
||||
void dacTimerInit()
|
||||
{
|
||||
AUDIO_TIMER->PSC = 0 ; // Max speed
|
||||
stm32_timer_enable_clock(AUDIO_TIMER);
|
||||
AUDIO_TIMER->PSC = 0 ; // Max speed
|
||||
AUDIO_TIMER->ARR = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 100000 - 1 ; // 10 uS, 100 kHz
|
||||
AUDIO_TIMER->CR2 = 0 ;
|
||||
AUDIO_TIMER->CR2 = 0x20 ;
|
||||
AUDIO_TIMER->CR1 = TIM_CR1_CEN ;
|
||||
}
|
||||
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
static inline void setMutePin(bool enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
#if defined(INVERTED_MUTE_PIN)
|
||||
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#else
|
||||
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
enabled = !enabled;
|
||||
#endif
|
||||
} else {
|
||||
#if defined(INVERTED_MUTE_PIN)
|
||||
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#else
|
||||
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#endif
|
||||
}
|
||||
gpio_write(AUDIO_MUTE_GPIO, enabled);
|
||||
}
|
||||
|
||||
static inline bool getMutePin(void)
|
||||
{
|
||||
bool enabled = gpio_read(AUDIO_MUTE_GPIO) ? 1 : 0;
|
||||
#if defined(INVERTED_MUTE_PIN)
|
||||
return !GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#else
|
||||
return GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
enabled = !enabled;
|
||||
#endif
|
||||
return enabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -76,27 +72,17 @@ static inline bool getMutePin(void)
|
||||
// Not sure why PB14 has not be allocated to the DAC, although it is an EXTRA function
|
||||
// So maybe it is automatically done
|
||||
void dacInit()
|
||||
{
|
||||
dacTimerInit();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
GPIO_InitStructure.GPIO_Pin = AUDIO_MUTE_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(AUDIO_MUTE_GPIO, &GPIO_InitStructure);
|
||||
{
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
// Mute before init anything
|
||||
gpio_init(AUDIO_MUTE_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
setMutePin(true);
|
||||
#endif
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = AUDIO_OUTPUT_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(AUDIO_OUTPUT_GPIO, &GPIO_InitStructure);
|
||||
dacTimerInit();
|
||||
|
||||
gpio_init_analog(AUDIO_OUTPUT_GPIO);
|
||||
stm32_dma_enable_clock(AUDIO_DMA);
|
||||
|
||||
// Chan 7, 16-bit wide, Medium priority, memory increments
|
||||
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN ; // Disable DMA
|
||||
@@ -108,6 +94,7 @@ void dacInit()
|
||||
AUDIO_DMA_Stream->FCR = 0x05 ; //DMA_SxFCR_DMDIS | DMA_SxFCR_FTH_0 ;
|
||||
// AUDIO_DMA_Stream->NDTR = 100 ;
|
||||
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DAC1);
|
||||
DAC->DHR12R1 = 2010 ;
|
||||
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
|
||||
DAC->CR = DAC_CR_TEN1 | DAC_CR_EN1 ; // Enable DAC
|
||||
@@ -117,7 +104,7 @@ void dacInit()
|
||||
NVIC_SetPriority(AUDIO_DMA_Stream_IRQn, 7);
|
||||
}
|
||||
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
void audioMute()
|
||||
{
|
||||
if (!g_eeGeneral.audioMuteEnable) return;
|
||||
@@ -129,7 +116,7 @@ void audioMute()
|
||||
}
|
||||
else if (now - audioQueue.lastAudioPlayTime > AUDIO_MUTE_DELAY / 10) {
|
||||
// delay expired, we may mute
|
||||
setMutePin(true);
|
||||
setMutePin(true);
|
||||
}
|
||||
#else
|
||||
// mute
|
||||
@@ -164,7 +151,7 @@ void audioConsumeCurrentBuffer()
|
||||
if (!nextBuffer) {
|
||||
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
|
||||
if (nextBuffer) {
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
audioUnmute();
|
||||
#endif
|
||||
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA channel
|
||||
@@ -175,7 +162,7 @@ void audioConsumeCurrentBuffer()
|
||||
DAC->SR = DAC_SR_DMAUDR1; // Write 1 to clear flag
|
||||
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1; // Enable DAC
|
||||
}
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
else {
|
||||
audioMute();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
*/
|
||||
|
||||
#include "bluetooth_driver.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_gpio.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
@@ -33,8 +36,8 @@
|
||||
|
||||
static const stm32_usart_t btUSART = {
|
||||
.USARTx = BT_USART,
|
||||
.GPIOx = BT_USART_GPIO,
|
||||
.GPIO_Pin = BT_TX_GPIO_PIN | BT_RX_GPIO_PIN,
|
||||
.txGPIO = BT_TX_GPIO,
|
||||
.rxGPIO = BT_RX_GPIO,
|
||||
.IRQn = BT_USART_IRQn,
|
||||
.IRQ_Prio = BT_USART_IRQ_PRIORITY,
|
||||
.txDMA = nullptr,
|
||||
@@ -57,16 +60,8 @@ void* _bt_usart_ctx = nullptr;
|
||||
|
||||
void bluetoothInit(uint32_t baudrate, bool enable)
|
||||
{
|
||||
#if defined(BT_EN_GPIO_PIN)
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = BT_EN_GPIO_PIN;
|
||||
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
pinInit.Pull = LL_GPIO_PULL_NO;
|
||||
|
||||
LL_GPIO_Init(BT_EN_GPIO, &pinInit);
|
||||
#if defined(BT_EN_GPIO)
|
||||
gpio_init(BT_EN_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
#endif
|
||||
|
||||
#if !defined(BOOT)
|
||||
@@ -85,21 +80,17 @@ void bluetoothInit(uint32_t baudrate, bool enable)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BT_EN_GPIO_PIN)
|
||||
if (enable) {
|
||||
LL_GPIO_ResetOutputPin(BT_EN_GPIO, BT_EN_GPIO_PIN);
|
||||
} else {
|
||||
LL_GPIO_SetOutputPin(BT_EN_GPIO, BT_EN_GPIO_PIN);
|
||||
}
|
||||
#if defined(BT_EN_GPIO)
|
||||
gpio_write(BT_EN_GPIO, !enable);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(BOOT)
|
||||
void bluetoothDisable()
|
||||
{
|
||||
#if defined(BT_EN_GPIO_PIN)
|
||||
#if defined(BT_EN_GPIO)
|
||||
// close bluetooth (recent modules will go to bootloader mode)
|
||||
LL_GPIO_SetOutputPin(BT_EN_GPIO, BT_EN_GPIO_PIN);
|
||||
gpio_set(BT_EN_GPIO);
|
||||
#endif
|
||||
if (_bt_usart_ctx) {
|
||||
STM32SerialDriver.deinit(_bt_usart_ctx);
|
||||
|
||||
@@ -28,58 +28,21 @@
|
||||
#if !defined(SIMU) && !defined(BACKUP)
|
||||
#if defined(STM32F4)
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
#include "stm32f4xx_syscfg.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_exti.h"
|
||||
#include "stm32f4xx_tim.h"
|
||||
#include "stm32f4xx_spi.h"
|
||||
#include "stm32f4xx_pwr.h"
|
||||
#include "stm32f4xx_dma.h"
|
||||
#include "stm32f4xx_dbgmcu.h"
|
||||
#include "misc.h"
|
||||
#else
|
||||
#include "stm32f2xx.h"
|
||||
#include "stm32f2xx_rcc.h"
|
||||
#include "stm32f2xx_syscfg.h"
|
||||
#include "stm32f2xx_gpio.h"
|
||||
#include "stm32f2xx_exti.h"
|
||||
#include "stm32f2xx_tim.h"
|
||||
#include "stm32f2xx_spi.h"
|
||||
#include "stm32f2xx_pwr.h"
|
||||
#include "stm32f2xx_dma.h"
|
||||
#include "stm32f2xx_dbgmcu.h"
|
||||
#include "misc.h"
|
||||
#include "dwt.h" // the old ST library that we use does not define DWT register for STM32F2xx
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//#include "usb_driver.h"
|
||||
|
||||
#if defined(SIMU)
|
||||
#include "../simu/simpgmspace.h"
|
||||
#endif
|
||||
|
||||
// Delays driver
|
||||
#define SYSTEM_TICKS_1MS ((CPU_FREQ + 500) / 1000)
|
||||
#define SYSTEM_TICKS_1US ((CPU_FREQ + 500000) / 1000000)
|
||||
#define SYSTEM_TICKS_01US ((CPU_FREQ + 5000000) / 10000000)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static inline uint32_t ticksNow()
|
||||
{
|
||||
#if !defined(SIMU) && !defined(BACKUP)
|
||||
return DWT->CYCCNT;
|
||||
#define ticksNow() ((uint32_t)(DWT->CYCCNT))
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#define ticksNow() ((uint32_t)(0UL))
|
||||
#endif
|
||||
|
||||
#include "delays_driver.h"
|
||||
|
||||
@@ -62,7 +62,7 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14 OR PCB STREQUAL PL
|
||||
../../../../../targets/common/arm/stm32/spi_flash.cpp
|
||||
../../../../../drivers/frftl.cpp
|
||||
../../../../../crc.cpp
|
||||
../../../../../targets/${TARGET_DIR}/sdram_driver.c
|
||||
../../../../../targets/common/arm/stm32/sdram_driver.cpp
|
||||
../../../../../targets/${TARGET_DIR}/haptic_driver.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_timer.h"
|
||||
#include "hal/usb_driver.h"
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
@@ -100,6 +101,7 @@ MemoryType memoryType;
|
||||
uint32_t unlocked = 0;
|
||||
|
||||
void per5ms() {} // make linker happy
|
||||
|
||||
void per10ms()
|
||||
{
|
||||
tenms |= 1u; // 10 mS has passed
|
||||
@@ -202,18 +204,12 @@ void writeEepromBlock()
|
||||
#if !defined(SIMU)
|
||||
void bootloaderInitApp()
|
||||
{
|
||||
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | LCD_RCC_AHB1Periph |
|
||||
BACKLIGHT_RCC_AHB1Periph |
|
||||
KEYS_BACKLIGHT_RCC_AHB1Periph,
|
||||
ENABLE);
|
||||
LL_AHB1_GRP1_EnableClock(LCD_RCC_AHB1Periph);
|
||||
#if defined(LCD_RCC_APB2Periph)
|
||||
LL_APB2_GRP1_EnableClock(LCD_RCC_APB2Periph);
|
||||
#endif
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
|
||||
RCC_APB1PeriphClockCmd(ROTARY_ENCODER_RCC_APB1Periph | LCD_RCC_APB1Periph |
|
||||
BACKLIGHT_RCC_APB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB2PeriphClockCmd(
|
||||
LCD_RCC_APB2Periph | BACKLIGHT_RCC_APB2Periph | RCC_APB2Periph_SYSCFG,
|
||||
ENABLE);
|
||||
|
||||
#if defined(HAVE_BOARD_BOOTLOADER_INIT)
|
||||
boardBootloaderInit();
|
||||
|
||||
@@ -19,8 +19,13 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "delays_driver.h"
|
||||
#include "board.h"
|
||||
|
||||
#define SYSTEM_TICKS_1MS ((CPU_FREQ + 500) / 1000)
|
||||
#define SYSTEM_TICKS_1US ((CPU_FREQ + 500000) / 1000000)
|
||||
#define SYSTEM_TICKS_01US ((CPU_FREQ + 5000000) / 10000000)
|
||||
|
||||
void delaysInit()
|
||||
{
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
|
||||
@@ -21,11 +21,13 @@
|
||||
|
||||
|
||||
#include "diskio_sdio.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
#include "stm32_dma.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_gpio.h"
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
@@ -215,7 +217,7 @@ static DSTATUS sdio_status(BYTE lun)
|
||||
DSTATUS stat = RES_OK;
|
||||
|
||||
#if defined(SD_PRESENT_GPIO)
|
||||
if ((LL_GPIO_ReadInputPort(SD_PRESENT_GPIO) & SD_PRESENT_LL_GPIO_PIN) != 0) {
|
||||
if (gpio_read(SD_PRESENT_GPIO)) {
|
||||
stat |= STA_NODISK;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -45,22 +45,15 @@ if(NOT NATIVE_BUILD)
|
||||
endif()
|
||||
|
||||
# StdPeriph library
|
||||
set(STM32LIB_DIR ${THIRDPARTY_DIR}/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries)
|
||||
include_directories(${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver/inc)
|
||||
set(STM32LIB_DIR ${THIRDPARTY_DIR})
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/Device/ST/STM32F2xx/Include)
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/Include)
|
||||
|
||||
add_definitions(-DSTM32F2)
|
||||
|
||||
set(STM32_STDPERIPH_DIR ${STM32LIB_DIR}/STM32F2xx_StdPeriph_Driver)
|
||||
|
||||
add_library(stm32_stdperiph OBJECT EXCLUDE_FROM_ALL
|
||||
targets/common/arm/stm32/f2/system_stm32f2xx.c
|
||||
boards/generic_stm32/startup/startup_stm32f205xx.s
|
||||
${STM32_STDPERIPH_DIR}/src/misc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_gpio.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_dbgmcu.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f2xx_rcc.c
|
||||
)
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32_stdperiph>)
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
*/
|
||||
|
||||
#include "stm32f2xx.h"
|
||||
#include "stm32_hal.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -87,8 +88,8 @@
|
||||
|
||||
uint32_t SystemCoreClock = 120000000;
|
||||
|
||||
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
__I uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -24,6 +24,7 @@ if(NOT NATIVE_BUILD)
|
||||
add_library(stm32cube_ll OBJECT EXCLUDE_FROM_ALL
|
||||
# LL drivers
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_gpio.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_fmc.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_tim.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_dma.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_ll_usart.c
|
||||
@@ -46,6 +47,8 @@ if(NOT NATIVE_BUILD)
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_dma.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_pcd.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_pcd_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_flash.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_flash_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32f4xx_hal_cortex.c
|
||||
|
||||
${STM32_COLORLCD_DRIVERS}
|
||||
@@ -62,29 +65,19 @@ if(NOT NATIVE_BUILD)
|
||||
endif()
|
||||
|
||||
# StdPeriph library
|
||||
set(STM32LIB_DIR ${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries)
|
||||
include_directories(${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/inc)
|
||||
set(STM32LIB_DIR ${THIRDPARTY_DIR})
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/Device/ST/STM32F4xx/Include)
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/Include)
|
||||
|
||||
add_definitions(-DSTM32F4)
|
||||
|
||||
set(STM32_STDPERIPH_DIR ${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver)
|
||||
|
||||
set(STM32_STDPERIPH_SRC
|
||||
targets/common/arm/stm32/f4/system_stm32f4xx.c
|
||||
${STM32_STDPERIPH_DIR}/src/misc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_gpio.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_dbgmcu.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_rcc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_flash.c
|
||||
)
|
||||
|
||||
if(CPU_TYPE_FULL STREQUAL STM32F429xI)
|
||||
set(STM32_STDPERIPH_SRC ${STM32_STDPERIPH_SRC}
|
||||
boards/generic_stm32/startup/startup_stm32f42_43xxx.s
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_fmc.c
|
||||
${STM32_STDPERIPH_DIR}/src/stm32f4xx_dma.c
|
||||
)
|
||||
elseif (CPU_TYPE_FULL STREQUAL STM32F413xG)
|
||||
set(STM32_STDPERIPH_SRC ${STM32_STDPERIPH_SRC}
|
||||
|
||||
@@ -120,7 +120,9 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
#include "thirdparty/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -195,8 +197,8 @@
|
||||
uint32_t SystemCoreClock = 168000000;
|
||||
#endif
|
||||
|
||||
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
__I uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
const uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -257,10 +259,8 @@ void SystemInit(void)
|
||||
|
||||
#if defined(SDRAM)
|
||||
void SDRAM_Init();
|
||||
void FMC_SDRAMWriteProtectionConfig(uint32_t SDRAM_Bank, FunctionalState NewState);
|
||||
|
||||
SDRAM_Init(); // calls SDRAM_GPIOConfig()
|
||||
FMC_SDRAMWriteProtectionConfig(((uint32_t)0x00000001), DISABLE);
|
||||
#endif
|
||||
|
||||
#ifdef DATA_IN_ExtSRAM
|
||||
|
||||
@@ -19,20 +19,18 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_cmsis.h"
|
||||
#include "stm32_hal.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "hal/watchdog_driver.h"
|
||||
|
||||
#if defined(STM32F4)
|
||||
#include "stm32f4xx_flash.h"
|
||||
#elif defined(STM32F2)
|
||||
#include "stm32f2xx_flash.h"
|
||||
#endif
|
||||
|
||||
void waitFlashIdle()
|
||||
{
|
||||
do {
|
||||
WDG_RESET();
|
||||
} while (FLASH->SR & FLASH_FLAG_BSY);
|
||||
} while (FLASH->SR & FLASH_SR_BSY);
|
||||
}
|
||||
|
||||
//After reset, write is not allowed in the Flash control register (FLASH_CR) to protect the
|
||||
@@ -64,8 +62,8 @@ void eraseSector(uint32_t sector)
|
||||
|
||||
waitFlashIdle();
|
||||
|
||||
FLASH->CR &= CR_PSIZE_MASK;
|
||||
FLASH->CR |= FLASH_PSIZE_WORD;
|
||||
FLASH->CR &= ~FLASH_CR_PSIZE;
|
||||
FLASH->CR |= FLASH_CR_PSIZE_1;
|
||||
FLASH->CR &= SECTOR_MASK;
|
||||
FLASH->CR |= FLASH_CR_SER | (sector << 3);
|
||||
FLASH->CR |= FLASH_CR_STRT;
|
||||
@@ -136,7 +134,7 @@ void flashWrite(uint32_t * address, const uint32_t * buffer) // page size is 256
|
||||
|
||||
#undef SECTOR_ADDRESS
|
||||
#undef FLASH_BANK
|
||||
|
||||
|
||||
for (uint32_t i=0; i<FLASH_PAGESIZE/4; i++) {
|
||||
/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
|
||||
be done by word */
|
||||
@@ -144,8 +142,8 @@ void flashWrite(uint32_t * address, const uint32_t * buffer) // page size is 256
|
||||
// Wait for last operation to be completed
|
||||
waitFlashIdle();
|
||||
|
||||
FLASH->CR &= CR_PSIZE_MASK;
|
||||
FLASH->CR |= FLASH_PSIZE_WORD;
|
||||
FLASH->CR &= ~FLASH_CR_PSIZE;
|
||||
FLASH->CR |= FLASH_CR_PSIZE_1;
|
||||
FLASH->CR |= FLASH_CR_PG;
|
||||
|
||||
*address = *buffer;
|
||||
|
||||
@@ -21,10 +21,12 @@
|
||||
|
||||
#include "flysky_gimbal_driver.h"
|
||||
#include "stm32_serial_driver.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_adc.h"
|
||||
|
||||
#include "delays_driver.h"
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "crc.h"
|
||||
@@ -33,8 +35,8 @@
|
||||
|
||||
static const stm32_usart_t fsUSART = {
|
||||
.USARTx = FLYSKY_HALL_SERIAL_USART,
|
||||
.GPIOx = FLYSKY_HALL_SERIAL_GPIO,
|
||||
.GPIO_Pin = FLYSKY_HALL_SERIAL_RX_GPIO_PIN,
|
||||
.txGPIO = GPIO_UNDEF,
|
||||
.rxGPIO = FLYSKY_HALL_SERIAL_RX_GPIO,
|
||||
.IRQn = FLYSKY_HALL_SERIAL_USART_IRQn,
|
||||
.IRQ_Prio = 6,
|
||||
.txDMA = nullptr,
|
||||
|
||||
@@ -19,8 +19,12 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "hal/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include "mixer_scheduler.h"
|
||||
#include "board.h"
|
||||
#include "debug.h"
|
||||
@@ -47,21 +51,9 @@ void init_intmodule_heartbeat()
|
||||
{
|
||||
TRACE("init_intmodule_heartbeat");
|
||||
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = INTMODULE_HEARTBEAT_GPIO_PIN;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
pinInit.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
pinInit.Pull = LL_GPIO_PULL_UP;
|
||||
|
||||
LL_GPIO_Init(INTMODULE_HEARTBEAT_GPIO, &pinInit);
|
||||
|
||||
LL_SYSCFG_SetEXTISource(INTMODULE_HEARTBEAT_EXTI_PORT, INTMODULE_HEARTBEAT_EXTI_SYS_LINE);
|
||||
|
||||
stm32_exti_enable(INTMODULE_HEARTBEAT_EXTI_LINE, INTMODULE_HEARTBEAT_TRIGGER,
|
||||
trigger_intmodule_heartbeat);
|
||||
gpio_init_int(INTMODULE_HEARTBEAT_GPIO, GPIO_IN_PU,
|
||||
INTMODULE_HEARTBEAT_TRIGGER,
|
||||
trigger_intmodule_heartbeat);
|
||||
|
||||
heartbeatCapture.valid = true;
|
||||
}
|
||||
|
||||
@@ -19,68 +19,58 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "hal/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "hal/abnormal_reboot.h"
|
||||
|
||||
void pwrInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
|
||||
#if defined(INTMODULE_BOOTCMD_GPIO)
|
||||
INIT_INTMODULE_BOOTCMD_PIN();
|
||||
GPIO_InitStructure.GPIO_Pin = INTMODULE_BOOTCMD_GPIO_PIN;
|
||||
GPIO_Init(INTMODULE_BOOTCMD_GPIO, &GPIO_InitStructure);
|
||||
gpio_init(INTMODULE_BOOTCMD_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
gpio_write(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_DEFAULT);
|
||||
#endif
|
||||
|
||||
// Internal module power
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
gpio_init(INTMODULE_PWR_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
INTERNAL_MODULE_OFF();
|
||||
GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN;
|
||||
GPIO_Init(INTMODULE_PWR_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
// External module power
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
gpio_init(EXTMODULE_PWR_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
EXTERNAL_MODULE_PWR_OFF();
|
||||
GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN;
|
||||
GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
||||
|
||||
// PWR switch
|
||||
#if defined(PWR_SWITCH_GPIO)
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_SWITCH_GPIO_PIN;
|
||||
GPIO_Init(PWR_SWITCH_GPIO, &GPIO_InitStructure);
|
||||
gpio_init(PWR_SWITCH_GPIO, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
|
||||
#endif
|
||||
|
||||
#if defined(PWR_EXTRA_SWITCH_GPIO)
|
||||
// PWR Extra switch
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_EXTRA_SWITCH_GPIO_PIN;
|
||||
GPIO_Init(PWR_EXTRA_SWITCH_GPIO, &GPIO_InitStructure);
|
||||
gpio_init(PWR_EXTRA_SWITCH_GPIO, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
|
||||
#endif
|
||||
|
||||
#if defined(PCBREV_HARDCODED)
|
||||
hardwareOptions.pcbrev = PCBREV_HARDCODED;
|
||||
#elif defined(PCBREV_GPIO_PIN)
|
||||
#elif defined(PCBREV_GPIO)
|
||||
#if defined(PCBREV_GPIO_PULL_DOWN)
|
||||
GPIO_ResetBits(PCBREV_GPIO, PCBREV_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
|
||||
gpio_init(PCBREV_GPIO, GPIO_IN_PD, GPIO_PIN_SPEED_LOW);
|
||||
#else
|
||||
gpio_init(PCBREV_GPIO, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
|
||||
#endif
|
||||
GPIO_InitStructure.GPIO_Pin = PCBREV_GPIO_PIN;
|
||||
GPIO_Init(PCBREV_GPIO, &GPIO_InitStructure);
|
||||
hardwareOptions.pcbrev = PCBREV_VALUE();
|
||||
#elif defined(PCBREV_GPIO_1) && defined(PCBREV_GPIO_2)
|
||||
gpio_init(PCBREV_GPIO_1, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
|
||||
#if defined(PCBREV_TOUCH_GPIO_PIN)
|
||||
#if defined(PCBREV_TOUCH_GPIO_PULL_UP)
|
||||
GPIO_ResetBits(PCBREV_TOUCH_GPIO, PCBREV_TOUCH_GPIO_PIN);
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
gpio_init(PCBREV_GPIO_2, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
|
||||
#else
|
||||
gpio_init(PCBREV_TOUCH_GPIO, GPIO_IN_PD, GPIO_PIN_SPEED_LOW);
|
||||
#endif
|
||||
GPIO_InitStructure.GPIO_Pin = PCBREV_TOUCH_GPIO_PIN;
|
||||
GPIO_Init(PCBREV_TOUCH_GPIO, &GPIO_InitStructure);
|
||||
#endif
|
||||
|
||||
hardwareOptions.pcbrev = PCBREV_VALUE();
|
||||
@@ -89,44 +79,32 @@ void pwrInit()
|
||||
|
||||
void pwrOn()
|
||||
{
|
||||
// we keep the init of the PIN to have pwrOn as quick as possible
|
||||
#if defined(PWR_ON_GPIO)
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = PWR_ON_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(PWR_ON_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_SetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
|
||||
gpio_init(PWR_ON_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
gpio_set(PWR_ON_GPIO);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pwrOff()
|
||||
{
|
||||
#if defined(PWR_ON_GPIO)
|
||||
GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
|
||||
gpio_clear(PWR_ON_GPIO);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PWR_EXTRA_SWITCH_GPIO)
|
||||
bool pwrForcePressed()
|
||||
{
|
||||
return (GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET && GPIO_ReadInputDataBit(PWR_EXTRA_SWITCH_GPIO, PWR_EXTRA_SWITCH_GPIO_PIN) == Bit_RESET);
|
||||
return !gpio_read(PWR_SWITCH_GPIO) && !gpio_read(PWR_EXTRA_SWITCH_GPIO);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool pwrPressed()
|
||||
{
|
||||
#if defined(PWR_EXTRA_SWITCH_GPIO)
|
||||
return (GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) ==
|
||||
Bit_RESET ||
|
||||
GPIO_ReadInputDataBit(PWR_EXTRA_SWITCH_GPIO,
|
||||
PWR_EXTRA_SWITCH_GPIO_PIN) == Bit_RESET);
|
||||
return !gpio_read(PWR_SWITCH_GPIO) && !gpio_read(PWR_EXTRA_SWITCH_GPIO);
|
||||
#elif defined(PWR_SWITCH_GPIO)
|
||||
return GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) ==
|
||||
Bit_RESET;
|
||||
return !gpio_read(PWR_SWITCH_GPIO);
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
@@ -145,13 +123,6 @@ bool pwrOffPressed()
|
||||
|
||||
void pwrResetHandler()
|
||||
{
|
||||
RCC->AHB1ENR |= PWR_RCC_AHB1Periph;
|
||||
|
||||
// these two NOPs are needed (see STM32F errata sheet) before the peripheral
|
||||
// register can be written after the peripheral clock was enabled
|
||||
__ASM volatile ("nop");
|
||||
__ASM volatile ("nop");
|
||||
|
||||
if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
|
||||
pwrOn();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "hal/rotary_encoder.h"
|
||||
|
||||
#include "board_common.h"
|
||||
#include "stm32_timer.h"
|
||||
|
||||
#if !defined(BOOT)
|
||||
#include "opentx.h"
|
||||
@@ -153,7 +154,8 @@ void rotaryEncoderInit()
|
||||
|
||||
stm32_gpio_enable_clock(ROTARY_ENCODER_GPIO);
|
||||
LL_GPIO_Init(ROTARY_ENCODER_GPIO, &pinInit);
|
||||
|
||||
|
||||
stm32_timer_enable_clock(ROTARY_ENCODER_TIMER);
|
||||
ROTARY_ENCODER_TIMER->ARR = 99; // 100uS
|
||||
ROTARY_ENCODER_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1; // 1uS
|
||||
ROTARY_ENCODER_TIMER->CCER = 0;
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "hal/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
#if defined(SDRAM_BANK1)
|
||||
#define SDRAM_BANK FMC_SDRAM_BANK1
|
||||
#define COMMAND_TARGET FMC_SDRAM_CMD_TARGET_BANK1
|
||||
#elif defined(SDRAM_BANK2)
|
||||
#define SDRAM_BANK FMC_SDRAM_BANK2
|
||||
#define COMMAND_TARGET FMC_SDRAM_CMD_TARGET_BANK2
|
||||
#else
|
||||
#error "No bank definition for SDRAM"
|
||||
#endif
|
||||
|
||||
#define SDRAM_MEMORY_WIDTH FMC_SDRAM_MEM_BUS_WIDTH_16
|
||||
#define SDRAM_CAS_LATENCY FMC_SDRAM_CAS_LATENCY_3
|
||||
#define SDRAM_READBURST FMC_SDRAM_RBURST_ENABLE
|
||||
#define SDRAM_READPIPEDELAY FMC_SDRAM_RPIPE_DELAY_1
|
||||
#define SDRAM_CLK_PERIOD FMC_SDRAM_CLOCK_PERIOD_2
|
||||
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_1 ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_2 ((uint16_t)0x0001)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_4 ((uint16_t)0x0002)
|
||||
#define SDRAM_MODEREG_BURST_LENGTH_8 ((uint16_t)0x0004)
|
||||
#define SDRAM_MODEREG_BURST_FULL_PAGE ((uint16_t)0x0007)
|
||||
#define SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_BURST_TYPE_INTERLEAVED ((uint16_t)0x0008)
|
||||
#define SDRAM_MODEREG_CAS_LATENCY_1 ((uint16_t)0x0010)
|
||||
#define SDRAM_MODEREG_CAS_LATENCY_2 ((uint16_t)0x0020)
|
||||
#define SDRAM_MODEREG_CAS_LATENCY_3 ((uint16_t)0x0030)
|
||||
#define SDRAM_MODEREG_OPERATING_MODE_STANDARD ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_WRITEBURST_MODE_PROGRAMMED ((uint16_t)0x0000)
|
||||
#define SDRAM_MODEREG_WRITEBURST_MODE_SINGLE ((uint16_t)0x0200)
|
||||
|
||||
#define GPIO_AF_FMC GPIO_AF12
|
||||
|
||||
extern "C" void SDRAM_GPIOConfig(void)
|
||||
{
|
||||
/*-- GPIOs Configuration -----------------------------------------------------*/
|
||||
/*
|
||||
+-------------------+--------------------+--------------------+--------------------+
|
||||
+ SDRAM pins assignment +
|
||||
+-------------------+--------------------+--------------------+--------------------+
|
||||
| PD0 <-> FMC_D2 | PE0 <-> FMC_NBL0 | PF0 <-> FMC_A0 | PG0 <-> FMC_A10 |
|
||||
| PD1 <-> FMC_D3 | PE1 <-> FMC_NBL1 | PF1 <-> FMC_A1 | PG1 <-> FMC_A11 |
|
||||
| PD8 <-> FMC_D13 | PE7 <-> FMC_D4 | PF2 <-> FMC_A2 | PG8 <-> FMC_SDCLK |
|
||||
| PD9 <-> FMC_D14 | PE8 <-> FMC_D5 | PF3 <-> FMC_A3 | PG15 <-> FMC_NCAS |
|
||||
| PD10 <-> FMC_D15 | PE9 <-> FMC_D6 | PF4 <-> FMC_A4 |--------------------+
|
||||
| PD14 <-> FMC_D0 | PE10 <-> FMC_D7 | PF5 <-> FMC_A5 |
|
||||
| PD15 <-> FMC_D1 | PE11 <-> FMC_D8 | PF11 <-> FMC_NRAS |
|
||||
+-------------------| PE12 <-> FMC_D9 | PF12 <-> FMC_A6 |
|
||||
| PE13 <-> FMC_D10 | PF13 <-> FMC_A7 |
|
||||
| PE14 <-> FMC_D11 | PF14 <-> FMC_A8 |
|
||||
| PE15 <-> FMC_D12 | PF15 <-> FMC_A9 |
|
||||
+-------------------+--------------------+--------------------+
|
||||
| PC3 <-> FMC_SDCKE0| PB5 <-> FMC_SDCKE1 |
|
||||
| PH3 <-> FMC_SDNE0 | PH6 <-> FMC_SDNE1 |
|
||||
| PH5 <-> FMC_SDNWE | |
|
||||
+-------------------++-------------------+
|
||||
*/
|
||||
|
||||
#if defined(SDRAM_BANK1)
|
||||
/* GPIOC configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOC, 3), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
#else
|
||||
/* GPIOB configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOB, 5), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
#endif
|
||||
|
||||
/* GPIOH configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOH, 5), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
#if defined(SDRAM_BANK1)
|
||||
gpio_init_af(GPIO_PIN(GPIOH, 3), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
#else
|
||||
gpio_init_af(GPIO_PIN(GPIOH, 6), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
#endif
|
||||
|
||||
/* GPIOD configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 1), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 8), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 9), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 10), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 14), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOD, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
/* GPIOE configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 1), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 7), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 8), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 9), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 10), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 11), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 12), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 13), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 14), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOE, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
/* GPIOF configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 1), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 2), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 3), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 4), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 5), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 11), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 12), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 13), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 14), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOF, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
/* GPIOG configuration */
|
||||
gpio_init_af(GPIO_PIN(GPIOG, 0), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOG, 1), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOG, 4), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOG, 5), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOG, 8), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(GPIO_PIN(GPIOG, 15), GPIO_AF_FMC, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
}
|
||||
|
||||
void SDRAM_InitSequence(void)
|
||||
{
|
||||
FMC_SDRAM_CommandTypeDef FMC_SDRAMCommandStructure;
|
||||
uint32_t tmpr = 0;
|
||||
|
||||
/* Step 3 --------------------------------------------------------------------*/
|
||||
/* Configure a clock configuration enable command */
|
||||
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_CLK_ENABLE;
|
||||
FMC_SDRAMCommandStructure.CommandTarget = COMMAND_TARGET;
|
||||
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
|
||||
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
|
||||
/* Wait until the SDRAM controller is ready */
|
||||
while((__FMC_SDRAM_GET_FLAG(FMC_SDRAM_DEVICE, FMC_SDRAM_FLAG_BUSY) != 0));
|
||||
|
||||
/* Send the command */
|
||||
FMC_SDRAM_SendCommand(FMC_SDRAM_DEVICE, &FMC_SDRAMCommandStructure, 10);
|
||||
|
||||
/* Step 4 --------------------------------------------------------------------*/
|
||||
/* Insert 100 ms delay */
|
||||
delay_ms(100);
|
||||
|
||||
/* Step 5 --------------------------------------------------------------------*/
|
||||
/* Configure a PALL (precharge all) command */
|
||||
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_PALL;
|
||||
FMC_SDRAMCommandStructure.CommandTarget = COMMAND_TARGET;
|
||||
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
|
||||
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
|
||||
/* Wait until the SDRAM controller is ready */
|
||||
while((__FMC_SDRAM_GET_FLAG(FMC_SDRAM_DEVICE, FMC_SDRAM_FLAG_BUSY) != 0));
|
||||
|
||||
/* Send the command */
|
||||
FMC_SDRAM_SendCommand(FMC_SDRAM_DEVICE, &FMC_SDRAMCommandStructure, 10);
|
||||
|
||||
/* Step 6 --------------------------------------------------------------------*/
|
||||
/* Configure a Auto-Refresh command */
|
||||
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_AUTOREFRESH_MODE;
|
||||
FMC_SDRAMCommandStructure.CommandTarget = COMMAND_TARGET;
|
||||
FMC_SDRAMCommandStructure.AutoRefreshNumber = 4;
|
||||
FMC_SDRAMCommandStructure.ModeRegisterDefinition = 0;
|
||||
|
||||
/* Wait until the SDRAM controller is ready */
|
||||
while((__FMC_SDRAM_GET_FLAG(FMC_SDRAM_DEVICE, FMC_SDRAM_FLAG_BUSY) != 0));
|
||||
|
||||
/* Send the command */
|
||||
FMC_SDRAM_SendCommand(FMC_SDRAM_DEVICE, &FMC_SDRAMCommandStructure, 10);
|
||||
|
||||
/* Step 7 --------------------------------------------------------------------*/
|
||||
/* Program the external memory mode register */
|
||||
tmpr = (uint32_t)SDRAM_MODEREG_BURST_LENGTH_2 |
|
||||
SDRAM_MODEREG_BURST_TYPE_SEQUENTIAL |
|
||||
SDRAM_MODEREG_CAS_LATENCY_3 |
|
||||
SDRAM_MODEREG_OPERATING_MODE_STANDARD |
|
||||
SDRAM_MODEREG_WRITEBURST_MODE_SINGLE;
|
||||
|
||||
/* Configure a load Mode register command*/
|
||||
FMC_SDRAMCommandStructure.CommandMode = FMC_SDRAM_CMD_LOAD_MODE;
|
||||
FMC_SDRAMCommandStructure.CommandTarget = COMMAND_TARGET;
|
||||
FMC_SDRAMCommandStructure.AutoRefreshNumber = 1;
|
||||
FMC_SDRAMCommandStructure.ModeRegisterDefinition = tmpr;
|
||||
|
||||
/* Wait until the SDRAM controller is ready */
|
||||
while((__FMC_SDRAM_GET_FLAG(FMC_SDRAM_DEVICE, FMC_SDRAM_FLAG_BUSY) != 0));
|
||||
|
||||
/* Send the command */
|
||||
FMC_SDRAM_SendCommand(FMC_SDRAM_DEVICE, &FMC_SDRAMCommandStructure, 10);
|
||||
|
||||
/* Step 8: Set the refresh rate counter - refer to section SDRAM refresh timer register in RM0455 */
|
||||
/* Set the device refresh rate
|
||||
* COUNT = [(SDRAM self refresh time / number of row) x SDRAM CLK] – 20
|
||||
= [(64ms/4096) * 84MHz] - 20 = 1312 - 20 ~ 1292 */
|
||||
FMC_SDRAM_ProgramRefreshRate(FMC_SDRAM_DEVICE, 1292);
|
||||
/* Wait until the SDRAM controller is ready */
|
||||
while((__FMC_SDRAM_GET_FLAG(FMC_SDRAM_DEVICE, FMC_SDRAM_FLAG_BUSY) != 0));
|
||||
}
|
||||
|
||||
extern "C" void SDRAM_Init(void)
|
||||
{
|
||||
//delay funcion needed
|
||||
delaysInit();
|
||||
// Clocks must be enabled here, because the sdramInit is called before main
|
||||
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_FMC);
|
||||
|
||||
/* GPIO configuration for FMC SDRAM bank */
|
||||
SDRAM_GPIOConfig();
|
||||
|
||||
|
||||
/* FMC Configuration ---------------------------------------------------------*/
|
||||
FMC_SDRAM_InitTypeDef FMC_SDRAMInitStructure;
|
||||
FMC_SDRAM_TimingTypeDef FMC_SDRAMTimingInitStructure;
|
||||
|
||||
/* FMC SDRAM Bank configuration */
|
||||
/* Timing configuration for 84 Mhz of SD clock frequency (168Mhz/2) */
|
||||
/* TMRD: 2 Clock cycles */
|
||||
FMC_SDRAMTimingInitStructure.LoadToActiveDelay = 2;
|
||||
/* TXSR: min=72ns (7x11.9ns) */
|
||||
FMC_SDRAMTimingInitStructure.ExitSelfRefreshDelay = 7;
|
||||
/* TRAS: min=42ns (4x11.9ns) max=120k (ns) */
|
||||
FMC_SDRAMTimingInitStructure.SelfRefreshTime = 4;
|
||||
/* TRC: min=60 (6x11.9ns) */
|
||||
FMC_SDRAMTimingInitStructure.RowCycleDelay = 6;
|
||||
/* TWR: 2 CLK */
|
||||
FMC_SDRAMTimingInitStructure.WriteRecoveryTime = 2;
|
||||
/* TRP: 15ns => 2x11.9ns */
|
||||
FMC_SDRAMTimingInitStructure.RPDelay = 2;
|
||||
/* TRCD: 15ns => 2x11.9ns */
|
||||
FMC_SDRAMTimingInitStructure.RCDDelay = 2;
|
||||
|
||||
/* FMC SDRAM control configuration */
|
||||
FMC_SDRAMInitStructure.SDBank = SDRAM_BANK;
|
||||
/* Row addressing: [7:0] */
|
||||
FMC_SDRAMInitStructure.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
|
||||
/* Column addressing: [11:0] */
|
||||
FMC_SDRAMInitStructure.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
|
||||
FMC_SDRAMInitStructure.MemoryDataWidth = SDRAM_MEMORY_WIDTH;
|
||||
FMC_SDRAMInitStructure.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
|
||||
FMC_SDRAMInitStructure.CASLatency = SDRAM_CAS_LATENCY;
|
||||
FMC_SDRAMInitStructure.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
|
||||
FMC_SDRAMInitStructure.SDClockPeriod = SDRAM_CLK_PERIOD;
|
||||
FMC_SDRAMInitStructure.ReadBurst = SDRAM_READBURST;
|
||||
FMC_SDRAMInitStructure.ReadPipeDelay = SDRAM_READPIPEDELAY;
|
||||
// FMC_SDRAMInitStructure.FMC_SDRAMTimingStruct = &FMC_SDRAMTimingInitStructure;
|
||||
|
||||
/* FMC SDRAM bank initialization */
|
||||
FMC_SDRAM_Init(FMC_SDRAM_DEVICE, &FMC_SDRAMInitStructure);
|
||||
FMC_SDRAM_Timing_Init(FMC_SDRAM_DEVICE, &FMC_SDRAMTimingInitStructure, SDRAM_BANK);
|
||||
|
||||
|
||||
/* FMC SDRAM device initialization sequence */
|
||||
SDRAM_InitSequence();
|
||||
FMC_SDRAM_WriteProtection_Disable(FMC_SDRAM_DEVICE, SDRAM_BANK);
|
||||
}
|
||||
@@ -98,6 +98,10 @@ void stm32_exti_enable(uint32_t line, uint8_t trigger, stm32_exti_handler_t cb)
|
||||
{
|
||||
if (line > LL_EXTI_LINE_15) return;
|
||||
|
||||
#if defined(LL_APB2_GRP1_PERIPH_EXTI)
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_EXTI);
|
||||
#endif
|
||||
|
||||
LL_EXTI_InitTypeDef EXTI_init;
|
||||
LL_EXTI_StructInit(&EXTI_init);
|
||||
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "hal/gpio.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
static inline GPIO_TypeDef* _port(gpio_t pin)
|
||||
{
|
||||
return (GPIO_TypeDef*)(pin & ~(0x0f));
|
||||
}
|
||||
|
||||
static inline int _port_num(gpio_t pin)
|
||||
{
|
||||
return (((pin - GPIOA_BASE) >> 10) & 0x0f);
|
||||
}
|
||||
|
||||
static inline void _enable_clock(GPIO_TypeDef* port)
|
||||
{
|
||||
uint32_t reg_idx = (((uint32_t)port) - GPIOA_BASE) >> 10;
|
||||
LL_AHB1_GRP1_EnableClock(RCC_AHB1ENR_GPIOAEN << reg_idx);
|
||||
}
|
||||
|
||||
static inline int _pin_num(gpio_t pin)
|
||||
{
|
||||
return (pin & 0x0f);
|
||||
}
|
||||
|
||||
static inline void _set_mode(GPIO_TypeDef* port, int pin_num, unsigned mode)
|
||||
{
|
||||
uint32_t tmp = port->MODER;
|
||||
tmp &= ~(0x3 << (2 * pin_num));
|
||||
tmp |= ((mode & 0x3) << (2 * pin_num));
|
||||
port->MODER = tmp;
|
||||
}
|
||||
|
||||
static inline unsigned _get_mode(GPIO_TypeDef* port, int pin_num)
|
||||
{
|
||||
uint32_t tmp = port->MODER;
|
||||
tmp >>= (2 * pin_num);
|
||||
return tmp & 0x03;
|
||||
}
|
||||
|
||||
|
||||
void gpio_init(gpio_t pin, gpio_mode_t mode, gpio_speed_t speed)
|
||||
{
|
||||
GPIO_TypeDef* port = _port(pin);
|
||||
int pin_num = _pin_num(pin);
|
||||
|
||||
_enable_clock(port);
|
||||
_set_mode(port, pin, mode);
|
||||
|
||||
// pull up/down
|
||||
port->PUPDR &= ~(0x3 << (2 * pin_num));
|
||||
port->PUPDR |= (((mode >> 2) & 0x3) << (2 * pin_num));
|
||||
|
||||
// output mode
|
||||
port->OTYPER &= ~(1 << pin_num);
|
||||
port->OTYPER |= (((mode >> 4) & 0x1) << pin_num);
|
||||
|
||||
// pin speed to max
|
||||
port->OSPEEDR |= (speed << (2 * pin_num));
|
||||
}
|
||||
|
||||
void gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t cb)
|
||||
{
|
||||
int port_num = _port_num(pin);
|
||||
int pin_num = _pin_num(pin);
|
||||
|
||||
gpio_init(pin, mode, GPIO_PIN_SPEED_LOW);
|
||||
|
||||
// enable specific pin as exti sources
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
SYSCFG->EXTICR[pin_num >> 2] &= ~(0xf << ((pin_num & 0x03) * 4));
|
||||
SYSCFG->EXTICR[pin_num >> 2] |= (port_num << ((pin_num & 0x03) * 4));
|
||||
|
||||
stm32_exti_enable(1 << pin_num, (uint8_t)flank, cb);
|
||||
}
|
||||
|
||||
void gpio_int_disable(gpio_t pin)
|
||||
{
|
||||
int pin_num = _pin_num(pin);
|
||||
stm32_exti_disable(1 << pin_num);
|
||||
}
|
||||
|
||||
void gpio_init_af(gpio_t pin, gpio_af_t af, gpio_speed_t speed)
|
||||
{
|
||||
GPIO_TypeDef* port = _port(pin);
|
||||
int pin_num = _pin_num(pin);
|
||||
|
||||
_enable_clock(port);
|
||||
|
||||
// set selected function
|
||||
port->AFR[(pin_num > 7) ? 1 : 0] &= ~(0xf << ((pin_num & 0x07) * 4));
|
||||
port->AFR[(pin_num > 7) ? 1 : 0] |= (af << ((pin_num & 0x07) * 4));
|
||||
// pin speed to max
|
||||
port->OSPEEDR |= (speed << (2 * pin_num));
|
||||
|
||||
_set_mode(port, pin_num, 2);
|
||||
}
|
||||
|
||||
void gpio_init_analog(gpio_t pin)
|
||||
{
|
||||
GPIO_TypeDef* port = _port(pin);
|
||||
int pin_num = _pin_num(pin);
|
||||
|
||||
_enable_clock(port);
|
||||
_set_mode(port, pin_num, 3);
|
||||
|
||||
// PUPD has to be 0b00
|
||||
port->PUPDR &= ~(0x3 << (2 * pin_num));
|
||||
}
|
||||
|
||||
gpio_mode_t gpio_get_mode(gpio_t pin)
|
||||
{
|
||||
return _get_mode(_port(pin), _pin_num(pin));
|
||||
}
|
||||
|
||||
int gpio_read(gpio_t pin)
|
||||
{
|
||||
return (_port(pin)->IDR & (1 << _pin_num(pin)));
|
||||
}
|
||||
|
||||
void gpio_set(gpio_t pin)
|
||||
{
|
||||
_port(pin)->BSRR = (1 << _pin_num(pin));
|
||||
}
|
||||
|
||||
void gpio_clear(gpio_t pin)
|
||||
{
|
||||
_port(pin)->BSRR = (1 << (_pin_num(pin) + 16));
|
||||
}
|
||||
|
||||
void gpio_toggle(gpio_t pin)
|
||||
{
|
||||
if (gpio_read(pin)) {
|
||||
gpio_clear(pin);
|
||||
} else {
|
||||
gpio_set(pin);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_write(gpio_t pin, int value)
|
||||
{
|
||||
if (value) {
|
||||
gpio_set(pin);
|
||||
} else {
|
||||
gpio_clear(pin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stm32_cmsis.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define GPIO_UNDEF (0xffffffff)
|
||||
|
||||
// #define GPIO_PIN(x, y) ((GPIOA_BASE + (x << 10)) | y)
|
||||
#define GPIO_PIN(x, y) ((intptr_t)x | y)
|
||||
|
||||
// Generate GPIO mode bitfields
|
||||
//
|
||||
// bit 0+1: pin mode (input / output)
|
||||
// bit 2+3: pull resistor configuration
|
||||
// bit 4: output type (0: push-pull, 1: open-drain)
|
||||
//
|
||||
#define _GPIO_MODE(io, pr, ot) ((io << 0) | (pr << 2) | (ot << 4))
|
||||
|
||||
enum {
|
||||
GPIO_IN = _GPIO_MODE(0, 0, 0), // input w/o pull R
|
||||
GPIO_IN_PD = _GPIO_MODE(0, 2, 0), // input with pull-down
|
||||
GPIO_IN_PU = _GPIO_MODE(0, 1, 0), // input with pull-up
|
||||
GPIO_OUT = _GPIO_MODE(1, 0, 0), // push-pull output
|
||||
GPIO_OD = _GPIO_MODE(1, 0, 1), // open-drain w/o pull R
|
||||
GPIO_OD_PU = _GPIO_MODE(1, 1, 1) // open-drain with pull-up
|
||||
};
|
||||
|
||||
enum {
|
||||
GPIO_AF0 = 0,
|
||||
GPIO_AF1,
|
||||
GPIO_AF2,
|
||||
GPIO_AF3,
|
||||
GPIO_AF4,
|
||||
GPIO_AF5,
|
||||
GPIO_AF6,
|
||||
GPIO_AF7,
|
||||
GPIO_AF8,
|
||||
GPIO_AF9,
|
||||
GPIO_AF10,
|
||||
GPIO_AF11,
|
||||
GPIO_AF12,
|
||||
GPIO_AF13,
|
||||
GPIO_AF14,
|
||||
GPIO_AF15,
|
||||
GPIO_AF_UNDEF
|
||||
};
|
||||
|
||||
enum {
|
||||
GPIO_PIN_SPEED_LOW = 0x00,
|
||||
GPIO_PIN_SPEED_MEDIUM = 0x01,
|
||||
GPIO_PIN_SPEED_HIGH = 0x02,
|
||||
GPIO_PIN_SPEED_VERY_HIGH = 0x03,
|
||||
};
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
void stm32_gpio_enable_clock(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_cmsis.h"
|
||||
|
||||
void stm32_gpio_enable_clock(GPIO_TypeDef *GPIOx);
|
||||
|
||||
@@ -35,6 +35,7 @@ extern "C" {
|
||||
#if defined(STM32F4)
|
||||
#define USE_RTOS 0U
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_fmc.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma2d.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h"
|
||||
#include "STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.h"
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_timer.h"
|
||||
#include "stm32_dma.h"
|
||||
#include "stm32_gpio.h"
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
@@ -76,20 +77,13 @@ int stm32_pulse_init(const stm32_pulse_timer_t* tim, uint32_t freq)
|
||||
if (stm32_timer_is_clock_enabled(tim->TIMx)) return -1;
|
||||
|
||||
// .. and GPIO pin is not used
|
||||
uint32_t pin_mode = LL_GPIO_GetPinMode(tim->GPIOx, tim->GPIO_Pin);
|
||||
if (pin_mode != LL_GPIO_MODE_INPUT) return -1;
|
||||
if(gpio_get_mode(tim->GPIO) != GPIO_IN) return -1;
|
||||
|
||||
if (tim->DMA_TC_CallbackPtr) {
|
||||
memset(tim->DMA_TC_CallbackPtr, 0, sizeof(stm32_pulse_dma_tc_cb_t));
|
||||
}
|
||||
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
pinInit.Pin = tim->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
pinInit.Alternate = tim->GPIO_Alternate;
|
||||
stm32_gpio_enable_clock(tim->GPIOx);
|
||||
LL_GPIO_Init(tim->GPIOx, &pinInit);
|
||||
gpio_init_af(tim->GPIO, tim->GPIO_Alternate, GPIO_PIN_SPEED_MEDIUM);
|
||||
|
||||
LL_TIM_InitTypeDef timInit;
|
||||
LL_TIM_StructInit(&timInit);
|
||||
@@ -140,13 +134,7 @@ void stm32_pulse_deinit(const stm32_pulse_timer_t* tim)
|
||||
LL_TIM_DeInit(tim->TIMx);
|
||||
stm32_timer_disable_clock(tim->TIMx);
|
||||
|
||||
// Reconfigure pin as input
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = tim->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
LL_GPIO_Init(tim->GPIOx, &pinInit);
|
||||
gpio_init(tim->GPIO, GPIO_IN, GPIO_PIN_SPEED_MEDIUM);
|
||||
}
|
||||
|
||||
static inline bool _is_complementary_channel(uint32_t channel)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
struct stm32_pulse_timer_t;
|
||||
typedef bool (*stm32_pulse_dma_tc_fct)(void*);
|
||||
@@ -34,8 +35,7 @@ struct stm32_pulse_dma_tc_cb_t {
|
||||
|
||||
struct stm32_pulse_timer_t {
|
||||
|
||||
GPIO_TypeDef* GPIOx;
|
||||
uint32_t GPIO_Pin;
|
||||
gpio_t GPIO;
|
||||
uint32_t GPIO_Alternate;
|
||||
|
||||
TIM_TypeDef* TIMx;
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "stm32_softserial_driver.h"
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "stm32_timer.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -48,8 +50,7 @@ static void _softserial_exti()
|
||||
|
||||
// cheap debouncing...
|
||||
for (uint8_t i = 0; i < 16; ++i) {
|
||||
if (LL_GPIO_IsInputPinSet(port->GPIOx, port->GPIO_Pin) == 0)
|
||||
return;
|
||||
if (!gpio_read(port->GPIO)) return;
|
||||
}
|
||||
|
||||
// enable timer counter
|
||||
@@ -72,8 +73,7 @@ static bool _softserial_init_rx(const stm32_softserial_rx_port* port,
|
||||
const etx_serial_init* params)
|
||||
{
|
||||
// Test if pin is in reset state
|
||||
uint32_t mode = LL_GPIO_GetPinMode(port->GPIOx, port->GPIO_Pin);
|
||||
if (mode != LL_GPIO_MODE_INPUT) return false;
|
||||
if(gpio_get_mode(port->GPIO) != GPIO_IN) return false;
|
||||
|
||||
rxBitCount = 0;
|
||||
rxBuffer = port->buffer.buffer;
|
||||
@@ -98,45 +98,41 @@ static bool _softserial_init_rx(const stm32_softserial_rx_port* port,
|
||||
NVIC_SetPriority(port->TIM_IRQn, 0);
|
||||
NVIC_EnableIRQ(port->TIM_IRQn);
|
||||
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
if (port->dir_GPIOx) {
|
||||
pinInit.Pin = port->dir_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
LL_GPIO_Init(port->dir_GPIOx, &pinInit);
|
||||
if (port->dir_GPIO != GPIO_UNDEF) {
|
||||
gpio_init(port->dir_GPIO, GPIO_OUT, GPIO_PIN_SPEED_MEDIUM);
|
||||
if (!port->dir_Input) {
|
||||
LL_GPIO_ResetOutputPin(port->dir_GPIOx, port->dir_Pin);
|
||||
gpio_clear(port->dir_GPIO);
|
||||
} else {
|
||||
LL_GPIO_SetOutputPin(port->dir_GPIOx, port->dir_Pin);
|
||||
gpio_set(port->dir_GPIO);
|
||||
}
|
||||
}
|
||||
|
||||
pinInit.Pin = port->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
pinInit.Pull = LL_GPIO_PULL_DOWN;
|
||||
LL_GPIO_Init(port->GPIOx, &pinInit);
|
||||
// pinInit.Pin = port->GPIO_Pin;
|
||||
// pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
// pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
// pinInit.Pull = LL_GPIO_PULL_DOWN;
|
||||
// LL_GPIO_Init(port->GPIOx, &pinInit);
|
||||
|
||||
// Connect EXTI line to TELEMETRY RX pin
|
||||
LL_SYSCFG_SetEXTISource(port->EXTI_Port, port->EXTI_SysLine);
|
||||
// LL_SYSCFG_SetEXTISource(port->EXTI_Port, port->EXTI_SysLine);
|
||||
|
||||
// Configure EXTI for raising edge (start bit; assuming inverted serial)
|
||||
_softserialPort = port;
|
||||
stm32_exti_enable(port->EXTI_Line, LL_EXTI_TRIGGER_RISING, _softserial_exti);
|
||||
|
||||
// stm32_exti_enable(port->EXTI_Line, LL_EXTI_TRIGGER_RISING, _softserial_exti);
|
||||
gpio_init_int(port->GPIO, GPIO_IN_PD, GPIO_RISING, _softserial_exti);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void _softserial_deinit_gpio(const stm32_softserial_rx_port* port)
|
||||
{
|
||||
// Reconfigure pin as input
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
gpio_init(port->GPIO, GPIO_IN, GPIO_PIN_SPEED_LOW);
|
||||
// LL_GPIO_InitTypeDef pinInit;
|
||||
// LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = port->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
LL_GPIO_Init(port->GPIOx, &pinInit);
|
||||
// pinInit.Pin = port->GPIO_Pin;
|
||||
// pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
// LL_GPIO_Init(port->GPIOx, &pinInit);
|
||||
}
|
||||
|
||||
static void _softserial_deinit_rx(const stm32_softserial_rx_port* port)
|
||||
@@ -200,7 +196,7 @@ void stm32_softserial_rx_timer_isr(const stm32_softserial_rx_port* port)
|
||||
rxByte >>= 1;
|
||||
}
|
||||
|
||||
if (LL_GPIO_IsInputPinSet(port->GPIOx, port->GPIO_Pin) == 0)
|
||||
if (!gpio_read(port->GPIO) == 0)
|
||||
rxByte |= 0x80;
|
||||
|
||||
++rxBitCount;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "stm32_serial_driver.h"
|
||||
#include "stm32_pulse_driver.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
//
|
||||
// RX soft-serial
|
||||
@@ -33,8 +34,7 @@
|
||||
//
|
||||
struct stm32_softserial_rx_port {
|
||||
|
||||
GPIO_TypeDef* GPIOx;
|
||||
uint32_t GPIO_Pin;
|
||||
gpio_t GPIO;
|
||||
TIM_TypeDef* TIMx;
|
||||
uint32_t TIM_Freq;
|
||||
IRQn_Type TIM_IRQn;
|
||||
@@ -43,8 +43,7 @@ struct stm32_softserial_rx_port {
|
||||
uint32_t EXTI_Line;
|
||||
|
||||
// Input/output direction pin
|
||||
GPIO_TypeDef* dir_GPIOx;
|
||||
uint32_t dir_Pin;
|
||||
gpio_t dir_GPIO;
|
||||
uint32_t dir_Input;
|
||||
|
||||
const stm32_serial_buffer buffer;
|
||||
|
||||
@@ -33,8 +33,18 @@ void stm32_timer_enable_clock(TIM_TypeDef *TIMx)
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||||
} else if (TIMx == TIM5) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM5);
|
||||
} else if (TIMx == TIM6) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM6);
|
||||
} else if (TIMx == TIM7) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM7);
|
||||
} else if (TIMx == TIM8) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM8);
|
||||
} else if (TIMx == TIM9) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM9);
|
||||
} else if (TIMx == TIM10) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM10);
|
||||
} else if (TIMx == TIM11) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM11);
|
||||
} else if (TIMx == TIM12) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM12);
|
||||
} else if (TIMx == TIM13) {
|
||||
@@ -56,15 +66,25 @@ void stm32_timer_disable_clock(TIM_TypeDef *TIMx)
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
||||
} else if (TIMx == TIM5) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM5);
|
||||
} else if (TIMx == TIM6) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM6);
|
||||
} else if (TIMx == TIM7) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM7);
|
||||
} else if (TIMx == TIM8) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM8);
|
||||
} else if (TIMx == TIM9) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM9);
|
||||
} else if (TIMx == TIM10) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM10);
|
||||
} else if (TIMx == TIM11) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM11);
|
||||
} else if (TIMx == TIM12) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM12);
|
||||
} else if (TIMx == TIM13) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM13);
|
||||
} else if (TIMx == TIM14) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM14);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool stm32_timer_is_clock_enabled(TIM_TypeDef *TIMx)
|
||||
@@ -79,14 +99,24 @@ bool stm32_timer_is_clock_enabled(TIM_TypeDef *TIMx)
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM4) != 0;
|
||||
} else if (TIMx == TIM5) {
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM5) != 0;
|
||||
} else if (TIMx == TIM6) {
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM6) != 0;
|
||||
} else if (TIMx == TIM7) {
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM7) != 0;
|
||||
} else if (TIMx == TIM8) {
|
||||
return LL_APB2_GRP1_IsEnabledClock(LL_APB2_GRP1_PERIPH_TIM8) != 0;
|
||||
} else if (TIMx == TIM9) {
|
||||
return LL_APB2_GRP1_IsEnabledClock(LL_APB2_GRP1_PERIPH_TIM9) != 0;
|
||||
} else if (TIMx == TIM10) {
|
||||
return LL_APB2_GRP1_IsEnabledClock(LL_APB2_GRP1_PERIPH_TIM10) != 0;
|
||||
} else if (TIMx == TIM11) {
|
||||
return LL_APB2_GRP1_IsEnabledClock(LL_APB2_GRP1_PERIPH_TIM11) != 0;
|
||||
} else if (TIMx == TIM12) {
|
||||
return LL_APB2_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM12) != 0;
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM12) != 0;
|
||||
} else if (TIMx == TIM13) {
|
||||
return LL_APB2_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM13) != 0;
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM13) != 0;
|
||||
} else if (TIMx == TIM14) {
|
||||
return LL_APB2_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM14) != 0;
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM14) != 0;
|
||||
}
|
||||
|
||||
// not supported
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
*/
|
||||
|
||||
#include "stm32_usart_driver.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_dma.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -35,6 +36,7 @@
|
||||
// The new CMSIS can be used when StdPeriph is gone, as it mandates
|
||||
// the old version located in "${STM32LIB_DIR}/CMSIS/Include"
|
||||
//
|
||||
#if 0
|
||||
static inline uint32_t NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
if ((int32_t)(IRQn) >= 0) {
|
||||
@@ -46,7 +48,7 @@ static inline uint32_t NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||
return (0U);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
static void _enable_usart_irq(const stm32_usart_t* usart)
|
||||
{
|
||||
NVIC_SetPriority(usart->IRQn, usart->IRQ_Prio);
|
||||
@@ -143,27 +145,27 @@ static void disable_usart_clock(USART_TypeDef* USARTx)
|
||||
|
||||
}
|
||||
|
||||
static uint32_t _get_pin_speed(uint32_t baudrate)
|
||||
static gpio_speed_t _get_pin_speed(uint32_t baudrate)
|
||||
{
|
||||
// 1 Mbps and above
|
||||
if (baudrate >= 1000000) {
|
||||
return LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
return GPIO_PIN_SPEED_VERY_HIGH;
|
||||
}
|
||||
// 400kbps and above
|
||||
else if (baudrate >= 400000) {
|
||||
return LL_GPIO_SPEED_FREQ_HIGH;
|
||||
return GPIO_PIN_SPEED_HIGH;
|
||||
}
|
||||
|
||||
// under 400kbps
|
||||
return LL_GPIO_SPEED_FREQ_LOW;
|
||||
return GPIO_PIN_SPEED_LOW;
|
||||
}
|
||||
|
||||
static uint32_t _get_usart_af(USART_TypeDef* USARTx)
|
||||
static gpio_af_t _get_usart_af(USART_TypeDef* USARTx)
|
||||
{
|
||||
if (USARTx == USART1 || USARTx == USART2 || USARTx == USART3) {
|
||||
return LL_GPIO_AF_7;
|
||||
return GPIO_AF7;
|
||||
} else {
|
||||
return LL_GPIO_AF_8;
|
||||
return GPIO_AF8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,29 +226,21 @@ void stm32_usart_deinit_rx_dma(const stm32_usart_t* usart)
|
||||
bool stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
|
||||
{
|
||||
// Test if the GPIO pins are in reset state
|
||||
uint32_t pins = usart->GPIO_Pin;
|
||||
while(pins != 0) {
|
||||
uint32_t pin = 1 << POSITION_VAL(pins);
|
||||
uint32_t mode = LL_GPIO_GetPinMode(usart->GPIOx, pin);
|
||||
if (mode != LL_GPIO_MODE_INPUT) return false;
|
||||
pins ^= pin;
|
||||
if(gpio_get_mode(usart->txGPIO) != GPIO_IN || gpio_get_mode(usart->rxGPIO) != GPIO_IN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
enable_usart_clock(usart->USARTx);
|
||||
LL_USART_DeInit(usart->USARTx);
|
||||
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Pin = usart->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
pinInit.Speed = _get_pin_speed(params->baudrate);
|
||||
pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
pinInit.Pull = LL_GPIO_PULL_UP;
|
||||
pinInit.Alternate = _get_usart_af(usart->USARTx);
|
||||
|
||||
stm32_gpio_enable_clock(usart->GPIOx);
|
||||
LL_GPIO_Init(usart->GPIOx, &pinInit);
|
||||
gpio_af_t af = _get_usart_af(usart->USARTx);
|
||||
if (usart->rxGPIO != GPIO_UNDEF) {
|
||||
gpio_init_af(usart->rxGPIO, af, _get_pin_speed(params->baudrate));
|
||||
}
|
||||
if (usart->txGPIO != GPIO_UNDEF) {
|
||||
gpio_init_af(usart->txGPIO, af, _get_pin_speed(params->baudrate));
|
||||
}
|
||||
|
||||
LL_USART_InitTypeDef usartInit;
|
||||
LL_USART_StructInit(&usartInit);
|
||||
@@ -330,13 +324,13 @@ void stm32_usart_deinit(const stm32_usart_t* usart)
|
||||
LL_USART_DeInit(usart->USARTx);
|
||||
disable_usart_clock(usart->USARTx);
|
||||
|
||||
// Reconfigure pin as output
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
pinInit.Pin = usart->GPIO_Pin;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
LL_GPIO_Init(usart->GPIOx, &pinInit);
|
||||
LL_GPIO_ResetOutputPin(usart->GPIOx, pinInit.Pin);
|
||||
// Reconfigure pin as input
|
||||
if (usart->rxGPIO != GPIO_UNDEF) {
|
||||
gpio_init(usart->rxGPIO, GPIO_IN, GPIO_PIN_SPEED_LOW);
|
||||
}
|
||||
if (usart->txGPIO != GPIO_UNDEF) {
|
||||
gpio_init(usart->txGPIO, GPIO_IN, GPIO_PIN_SPEED_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_usart_send_byte(const stm32_usart_t* usart, uint8_t byte)
|
||||
@@ -508,19 +502,6 @@ void stm32_usart_set_baudrate(const stm32_usart_t* usart, uint32_t baudrate)
|
||||
auto periphclk = _get_usart_periph_clock(usart->USARTx);
|
||||
auto oversampling = LL_USART_GetOverSampling(usart->USARTx);
|
||||
LL_USART_SetBaudRate(usart->USARTx, periphclk, oversampling, baudrate);
|
||||
|
||||
// update pin speed accordingly (must be done one-by-one)
|
||||
uint32_t pin_speed = _get_pin_speed(baudrate);
|
||||
uint32_t pindef = usart->GPIO_Pin;
|
||||
|
||||
// loop borrowed from LL_GPIO_init()
|
||||
uint32_t pinpos = POSITION_VAL(pindef);
|
||||
uint32_t currentpin = 0;
|
||||
while ((pindef >> pinpos) != 0) {
|
||||
currentpin = pindef & (1 << pinpos);
|
||||
if (currentpin) LL_GPIO_SetPinSpeed(usart->GPIOx, currentpin, pin_speed);
|
||||
pinpos++;
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_usart_set_hw_option(const stm32_usart_t* usart, uint32_t option)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "hal/serial_driver.h"
|
||||
#include "hal/gpio.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
typedef void (*pin_setter_t)(uint8_t enable);
|
||||
@@ -31,8 +32,8 @@ struct stm32_usart_t {
|
||||
|
||||
// USART defs
|
||||
USART_TypeDef* USARTx;
|
||||
GPIO_TypeDef* GPIOx;
|
||||
uint32_t GPIO_Pin;
|
||||
gpio_t txGPIO;
|
||||
gpio_t rxGPIO;
|
||||
|
||||
// USART IRQ
|
||||
IRQn_Type IRQn;
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
// #define HAL_NOR_MODULE_ENABLED
|
||||
// #define HAL_PCCARD_MODULE_ENABLED
|
||||
// #define HAL_SRAM_MODULE_ENABLED
|
||||
// #define HAL_SDRAM_MODULE_ENABLED
|
||||
#define HAL_SDRAM_MODULE_ENABLED
|
||||
// #define HAL_HASH_MODULE_ENABLED
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
// #define HAL_EXTI_MODULE_ENABLED
|
||||
@@ -101,7 +101,7 @@
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
|
||||
#define HSE_STARTUP_TIMEOUT 2000U /*!< Time out for HSE start up, in cycles through a loop, normal values seem to bs around 900 */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,6 +37,9 @@ extern "C" {
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
|
||||
#include "stm32_gpio.h"
|
||||
|
||||
#include "hal/gpio.h"
|
||||
#include "hal/usb_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
@@ -61,7 +64,7 @@ void setSelectedUsbMode(int mode)
|
||||
selectedUsbMode = usbMode(mode);
|
||||
}
|
||||
|
||||
#if defined(USB_GPIO_PIN_VBUS)
|
||||
#if defined(USB_GPIO_VBUS)
|
||||
int usbPlugged()
|
||||
{
|
||||
#if defined(DEBUG_DISABLE_USB)
|
||||
@@ -71,8 +74,8 @@ int usbPlugged()
|
||||
static uint8_t debouncedState = 0;
|
||||
static uint8_t lastState = 0;
|
||||
|
||||
uint8_t state = LL_GPIO_IsInputPinSet(USB_GPIO, USB_GPIO_PIN_VBUS);
|
||||
|
||||
// uint8_t state = GPIO_ReadInputDataBit(USB_GPIO, USB_GPIO_PIN_VBUS);
|
||||
uint8_t state = gpio_read(USB_GPIO_VBUS) ? 1 : 0;
|
||||
if (state == lastState)
|
||||
debouncedState = state;
|
||||
else
|
||||
@@ -92,27 +95,15 @@ extern "C" void OTG_FS_IRQHandler()
|
||||
|
||||
void usbInit()
|
||||
{
|
||||
// Initialize hardware
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct;
|
||||
LL_GPIO_StructInit(&GPIO_InitStruct);
|
||||
|
||||
#if defined(USB_GPIO_PIN_VBUS)
|
||||
GPIO_InitStruct.Pin = USB_GPIO_PIN_VBUS;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(USB_GPIO, &GPIO_InitStruct);
|
||||
gpio_init_af(USB_GPIO_DM, USB_GPIO_AF, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_init_af(USB_GPIO_DP, USB_GPIO_AF, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
|
||||
#if defined(USB_GPIO_VBUS)
|
||||
gpio_init(USB_GPIO_VBUS, GPIO_IN, GPIO_PIN_SPEED_LOW);
|
||||
#endif
|
||||
|
||||
GPIO_InitStruct.Pin = USB_GPIO_PIN_DM | USB_GPIO_PIN_DP;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
|
||||
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = LL_GPIO_AF_10; // USB
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_OTGFS);
|
||||
|
||||
usbDriverStarted = false;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,11 @@
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_spi.h"
|
||||
|
||||
#include "hal/gpio.h"
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if !defined(SIMU)
|
||||
@@ -310,31 +313,22 @@ void audioSendRiffHeader()
|
||||
audioSpiWriteBuffer(RiffHeader, sizeof(RiffHeader));
|
||||
}
|
||||
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
static inline void setMutePin(bool enabled)
|
||||
{
|
||||
if (enabled) {
|
||||
#if defined(INVERTED_MUTE_PIN)
|
||||
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#else
|
||||
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
enabled = !enabled;
|
||||
#endif
|
||||
} else {
|
||||
#if defined(INVERTED_MUTE_PIN)
|
||||
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#else
|
||||
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#endif
|
||||
}
|
||||
gpio_write(AUDIO_MUTE_GPIO, enabled);
|
||||
}
|
||||
|
||||
static inline bool getMutePin(void)
|
||||
{
|
||||
bool muted = gpio_read(AUDIO_MUTE_GPIO) ? 1 : 0;
|
||||
#if defined(INVERTED_MUTE_PIN)
|
||||
return !GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
#else
|
||||
return GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
muted = !muted;
|
||||
#endif
|
||||
return muted;
|
||||
}
|
||||
|
||||
void audioMute()
|
||||
@@ -374,42 +368,27 @@ void audioUnmute()
|
||||
setMutePin(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
void audioMuteInit()
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = AUDIO_MUTE_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
||||
GPIO_Init(AUDIO_MUTE_GPIO, &GPIO_InitStructure);
|
||||
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PCBX12S)
|
||||
void audioShutdownInit()
|
||||
{
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||
pinInit.Pin = AUDIO_SHUTDOWN_GPIO_PIN;
|
||||
LL_GPIO_Init(AUDIO_SHUTDOWN_GPIO, &pinInit);
|
||||
gpio_init(AUDIO_SHUTDOWN_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
|
||||
// we never RESET it, there is a 2s delay on STARTUP
|
||||
LL_GPIO_SetOutputPin(AUDIO_SHUTDOWN_GPIO, AUDIO_SHUTDOWN_GPIO_PIN);
|
||||
gpio_set(AUDIO_SHUTDOWN_GPIO);
|
||||
}
|
||||
#endif
|
||||
|
||||
void audioInit()
|
||||
{
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
audioMuteInit();
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
// Mute before init anything
|
||||
gpio_init(AUDIO_MUTE_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
setMutePin(true);
|
||||
#endif
|
||||
|
||||
#if defined(PCBX12S)
|
||||
#if defined(PCBX12S)
|
||||
audioShutdownInit();
|
||||
#endif
|
||||
|
||||
@@ -451,7 +430,7 @@ void audioConsumeCurrentBuffer()
|
||||
}
|
||||
|
||||
if (currentBuffer) {
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
audioUnmute();
|
||||
#endif
|
||||
uint32_t written = audioSpiWriteData(currentBuffer, currentSize);
|
||||
@@ -463,7 +442,7 @@ void audioConsumeCurrentBuffer()
|
||||
currentSize = 0;
|
||||
}
|
||||
}
|
||||
#if defined(AUDIO_MUTE_GPIO_PIN)
|
||||
#if defined(AUDIO_MUTE_GPIO)
|
||||
else {
|
||||
audioMute();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user