feat: basic H7 support (#5228)
Co-authored-by: Malte Langermann <malte@langermann.net> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com> Co-authored-by: Richard Li <richard.li@ces.hk>
This commit is contained in:
co-authored by
Malte Langermann
3djc
raphaelcoeffic
Richard Li
parent
2110f1b938
commit
6f8a5313d5
@@ -181,7 +181,6 @@ endif()
|
||||
if(HAPTIC)
|
||||
add_definitions(-DHAPTIC)
|
||||
set(SRC ${SRC} haptic.cpp)
|
||||
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} haptic_driver.cpp)
|
||||
endif()
|
||||
|
||||
# Protocols supported
|
||||
|
||||
@@ -49,7 +49,11 @@ void _init_reboot_cause()
|
||||
_dbg_csr = LL_RCC_ReadReg(CSR);
|
||||
#endif
|
||||
|
||||
#ifdef STM32H7
|
||||
if (LL_RCC_IsActiveFlag_IWDG1RST()) {
|
||||
#else
|
||||
if (LL_RCC_IsActiveFlag_IWDGRST()) {
|
||||
#endif
|
||||
_reboot_cause = ARC_Watchdog;
|
||||
} else if (LL_RCC_IsActiveFlag_SFTRST()) {
|
||||
_reboot_cause = ARC_Software;
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
#include "cpu_id.h"
|
||||
|
||||
#if !defined(SIMU) && !defined(BACKUP)
|
||||
#if defined(STM32F4)
|
||||
#if defined(STM32H7)
|
||||
#include "stm32h7xx.h"
|
||||
#elif defined(STM32F4)
|
||||
#include "stm32f4xx.h"
|
||||
#else
|
||||
#include "stm32f2xx.h"
|
||||
|
||||
@@ -21,7 +21,6 @@ set(BOOTLOADER_SRC
|
||||
../flash_driver.cpp
|
||||
../watchdog_driver.cpp
|
||||
../abnormal_reboot.cpp
|
||||
init.c
|
||||
boot.cpp
|
||||
bin_files.cpp
|
||||
)
|
||||
@@ -138,7 +137,7 @@ add_executable(bootloader EXCLUDE_FROM_ALL ${BOOTLOADER_SRC})
|
||||
add_dependencies(bootloader ${BITMAPS_TARGET})
|
||||
|
||||
target_link_options(bootloader PRIVATE
|
||||
-lm -nostartfiles -T${LINKER_DIR}/bootloader.ld
|
||||
-lm -T${LINKER_DIR}/bootloader.ld
|
||||
-Wl,-Map=bootloader.map,--cref,--no-warn-mismatch,--gc-sections
|
||||
--specs=nano.specs
|
||||
)
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#if !defined(SIMU)
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_timer.h"
|
||||
#endif
|
||||
|
||||
#include "hal/usb_driver.h"
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
@@ -178,10 +181,9 @@ int menuFlashFile(uint32_t index, event_t event)
|
||||
void flashWriteBlock()
|
||||
{
|
||||
uint32_t blockOffset = 0;
|
||||
while (BlockCount) {
|
||||
#if !defined(SIMU)
|
||||
while (BlockCount) {
|
||||
flashWrite((uint32_t *)firmwareAddress, (uint32_t *)&Block_buffer[blockOffset]);
|
||||
#endif
|
||||
blockOffset += FLASH_PAGESIZE;
|
||||
firmwareAddress += FLASH_PAGESIZE;
|
||||
if (BlockCount > FLASH_PAGESIZE) {
|
||||
@@ -191,6 +193,7 @@ void flashWriteBlock()
|
||||
BlockCount = 0;
|
||||
}
|
||||
}
|
||||
#endif // SIMU
|
||||
}
|
||||
|
||||
#if defined(EEPROM)
|
||||
@@ -225,7 +228,7 @@ void bootloaderInitApp()
|
||||
// wait a bit for the inputs to stabilize...
|
||||
if (!WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
|
||||
for (uint32_t i = 0; i < 150000; i++) {
|
||||
__ASM volatile ("nop");
|
||||
__ASM volatile("nop");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,6 +593,3 @@ int bootloaderMain()
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(SIMU) && (defined(PCBHORUS) || defined(PCBFLYSKY))
|
||||
void *__dso_handle = nullptr;
|
||||
#endif
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
void _init (void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void _fini(void)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "hal.h"
|
||||
|
||||
|
||||
#if !defined(SD_SPI)
|
||||
|
||||
// #include "delays_driver.h"
|
||||
@@ -38,22 +39,83 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins */
|
||||
#if !defined(SD_SDIO_DATA_GPIO) && !defined(SD_SDIO_DATA_GPIO_PINS)
|
||||
#define SD_SDIO_DATA_GPIO GPIOC
|
||||
#define SD_SDIO_DATA_GPIO_PINS \
|
||||
(LL_GPIO_PIN_8 | LL_GPIO_PIN_9 | LL_GPIO_PIN_10 | LL_GPIO_PIN_11)
|
||||
#if !defined(SD_SDIO_PIN_D0)
|
||||
# define SD_SDIO_PIN_D0 GPIO_PIN(GPIOC, 8)
|
||||
# if defined(STM32H7RS)
|
||||
# define SD_SDIO_AF_D0 GPIO_AF11
|
||||
# else
|
||||
# define SD_SDIO_AF_D0 GPIO_AF12
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Configure PD.02 CMD line */
|
||||
#if !defined(SD_SDIO_CMD_GPIO) && !defined(SD_SDIO_CMD_GPIO_PIN)
|
||||
#define SD_SDIO_CMD_GPIO GPIOD
|
||||
#define SD_SDIO_CMD_GPIO_PIN LL_GPIO_PIN_2
|
||||
#if !defined(SD_SDIO_PIN_D1)
|
||||
# define SD_SDIO_PIN_D1 GPIO_PIN(GPIOC, 9)
|
||||
# if defined(STM32H7RS)
|
||||
# define SD_SDIO_AF_D1 GPIO_AF11
|
||||
# else
|
||||
# define SD_SDIO_AF_D1 GPIO_AF12
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(SD_SDIO_CLK_GPIO) && !defined(SD_SDIO_CLK_GPIO_PIN)
|
||||
#define SD_SDIO_CLK_GPIO GPIOC
|
||||
#define SD_SDIO_CLK_GPIO_PIN LL_GPIO_PIN_12
|
||||
#if !defined(SD_SDIO_PIN_D2)
|
||||
# define SD_SDIO_PIN_D2 GPIO_PIN(GPIOC, 10)
|
||||
# define SD_SDIO_AF_D2 GPIO_AF12
|
||||
#endif
|
||||
|
||||
#if !defined(SD_SDIO_PIN_D3)
|
||||
# define SD_SDIO_PIN_D3 GPIO_PIN(GPIOC, 11)
|
||||
# if defined(STM32H7RS)
|
||||
# define SD_SDIO_AF_D3 GPIO_AF11
|
||||
# else
|
||||
# define SD_SDIO_AF_D3 GPIO_AF12
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(SD_SDIO_PIN_CMD)
|
||||
# define SD_SDIO_PIN_CMD GPIO_PIN(GPIOD, 2)
|
||||
# if defined(STM32H7RS)
|
||||
# define SD_SDIO_AF_CMD GPIO_AF11
|
||||
# else
|
||||
# define SD_SDIO_AF_CMD GPIO_AF12
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(SD_SDIO_PIN_CLK)
|
||||
# define SD_SDIO_PIN_CLK GPIO_PIN(GPIOC, 12)
|
||||
# if defined(STM32H7RS)
|
||||
# define SD_SDIO_AF_CLK GPIO_AF11
|
||||
# else
|
||||
# define SD_SDIO_AF_CLK GPIO_AF12
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(SDMMC1) && defined(SD_SDIO)
|
||||
# if !defined(SD_SDIO_IRQHandler)
|
||||
# define SD_SDIO_IRQHandler SDMMC1_IRQHandler
|
||||
# define SD_SDIO_IRQn SDMMC1_IRQn
|
||||
# endif
|
||||
# define SD_SDIO_TypeDef SDMMC_TypeDef
|
||||
# define SD_SDIO_CLOCK_EDGE_RISING SDMMC_CLOCK_EDGE_RISING
|
||||
# define SD_SDIO_CLOCK_POWER_SAVE_DISABLE SDMMC_CLOCK_POWER_SAVE_DISABLE
|
||||
# define SD_SDIO_BUS_WIDE_1B SDMMC_BUS_WIDE_1B
|
||||
# define SD_SDIO_BUS_WIDE_4B SDMMC_BUS_WIDE_4B
|
||||
# define SD_SDIO_HARDWARE_FLOW_CONTROL_DISABLE SDMMC_HARDWARE_FLOW_CONTROL_DISABLE
|
||||
#elif !defined(SDMMC1)
|
||||
# if !defined(SD_SDIO)
|
||||
# define SD_SDIO SDIO
|
||||
# endif
|
||||
# define _SD_SDIO_CLK_ENABLE() __HAL_RCC_SDIO_CLK_ENABLE()
|
||||
# define _SD_SDIO_CLK_DISABLE() __HAL_RCC_SDIO_CLK_DISABLE()
|
||||
# define SD_SDIO_IRQHandler SDIO_IRQHandler
|
||||
# define SD_SDIO_IRQn SDIO_IRQn
|
||||
# define SD_SDIO_TypeDef SDIO_TypeDef
|
||||
# define SD_SDIO_CLOCK_EDGE_RISING SDIO_CLOCK_EDGE_RISING
|
||||
# define SD_SDIO_CLOCK_POWER_SAVE_DISABLE SDIO_CLOCK_POWER_SAVE_DISABLE
|
||||
# define SD_SDIO_CLOCK_BYPASS_DISABLE SDIO_CLOCK_BYPASS_DISABLE
|
||||
# define SD_SDIO_BUS_WIDE_1B SDIO_BUS_WIDE_1B
|
||||
# define SD_SDIO_BUS_WIDE_4B SDIO_BUS_WIDE_4B
|
||||
# define SD_SDIO_HARDWARE_FLOW_CONTROL_DISABLE SDIO_HARDWARE_FLOW_CONTROL_DISABLE
|
||||
#endif
|
||||
|
||||
#if FF_MAX_SS != FF_MIN_SS
|
||||
@@ -63,46 +125,64 @@
|
||||
#define BLOCK_SIZE FF_MAX_SS
|
||||
#define SD_TIMEOUT 300 /* 300ms */
|
||||
|
||||
#if defined(STM32H7) || defined(STM32H7RS) || defined(STM32F4)
|
||||
extern uint32_t _sram;
|
||||
extern uint32_t _eram;
|
||||
#define _IS_DMA_BUFFER(addr) \
|
||||
((intptr_t)(addr) >= (intptr_t)&_sram && (intptr_t)(addr) <= (intptr_t)&_eram)
|
||||
#else
|
||||
#define _IS_DMA_BUFFER(addr) (true)
|
||||
#endif
|
||||
|
||||
#define _IS_ALIGNED(addr) (((intptr_t)(addr) & 3U) == 0U)
|
||||
|
||||
// HAL state
|
||||
static SD_HandleTypeDef sdio;
|
||||
#if defined(SD_SDIO_DMA)
|
||||
static DMA_HandleTypeDef sdioTxDma;
|
||||
#endif
|
||||
|
||||
// Disk status
|
||||
static volatile uint32_t WriteStatus;
|
||||
static volatile uint32_t ReadStatus;
|
||||
|
||||
static void _sd_sdio_clk_enable(SD_SDIO_TypeDef* periph)
|
||||
{
|
||||
#if defined(SDMMC1)
|
||||
if (periph == SDMMC1) {
|
||||
__HAL_RCC_SDMMC1_CLK_ENABLE();
|
||||
} else if(periph == SDMMC2) {
|
||||
__HAL_RCC_SDMMC2_CLK_ENABLE();
|
||||
}
|
||||
#else
|
||||
(void)periph;
|
||||
__HAL_RCC_SDIO_CLK_ENABLE();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void sdio_low_level_init(void)
|
||||
{
|
||||
/* Enable the SDIO APB2 Clock */
|
||||
__HAL_RCC_SDIO_CLK_ENABLE();
|
||||
_sd_sdio_clk_enable(SD_SDIO);
|
||||
|
||||
LL_GPIO_InitTypeDef GPIO_InitStructure;
|
||||
LL_GPIO_StructInit(&GPIO_InitStructure);
|
||||
gpio_init_af(SD_SDIO_PIN_D0, SD_SDIO_AF_D0, GPIO_PIN_SPEED_HIGH);
|
||||
gpio_init_af(SD_SDIO_PIN_D1, SD_SDIO_AF_D1, GPIO_PIN_SPEED_HIGH);
|
||||
gpio_init_af(SD_SDIO_PIN_D2, SD_SDIO_AF_D2, GPIO_PIN_SPEED_HIGH);
|
||||
gpio_init_af(SD_SDIO_PIN_D3, SD_SDIO_AF_D3, GPIO_PIN_SPEED_HIGH);
|
||||
gpio_init_af(SD_SDIO_PIN_CMD, SD_SDIO_AF_CMD, GPIO_PIN_SPEED_HIGH);
|
||||
gpio_init_af(SD_SDIO_PIN_CLK, SD_SDIO_AF_CLK, GPIO_PIN_SPEED_HIGH);
|
||||
|
||||
stm32_gpio_enable_clock(SD_SDIO_DATA_GPIO);
|
||||
stm32_gpio_enable_clock(SD_SDIO_CMD_GPIO);
|
||||
stm32_gpio_enable_clock(SD_SDIO_CLK_GPIO);
|
||||
|
||||
GPIO_InitStructure.Pin = SD_SDIO_DATA_GPIO_PINS;
|
||||
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStructure.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||
GPIO_InitStructure.Pull = LL_GPIO_PULL_UP;
|
||||
GPIO_InitStructure.Alternate = LL_GPIO_AF_12; // SDIO
|
||||
LL_GPIO_Init(SD_SDIO_DATA_GPIO, &GPIO_InitStructure);
|
||||
|
||||
GPIO_InitStructure.Pin = SD_SDIO_CMD_GPIO_PIN;
|
||||
LL_GPIO_Init(SD_SDIO_CMD_GPIO, &GPIO_InitStructure);
|
||||
|
||||
/* Configure PC.12 pin: CLK pin */
|
||||
GPIO_InitStructure.Pin = SD_SDIO_CLK_GPIO_PIN;
|
||||
GPIO_InitStructure.Pull = LL_GPIO_PULL_NO;
|
||||
LL_GPIO_Init(SD_SDIO_CLK_GPIO, &GPIO_InitStructure);
|
||||
#if defined(SD_SDIO_HAS_TRANSCEIVER)
|
||||
gpio_init_af(SD_SDIO_PIN_CKIN, SD_SDIO_AF_CKIN, GPIO_PIN_SPEED_HIGH);
|
||||
gpio_init_af(SD_SDIO_PIN_CDIR, SD_SDIO_AF_CDIR, GPIO_PIN_SPEED_HIGH);
|
||||
gpio_init_af(SD_SDIO_PIN_D0DIR, SD_SDIO_AF_D0DIR, GPIO_PIN_SPEED_HIGH);
|
||||
gpio_init_af(SD_SDIO_PIN_D123DIR, SD_SDIO_AF_D123DIR, GPIO_PIN_SPEED_HIGH);
|
||||
#endif
|
||||
|
||||
// SDIO Interrupt ENABLE
|
||||
NVIC_SetPriority(SDIO_IRQn, 0);
|
||||
NVIC_EnableIRQ(SDIO_IRQn);
|
||||
NVIC_SetPriority(SD_SDIO_IRQn, 0);
|
||||
NVIC_EnableIRQ(SD_SDIO_IRQn);
|
||||
|
||||
#if defined(SD_SDIO_DMA)
|
||||
// Init SDIO DMA instance
|
||||
sdioTxDma.Instance = SD_SDIO_DMA_STREAM;
|
||||
sdioTxDma.Init.Channel = SD_SDIO_DMA_CHANNEL;
|
||||
@@ -126,8 +206,10 @@ static void sdio_low_level_init(void)
|
||||
// DMA2 STREAMx Interrupt ENABLE
|
||||
NVIC_SetPriority(SD_SDIO_DMA_IRQn, 0);
|
||||
NVIC_EnableIRQ(SD_SDIO_DMA_IRQn);
|
||||
#endif
|
||||
}
|
||||
|
||||
HAL_SD_CardInfoTypeDef cardInfo;
|
||||
static DSTATUS sdio_initialize(BYTE lun)
|
||||
{
|
||||
/* SDIO Peripheral Low Level Init */
|
||||
@@ -136,14 +218,19 @@ static DSTATUS sdio_initialize(BYTE lun)
|
||||
/*!< Configure the SDIO peripheral */
|
||||
/*!< SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2) */
|
||||
/*!< on STM32F4xx devices, SDIOCLK is fixed to 48MHz */
|
||||
sdio.Instance = SDIO;
|
||||
sdio.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
|
||||
sdio.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
|
||||
sdio.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
|
||||
sdio.Init.BusWide = SDIO_BUS_WIDE_1B;
|
||||
|
||||
sdio.Instance = SD_SDIO;
|
||||
sdio.Init.ClockEdge = SD_SDIO_CLOCK_EDGE_RISING;
|
||||
sdio.Init.ClockPowerSave = SD_SDIO_CLOCK_POWER_SAVE_DISABLE;
|
||||
sdio.Init.BusWide = SD_SDIO_BUS_WIDE_1B;
|
||||
sdio.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
|
||||
#if ( USE_SD_TRANSCEIVER > 0U )
|
||||
sdio.Init.TranceiverPresent = SDMMC_TRANSCEIVER_PRESENT;
|
||||
#endif
|
||||
#if defined(SD_SDIO_CLOCK_BYPASS_DISABLE)
|
||||
sdio.Init.ClockBypass = SD_SDIO_CLOCK_BYPASS_DISABLE;
|
||||
#endif
|
||||
sdio.Init.ClockDiv = SD_SDIO_TRANSFER_CLK_DIV;
|
||||
HAL_SD_DeInit(&sdio);
|
||||
|
||||
HAL_StatusTypeDef halStatus = HAL_SD_Init(&sdio);
|
||||
if (halStatus != HAL_OK) {
|
||||
@@ -152,13 +239,12 @@ static DSTATUS sdio_initialize(BYTE lun)
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
HAL_SD_CardInfoTypeDef cardInfo;
|
||||
HAL_StatusTypeDef es = HAL_SD_GetCardInfo(&sdio, &cardInfo);
|
||||
if(es != HAL_OK) {
|
||||
return STA_NOINIT;
|
||||
}
|
||||
|
||||
halStatus = HAL_SD_ConfigWideBusOperation(&sdio, SDIO_BUS_WIDE_4B);
|
||||
halStatus = HAL_SD_ConfigWideBusOperation(&sdio, SD_SDIO_BUS_WIDE_4B);
|
||||
if (halStatus != HAL_OK) {
|
||||
TRACE("HAL_SD_ConfigWideBusOperation() status=%d", halStatus);
|
||||
} else {
|
||||
@@ -174,8 +260,10 @@ static DSTATUS sdio_initialize(BYTE lun)
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
// #if defined(SRAM_BASE)
|
||||
// DMA scratch buffer used in case the input buffer is not aligned
|
||||
static uint8_t scratch[BLOCK_SIZE] __DMA;
|
||||
// #endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -228,11 +316,19 @@ static DSTATUS sdio_status(BYTE lun)
|
||||
static DRESULT _read_dma(BYTE* buff, DWORD sector, UINT count)
|
||||
{
|
||||
ReadStatus = 0;
|
||||
#if __CORTEX_M >= 0x07
|
||||
SCB_CleanInvalidateDCache();
|
||||
#endif
|
||||
|
||||
if (HAL_SD_ReadBlocks_DMA(&sdio, buff, sector, count) != HAL_OK) {
|
||||
TRACE("SD ReadBlocks failed (s:%u/c:%u)", sector, (uint32_t)count);
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
#if __CORTEX_M >= 0x07
|
||||
SCB_CleanInvalidateDCache();
|
||||
#endif
|
||||
|
||||
// Wait for the reading process to complete or a timeout to occur
|
||||
uint32_t timeout = HAL_GetTick();
|
||||
while((ReadStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT));
|
||||
@@ -241,7 +337,7 @@ static DRESULT _read_dma(BYTE* buff, DWORD sector, UINT count)
|
||||
TRACE("SD read timeout (s:%u c:%u)", sector, (uint32_t)count);
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
|
||||
ReadStatus = 0;
|
||||
return RES_OK;
|
||||
}
|
||||
@@ -256,8 +352,7 @@ static DRESULT sdio_read(BYTE lun, BYTE * buff, DWORD sector, UINT count)
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
if ((DWORD)buff < SRAM_BASE || ((DWORD)buff & 3)) {
|
||||
// TRACE("disk_read bad alignment (%p)", buff);
|
||||
if (!_IS_DMA_BUFFER(buff) || !_IS_ALIGNED(buff)) {
|
||||
while (count--) {
|
||||
res = _read_dma(scratch, sector++, 1);
|
||||
if (res != RES_OK) break;
|
||||
@@ -280,6 +375,10 @@ static DRESULT sdio_read(BYTE lun, BYTE * buff, DWORD sector, UINT count)
|
||||
|
||||
static DRESULT _write_dma(const BYTE *buff, DWORD sector, UINT count)
|
||||
{
|
||||
#if __CORTEX_M >= 0x07
|
||||
SCB_CleanDCache();
|
||||
#endif
|
||||
|
||||
WriteStatus = 0;
|
||||
if (HAL_SD_WriteBlocks_DMA(&sdio, (uint8_t*)buff, sector, count) != HAL_OK) {
|
||||
TRACE("SD WriteBlocks failed (s:%u/c:%u)", sector, (uint32_t)count);
|
||||
@@ -309,14 +408,13 @@ static DRESULT sdio_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
|
||||
return RES_ERROR;
|
||||
}
|
||||
|
||||
if ((DWORD)buff < SRAM_BASE || ((DWORD)buff & 3)) {
|
||||
//TRACE("disk_write bad alignment (%p)", buff);
|
||||
while(count--) {
|
||||
if (!_IS_DMA_BUFFER(buff) || !_IS_ALIGNED(buff)) {
|
||||
while (count--) {
|
||||
memcpy(scratch, buff, BLOCK_SIZE);
|
||||
res = _write_dma((BYTE *)scratch, sector++, 1);
|
||||
if (res != RES_OK) break;
|
||||
buff += BLOCK_SIZE;
|
||||
|
||||
|
||||
if (sdio_check_card_state_with_timeout(SD_TIMEOUT) < 0) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
@@ -394,7 +492,6 @@ DRESULT sdio_ioctl(BYTE lun, BYTE ctrl, void *buff)
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const diskio_driver_t sdio_diskio_driver = {
|
||||
.initialize = sdio_initialize,
|
||||
.status = sdio_status,
|
||||
@@ -402,13 +499,18 @@ const diskio_driver_t sdio_diskio_driver = {
|
||||
.write = sdio_write,
|
||||
.ioctl = sdio_ioctl,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Tx Transfer completed callbacks
|
||||
* @param hsd: SD handle
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
extern "C" void HAL_SD_ErrorCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
UNUSED(hsd);
|
||||
WriteStatus = 2;
|
||||
}
|
||||
|
||||
extern "C" void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)
|
||||
{
|
||||
UNUSED(hsd);
|
||||
@@ -427,11 +529,13 @@ extern "C" void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
|
||||
ReadStatus = 1;
|
||||
}
|
||||
|
||||
extern "C" void SDIO_IRQHandler(void)
|
||||
extern "C" void SD_SDIO_IRQHandler(void)
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_SDIO);
|
||||
HAL_SD_IRQHandler(&sdio);
|
||||
}
|
||||
|
||||
#if defined(SD_SDIO_DMA)
|
||||
extern "C" void SD_SDIO_DMA_IRQHANDLER(void)
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_SDIO_DMA);
|
||||
@@ -439,3 +543,4 @@ extern "C" void SD_SDIO_DMA_IRQHANDLER(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,10 @@ void DMACopyBitmap(uint16_t *dest, uint16_t destw, uint16_t desth, uint16_t x,
|
||||
{
|
||||
DMAWait();
|
||||
|
||||
#if __CORTEX_M >= 0x07
|
||||
SCB_CleanInvalidateDCache();
|
||||
#endif
|
||||
|
||||
LL_DMA2D_DeInit(DMA2D);
|
||||
|
||||
LL_DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
@@ -53,6 +57,7 @@ void DMACopyBitmap(uint16_t *dest, uint16_t destw, uint16_t desth, uint16_t x,
|
||||
|
||||
/* Start Transfer */
|
||||
LL_DMA2D_Start(DMA2D);
|
||||
|
||||
}
|
||||
|
||||
void DMACopyAlphaBitmap(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
@@ -61,6 +66,11 @@ void DMACopyAlphaBitmap(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
uint16_t srcy, uint16_t w, uint16_t h)
|
||||
{
|
||||
DMAWait();
|
||||
|
||||
#if __CORTEX_M >= 0x07
|
||||
SCB_CleanInvalidateDCache();
|
||||
#endif
|
||||
|
||||
LL_DMA2D_DeInit(DMA2D);
|
||||
|
||||
LL_DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
@@ -88,6 +98,7 @@ void DMACopyAlphaBitmap(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
|
||||
/* Start Transfer */
|
||||
LL_DMA2D_Start(DMA2D);
|
||||
|
||||
}
|
||||
|
||||
// same as DMACopyAlphaBitmap(), but with an 8 bit mask for each pixel (used by fonts)
|
||||
@@ -97,6 +108,11 @@ void DMACopyAlphaMask(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
uint16_t h, uint16_t bg_color)
|
||||
{
|
||||
DMAWait();
|
||||
|
||||
#if __CORTEX_M >= 0x07
|
||||
SCB_CleanInvalidateDCache();
|
||||
#endif
|
||||
|
||||
LL_DMA2D_DeInit(DMA2D);
|
||||
|
||||
LL_DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
@@ -127,12 +143,16 @@ void DMACopyAlphaMask(uint16_t *dest, uint16_t destw, uint16_t desth,
|
||||
|
||||
/* Start Transfer */
|
||||
LL_DMA2D_Start(DMA2D);
|
||||
DMAWait();
|
||||
|
||||
}
|
||||
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format)
|
||||
{
|
||||
DMAWait();
|
||||
#if __CORTEX_M >= 0x07
|
||||
SCB_CleanInvalidateDCache();
|
||||
#endif
|
||||
|
||||
LL_DMA2D_DeInit(DMA2D);
|
||||
|
||||
LL_DMA2D_InitTypeDef DMA2D_InitStruct;
|
||||
@@ -153,4 +173,5 @@ void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t
|
||||
|
||||
/* Start Transfer */
|
||||
LL_DMA2D_Start(DMA2D);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,11 +26,27 @@
|
||||
#include "hal/watchdog_driver.h"
|
||||
|
||||
|
||||
#if defined(STM32H7)
|
||||
#define FLASH_CR FLASH->CR1
|
||||
#define FLASH_SR FLASH->SR1
|
||||
#else
|
||||
#define FLASH_CR FLASH->CR
|
||||
#define FLASH_SR FLASH->SR
|
||||
#endif
|
||||
|
||||
#if !defined(FLASH_CR_START)
|
||||
# define FLASH_CR_START FLASH_CR_STRT
|
||||
#endif
|
||||
|
||||
#if !defined(FLASH_SR_BUSY)
|
||||
# define FLASH_SR_BUSY FLASH_SR_BSY
|
||||
#endif
|
||||
|
||||
void waitFlashIdle()
|
||||
{
|
||||
do {
|
||||
WDG_RESET();
|
||||
} while (FLASH->SR & FLASH_SR_BSY);
|
||||
} while (FLASH_SR & FLASH_SR_BUSY);
|
||||
}
|
||||
|
||||
//After reset, write is not allowed in the Flash control register (FLASH_CR) to protect the
|
||||
@@ -44,17 +60,22 @@ void waitFlashIdle()
|
||||
//FLASH_CR register.
|
||||
void unlockFlash()
|
||||
{
|
||||
FLASH->KEYR = 0x45670123;
|
||||
FLASH->KEYR = 0xCDEF89AB;
|
||||
#if defined(STM32H7)
|
||||
FLASH->KEYR1 = FLASH_KEY1;
|
||||
FLASH->KEYR1 = FLASH_KEY2;
|
||||
#else
|
||||
FLASH->KEYR = FLASH_KEY1;
|
||||
FLASH->KEYR = FLASH_KEY2;
|
||||
#endif
|
||||
}
|
||||
|
||||
void lockFlash()
|
||||
{
|
||||
waitFlashIdle();
|
||||
FLASH->CR |= FLASH_CR_LOCK;
|
||||
FLASH_CR |= FLASH_CR_LOCK;
|
||||
}
|
||||
|
||||
#define SECTOR_MASK ((uint32_t)0xFFFFFF07)
|
||||
#define SECTOR_MASK ((uint32_t)0xFFFFFF07)
|
||||
|
||||
void eraseSector(uint32_t sector)
|
||||
{
|
||||
@@ -62,18 +83,20 @@ void eraseSector(uint32_t sector)
|
||||
|
||||
waitFlashIdle();
|
||||
|
||||
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;
|
||||
#if defined(FLASH_CR_PSIZE)
|
||||
FLASH_CR &= ~FLASH_CR_PSIZE;
|
||||
FLASH_CR |= FLASH_CR_PSIZE_1;
|
||||
#endif
|
||||
FLASH_CR &= SECTOR_MASK;
|
||||
FLASH_CR |= FLASH_CR_SER | (sector << 3);
|
||||
FLASH_CR |= FLASH_CR_START;
|
||||
|
||||
/* Wait for operation to be completed */
|
||||
waitFlashIdle();
|
||||
|
||||
/* if the erase operation is completed, disable the SER Bit */
|
||||
FLASH->CR &= (~FLASH_CR_SER);
|
||||
FLASH->CR &= SECTOR_MASK;
|
||||
FLASH_CR &= (~FLASH_CR_SER);
|
||||
FLASH_CR &= SECTOR_MASK;
|
||||
|
||||
WDG_ENABLE(WDG_DURATION);
|
||||
}
|
||||
@@ -142,15 +165,17 @@ void flashWrite(uint32_t * address, const uint32_t * buffer) // page size is 256
|
||||
// Wait for last operation to be completed
|
||||
waitFlashIdle();
|
||||
|
||||
FLASH->CR &= ~FLASH_CR_PSIZE;
|
||||
FLASH->CR |= FLASH_CR_PSIZE_1;
|
||||
FLASH->CR |= FLASH_CR_PG;
|
||||
#if defined(FLASH_CR_PSIZE)
|
||||
FLASH_CR &= ~FLASH_CR_PSIZE;
|
||||
FLASH_CR |= FLASH_CR_PSIZE_1;
|
||||
#endif
|
||||
FLASH_CR |= FLASH_CR_PG;
|
||||
|
||||
*address = *buffer;
|
||||
|
||||
/* Wait for operation to be completed */
|
||||
waitFlashIdle();
|
||||
FLASH->CR &= ~FLASH_CR_PG;
|
||||
FLASH_CR &= ~FLASH_CR_PG;
|
||||
|
||||
/* Check the written value */
|
||||
if (*address != *buffer) {
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
set(CPU_FAMILY STM32)
|
||||
set(MCU cortex-m7)
|
||||
set(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16")
|
||||
|
||||
if(NOT NATIVE_BUILD)
|
||||
# STM32 HAL/LL library
|
||||
set(STM32CUBE_DIR ${THIRDPARTY_DIR}/STM32H7xx_HAL_Driver)
|
||||
include_directories(${STM32CUBE_DIR}/Inc)
|
||||
|
||||
add_library(stm32cube_ll OBJECT EXCLUDE_FROM_ALL
|
||||
# LL drivers
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_gpio.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_fmc.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_tim.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_dma.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_usart.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_rcc.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_exti.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_sdmmc.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_adc.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_spi.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_usb.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_ll_dma2d.c
|
||||
# HAL drivers
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_pwr.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_pwr_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_rcc.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_rcc_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_rtc.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_i2c.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_i2c_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_sd.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_dma.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_mdma.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_pcd.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_pcd_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_qspi.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_flash.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_flash_ex.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_cortex.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_sdram.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_gpio.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_dsi.c
|
||||
${STM32CUBE_DIR}/Src/stm32h7xx_hal_ltdc.c
|
||||
)
|
||||
|
||||
target_compile_definitions(stm32cube_ll PRIVATE USE_FULL_LL_DRIVER)
|
||||
target_include_directories(stm32cube_ll PRIVATE
|
||||
${THIRDPARTY_DIR}/CMSIS/Device/ST/STM32H7xx/Include
|
||||
${THIRDPARTY_DIR}/CMSIS/Include)
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
|
||||
endif()
|
||||
|
||||
# StdPeriph library
|
||||
set(STM32LIB_DIR ${THIRDPARTY_DIR})
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/Device/ST/STM32H7xx/Include)
|
||||
include_directories(${STM32LIB_DIR}/CMSIS/Include)
|
||||
|
||||
add_definitions(-DSTM32H7)
|
||||
|
||||
set(STM32_STDPERIPH_SRC
|
||||
targets/common/arm/stm32/h7/system_stm32h7xx.c
|
||||
)
|
||||
|
||||
if(CPU_TYPE_FULL STREQUAL STM32H750Ix)
|
||||
set(STM32_STDPERIPH_SRC ${STM32_STDPERIPH_SRC}
|
||||
boards/generic_stm32/startup/startup_stm32h750xx.s
|
||||
)
|
||||
elseif(CPU_TYPE_FULL STREQUAL STM32H747Ix)
|
||||
set(STM32_STDPERIPH_SRC ${STM32_STDPERIPH_SRC}
|
||||
boards/generic_stm32/startup/startup_stm32h747xx.s
|
||||
)
|
||||
else()
|
||||
message("### ERROR ####: ${CPU_TYPE_FULL}")
|
||||
endif()
|
||||
|
||||
add_library(stm32_stdperiph OBJECT EXCLUDE_FROM_ALL
|
||||
${STM32_STDPERIPH_SRC}
|
||||
)
|
||||
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32_stdperiph>)
|
||||
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32_stdperiph>)
|
||||
|
||||
if(NOT NATIVE_BUILD)
|
||||
#
|
||||
# FreeRTOS port specific include
|
||||
#
|
||||
add_library(freertos OBJECT EXCLUDE_FROM_ALL
|
||||
${RTOS_DIR}/list.c
|
||||
${RTOS_DIR}/queue.c
|
||||
${RTOS_DIR}/tasks.c
|
||||
${RTOS_DIR}/event_groups.c
|
||||
${RTOS_DIR}/timers.c
|
||||
${RTOS_DIR}/stream_buffer.c
|
||||
${RTOS_DIR}/portable/GCC/ARM_CM4F/port.c
|
||||
)
|
||||
|
||||
target_include_directories(freertos
|
||||
PUBLIC ${RTOS_DIR}/portable/GCC/ARM_CM4F
|
||||
PRIVATE ${RTOS_DIR}/include
|
||||
)
|
||||
|
||||
include_directories(${RTOS_DIR}/portable/GCC/ARM_CM4F)
|
||||
|
||||
# EdgeTx Compat layer
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} rtos.c)
|
||||
|
||||
#
|
||||
# System and FreeRTOS port files
|
||||
#
|
||||
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:freertos>)
|
||||
endif()
|
||||
@@ -0,0 +1,583 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file system_stm32h7xx.c
|
||||
* @author MCD Application Team
|
||||
* @brief CMSIS Cortex-Mx Device Peripheral Access Layer System Source File.
|
||||
*
|
||||
* This file provides two functions and one global variable to be called from
|
||||
* user application:
|
||||
* - SystemInit(): This function is called at startup just after reset and
|
||||
* before branch to main program. This call is made inside
|
||||
* the "startup_stm32h7xx.s" file.
|
||||
*
|
||||
* - SystemCoreClock variable: Contains the core clock, it can be used
|
||||
* by the user application to setup the SysTick
|
||||
* timer or configure other parameters.
|
||||
*
|
||||
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
|
||||
* be called whenever the core clock is changed
|
||||
* during program execution.
|
||||
*
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup CMSIS
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup stm32h7xx_system
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32H7xx_System_Private_Includes
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "stm32h7xx.h"
|
||||
#include <math.h>
|
||||
|
||||
// TODO: remove this
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32h7xx_hal_cortex.h"
|
||||
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (CSI_VALUE)
|
||||
#define CSI_VALUE ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* CSI_VALUE */
|
||||
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE ((uint32_t)64000000) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32H7xx_System_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32H7xx_System_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/************************* Miscellaneous Configuration ************************/
|
||||
/*!< Uncomment the following line if you need to use initialized data in D2 domain SRAM (AHB SRAM) */
|
||||
/* #define DATA_IN_D2_SRAM */
|
||||
|
||||
/* Note: Following vector table addresses must be defined in line with linker
|
||||
configuration. */
|
||||
/*!< Uncomment the following line if you need to relocate the vector table
|
||||
anywhere in FLASH BANK1 or AXI SRAM, else the vector table is kept at the automatic
|
||||
remap of boot address selected */
|
||||
/* #define USER_VECT_TAB_ADDRESS */
|
||||
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
#if defined(DUAL_CORE) && defined(CORE_CM4)
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||
in D2 AXI SRAM else user remap will be done in FLASH BANK2. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#if defined(VECT_TAB_SRAM)
|
||||
#define VECT_TAB_BASE_ADDRESS D2_AXISRAM_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x400. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x400. */
|
||||
#else
|
||||
#define VECT_TAB_BASE_ADDRESS FLASH_BANK2_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x400. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x400. */
|
||||
#endif /* VECT_TAB_SRAM */
|
||||
#else
|
||||
/*!< Uncomment the following line if you need to relocate your vector Table
|
||||
in D1 AXI SRAM else user remap will be done in FLASH BANK1. */
|
||||
/* #define VECT_TAB_SRAM */
|
||||
#if defined(VECT_TAB_SRAM)
|
||||
#define VECT_TAB_BASE_ADDRESS D1_AXISRAM_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x400. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x400. */
|
||||
#else
|
||||
#define VECT_TAB_BASE_ADDRESS FLASH_BANK1_BASE /*!< Vector Table base address field.
|
||||
This value must be a multiple of 0x400. */
|
||||
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
|
||||
This value must be a multiple of 0x400. */
|
||||
#endif /* VECT_TAB_SRAM */
|
||||
#endif /* DUAL_CORE && CORE_CM4 */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32H7xx_System_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32H7xx_System_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
/* This variable is updated in three ways:
|
||||
1) by calling CMSIS function SystemCoreClockUpdate()
|
||||
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
|
||||
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
|
||||
Note: If you use this function to configure the system clock; then there
|
||||
is no need to call the 2 first functions listed above, since SystemCoreClock
|
||||
variable is updated automatically.
|
||||
*/
|
||||
uint32_t SystemCoreClock = 64000000;
|
||||
uint32_t SystemD2Clock = 64000000;
|
||||
const uint8_t D1CorePrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32H7xx_System_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @addtogroup STM32H7xx_System_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
* Initialize the FPU setting and vector table location
|
||||
* configuration.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit (void)
|
||||
{
|
||||
#if defined (DATA_IN_D2_SRAM)
|
||||
__IO uint32_t tmpreg;
|
||||
#endif /* DATA_IN_D2_SRAM */
|
||||
|
||||
/* FPU settings ------------------------------------------------------------*/
|
||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
||||
SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */
|
||||
#endif
|
||||
/* Reset the RCC clock configuration to the default reset state ------------*/
|
||||
|
||||
/* Increasing the CPU frequency */
|
||||
if(FLASH_LATENCY_DEFAULT > (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)))
|
||||
{
|
||||
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
|
||||
MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(FLASH_LATENCY_DEFAULT));
|
||||
}
|
||||
|
||||
/* Set HSION bit */
|
||||
RCC->CR |= RCC_CR_HSION;
|
||||
|
||||
/* Reset CFGR register */
|
||||
RCC->CFGR = 0x00000000;
|
||||
|
||||
/* Reset HSEON, HSECSSON, CSION, HSI48ON, CSIKERON, PLL1ON, PLL2ON and PLL3ON bits */
|
||||
RCC->CR &= 0xEAF6ED7FU;
|
||||
|
||||
/* Decreasing the number of wait states because of lower CPU frequency */
|
||||
if(FLASH_LATENCY_DEFAULT < (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY)))
|
||||
{
|
||||
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
|
||||
MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (uint32_t)(FLASH_LATENCY_DEFAULT));
|
||||
}
|
||||
|
||||
#if defined(D3_SRAM_BASE)
|
||||
/* Reset D1CFGR register */
|
||||
RCC->D1CFGR = 0x00000000;
|
||||
|
||||
/* Reset D2CFGR register */
|
||||
RCC->D2CFGR = 0x00000000;
|
||||
|
||||
/* Reset D3CFGR register */
|
||||
RCC->D3CFGR = 0x00000000;
|
||||
#else
|
||||
/* Reset CDCFGR1 register */
|
||||
RCC->CDCFGR1 = 0x00000000;
|
||||
|
||||
/* Reset CDCFGR2 register */
|
||||
RCC->CDCFGR2 = 0x00000000;
|
||||
|
||||
/* Reset SRDCFGR register */
|
||||
RCC->SRDCFGR = 0x00000000;
|
||||
#endif
|
||||
/* Reset PLLCKSELR register */
|
||||
RCC->PLLCKSELR = 0x02020200;
|
||||
|
||||
/* Reset PLLCFGR register */
|
||||
RCC->PLLCFGR = 0x01FF0000;
|
||||
/* Reset PLL1DIVR register */
|
||||
RCC->PLL1DIVR = 0x01010280;
|
||||
/* Reset PLL1FRACR register */
|
||||
RCC->PLL1FRACR = 0x00000000;
|
||||
|
||||
/* Reset PLL2DIVR register */
|
||||
RCC->PLL2DIVR = 0x01010280;
|
||||
|
||||
/* Reset PLL2FRACR register */
|
||||
|
||||
RCC->PLL2FRACR = 0x00000000;
|
||||
/* Reset PLL3DIVR register */
|
||||
RCC->PLL3DIVR = 0x01010280;
|
||||
|
||||
/* Reset PLL3FRACR register */
|
||||
RCC->PLL3FRACR = 0x00000000;
|
||||
|
||||
/* Reset HSEBYP bit */
|
||||
RCC->CR &= 0xFFFBFFFFU;
|
||||
|
||||
/* Disable all interrupts */
|
||||
RCC->CIER = 0x00000000;
|
||||
|
||||
#if (STM32H7_DEV_ID == 0x450UL)
|
||||
/* dual core CM7 or single core line */
|
||||
if((DBGMCU->IDCODE & 0xFFFF0000U) < 0x20000000U)
|
||||
{
|
||||
/* if stm32h7 revY*/
|
||||
/* Change the switch matrix read issuing capability to 1 for the AXI SRAM target (Target 7) */
|
||||
*((__IO uint32_t*)0x51008108) = 0x000000001U;
|
||||
}
|
||||
#endif /* STM32H7_DEV_ID */
|
||||
|
||||
#if defined(DATA_IN_D2_SRAM)
|
||||
/* in case of initialized data in D2 SRAM (AHB SRAM), enable the D2 SRAM clock (AHB SRAM clock) */
|
||||
#if defined(RCC_AHB2ENR_D2SRAM3EN)
|
||||
RCC->AHB2ENR |= (RCC_AHB2ENR_D2SRAM1EN | RCC_AHB2ENR_D2SRAM2EN | RCC_AHB2ENR_D2SRAM3EN);
|
||||
#elif defined(RCC_AHB2ENR_D2SRAM2EN)
|
||||
RCC->AHB2ENR |= (RCC_AHB2ENR_D2SRAM1EN | RCC_AHB2ENR_D2SRAM2EN);
|
||||
#else
|
||||
RCC->AHB2ENR |= (RCC_AHB2ENR_AHBSRAM1EN | RCC_AHB2ENR_AHBSRAM2EN);
|
||||
#endif /* RCC_AHB2ENR_D2SRAM3EN */
|
||||
|
||||
tmpreg = RCC->AHB2ENR;
|
||||
(void) tmpreg;
|
||||
#endif /* DATA_IN_D2_SRAM */
|
||||
|
||||
#if defined(DUAL_CORE) && defined(CORE_CM4)
|
||||
/* Configure the Vector Table location add offset address for cortex-M4 ------------------*/
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal D2 AXI-RAM or in Internal FLASH */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
|
||||
#else
|
||||
/*
|
||||
* Disable the FMC bank1 (enabled after reset).
|
||||
* This, prevents CPU speculation access on this bank which blocks the use of FMC during
|
||||
* 24us. During this time the others FMC master (such as LTDC) cannot use it!
|
||||
*/
|
||||
FMC_Bank1_R->BTCR[0] = 0x000030D2;
|
||||
/* Configure the Vector Table location -------------------------------------*/
|
||||
#if defined(USER_VECT_TAB_ADDRESS)
|
||||
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal D1 AXI-RAM or in Internal FLASH */
|
||||
#endif /* USER_VECT_TAB_ADDRESS */
|
||||
|
||||
#endif /*DUAL_CORE && CORE_CM4*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update SystemCoreClock variable according to Clock Register Values.
|
||||
* The SystemCoreClock variable contains the core clock , it can
|
||||
* be used by the user application to setup the SysTick timer or configure
|
||||
* other parameters.
|
||||
*
|
||||
* @note Each time the core clock changes, this function must be called
|
||||
* to update SystemCoreClock variable value. Otherwise, any configuration
|
||||
* based on this variable will be incorrect.
|
||||
*
|
||||
* @note - The system frequency computed by this function is not the real
|
||||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*
|
||||
* - If SYSCLK source is CSI, SystemCoreClock will contain the CSI_VALUE(*)
|
||||
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**)
|
||||
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***)
|
||||
* - If SYSCLK source is PLL, SystemCoreClock will contain the CSI_VALUE(*),
|
||||
* HSI_VALUE(**) or HSE_VALUE(***) multiplied/divided by the PLL factors.
|
||||
*
|
||||
* (*) CSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
|
||||
* 4 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
* (**) HSI_VALUE is a constant defined in stm32h7xx_hal.h file (default value
|
||||
* 64 MHz) but the real value may vary depending on the variations
|
||||
* in voltage and temperature.
|
||||
*
|
||||
* (***)HSE_VALUE is a constant defined in stm32h7xx_hal.h file (default value
|
||||
* 25 MHz), user has to ensure that HSE_VALUE is same as the real
|
||||
* frequency of the crystal used. Otherwise, this function may
|
||||
* have wrong result.
|
||||
*
|
||||
* - The result of this function could be not correct when using fractional
|
||||
* value for HSE crystal.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemCoreClockUpdate (void)
|
||||
{
|
||||
uint32_t pllp, pllsource, pllm, pllfracen, hsivalue, tmp;
|
||||
uint32_t common_system_clock;
|
||||
float_t fracn1, pllvco;
|
||||
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
|
||||
switch (RCC->CFGR & RCC_CFGR_SWS)
|
||||
{
|
||||
case RCC_CFGR_SWS_HSI: /* HSI used as system clock source */
|
||||
common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
|
||||
break;
|
||||
|
||||
case RCC_CFGR_SWS_CSI: /* CSI used as system clock source */
|
||||
common_system_clock = CSI_VALUE;
|
||||
break;
|
||||
|
||||
case RCC_CFGR_SWS_HSE: /* HSE used as system clock source */
|
||||
common_system_clock = HSE_VALUE;
|
||||
break;
|
||||
|
||||
case RCC_CFGR_SWS_PLL1: /* PLL1 used as system clock source */
|
||||
|
||||
/* PLL_VCO = (HSE_VALUE or HSI_VALUE or CSI_VALUE/ PLLM) * PLLN
|
||||
SYSCLK = PLL_VCO / PLLR
|
||||
*/
|
||||
pllsource = (RCC->PLLCKSELR & RCC_PLLCKSELR_PLLSRC);
|
||||
pllm = ((RCC->PLLCKSELR & RCC_PLLCKSELR_DIVM1)>> 4) ;
|
||||
pllfracen = ((RCC->PLLCFGR & RCC_PLLCFGR_PLL1FRACEN)>>RCC_PLLCFGR_PLL1FRACEN_Pos);
|
||||
fracn1 = (float_t)(uint32_t)(pllfracen* ((RCC->PLL1FRACR & RCC_PLL1FRACR_FRACN1)>> 3));
|
||||
|
||||
if (pllm != 0U)
|
||||
{
|
||||
switch (pllsource)
|
||||
{
|
||||
case RCC_PLLCKSELR_PLLSRC_HSI: /* HSI used as PLL clock source */
|
||||
|
||||
hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
|
||||
pllvco = ( (float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
|
||||
|
||||
break;
|
||||
|
||||
case RCC_PLLCKSELR_PLLSRC_CSI: /* CSI used as PLL clock source */
|
||||
pllvco = ((float_t)CSI_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
|
||||
break;
|
||||
|
||||
case RCC_PLLCKSELR_PLLSRC_HSE: /* HSE used as PLL clock source */
|
||||
pllvco = ((float_t)HSE_VALUE / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
|
||||
break;
|
||||
|
||||
default:
|
||||
hsivalue = (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3)) ;
|
||||
pllvco = ((float_t)hsivalue / (float_t)pllm) * ((float_t)(uint32_t)(RCC->PLL1DIVR & RCC_PLL1DIVR_N1) + (fracn1/(float_t)0x2000) +(float_t)1 );
|
||||
break;
|
||||
}
|
||||
pllp = (((RCC->PLL1DIVR & RCC_PLL1DIVR_P1) >>9) + 1U ) ;
|
||||
common_system_clock = (uint32_t)(float_t)(pllvco/(float_t)pllp);
|
||||
}
|
||||
else
|
||||
{
|
||||
common_system_clock = 0U;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
common_system_clock = (uint32_t) (HSI_VALUE >> ((RCC->CR & RCC_CR_HSIDIV)>> 3));
|
||||
break;
|
||||
}
|
||||
|
||||
/* Compute SystemClock frequency --------------------------------------------------*/
|
||||
#if defined (RCC_D1CFGR_D1CPRE)
|
||||
tmp = D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos];
|
||||
|
||||
/* common_system_clock frequency : CM7 CPU frequency */
|
||||
common_system_clock >>= tmp;
|
||||
|
||||
/* SystemD2Clock frequency : CM4 CPU, AXI and AHBs Clock frequency */
|
||||
SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
|
||||
|
||||
#else
|
||||
tmp = D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE)>> RCC_CDCFGR1_CDCPRE_Pos];
|
||||
|
||||
/* common_system_clock frequency : CM7 CPU frequency */
|
||||
common_system_clock >>= tmp;
|
||||
|
||||
/* SystemD2Clock frequency : AXI and AHBs Clock frequency */
|
||||
SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(DUAL_CORE) && defined(CORE_CM4)
|
||||
SystemCoreClock = SystemD2Clock;
|
||||
#else
|
||||
SystemCoreClock = common_system_clock;
|
||||
#endif /* DUAL_CORE && CORE_CM4 */
|
||||
}
|
||||
|
||||
// TODO: better exception handler
|
||||
void NMI_Handler(void){asm("BKPT");}
|
||||
void HardFault_Handler(void){asm("BKPT");}
|
||||
void MemManage_Handler(void){asm("BKPT");}
|
||||
void BusFault_Handler(void){asm("BKPT");}
|
||||
void UsageFault_Handler(void){asm("BKPT");}
|
||||
//void SVC_Handler(void){asm("BKPT");}
|
||||
void DebugMon_Handler(void){asm("BKPT");}
|
||||
//void PendSV_Handler(void){asm("BKPT");}
|
||||
//void SysTick_Handler(void){asm("BKPT");}
|
||||
void WWDG_IRQHandler(void){asm("BKPT");}
|
||||
void PVD_AVD_IRQHandler(void){asm("BKPT");}
|
||||
void TAMP_STAMP_IRQHandler(void){asm("BKPT");}
|
||||
void RTC_WKUP_IRQHandler(void){asm("BKPT");}
|
||||
void FLASH_IRQHandler(void){asm("BKPT");}
|
||||
void RCC_IRQHandler(void){asm("BKPT");}
|
||||
void EXTI0_IRQHandler(void){asm("BKPT");}
|
||||
void EXTI1_IRQHandler(void){asm("BKPT");}
|
||||
void DMA1_Stream1_IRQHandler(void){asm("BKPT");}
|
||||
void DMA1_Stream2_IRQHandler(void){asm("BKPT");}
|
||||
void DMA1_Stream3_IRQHandler(void){asm("BKPT");}
|
||||
void DMA1_Stream4_IRQHandler(void){asm("BKPT");}
|
||||
//void ADC_IRQHandler(void){asm("BKPT");}
|
||||
void FDCAN1_IT0_IRQHandler(void){asm("BKPT");}
|
||||
void FDCAN2_IT0_IRQHandler(void){asm("BKPT");}
|
||||
void FDCAN1_IT1_IRQHandler(void){asm("BKPT");}
|
||||
void FDCAN2_IT1_IRQHandler(void){asm("BKPT");}
|
||||
void TIM1_BRK_IRQHandler(void){asm("BKPT");}
|
||||
void TIM1_UP_IRQHandler(void){asm("BKPT");}
|
||||
void TIM1_TRG_COM_IRQHandler(void){asm("BKPT");}
|
||||
void TIM1_CC_IRQHandler(void){asm("BKPT");}
|
||||
void TIM2_IRQHandler(void){asm("BKPT");}
|
||||
void TIM3_IRQHandler(void){asm("BKPT");}
|
||||
// void TIM4_IRQHandler(void){asm("BKPT");}
|
||||
void I2C1_EV_IRQHandler(void){asm("BKPT");}
|
||||
void I2C1_ER_IRQHandler(void){asm("BKPT");}
|
||||
void I2C2_EV_IRQHandler(void){asm("BKPT");}
|
||||
void I2C2_ER_IRQHandler(void){asm("BKPT");}
|
||||
void SPI1_IRQHandler(void){asm("BKPT");}
|
||||
void SPI2_IRQHandler(void){asm("BKPT");}
|
||||
void EXTI15_10_IRQHandler(void){asm("BKPT");}
|
||||
void RTC_Alarm_IRQHandler(void){asm("BKPT");}
|
||||
void TIM8_CC_IRQHandler(void){asm("BKPT");}
|
||||
void DMA1_Stream7_IRQHandler(void){asm("BKPT");}
|
||||
void FMC_IRQHandler(void){asm("BKPT");}
|
||||
void TIM5_IRQHandler(void){asm("BKPT");}
|
||||
void SPI3_IRQHandler(void){asm("BKPT");}
|
||||
void UART5_IRQHandler(void){asm("BKPT");}
|
||||
void TIM7_IRQHandler(void){asm("BKPT");}
|
||||
//void DMA2_Stream0_IRQHandler(void){asm("BKPT");}
|
||||
void DMA2_Stream2_IRQHandler(void){asm("BKPT");}
|
||||
void DMA2_Stream3_IRQHandler(void){asm("BKPT");}
|
||||
//void DMA2_Stream4_IRQHandler(void){asm("BKPT");}
|
||||
void ETH_IRQHandler(void){asm("BKPT");}
|
||||
void ETH_WKUP_IRQHandler(void){asm("BKPT");}
|
||||
void FDCAN_CAL_IRQHandler(void){asm("BKPT");}
|
||||
void DMA2_Stream5_IRQHandler(void){asm("BKPT");}
|
||||
void DMA2_Stream6_IRQHandler(void){asm("BKPT");}
|
||||
void DMA2_Stream7_IRQHandler(void){asm("BKPT");}
|
||||
void I2C3_EV_IRQHandler(void){asm("BKPT");}
|
||||
void I2C3_ER_IRQHandler(void){asm("BKPT");}
|
||||
void OTG_HS_EP1_OUT_IRQHandler(void){asm("BKPT");}
|
||||
void OTG_HS_EP1_IN_IRQHandler(void){asm("BKPT");}
|
||||
void OTG_HS_WKUP_IRQHandler(void){asm("BKPT");}
|
||||
void OTG_HS_IRQHandler(void){asm("BKPT");}
|
||||
void DCMI_IRQHandler(void){asm("BKPT");}
|
||||
void CRYP_IRQHandler(void){asm("BKPT");}
|
||||
void HASH_RNG_IRQHandler(void){asm("BKPT");}
|
||||
void FPU_IRQHandler(void){asm("BKPT");}
|
||||
void UART8_IRQHandler(void){asm("BKPT");}
|
||||
void SPI4_IRQHandler(void){asm("BKPT");}
|
||||
void SPI5_IRQHandler(void){asm("BKPT");}
|
||||
void SPI6_IRQHandler(void){asm("BKPT");}
|
||||
void SAI1_IRQHandler(void){asm("BKPT");}
|
||||
void LTDC_ER_IRQHandler(void){asm("BKPT");}
|
||||
void DMA2D_IRQHandler(void){asm("BKPT");}
|
||||
void SAI2_IRQHandler(void){asm("BKPT");}
|
||||
void QUADSPI_IRQHandler(void){asm("BKPT");}
|
||||
void LPTIM1_IRQHandler(void){asm("BKPT");}
|
||||
void CEC_IRQHandler(void){asm("BKPT");}
|
||||
void I2C4_EV_IRQHandler(void){asm("BKPT");}
|
||||
void I2C4_ER_IRQHandler(void){asm("BKPT");}
|
||||
void SPDIF_RX_IRQHandler(void){asm("BKPT");}
|
||||
void OTG_FS_EP1_OUT_IRQHandler(void){asm("BKPT");}
|
||||
void OTG_FS_EP1_IN_IRQHandler(void){asm("BKPT");}
|
||||
void OTG_FS_WKUP_IRQHandler(void){asm("BKPT");}
|
||||
void DMAMUX1_OVR_IRQHandler(void){asm("BKPT");}
|
||||
void HRTIM1_Master_IRQHandler(void){asm("BKPT");}
|
||||
void HRTIM1_TIMA_IRQHandler(void){asm("BKPT");}
|
||||
void HRTIM1_TIMB_IRQHandler(void){asm("BKPT");}
|
||||
void HRTIM1_TIMC_IRQHandler(void){asm("BKPT");}
|
||||
void HRTIM1_TIMD_IRQHandler(void){asm("BKPT");}
|
||||
void HRTIM1_TIME_IRQHandler(void){asm("BKPT");}
|
||||
void HRTIM1_FLT_IRQHandler(void){asm("BKPT");}
|
||||
void DFSDM1_FLT0_IRQHandler(void){asm("BKPT");}
|
||||
void DFSDM1_FLT1_IRQHandler(void){asm("BKPT");}
|
||||
void DFSDM1_FLT2_IRQHandler(void){asm("BKPT");}
|
||||
void DFSDM1_FLT3_IRQHandler(void){asm("BKPT");}
|
||||
void SAI3_IRQHandler(void){asm("BKPT");}
|
||||
void SWPMI1_IRQHandler(void){asm("BKPT");}
|
||||
void TIM15_IRQHandler(void){asm("BKPT");}
|
||||
void TIM16_IRQHandler(void){asm("BKPT");}
|
||||
void MDIOS_WKUP_IRQHandler(void){asm("BKPT");}
|
||||
void MDIOS_IRQHandler(void){asm("BKPT");}
|
||||
void JPEG_IRQHandler(void){asm("BKPT");}
|
||||
void MDMA_IRQHandler(void){asm("BKPT");}
|
||||
void SDMMC2_IRQHandler(void){asm("BKPT");}
|
||||
void HSEM1_IRQHandler(void){asm("BKPT");}
|
||||
// void ADC3_IRQHandler(void){asm("BKPT");}
|
||||
void DMAMUX2_OVR_IRQHandler(void){asm("BKPT");}
|
||||
void BDMA_Channel0_IRQHandler(void){asm("BKPT");}
|
||||
void BDMA_Channel1_IRQHandler(void){asm("BKPT");}
|
||||
void BDMA_Channel2_IRQHandler(void){asm("BKPT");}
|
||||
void BDMA_Channel3_IRQHandler(void){asm("BKPT");}
|
||||
void BDMA_Channel4_IRQHandler(void){asm("BKPT");}
|
||||
void BDMA_Channel5_IRQHandler(void){asm("BKPT");}
|
||||
void BDMA_Channel6_IRQHandler(void){asm("BKPT");}
|
||||
void BDMA_Channel7_IRQHandler(void){asm("BKPT");}
|
||||
void COMP1_IRQHandler(void){asm("BKPT");}
|
||||
void LPTIM2_IRQHandler(void){asm("BKPT");}
|
||||
void LPTIM3_IRQHandler(void){asm("BKPT");}
|
||||
void LPTIM4_IRQHandler(void){asm("BKPT");}
|
||||
void LPTIM5_IRQHandler(void){asm("BKPT");}
|
||||
void LPUART1_IRQHandler(void){asm("BKPT");}
|
||||
void CRS_IRQHandler(void){asm("BKPT");}
|
||||
void ECC_IRQHandler(void){asm("BKPT");}
|
||||
void SAI4_IRQHandler(void){asm("BKPT");}
|
||||
void WAKEUP_PIN_IRQHandler(void){asm("BKPT");}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -22,11 +22,17 @@
|
||||
#include "stm32_adc.h"
|
||||
#include "stm32_dma.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_hal.h"
|
||||
|
||||
#include "timers_driver.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "FreeRTOSConfig.h"
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define ADC_COMMON ((ADC_Common_TypeDef *)ADC_BASE)
|
||||
#define OVERSAMPLING 4
|
||||
|
||||
#define SAMPLING_TIMEOUT_US 500
|
||||
@@ -35,6 +41,20 @@
|
||||
// to avoid issues with preemption between these 2
|
||||
#define ADC_IRQ_PRIO configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
|
||||
|
||||
#if defined(STM32H7) || defined(STM32H7RS)
|
||||
# define _ENABLE_EOCIE(ADCx) SET_BIT(ADCx->IER, ADC_IER_EOCIE)
|
||||
# define _DISABLE_EOCIE(ADCx) CLEAR_BIT(ADCx->IER, ADC_IER_EOCIE)
|
||||
# define _START_ADC_SINGLE(ADCx) SET_BIT(ADCx->CR, ADC_CR_ADSTART)
|
||||
# define _START_ADC_DMA(ADCx) _START_ADC_SINGLE(ADCx)
|
||||
# define _CLEAR_ADC_STATUS(ADCx) CLEAR_BIT(ADCx->ISR, ADC_ISR_EOC | ADC_ISR_OVR)
|
||||
#else
|
||||
# define _ENABLE_EOCIE(ADCx) SET_BIT(ADCx->CR1, ADC_CR1_EOCIE)
|
||||
# define _DISABLE_EOCIE(ADCx) CLEAR_BIT(ADCx->CR1, ADC_CR1_EOCIE)
|
||||
# define _START_ADC_SINGLE(ADCx) SET_BIT(ADCx->CR2, ADC_CR2_SWSTART)
|
||||
# define _START_ADC_DMA(ADCx) SET_BIT(ADCx->CR2, ADC_CR2_SWSTART | ADC_CR2_DMA)
|
||||
# define _CLEAR_ADC_STATUS(ADCx) CLEAR_BIT(ADCx->SR, ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR)
|
||||
#endif
|
||||
|
||||
// Max 32 inputs supported
|
||||
static uint32_t _adc_input_mask;
|
||||
static uint32_t _adc_input_inhibt_mask = 0;
|
||||
@@ -70,7 +90,7 @@ void enableVBatBridge()
|
||||
if (adcGetMaxInputs(ADC_INPUT_RTC_BAT) < 1) return;
|
||||
|
||||
// Set internal measurement path for vbat sensor
|
||||
LL_ADC_SetCommonPathInternalCh(ADC_COMMON, LL_ADC_PATH_INTERNAL_VBAT);
|
||||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_VBAT);
|
||||
|
||||
auto channel = adcGetInputOffset(ADC_INPUT_RTC_BAT);
|
||||
_adc_inhibit_mask &= ~(1 << channel);
|
||||
@@ -84,20 +104,33 @@ void disableVBatBridge()
|
||||
_adc_inhibit_mask |= (1 << channel);
|
||||
|
||||
// Set internal measurement path to none
|
||||
LL_ADC_SetCommonPathInternalCh(ADC_COMMON, LL_ADC_PATH_INTERNAL_NONE);
|
||||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1), LL_ADC_PATH_INTERNAL_NONE);
|
||||
}
|
||||
|
||||
bool isVBatBridgeEnabled()
|
||||
{
|
||||
// && !(_adc_inhibit_mask & (1 << channel));
|
||||
return LL_ADC_GetCommonPathInternalCh(ADC_COMMON) == LL_ADC_PATH_INTERNAL_VBAT;
|
||||
return LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC1)) == LL_ADC_PATH_INTERNAL_VBAT;
|
||||
}
|
||||
|
||||
static void adc_enable_clock(ADC_TypeDef* ADCx)
|
||||
{
|
||||
#if defined(RCC_AHB1ENR_ADC12EN)
|
||||
# if defined(ADC3)
|
||||
if (ADCx == ADC3) {
|
||||
LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_ADC3);
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
// ADC1 / ADC2
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_ADC12);
|
||||
#elif defined(RCC_APB2ENR_ADC1EN)
|
||||
uint32_t adc_idx = (((uint32_t) ADCx) - ADC1_BASE) / 0x100UL;
|
||||
uint32_t adc_msk = RCC_APB2ENR_ADC1EN << adc_idx;
|
||||
LL_APB2_GRP1_EnableClock(adc_msk);
|
||||
#else
|
||||
# warning "Unknown ADC clock enable"
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool adc_disable_dma(DMA_TypeDef* DMAx, uint32_t stream);
|
||||
@@ -133,59 +166,89 @@ static void adc_init_pins(const stm32_adc_gpio_t* GPIOs, uint8_t n_GPIO)
|
||||
}
|
||||
}
|
||||
|
||||
static const uint32_t _seq_length_lookup[] = {
|
||||
LL_ADC_REG_SEQ_SCAN_DISABLE,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS,
|
||||
LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS,
|
||||
};
|
||||
|
||||
static void adc_setup_scan_mode(ADC_TypeDef* ADCx, uint8_t nconv)
|
||||
{
|
||||
// ADC must be disabled for the functions used here
|
||||
LL_ADC_Disable(ADCx);
|
||||
|
||||
LL_ADC_InitTypeDef adcInit;
|
||||
LL_ADC_StructInit(&adcInit);
|
||||
|
||||
LL_ADC_REG_InitTypeDef adcRegInit;
|
||||
LL_ADC_REG_StructInit(&adcRegInit);
|
||||
|
||||
#if !defined(STM32H7) && !defined(STM32H7RS)
|
||||
if (nconv > 1) {
|
||||
adcInit.SequencersScanMode = LL_ADC_SEQ_SCAN_ENABLE;
|
||||
} else {
|
||||
adcInit.SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE;
|
||||
}
|
||||
#endif
|
||||
|
||||
adcInit.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
|
||||
#if !defined(STM32H7)
|
||||
adcInit.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(STM32H7) || defined(STM32H7RS)
|
||||
/* - Exit from deep-power-down mode and ADC voltage regulator enable */
|
||||
if (LL_ADC_IsDeepPowerDownEnabled(ADCx) != 0UL)
|
||||
{
|
||||
/* Disable ADC deep power down mode */
|
||||
LL_ADC_DisableDeepPowerDown(ADCx);
|
||||
|
||||
/* System was in deep power down mode, calibration must
|
||||
be relaunched or a previously saved calibration factor
|
||||
re-applied once the ADC voltage regulator is enabled */
|
||||
}
|
||||
|
||||
if (LL_ADC_IsInternalRegulatorEnabled(ADCx) == 0UL)
|
||||
{
|
||||
/* Enable ADC internal voltage regulator */
|
||||
LL_ADC_EnableInternalRegulator(ADCx);
|
||||
|
||||
/* Note: Variable divided by 2 to compensate partially */
|
||||
/* CPU processing cycles, scaling in us split to not */
|
||||
/* exceed 32 bits register capacity and handle low frequency. */
|
||||
uint32_t wait_loop_index = ((LL_ADC_DELAY_INTERNAL_REGUL_STAB_US / 10UL) *
|
||||
((SystemCoreClock / (100000UL * 2UL)) + 1UL));
|
||||
while (wait_loop_index != 0UL) {
|
||||
wait_loop_index--;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LL_ADC_RESOLUTION_12B_OPT)
|
||||
adcInit.Resolution = LL_ADC_RESOLUTION_12B_OPT;
|
||||
#else
|
||||
adcInit.Resolution = LL_ADC_RESOLUTION_12B;
|
||||
#endif
|
||||
LL_ADC_Init(ADCx, &adcInit);
|
||||
|
||||
LL_ADC_REG_InitTypeDef adcRegInit;
|
||||
LL_ADC_REG_StructInit(&adcRegInit);
|
||||
|
||||
adcRegInit.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
|
||||
adcRegInit.ContinuousMode = LL_ADC_REG_CONV_SINGLE;
|
||||
|
||||
if (nconv > 1) {
|
||||
adcRegInit.SequencerLength = _seq_length_lookup[nconv - 1];
|
||||
adcRegInit.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED;
|
||||
adcRegInit.SequencerLength = (nconv - 1) << ADC_SQR1_L_Pos;
|
||||
#if defined(STM32H7)
|
||||
adcRegInit.DataTransferMode = LL_ADC_REG_DMA_TRANSFER_LIMITED;
|
||||
#else
|
||||
adcRegInit.DMATransfer = LL_ADC_REG_DMA_TRANSFER_LIMITED;
|
||||
#endif
|
||||
}
|
||||
|
||||
LL_ADC_REG_Init(ADCx, &adcRegInit);
|
||||
|
||||
// Enable ADC
|
||||
// TODO: check ADC_CR2_DDS (normally only for circular DMA
|
||||
// but the old was using it (no clue why)
|
||||
#if defined(STM32H7RS) || defined(STM32H7)
|
||||
LL_ADC_ClearFlag_ADRDY(ADCx);
|
||||
LL_ADC_Enable(ADCx);
|
||||
while(!LL_ADC_IsActiveFlag_ADRDY(ADCx)) {
|
||||
if (!LL_ADC_IsEnabled(ADCx)) LL_ADC_Enable(ADCx);
|
||||
}
|
||||
#else
|
||||
LL_ADC_Enable(ADCx);
|
||||
#endif
|
||||
}
|
||||
|
||||
static const uint32_t _rank_lookup[] = {
|
||||
@@ -229,7 +292,7 @@ static uint8_t adc_init_channels(const stm32_adc_t* adc,
|
||||
}
|
||||
|
||||
// internal channel don't have a GPIO + pin defined
|
||||
uint32_t mask = (1 << (ADC_CHANNEL_ID_MASK & input->ADC_Channel));
|
||||
uint32_t mask = 1 << __LL_ADC_CHANNEL_TO_DECIMAL_NB(input->ADC_Channel);
|
||||
if (!__LL_ADC_IS_CHANNEL_INTERNAL(input->ADC_Channel)) {
|
||||
uint32_t mode = LL_GPIO_GetPinMode(input->GPIOx, input->GPIO_Pin);
|
||||
if (mode != LL_GPIO_MODE_ANALOG) {
|
||||
@@ -261,6 +324,9 @@ static uint8_t adc_init_channels(const stm32_adc_t* adc,
|
||||
LL_ADC_SetChannelSamplingTime(adc->ADCx, input->ADC_Channel,
|
||||
adc->sample_time);
|
||||
|
||||
#if defined(STM32H7)
|
||||
LL_ADC_SetChannelPreselection(adc->ADCx, input->ADC_Channel);
|
||||
#endif
|
||||
|
||||
nconv--;
|
||||
rank++;
|
||||
@@ -284,6 +350,48 @@ static bool adc_init_dma_stream(ADC_TypeDef* adc, DMA_TypeDef* DMAx,
|
||||
adc_dma_clear_flags(DMAx, stream);
|
||||
|
||||
// setup DMA request
|
||||
#if defined(STM32H7RS)
|
||||
LL_DMA_SetSrcAddress(DMAx, stream, (intptr_t)&adc->DR);
|
||||
LL_DMA_ConfigTransfer(DMAx, stream,
|
||||
LL_DMA_SRC_DATAWIDTH_HALFWORD |
|
||||
LL_DMA_DEST_DATAWIDTH_HALFWORD |
|
||||
LL_DMA_DEST_INCREMENT);
|
||||
LL_DMA_SetPeriphRequest(DMAx, stream, channel);
|
||||
LL_DMA_SetChannelPriorityLevel(DMAx, stream, LL_DMA_HIGH_PRIORITY);
|
||||
// TODO: check FIFO mode
|
||||
#elif defined(STM32H7)
|
||||
if (DMAx != (DMA_TypeDef*)BDMA) {
|
||||
LL_DMA_ConfigAddresses(DMAx, stream, (intptr_t)&adc->DR, (intptr_t)dest,
|
||||
LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
|
||||
LL_DMA_SetDataLength(DMAx, stream, nconv);
|
||||
LL_DMA_SetPeriphRequest(DMAx, stream, channel);
|
||||
|
||||
// Very high priority, half-word transfers, increment memory
|
||||
LL_DMA_ConfigTransfer(
|
||||
DMAx, stream,
|
||||
LL_DMA_PRIORITY_VERYHIGH | LL_DMA_MDATAALIGN_HALFWORD |
|
||||
LL_DMA_PDATAALIGN_HALFWORD | LL_DMA_MEMORY_INCREMENT |
|
||||
LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
|
||||
|
||||
// disable direct mode, half full FIFO
|
||||
LL_DMA_EnableFifoMode(DMAx, stream);
|
||||
LL_DMA_SetFIFOThreshold(DMAx, stream, LL_DMA_FIFOTHRESHOLD_1_2);
|
||||
LL_DMA_SetMemoryBurstxfer(DMAx, stream, LL_DMA_MBURST_INC4);
|
||||
} else {
|
||||
BDMA_TypeDef* BDMAx = (BDMA_TypeDef*)DMAx;
|
||||
LL_BDMA_ConfigAddresses(BDMAx, stream, (intptr_t)&adc->DR, (intptr_t)dest,
|
||||
LL_BDMA_DIRECTION_PERIPH_TO_MEMORY);
|
||||
LL_BDMA_SetDataLength(BDMAx, stream, nconv);
|
||||
LL_BDMA_SetPeriphRequest(BDMAx, stream, channel);
|
||||
|
||||
// Very high priority, half-word transfers, increment memory
|
||||
LL_BDMA_ConfigTransfer(
|
||||
BDMAx, stream,
|
||||
LL_BDMA_PRIORITY_VERYHIGH | LL_BDMA_MDATAALIGN_HALFWORD |
|
||||
LL_BDMA_PDATAALIGN_HALFWORD | LL_BDMA_MEMORY_INCREMENT |
|
||||
LL_BDMA_DIRECTION_PERIPH_TO_MEMORY);
|
||||
}
|
||||
#elif defined(STM32F4) || defined(STM32F2)
|
||||
LL_DMA_ConfigAddresses(DMAx, stream, CONVERT_PTR_UINT(&adc->DR),
|
||||
CONVERT_PTR_UINT(dest),
|
||||
LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
|
||||
@@ -301,6 +409,10 @@ static bool adc_init_dma_stream(ADC_TypeDef* adc, DMA_TypeDef* DMAx,
|
||||
LL_DMA_SetFIFOThreshold(DMAx, stream, LL_DMA_FIFOTHRESHOLD_1_2);
|
||||
LL_DMA_SetMemoryBurstxfer(DMAx, stream, LL_DMA_MBURST_INC4);
|
||||
|
||||
#else
|
||||
# warning "Unsupported DMA configuration for MCU type"
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -313,22 +425,31 @@ bool stm32_hal_adc_init(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
_adc_oversampling_disabled = 0;
|
||||
|
||||
adc_init_pins(ADC_GPIOs, n_GPIO);
|
||||
memset(_adc_dma_buffer, 0, sizeof(_adc_dma_buffer));
|
||||
|
||||
// Init common to all ADCs
|
||||
LL_ADC_CommonInitTypeDef commonInit;
|
||||
LL_ADC_CommonStructInit(&commonInit);
|
||||
|
||||
commonInit.CommonClock = LL_ADC_CLOCK_SYNC_PCLK_DIV2;
|
||||
LL_ADC_CommonInit(ADC_COMMON, &commonInit);
|
||||
#if defined(LL_ADC_CLOCK_ASYNC_DIV4)
|
||||
// H7 and H7RS use their own clock
|
||||
commonInit.CommonClock = LL_ADC_CLOCK_ASYNC_DIV4;
|
||||
#else
|
||||
// others can only use the peripheral clock
|
||||
commonInit.CommonClock = LL_ADC_CLOCK_SYNC_PCLK_DIV4;
|
||||
#endif
|
||||
|
||||
_adc_input_mask = 0;
|
||||
// uint16_t* dma_buffer = _adc_dma_buffer;
|
||||
const stm32_adc_t* adc = ADCs;
|
||||
|
||||
while (n_ADC > 0) {
|
||||
|
||||
uint8_t nconv = adc->n_channels;
|
||||
if (nconv > 0) {
|
||||
|
||||
// enable common instance
|
||||
LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(adc->ADCx), &commonInit);
|
||||
|
||||
// enable periph clock
|
||||
adc_enable_clock(adc->ADCx);
|
||||
|
||||
@@ -353,8 +474,22 @@ bool stm32_hal_adc_init(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
}
|
||||
} else {
|
||||
// single conversion
|
||||
#if defined(STM32H7)
|
||||
if (adc->ADCx == ADC3) {
|
||||
NVIC_SetPriority(ADC3_IRQn, ADC_IRQ_PRIO);
|
||||
NVIC_EnableIRQ(ADC3_IRQn);
|
||||
} else {
|
||||
NVIC_SetPriority(ADC_IRQn, ADC_IRQ_PRIO);
|
||||
NVIC_EnableIRQ(ADC_IRQn);
|
||||
}
|
||||
#else
|
||||
|
||||
#if defined(STM32H7RS)
|
||||
# define ADC_IRQn ADC1_2_IRQn
|
||||
#endif
|
||||
NVIC_SetPriority(ADC_IRQn, ADC_IRQ_PRIO);
|
||||
NVIC_EnableIRQ(ADC_IRQn);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,6 +500,29 @@ bool stm32_hal_adc_init(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(STM32H7RS)
|
||||
|
||||
static inline DMA_Channel_TypeDef* _dma_get_stream(DMA_TypeDef *DMAx, uint32_t Channel)
|
||||
{
|
||||
return ((DMA_Channel_TypeDef*)((uint32_t)((uint32_t)DMAx + LL_DMA_CH_OFFSET_TAB[Channel])));
|
||||
}
|
||||
|
||||
#else // STM32H7RS
|
||||
|
||||
static inline DMA_Stream_TypeDef* _dma_get_stream(DMA_TypeDef *DMAx, uint32_t Stream)
|
||||
{
|
||||
#if defined(STM32H7)
|
||||
# define __STREAM_OFFSET_TAB LL_DMA_STR_OFFSET_TAB
|
||||
#else
|
||||
# define __STREAM_OFFSET_TAB STREAM_OFFSET_TAB
|
||||
#endif
|
||||
return ((DMA_Stream_TypeDef*)((uint32_t)((uint32_t)DMAx + __STREAM_OFFSET_TAB[Stream])));
|
||||
#undef __STREAM_OFFSET_TAB
|
||||
}
|
||||
|
||||
#endif // !STM32H7RS
|
||||
|
||||
|
||||
#define DMA_Stream0_IT_MASK (uint32_t)(DMA_LISR_FEIF0 | DMA_LISR_DMEIF0 | \
|
||||
DMA_LISR_TEIF0 | DMA_LISR_HTIF0 | \
|
||||
DMA_LISR_TCIF0)
|
||||
@@ -375,6 +533,10 @@ bool stm32_hal_adc_init(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
|
||||
static void adc_dma_clear_flags(DMA_TypeDef* DMAx, uint32_t stream)
|
||||
{
|
||||
#if defined(STM32H7RS)
|
||||
DMA_Channel_TypeDef* ch = _dma_get_stream(DMAx, stream);
|
||||
WRITE_REG(ch->CFCR, DMA_CFCR_DTEF | DMA_CFCR_HTF | DMA_CFCR_TCF);
|
||||
#else
|
||||
// no other choice, sorry for that...
|
||||
if (stream == LL_DMA_STREAM_4) {
|
||||
/* Reset interrupt pending bits for DMA2 Stream4 */
|
||||
@@ -384,33 +546,64 @@ static void adc_dma_clear_flags(DMA_TypeDef* DMAx, uint32_t stream)
|
||||
/* Reset interrupt pending bits for DMA2 Stream0 */
|
||||
WRITE_REG(DMAx->LIFCR, DMA_Stream0_IT_MASK);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline DMA_Stream_TypeDef* _dma_get_stream(DMA_TypeDef *DMAx, uint32_t Stream)
|
||||
static void adc_start_dma_conversion(const stm32_adc_t* adc)
|
||||
{
|
||||
return ((DMA_Stream_TypeDef*)((uint32_t)((uint32_t)DMAx + STREAM_OFFSET_TAB[Stream])));
|
||||
}
|
||||
ADC_TypeDef* ADCx = adc->ADCx;
|
||||
DMA_TypeDef* DMAx = adc->DMAx;
|
||||
uint32_t stream = adc->DMA_Stream;
|
||||
|
||||
static void adc_start_dma_conversion(ADC_TypeDef* ADCx, DMA_TypeDef* DMAx, uint32_t stream)
|
||||
{
|
||||
// Clear Interrupt flags
|
||||
adc_dma_clear_flags(DMAx, stream);
|
||||
|
||||
// Clear ADC status register & disable ADC IRQ
|
||||
CLEAR_BIT(ADCx->SR, ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
CLEAR_BIT(ADCx->CR1, ADC_CR1_EOCIE);
|
||||
_CLEAR_ADC_STATUS(ADCx);
|
||||
_DISABLE_EOCIE(ADCx);
|
||||
|
||||
// Enable DMA
|
||||
auto dma_stream = _dma_get_stream(DMAx, stream);
|
||||
#if defined(STM32H7RS)
|
||||
// transfer length must be configured for every transfer
|
||||
uint32_t seq_len = LL_ADC_REG_GetSequencerLength(ADCx) + 1;
|
||||
LL_DMA_SetBlkDataLength(DMAx, stream, seq_len * 2);
|
||||
|
||||
uint16_t* dest_addr = _adc_dma_buffer + adc->offset;
|
||||
LL_DMA_SetDestAddress(DMAx, stream, (intptr_t)dest_addr);
|
||||
|
||||
DMA_Channel_TypeDef* ch = _dma_get_stream(DMAx, stream);
|
||||
SET_BIT(ch->CCR, DMA_CCR_TCIE | DMA_CCR_DTEIE);
|
||||
SET_BIT(ch->CCR, DMA_CCR_EN);
|
||||
#else
|
||||
DMA_Stream_TypeDef* dma_stream = _dma_get_stream(DMAx, stream);
|
||||
SET_BIT(dma_stream->CR, DMA_SxCR_TCIE | DMA_SxCR_TEIE | DMA_SxCR_DMEIE);
|
||||
SET_BIT(dma_stream->CR, DMA_SxCR_EN);
|
||||
#endif
|
||||
|
||||
// Trigger ADC start
|
||||
SET_BIT(ADCx->CR2, ADC_CR2_DMA | ADC_CR2_SWSTART);
|
||||
_START_ADC_DMA(ADCx);
|
||||
}
|
||||
|
||||
static bool adc_disable_dma(DMA_TypeDef* DMAx, uint32_t stream)
|
||||
{
|
||||
#if defined(STM32H7RS)
|
||||
DMA_Channel_TypeDef* ch = _dma_get_stream(DMAx, stream);
|
||||
CLEAR_BIT(ch->CCR, DMA_CCR_TCIE | DMA_CCR_DTEIE);
|
||||
|
||||
LL_DMA_DisableChannel(DMAx, stream);
|
||||
|
||||
// wait until DMA EN bit gets cleared by hardware
|
||||
uint16_t timeout = 1000;
|
||||
while (LL_DMA_IsEnabledChannel(DMAx, stream)) {
|
||||
if (--timeout == 0) {
|
||||
// Timeout. Failed to disable DMA
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
auto dma_stream = _dma_get_stream(DMAx, stream);
|
||||
CLEAR_BIT(dma_stream->CR, DMA_SxCR_TCIE | DMA_SxCR_TEIE | DMA_SxCR_DMEIE);
|
||||
|
||||
LL_DMA_DisableStream(DMAx, stream);
|
||||
|
||||
// wait until DMA EN bit gets cleared by hardware
|
||||
@@ -421,19 +614,21 @@ static bool adc_disable_dma(DMA_TypeDef* DMAx, uint32_t stream)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void adc_start_normal_conversion(ADC_TypeDef* ADCx)
|
||||
{
|
||||
// clear status flags
|
||||
CLEAR_BIT(ADCx->SR, ADC_SR_EOC | ADC_SR_STRT | ADC_SR_OVR);
|
||||
_CLEAR_ADC_STATUS(ADCx);
|
||||
|
||||
// enble ADC IRQ
|
||||
SET_BIT(ADCx->CR1, ADC_CR1_EOCIE);
|
||||
_ENABLE_EOCIE(ADCx);
|
||||
|
||||
// and start!
|
||||
SET_BIT(ADCx->CR2, ADC_CR2_SWSTART);
|
||||
_START_ADC_SINGLE(ADCx);
|
||||
}
|
||||
|
||||
static void adc_start_read(const stm32_adc_t* ADCs, uint8_t n_ADC)
|
||||
@@ -455,14 +650,20 @@ static void adc_start_read(const stm32_adc_t* ADCs, uint8_t n_ADC)
|
||||
}
|
||||
|
||||
// more than one channel enabled on this ADC
|
||||
if (LL_ADC_GetSequencersScanMode(ADCx) == LL_ADC_SEQ_SCAN_ENABLE) {
|
||||
bool seq_mode_enabled = false;
|
||||
#if defined(STM32H7) || defined(STM32H7RS)
|
||||
seq_mode_enabled = (LL_ADC_REG_GetSequencerLength(ADCx) != LL_ADC_REG_SEQ_SCAN_DISABLE);
|
||||
#else
|
||||
seq_mode_enabled = (LL_ADC_GetSequencersScanMode(ADCx) == LL_ADC_SEQ_SCAN_ENABLE);
|
||||
#endif
|
||||
|
||||
if (seq_mode_enabled) {
|
||||
// Disable DMA before continuing (see ref. manual "Stream configuration procedure")
|
||||
auto DMAx = adc->DMAx;
|
||||
auto stream = adc->DMA_Stream;
|
||||
if (DMAx && adc_disable_dma(DMAx, stream)) {
|
||||
_adc_started_mask |= adc_mask;
|
||||
adc_start_dma_conversion(ADCx, DMAx, stream);
|
||||
adc_start_dma_conversion(adc);
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -487,7 +688,7 @@ bool stm32_hal_adc_start_read(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
_adc_inputs = inputs;
|
||||
_adc_n_inputs = n_inputs;
|
||||
|
||||
memclear(_adc_oversampling, sizeof(_adc_oversampling));
|
||||
memset(_adc_oversampling, 0, sizeof(_adc_oversampling));
|
||||
adc_start_read(_adc_ADCs, _adc_n_ADC);
|
||||
|
||||
return true;
|
||||
@@ -582,8 +783,10 @@ void stm32_hal_adc_dma_isr(const stm32_adc_t* adc)
|
||||
// Disable IRQ
|
||||
adc_dma_clear_flags(adc->DMAx, adc->DMA_Stream);
|
||||
|
||||
#if !defined(STM32H7) && !defined(STM32H7RS)
|
||||
// Disable DMA
|
||||
CLEAR_BIT(adc->ADCx->CR2, ADC_CR2_DMA);
|
||||
#endif
|
||||
|
||||
uint16_t* dma_buffer = _adc_dma_buffer + adc->offset;
|
||||
copy_adc_values(dma_buffer, adc, _adc_inputs);
|
||||
@@ -595,11 +798,16 @@ void stm32_hal_adc_isr(const stm32_adc_t* adc)
|
||||
{
|
||||
// check if this ADC triggered the IRQ
|
||||
auto ADCx = adc->ADCx;
|
||||
#if defined(STM32H7) || defined(STM32H7RS)
|
||||
if (!LL_ADC_IsActiveFlag_EOC(ADCx) || !LL_ADC_IsEnabledIT_EOC(ADCx))
|
||||
return;
|
||||
#else
|
||||
if (!LL_ADC_IsActiveFlag_EOCS(ADCx) || !LL_ADC_IsEnabledIT_EOCS(ADCx))
|
||||
return;
|
||||
#endif
|
||||
|
||||
// Disable end-of-conversion IRQ
|
||||
CLEAR_BIT(ADCx->CR1, ADC_CR1_EOCIE);
|
||||
_DISABLE_EOCIE(ADCx);
|
||||
|
||||
uint16_t* dma_buffer = _adc_dma_buffer + adc->offset;
|
||||
*dma_buffer = adc->ADCx->DR;
|
||||
|
||||
@@ -25,21 +25,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(STM32F4)
|
||||
|
||||
// Workaround to prevent the other CMSIS header to be included
|
||||
// and fix some missing items in the old one
|
||||
#include "thirdparty/CMSIS/Include/cmsis_compiler.h"
|
||||
#define __CORE_CM4_H_GENERIC
|
||||
|
||||
#if defined(STM32H7)
|
||||
#include "CMSIS/Device/ST/STM32H7xx/Include/stm32h7xx.h"
|
||||
#elif defined(STM32F4)
|
||||
#include "CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
|
||||
#elif defined(STM32F2)
|
||||
|
||||
// Workaround to prevent the other CMSIS header to be included
|
||||
// and fix some missing items in the old one
|
||||
#include "thirdparty/CMSIS/Include/cmsis_compiler.h"
|
||||
#define __CORE_CM3_H_GENERIC
|
||||
|
||||
#include "CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,9 +23,19 @@
|
||||
|
||||
void stm32_dma_enable_clock(DMA_TypeDef* DMAx)
|
||||
{
|
||||
#if defined(DMA1) && defined(DMA2)
|
||||
if (DMAx == DMA1) {
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
|
||||
} else if (DMAx == DMA2) {
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(GPDMA1) && defined(HPDMA1)
|
||||
if (DMAx == GPDMA1) {
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPDMA1);
|
||||
} else if (DMAx == HPDMA1) {
|
||||
LL_AHB5_GRP1_EnableClock(LL_AHB5_GRP1_PERIPH_HPDMA1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -30,6 +30,20 @@
|
||||
(stream) == LL_DMA_STREAM_4 || (stream) == LL_DMA_STREAM_5 || \
|
||||
(stream) == LL_DMA_STREAM_6 || (stream) == LL_DMA_STREAM_7)
|
||||
|
||||
#if defined(STM32H7RS)
|
||||
|
||||
inline static bool stm32_dma_check_tc_flag(DMA_TypeDef* DMAx, uint32_t DMA_Stream)
|
||||
{
|
||||
return LL_DMA_IsActiveFlag_TC(DMAx, DMA_Stream);
|
||||
}
|
||||
|
||||
inline static bool stm32_dma_check_ht_flag(DMA_TypeDef* DMAx, uint32_t DMA_Stream)
|
||||
{
|
||||
return LL_DMA_IsActiveFlag_HT(DMAx, DMA_Stream);
|
||||
}
|
||||
|
||||
#else // STM32H7RS
|
||||
|
||||
inline static bool stm32_dma_check_tc_flag(DMA_TypeDef* DMAx, uint32_t DMA_Stream)
|
||||
{
|
||||
switch(DMA_Stream) {
|
||||
@@ -110,4 +124,6 @@ inline static bool stm32_dma_check_ht_flag(DMA_TypeDef* DMAx, uint32_t DMA_Strea
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // !STM32H7RS
|
||||
|
||||
void stm32_dma_enable_clock(DMA_TypeDef* DMAx);
|
||||
|
||||
@@ -19,10 +19,17 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "hal.h"
|
||||
|
||||
#if defined(EXTI_PR1_PR)
|
||||
# define _PR_Reg PR1
|
||||
#else
|
||||
# define _PR_Reg PR
|
||||
#endif
|
||||
|
||||
#define _EXTI_HANDLERS(irq_name) _handlers_ ## irq_name
|
||||
|
||||
#define _PR_MASK(first, last) (((1 << (last - first + 1))-1))
|
||||
@@ -33,7 +40,7 @@
|
||||
{ \
|
||||
/* Read Pending register */ \
|
||||
/* (shifted by start line) */ \
|
||||
uint32_t pr = LL_EXTI_ReadReg(PR) >> first; \
|
||||
uint32_t pr = LL_EXTI_ReadReg(_PR_Reg) >> first; \
|
||||
pr &= _PR_MASK(first,last); \
|
||||
while (pr) { \
|
||||
uint32_t i = POSITION_VAL(pr); \
|
||||
@@ -79,6 +86,54 @@
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI4_IRQ, 4, 4);
|
||||
#endif
|
||||
|
||||
#if defined(STM32H7RS)
|
||||
|
||||
#if defined(USE_EXTI5_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI5_IRQ, 5, 5);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI6_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI6_IRQ, 6, 6);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI7_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI7_IRQ, 7, 7);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI8_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI8_IRQ, 8, 8);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI9_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI9_IRQ, 9, 9);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI10_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI10_IRQ, 10, 10);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI11_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI11_IRQ, 11, 11);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI12_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI12_IRQ, 12, 12);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI13_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI13_IRQ, 13, 13);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI14_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI14_IRQ, 14, 14);
|
||||
#endif
|
||||
|
||||
#if defined(USE_EXTI15_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI15_IRQ, 15, 15);
|
||||
#endif
|
||||
|
||||
#else // STM32H7RS
|
||||
|
||||
#if defined(USE_EXTI9_5_IRQ)
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI9_5_IRQ, 5, 9);
|
||||
#endif
|
||||
@@ -87,6 +142,8 @@
|
||||
_DEFINE_EXTI_IRQ_HANDLER(EXTI15_10_IRQ, 10, 15);
|
||||
#endif
|
||||
|
||||
#endif // !STM32H7RS
|
||||
|
||||
static bool _has_handler(stm32_exti_handler_t* _handlers, uint8_t len)
|
||||
{
|
||||
for (uint8_t i = 0; i < len; i++)
|
||||
@@ -100,8 +157,11 @@ void stm32_exti_enable(uint32_t line, uint8_t trigger, stm32_exti_handler_t cb)
|
||||
|
||||
#if defined(LL_APB2_GRP1_PERIPH_EXTI)
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_EXTI);
|
||||
#elif defined(LL_CKGA_PERIPH_EXTI)
|
||||
LL_CKGA_Enable(LL_CKGA_PERIPH_EXTI);
|
||||
#endif
|
||||
|
||||
|
||||
LL_EXTI_InitTypeDef EXTI_init;
|
||||
LL_EXTI_StructInit(&EXTI_init);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_exti_driver.h"
|
||||
#include "stm32_gpio_driver.h"
|
||||
#include "stm32_hal.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
static inline GPIO_TypeDef* _port(gpio_t pin)
|
||||
@@ -37,8 +38,16 @@ static inline int _port_num(gpio_t pin)
|
||||
|
||||
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);
|
||||
uint32_t reg_idx = (((uint32_t)port) - GPIOA_BASE) / 0x0400UL;
|
||||
#if defined(RCC_AHB4ENR_GPIOAEN)
|
||||
uint32_t reg_msk = RCC_AHB4ENR_GPIOAEN << reg_idx;
|
||||
LL_AHB4_GRP1_EnableClock(reg_msk);
|
||||
#elif defined(RCC_AHB1ENR_GPIOAEN)
|
||||
uint32_t reg_msk = RCC_AHB1ENR_GPIOAEN << reg_idx;
|
||||
LL_AHB1_GRP1_EnableClock(reg_msk);
|
||||
#else
|
||||
#error "Unsupported GPIO clock"
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int _pin_num(gpio_t pin)
|
||||
@@ -90,7 +99,17 @@ void gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t c
|
||||
gpio_init(pin, mode, GPIO_PIN_SPEED_LOW);
|
||||
|
||||
// enable specific pin as exti sources
|
||||
#if defined(LL_APB4_GRP1_PERIPH_SYSCFG)
|
||||
LL_APB4_GRP1_EnableClock(LL_APB4_GRP1_PERIPH_SYSCFG);
|
||||
#elif defined(LL_APB2_GRP1_PERIPH_SYSCFG)
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
#elif defined(LL_APB4_GRP1_PERIPH_SBS)
|
||||
# define SYSCFG SBS
|
||||
LL_APB4_GRP1_EnableClock(LL_APB4_GRP1_PERIPH_SBS);
|
||||
#else
|
||||
#error "Unsupported SYSCFG clock"
|
||||
#endif
|
||||
|
||||
SYSCFG->EXTICR[pin_num >> 2] &= ~(0xf << ((pin_num & 0x03) * 4));
|
||||
SYSCFG->EXTICR[pin_num >> 2] |= (port_num << ((pin_num & 0x03) * 4));
|
||||
|
||||
@@ -110,6 +129,9 @@ void gpio_init_af(gpio_t pin, gpio_af_t af, gpio_speed_t speed)
|
||||
|
||||
_enable_clock(port);
|
||||
|
||||
// Clear PUPDR
|
||||
port->PUPDR &= ~(0x3 << (2 * pin_num));
|
||||
|
||||
// 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));
|
||||
|
||||
@@ -25,7 +25,12 @@
|
||||
void stm32_gpio_enable_clock(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
uint32_t reg_idx = (((uint32_t) GPIOx) - GPIOA_BASE) / 0x0400UL;
|
||||
#if defined(RCC_AHB4ENR_GPIOAEN)
|
||||
uint32_t reg_msk = RCC_AHB4ENR_GPIOAEN << reg_idx;
|
||||
LL_AHB4_GRP1_EnableClock(reg_msk);
|
||||
#else
|
||||
uint32_t reg_msk = RCC_AHB1ENR_GPIOAEN << reg_idx;
|
||||
LL_AHB1_GRP1_EnableClock(reg_msk);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@ extern "C" {
|
||||
#elif defined(STM32F2)
|
||||
#include "CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h"
|
||||
#include "stm32f2xx_hal.h"
|
||||
#elif defined(STM32H7)
|
||||
#include "CMSIS/Device/ST/STM32H7xx/Include/stm32h7xx.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -62,6 +62,22 @@ extern "C" {
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_spi.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_iwdg.h"
|
||||
#include "STM32F2xx_HAL_Driver/Inc/stm32f2xx_ll_usb.h"
|
||||
#elif defined(STM32H7)
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_bus.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_fmc.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_dma2d.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_gpio.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_tim.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_dma.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_bdma.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_usart.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_exti.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_system.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_rcc.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_spi.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_iwdg.h"
|
||||
#include "STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_usb.h"
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -109,19 +109,349 @@ static I2C_HandleTypeDef* get_i2c_handle(uint8_t bus)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if defined(STM32H7) || defined(STM32H7RS)
|
||||
|
||||
/* ST's I2C timing computation */
|
||||
|
||||
#define I2C_VALID_TIMING_NBR 8U
|
||||
#define I2C_SPEED_FREQ_STANDARD 0U /* 100 kHz */
|
||||
#define I2C_SPEED_FREQ_FAST 1U /* 400 kHz */
|
||||
#define I2C_SPEED_FREQ_FAST_PLUS 2U /* 1 MHz */
|
||||
#define I2C_ANALOG_FILTER_DELAY_MIN 50U /* ns */
|
||||
#define I2C_ANALOG_FILTER_DELAY_MAX 260U /* ns */
|
||||
#define I2C_USE_ANALOG_FILTER 1U
|
||||
#define I2C_DIGITAL_FILTER_COEF 0U
|
||||
#define I2C_PRESC_MAX 16U
|
||||
#define I2C_SCLDEL_MAX 16U
|
||||
#define I2C_SDADEL_MAX 16U
|
||||
#define I2C_SCLH_MAX 256U
|
||||
#define I2C_SCLL_MAX 256U
|
||||
#define SEC2NSEC 1000000000UL
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t freq; /* Frequency in Hz */
|
||||
uint32_t freq_min; /* Minimum frequency in Hz */
|
||||
uint32_t freq_max; /* Maximum frequency in Hz */
|
||||
uint32_t hddat_min; /* Minimum data hold time in ns */
|
||||
uint32_t vddat_max; /* Maximum data valid time in ns */
|
||||
uint32_t sudat_min; /* Minimum data setup time in ns */
|
||||
uint32_t lscl_min; /* Minimum low period of the SCL clock in ns */
|
||||
uint32_t hscl_min; /* Minimum high period of SCL clock in ns */
|
||||
uint32_t trise; /* Rise time in ns */
|
||||
uint32_t tfall; /* Fall time in ns */
|
||||
uint32_t dnf; /* Digital noise filter coefficient */
|
||||
} I2C_Charac_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t presc; /* Timing prescaler */
|
||||
uint32_t tscldel; /* SCL delay */
|
||||
uint32_t tsdadel; /* SDA delay */
|
||||
uint32_t sclh; /* SCL high period */
|
||||
uint32_t scll; /* SCL low period */
|
||||
} I2C_Timings_t;
|
||||
|
||||
static const I2C_Charac_t I2C_Charac[] =
|
||||
{
|
||||
/* I2C_SPEED_FREQ_STANDARD */
|
||||
{
|
||||
.freq = 100000,
|
||||
.freq_min = 80000,
|
||||
.freq_max = 120000,
|
||||
.hddat_min = 0,
|
||||
.vddat_max = 3450,
|
||||
.sudat_min = 250,
|
||||
.lscl_min = 4700,
|
||||
.hscl_min = 4000,
|
||||
.trise = 640,
|
||||
.tfall = 20,
|
||||
.dnf = I2C_DIGITAL_FILTER_COEF,
|
||||
},
|
||||
/* I2C_SPEED_FREQ_FAST */
|
||||
{
|
||||
.freq = 400000,
|
||||
.freq_min = 320000,
|
||||
.freq_max = 480000,
|
||||
.hddat_min = 0,
|
||||
.vddat_max = 900,
|
||||
.sudat_min = 100,
|
||||
.lscl_min = 1300,
|
||||
.hscl_min = 600,
|
||||
.trise = 250,
|
||||
.tfall = 100,
|
||||
.dnf = I2C_DIGITAL_FILTER_COEF,
|
||||
},
|
||||
/* I2C_SPEED_FREQ_FAST_PLUS */
|
||||
{
|
||||
.freq = 1000000,
|
||||
.freq_min = 800000,
|
||||
.freq_max = 1200000,
|
||||
.hddat_min = 0,
|
||||
.vddat_max = 450,
|
||||
.sudat_min = 50,
|
||||
.lscl_min = 500,
|
||||
.hscl_min = 260,
|
||||
.trise = 60,
|
||||
.tfall = 100,
|
||||
.dnf = I2C_DIGITAL_FILTER_COEF,
|
||||
},
|
||||
};
|
||||
|
||||
static I2C_Timings_t I2c_valid_timing[I2C_VALID_TIMING_NBR];
|
||||
static uint32_t I2c_valid_timing_nbr = 0;
|
||||
|
||||
static void I2C_Compute_PRESC_SCLDEL_SDADEL(uint32_t clock_src_freq, uint32_t I2C_speed);
|
||||
static uint32_t I2C_Compute_SCLL_SCLH (uint32_t clock_src_freq, uint32_t I2C_speed);
|
||||
|
||||
/**
|
||||
* @brief Compute I2C timing according current I2C clock source and required I2C clock.
|
||||
* @param clock_src_freq I2C clock source in Hz.
|
||||
* @param i2c_freq Required I2C clock in Hz.
|
||||
* @retval I2C timing or 0 in case of error.
|
||||
*/
|
||||
static uint32_t I2C_GetTiming(uint32_t clock_src_freq, uint32_t i2c_freq)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
uint32_t speed;
|
||||
uint32_t idx;
|
||||
|
||||
if((clock_src_freq != 0U) && (i2c_freq != 0U))
|
||||
{
|
||||
for ( speed = 0 ; speed <= (uint32_t)I2C_SPEED_FREQ_FAST_PLUS ; speed++)
|
||||
{
|
||||
if ((i2c_freq >= I2C_Charac[speed].freq_min) &&
|
||||
(i2c_freq <= I2C_Charac[speed].freq_max))
|
||||
{
|
||||
I2C_Compute_PRESC_SCLDEL_SDADEL(clock_src_freq, speed);
|
||||
idx = I2C_Compute_SCLL_SCLH(clock_src_freq, speed);
|
||||
|
||||
if (idx < I2C_VALID_TIMING_NBR)
|
||||
{
|
||||
ret = ((I2c_valid_timing[idx].presc & 0x0FU) << 28) |\
|
||||
((I2c_valid_timing[idx].tscldel & 0x0FU) << 20) |\
|
||||
((I2c_valid_timing[idx].tsdadel & 0x0FU) << 16) |\
|
||||
((I2c_valid_timing[idx].sclh & 0xFFU) << 8) |\
|
||||
((I2c_valid_timing[idx].scll & 0xFFU) << 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Compute PRESC, SCLDEL and SDADEL.
|
||||
* @param clock_src_freq I2C source clock in HZ.
|
||||
* @param I2C_speed I2C frequency (index).
|
||||
* @retval None.
|
||||
*/
|
||||
static void I2C_Compute_PRESC_SCLDEL_SDADEL(uint32_t clock_src_freq, uint32_t I2C_speed)
|
||||
{
|
||||
uint32_t prev_presc = I2C_PRESC_MAX;
|
||||
uint32_t ti2cclk;
|
||||
int32_t tsdadel_min, tsdadel_max;
|
||||
int32_t tscldel_min;
|
||||
uint32_t presc, scldel, sdadel;
|
||||
uint32_t tafdel_min, tafdel_max;
|
||||
|
||||
ti2cclk = (SEC2NSEC + (clock_src_freq / 2U))/ clock_src_freq;
|
||||
|
||||
tafdel_min = (I2C_USE_ANALOG_FILTER == 1U) ? I2C_ANALOG_FILTER_DELAY_MIN : 0U;
|
||||
tafdel_max = (I2C_USE_ANALOG_FILTER == 1U) ? I2C_ANALOG_FILTER_DELAY_MAX : 0U;
|
||||
|
||||
/* tDNF = DNF x tI2CCLK
|
||||
tPRESC = (PRESC+1) x tI2CCLK
|
||||
SDADEL >= {tf +tHD;DAT(min) - tAF(min) - tDNF - [3 x tI2CCLK]} / {tPRESC}
|
||||
SDADEL <= {tVD;DAT(max) - tr - tAF(max) - tDNF- [4 x tI2CCLK]} / {tPRESC} */
|
||||
|
||||
tsdadel_min = (int32_t)I2C_Charac[I2C_speed].tfall + (int32_t)I2C_Charac[I2C_speed].hddat_min -
|
||||
(int32_t)tafdel_min - (int32_t)(((int32_t)I2C_Charac[I2C_speed].dnf + 3) * (int32_t)ti2cclk);
|
||||
|
||||
tsdadel_max = (int32_t)I2C_Charac[I2C_speed].vddat_max - (int32_t)I2C_Charac[I2C_speed].trise -
|
||||
(int32_t)tafdel_max - (int32_t)(((int32_t)I2C_Charac[I2C_speed].dnf + 4) * (int32_t)ti2cclk);
|
||||
|
||||
|
||||
/* {[tr+ tSU;DAT(min)] / [tPRESC]} - 1 <= SCLDEL */
|
||||
tscldel_min = (int32_t)I2C_Charac[I2C_speed].trise + (int32_t)I2C_Charac[I2C_speed].sudat_min;
|
||||
|
||||
if (tsdadel_min <= 0)
|
||||
{
|
||||
tsdadel_min = 0;
|
||||
}
|
||||
|
||||
if (tsdadel_max <= 0)
|
||||
{
|
||||
tsdadel_max = 0;
|
||||
}
|
||||
|
||||
for (presc = 0; presc < I2C_PRESC_MAX; presc++)
|
||||
{
|
||||
for (scldel = 0; scldel < I2C_SCLDEL_MAX; scldel++)
|
||||
{
|
||||
/* TSCLDEL = (SCLDEL+1) * (PRESC+1) * TI2CCLK */
|
||||
uint32_t tscldel = (scldel + 1U) * (presc + 1U) * ti2cclk;
|
||||
|
||||
if (tscldel >= (uint32_t)tscldel_min)
|
||||
{
|
||||
for (sdadel = 0; sdadel < I2C_SDADEL_MAX; sdadel++)
|
||||
{
|
||||
/* TSDADEL = SDADEL * (PRESC+1) * TI2CCLK */
|
||||
uint32_t tsdadel = (sdadel * (presc + 1U)) * ti2cclk;
|
||||
|
||||
if ((tsdadel >= (uint32_t)tsdadel_min) && (tsdadel <= (uint32_t)tsdadel_max))
|
||||
{
|
||||
if(presc != prev_presc)
|
||||
{
|
||||
I2c_valid_timing[I2c_valid_timing_nbr].presc = presc;
|
||||
I2c_valid_timing[I2c_valid_timing_nbr].tscldel = scldel;
|
||||
I2c_valid_timing[I2c_valid_timing_nbr].tsdadel = sdadel;
|
||||
prev_presc = presc;
|
||||
I2c_valid_timing_nbr ++;
|
||||
|
||||
if(I2c_valid_timing_nbr >= I2C_VALID_TIMING_NBR)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate SCLL and SCLH and find best configuration.
|
||||
* @param clock_src_freq I2C source clock in HZ.
|
||||
* @param I2C_speed I2C frequency (index).
|
||||
* @retval config index (0 to I2C_VALID_TIMING_NBR], 0xFFFFFFFF for no valid config.
|
||||
*/
|
||||
static uint32_t I2C_Compute_SCLL_SCLH (uint32_t clock_src_freq, uint32_t I2C_speed)
|
||||
{
|
||||
uint32_t ret = 0xFFFFFFFFU;
|
||||
uint32_t ti2cclk;
|
||||
uint32_t ti2cspeed;
|
||||
uint32_t prev_error;
|
||||
uint32_t dnf_delay;
|
||||
uint32_t clk_min, clk_max;
|
||||
uint32_t scll, sclh;
|
||||
uint32_t tafdel_min;
|
||||
|
||||
ti2cclk = (SEC2NSEC + (clock_src_freq / 2U))/ clock_src_freq;
|
||||
ti2cspeed = (SEC2NSEC + (I2C_Charac[I2C_speed].freq / 2U))/ I2C_Charac[I2C_speed].freq;
|
||||
|
||||
tafdel_min = (I2C_USE_ANALOG_FILTER == 1U) ? I2C_ANALOG_FILTER_DELAY_MIN : 0U;
|
||||
|
||||
/* tDNF = DNF x tI2CCLK */
|
||||
dnf_delay = I2C_Charac[I2C_speed].dnf * ti2cclk;
|
||||
|
||||
clk_max = SEC2NSEC / I2C_Charac[I2C_speed].freq_min;
|
||||
clk_min = SEC2NSEC / I2C_Charac[I2C_speed].freq_max;
|
||||
|
||||
prev_error = ti2cspeed;
|
||||
|
||||
for (uint32_t count = 0; count < I2c_valid_timing_nbr; count++)
|
||||
{
|
||||
/* tPRESC = (PRESC+1) x tI2CCLK*/
|
||||
uint32_t tpresc = (I2c_valid_timing[count].presc + 1U) * ti2cclk;
|
||||
|
||||
for (scll = 0; scll < I2C_SCLL_MAX; scll++)
|
||||
{
|
||||
/* tLOW(min) <= tAF(min) + tDNF + 2 x tI2CCLK + [(SCLL+1) x tPRESC ] */
|
||||
uint32_t tscl_l = tafdel_min + dnf_delay + (2U * ti2cclk) + ((scll + 1U) * tpresc);
|
||||
|
||||
|
||||
/* The I2CCLK period tI2CCLK must respect the following conditions:
|
||||
tI2CCLK < (tLOW - tfilters) / 4 and tI2CCLK < tHIGH */
|
||||
if ((tscl_l > I2C_Charac[I2C_speed].lscl_min) && (ti2cclk < ((tscl_l - tafdel_min - dnf_delay) / 4U)))
|
||||
{
|
||||
for (sclh = 0; sclh < I2C_SCLH_MAX; sclh++)
|
||||
{
|
||||
/* tHIGH(min) <= tAF(min) + tDNF + 2 x tI2CCLK + [(SCLH+1) x tPRESC] */
|
||||
uint32_t tscl_h = tafdel_min + dnf_delay + (2U * ti2cclk) + ((sclh + 1U) * tpresc);
|
||||
|
||||
/* tSCL = tf + tLOW + tr + tHIGH */
|
||||
uint32_t tscl = tscl_l + tscl_h + I2C_Charac[I2C_speed].trise + I2C_Charac[I2C_speed].tfall;
|
||||
|
||||
if ((tscl >= clk_min) && (tscl <= clk_max) && (tscl_h >= I2C_Charac[I2C_speed].hscl_min) && (ti2cclk < tscl_h))
|
||||
{
|
||||
int32_t error = (int32_t)tscl - (int32_t)ti2cspeed;
|
||||
|
||||
if (error < 0)
|
||||
{
|
||||
error = -error;
|
||||
}
|
||||
|
||||
/* look for the timings with the lowest clock error */
|
||||
if ((uint32_t)error < prev_error)
|
||||
{
|
||||
prev_error = (uint32_t)error;
|
||||
I2c_valid_timing[count].scll = scll;
|
||||
I2c_valid_timing[count].sclh = sclh;
|
||||
ret = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int i2c_init_clock_source(I2C_TypeDef* instance)
|
||||
{
|
||||
#if defined(LL_RCC_I2C1_CLKSOURCE)
|
||||
if (instance == I2C1) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
|
||||
LL_RCC_SetClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LL_RCC_I2C23_CLKSOURCE)
|
||||
if (instance == I2C2) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2);
|
||||
LL_RCC_SetClockSource(LL_RCC_I2C23_CLKSOURCE_PCLK1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LL_RCC_I2C123_CLKSOURCE)
|
||||
LL_RCC_SetClockSource(LL_RCC_I2C123_CLKSOURCE_PCLK1);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int stm32_i2c_init(uint8_t bus, uint32_t clock_rate)
|
||||
{
|
||||
I2C_HandleTypeDef* h = get_i2c_handle(bus);
|
||||
if (!h) return -1;
|
||||
|
||||
I2C_InitTypeDef& init = h->Init;
|
||||
|
||||
#if defined(STM32H7) || defined(STM32H7RS)
|
||||
i2c_init_clock_source(h->Instance);
|
||||
# if defined(LL_RCC_I2C123_CLKSOURCE_PCLK1)
|
||||
uint32_t pclk_freq = LL_RCC_GetI2CClockFreq(LL_RCC_I2C123_CLKSOURCE_PCLK1);
|
||||
# elif defined(LL_RCC_I2C1_CLKSOURCE_PCLK1)
|
||||
uint32_t pclk_freq = LL_RCC_GetI2CClockFreq(LL_RCC_I2C1_CLKSOURCE_PCLK1);
|
||||
# endif
|
||||
init.Timing = I2C_GetTiming(pclk_freq, clock_rate);
|
||||
#else
|
||||
if (init.ClockSpeed > 0) {
|
||||
if (init.ClockSpeed != clock_rate) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
init.ClockSpeed = clock_rate;
|
||||
init.DutyCycle = I2C_DUTYCYCLE_16_9;
|
||||
#endif
|
||||
|
||||
init.OwnAddress1 = 0;
|
||||
init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
@@ -134,7 +464,8 @@ int stm32_i2c_init(uint8_t bus, uint32_t clock_rate)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(I2C_FLTR_ANOFF) && defined(I2C_FLTR_DNF)
|
||||
#if defined(I2C_FLTR_ANOFF) && defined(I2C_FLTR_DNF) || defined(STM32H7) || \
|
||||
defined(STM32H7RS)
|
||||
// Configure Analogue filter
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(h, I2C_ANALOGFILTER_ENABLE) != HAL_OK) {
|
||||
TRACE("I2C ERROR: HAL_I2CEx_ConfigAnalogFilter() failed");
|
||||
@@ -157,7 +488,7 @@ int stm32_i2c_deinit(uint8_t bus)
|
||||
if (!h) return -1;
|
||||
|
||||
if (HAL_I2C_DeInit(h) != HAL_OK) return -1;
|
||||
h->Init.ClockSpeed = 0;
|
||||
//h->Init.ClockSpeed = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -233,30 +564,30 @@ int stm32_i2c_is_dev_ready(uint8_t bus, uint16_t addr, uint32_t timeout)
|
||||
static int i2c_enable_gpio_clock(GPIO_TypeDef *GPIOx)
|
||||
{
|
||||
if (GPIOx == GPIOA)
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
else if (GPIOx == GPIOB)
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
else if (GPIOx == GPIOC)
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOC);
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
else if (GPIOx == GPIOH)
|
||||
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOH);
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
else
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int i2c_enable_clock(I2C_TypeDef* instance)
|
||||
{
|
||||
/* Peripheral clock enable */
|
||||
if (instance == I2C1)
|
||||
if (instance == I2C1) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
|
||||
else if (instance == I2C2)
|
||||
} else if (instance == I2C2) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2);
|
||||
else if (instance == I2C3)
|
||||
} else if (instance == I2C3) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C3);
|
||||
else
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -312,7 +643,7 @@ static int i2c_pins_deinit(const _i2c_defs* def)
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
|
||||
pinInit.Speed = LL_GPIO_SPEED_FREQ_LOW;
|
||||
pinInit.Speed = LL_GPIO_SPEED_FREQ_MEDIUM;
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
pinInit.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
|
||||
pinInit.Pull = LL_GPIO_PULL_NO;
|
||||
|
||||
@@ -191,10 +191,19 @@ static void stm32_serial_free_state(stm32_serial_state* st)
|
||||
memset(st, 0, sizeof(stm32_serial_state));
|
||||
}
|
||||
|
||||
static inline uint32_t _dma_get_data_length(DMA_TypeDef* DMAx, uint32_t stream)
|
||||
{
|
||||
#if defined(STM32H7RS)
|
||||
return LL_DMA_GetBlkDataLength(DMAx, stream);
|
||||
#else
|
||||
return LL_DMA_GetDataLength(DMAx, stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void _dma_clear(stm32_buffer_state* buf_st, uint32_t length,
|
||||
DMA_TypeDef* DMAx, uint32_t stream)
|
||||
{
|
||||
buf_st->ridx = length - LL_DMA_GetDataLength(DMAx, stream);
|
||||
buf_st->ridx = length - _dma_get_data_length(DMAx, stream);
|
||||
}
|
||||
|
||||
static inline void _fifo_clear(stm32_buffer_state* buf_st)
|
||||
@@ -235,9 +244,15 @@ static void* stm32_serial_init(void* hw_def, const etx_serial_init* params)
|
||||
auto st = stm32_serial_find_state(usart);
|
||||
if (!st || st->sp) return nullptr;
|
||||
|
||||
if (!stm32_usart_init(usart, params)) return nullptr;
|
||||
// Set serial port instance *before* in case an interrupt is triggered
|
||||
// before this method returns.
|
||||
st->sp = sp;
|
||||
|
||||
if (!stm32_usart_init(usart, params)) {
|
||||
st->sp = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (params->direction & ETX_Dir_TX) {
|
||||
// prepare for send_byte()
|
||||
if (sp->tx_buffer.length > 0) {
|
||||
@@ -372,7 +387,7 @@ static int stm32_serial_get_byte(void* ctx, uint8_t* data)
|
||||
if (LL_USART_IsEnabledDMAReq_RX(usart->USARTx)) {
|
||||
auto dma = usart->rxDMA;
|
||||
auto stream = usart->rxDMA_Stream;
|
||||
widx = buf_len - LL_DMA_GetDataLength(dma, stream);
|
||||
widx = buf_len - _dma_get_data_length(dma, stream);
|
||||
} else {
|
||||
widx = buf_st.widx;
|
||||
}
|
||||
@@ -404,7 +419,7 @@ static int stm32_serial_get_last_byte(void* ctx, uint32_t idx, uint8_t* data)
|
||||
if (LL_USART_IsEnabledDMAReq_RX(usart->USARTx)) {
|
||||
auto dma = usart->rxDMA;
|
||||
auto stream = usart->rxDMA_Stream;
|
||||
widx = buf_len - LL_DMA_GetDataLength(dma, stream);
|
||||
widx = buf_len - _dma_get_data_length(dma, stream);
|
||||
} else {
|
||||
widx = buf_st.widx;
|
||||
}
|
||||
@@ -435,7 +450,7 @@ static int stm32_serial_get_buffered_bytes(void* ctx)
|
||||
if (LL_USART_IsEnabledDMAReq_RX(usart->USARTx)) {
|
||||
auto dma = usart->rxDMA;
|
||||
auto stream = usart->rxDMA_Stream;
|
||||
widx = buf_len - LL_DMA_GetDataLength(dma, stream);
|
||||
widx = buf_len - _dma_get_data_length(dma, stream);
|
||||
} else {
|
||||
widx = buf_st.widx;
|
||||
}
|
||||
@@ -468,7 +483,7 @@ static int stm32_serial_copy_rx_buffer(void* ctx, uint8_t* buf, uint32_t len)
|
||||
if (LL_USART_IsEnabledDMAReq_RX(usart->USARTx)) {
|
||||
auto dma = usart->rxDMA;
|
||||
auto stream = usart->rxDMA_Stream;
|
||||
widx = buf_len - LL_DMA_GetDataLength(dma, stream);
|
||||
widx = buf_len - _dma_get_data_length(dma, stream);
|
||||
} else {
|
||||
widx = buf_st.widx;
|
||||
}
|
||||
|
||||
@@ -20,103 +20,38 @@
|
||||
*/
|
||||
|
||||
#include "stm32_timer.h"
|
||||
#include "stm32_hal.h"
|
||||
|
||||
void stm32_timer_enable_clock(TIM_TypeDef *TIMx)
|
||||
{
|
||||
if (TIMx == TIM1) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
||||
} else if (TIMx == TIM2) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
} else if (TIMx == TIM3) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
||||
} else if (TIMx == TIM4) {
|
||||
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) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM13);
|
||||
} else if (TIMx == TIM14) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM14);
|
||||
}
|
||||
if (((intptr_t)TIMx & 0xFFFF0000) == APB1PERIPH_BASE) {
|
||||
uint32_t offset = ((intptr_t)TIMx - APB1PERIPH_BASE) >> 10;
|
||||
LL_APB1_GRP1_EnableClock(1U << offset);
|
||||
} else if (((intptr_t)TIMx & 0xFFFF0000) == APB2PERIPH_BASE) {
|
||||
uint32_t offset = ((intptr_t)TIMx - APB2PERIPH_BASE) >> 10;
|
||||
LL_APB2_GRP1_EnableClock(1U << offset);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_timer_disable_clock(TIM_TypeDef *TIMx)
|
||||
{
|
||||
if (TIMx == TIM1) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
||||
} else if (TIMx == TIM2) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
} else if (TIMx == TIM3) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
||||
} else if (TIMx == TIM4) {
|
||||
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);
|
||||
if (((intptr_t)TIMx & 0xFFFF0000) == APB1PERIPH_BASE) {
|
||||
uint32_t offset = ((intptr_t)TIMx - APB1PERIPH_BASE) >> 10;
|
||||
LL_APB1_GRP1_DisableClock(1U << offset);
|
||||
} else if (((intptr_t)TIMx & 0xFFFF0000) == APB2PERIPH_BASE) {
|
||||
uint32_t offset = ((intptr_t)TIMx - APB2PERIPH_BASE) >> 10;
|
||||
LL_APB2_GRP1_DisableClock(1U << offset);
|
||||
}
|
||||
}
|
||||
|
||||
bool stm32_timer_is_clock_enabled(TIM_TypeDef *TIMx)
|
||||
{
|
||||
if (TIMx == TIM1) {
|
||||
return LL_APB2_GRP1_IsEnabledClock(LL_APB2_GRP1_PERIPH_TIM1) != 0;
|
||||
} else if (TIMx == TIM2) {
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM2) != 0;
|
||||
} else if (TIMx == TIM3) {
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM3) != 0;
|
||||
} else if (TIMx == TIM4) {
|
||||
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_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM12) != 0;
|
||||
} else if (TIMx == TIM13) {
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM13) != 0;
|
||||
} else if (TIMx == TIM14) {
|
||||
return LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_TIM14) != 0;
|
||||
if (((intptr_t)TIMx & 0xFFFF0000) == APB1PERIPH_BASE) {
|
||||
uint32_t offset = ((intptr_t)TIMx - APB1PERIPH_BASE) >> 10;
|
||||
return LL_APB1_GRP1_IsEnabledClock(1U << offset);
|
||||
} else if (((intptr_t)TIMx & 0xFFFF0000) == APB2PERIPH_BASE) {
|
||||
uint32_t offset = ((intptr_t)TIMx - APB2PERIPH_BASE) >> 10;
|
||||
return LL_APB2_GRP1_IsEnabledClock(1U << offset);
|
||||
}
|
||||
|
||||
// not supported
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "stm32_dma.h"
|
||||
#include "hal/gpio.h"
|
||||
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// WARNING:
|
||||
@@ -36,7 +38,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
|
||||
#if !defined(NVIC_GetEnableIRQ)
|
||||
static inline uint32_t NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
if ((int32_t)(IRQn) >= 0) {
|
||||
@@ -49,6 +51,7 @@ static inline uint32_t NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _enable_usart_irq(const stm32_usart_t* usart)
|
||||
{
|
||||
NVIC_SetPriority(usart->IRQn, usart->IRQ_Prio);
|
||||
@@ -114,9 +117,12 @@ static void enable_usart_clock(USART_TypeDef* USARTx)
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART3);
|
||||
} else if (USARTx == UART4) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART4);
|
||||
} else if (USARTx == USART6) {
|
||||
}
|
||||
#if defined(USART6)
|
||||
else if (USARTx == USART6) {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART6);
|
||||
}
|
||||
#endif
|
||||
#if defined(UART7) // does not exist on F2
|
||||
else if (USARTx == UART7) {
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_UART7);
|
||||
@@ -134,9 +140,12 @@ static void disable_usart_clock(USART_TypeDef* USARTx)
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_USART3);
|
||||
} else if (USARTx == UART4) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UART4);
|
||||
} else if (USARTx == USART6) {
|
||||
}
|
||||
#if defined(USART6)
|
||||
else if (USARTx == USART6) {
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_USART6);
|
||||
}
|
||||
#endif
|
||||
#if defined(UART7) // does not exist on F2
|
||||
else if (USARTx == UART7) {
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_UART7);
|
||||
@@ -160,13 +169,20 @@ static gpio_speed_t _get_pin_speed(uint32_t baudrate)
|
||||
return GPIO_PIN_SPEED_LOW;
|
||||
}
|
||||
|
||||
#if defined(STM32H7)
|
||||
# define _AF7_USART(x) \
|
||||
(x == USART1 || x == USART2 || x == USART3 || x == USART6 || x == UART7)
|
||||
#elif defined(STM32H7RS)
|
||||
# define _AF7_USART(x) \
|
||||
(x == USART1 || x == USART2 || x == USART3 || x == UART7)
|
||||
#else // F2, F4
|
||||
# define _AF7_USART(x) \
|
||||
(x == USART1 || x == USART2 || x == USART3)
|
||||
#endif
|
||||
|
||||
static gpio_af_t _get_usart_af(USART_TypeDef* USARTx)
|
||||
{
|
||||
if (USARTx == USART1 || USARTx == USART2 || USARTx == USART3) {
|
||||
return GPIO_AF7;
|
||||
} else {
|
||||
return GPIO_AF8;
|
||||
}
|
||||
return _AF7_USART(USARTx) ? GPIO_AF7 : GPIO_AF8;
|
||||
}
|
||||
|
||||
void stm32_usart_init_rx_dma(const stm32_usart_t* usart, const void* buffer, uint32_t length)
|
||||
@@ -186,8 +202,22 @@ void stm32_usart_init_rx_dma(const stm32_usart_t* usart, const void* buffer, uin
|
||||
|
||||
LL_DMA_InitTypeDef dmaInit;
|
||||
LL_DMA_StructInit(&dmaInit);
|
||||
|
||||
#if defined(STM32H7RS)
|
||||
// TODO
|
||||
#else // STM32H7RS
|
||||
|
||||
#if defined(STM32H7)
|
||||
dmaInit.PeriphRequest = usart->rxDMA_Channel;
|
||||
#else
|
||||
dmaInit.Channel = usart->rxDMA_Channel;
|
||||
dmaInit.PeriphOrM2MSrcAddress = (uint32_t)&usart->USARTx->DR;
|
||||
#endif
|
||||
|
||||
#if defined(LL_USART_DMA_REG_DATA_RECEIVE)
|
||||
dmaInit.PeriphOrM2MSrcAddress = LL_USART_DMA_GetRegAddr(usart->USARTx, LL_USART_DMA_REG_DATA_RECEIVE);
|
||||
#else
|
||||
dmaInit.PeriphOrM2MSrcAddress = LL_USART_DMA_GetRegAddr(usart->USARTx);
|
||||
#endif
|
||||
dmaInit.Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY;
|
||||
dmaInit.MemoryOrM2MDstAddress = (uint32_t)buffer;
|
||||
dmaInit.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
|
||||
@@ -197,8 +227,14 @@ void stm32_usart_init_rx_dma(const stm32_usart_t* usart, const void* buffer, uin
|
||||
LL_DMA_Init(usart->rxDMA, usart->rxDMA_Stream, &dmaInit);
|
||||
LL_USART_EnableDMAReq_RX(usart->USARTx);
|
||||
|
||||
#endif // !STM32H7RS
|
||||
|
||||
// Stream can be enable as the USART has alread been enabled
|
||||
#if defined(STM32H7RS)
|
||||
LL_DMA_EnableChannel(usart->rxDMA, usart->rxDMA_Stream);
|
||||
#else
|
||||
LL_DMA_EnableStream(usart->rxDMA, usart->rxDMA_Stream);
|
||||
#endif
|
||||
}
|
||||
|
||||
void stm32_usart_deinit_rx_dma(const stm32_usart_t* usart)
|
||||
@@ -226,10 +262,12 @@ 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
|
||||
if(gpio_get_mode(usart->txGPIO) != GPIO_IN || gpio_get_mode(usart->rxGPIO) != GPIO_IN)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// if (((usart->txGPIO != GPIO_UNDEF) &&
|
||||
// (gpio_get_mode(usart->txGPIO) != GPIO_IN)) ||
|
||||
// ((usart->rxGPIO != GPIO_UNDEF) &&
|
||||
// (gpio_get_mode(usart->rxGPIO) != GPIO_IN))) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
enable_usart_clock(usart->USARTx);
|
||||
LL_USART_DeInit(usart->USARTx);
|
||||
@@ -360,13 +398,19 @@ void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, u
|
||||
LL_DMA_InitTypeDef dmaInit;
|
||||
LL_DMA_StructInit(&dmaInit);
|
||||
|
||||
#if !defined(STM32H7RS)
|
||||
dmaInit.Channel = usart->txDMA_Channel;
|
||||
dmaInit.PeriphOrM2MSrcAddress = (uint32_t)&usart->USARTx->DR;
|
||||
#if defined(LL_USART_DMA_REG_DATA_RECEIVE)
|
||||
dmaInit.PeriphOrM2MSrcAddress =
|
||||
LL_USART_DMA_GetRegAddr(usart->USARTx, LL_USART_DMA_REG_DATA_RECEIVE);
|
||||
#else
|
||||
dmaInit.PeriphOrM2MSrcAddress = LL_USART_DMA_GetRegAddr(usart->USARTx);
|
||||
#endif
|
||||
dmaInit.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
|
||||
dmaInit.MemoryOrM2MDstAddress = (uint32_t)data;
|
||||
dmaInit.MemoryOrM2MDstIncMode = LL_DMA_MEMORY_INCREMENT;
|
||||
dmaInit.NbData = size;
|
||||
dmaInit.Priority = LL_DMA_PRIORITY_VERYHIGH; // TODO: make it configurable
|
||||
dmaInit.Priority = LL_DMA_PRIORITY_VERYHIGH; // TODO: make it configurable
|
||||
|
||||
LL_DMA_Init(usart->txDMA, usart->txDMA_Stream, &dmaInit);
|
||||
|
||||
@@ -374,6 +418,7 @@ void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, u
|
||||
LL_DMA_EnableIT_TC(usart->txDMA, usart->txDMA_Stream);
|
||||
}
|
||||
LL_DMA_EnableStream(usart->txDMA, usart->txDMA_Stream);
|
||||
#endif
|
||||
|
||||
return;
|
||||
} else {
|
||||
@@ -387,10 +432,12 @@ void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, u
|
||||
uint8_t stm32_usart_tx_completed(const stm32_usart_t* usart)
|
||||
{
|
||||
if (LL_USART_IsEnabledDMAReq_TX(usart->USARTx)) {
|
||||
#if !defined(STM32H7RS)
|
||||
// TX DMA is configured, let's check if the stream is currently enabled
|
||||
if (LL_DMA_IsEnabledStream(usart->txDMA, usart->txDMA_Stream) ||
|
||||
!LL_USART_IsActiveFlag_TXE(usart->USARTx))
|
||||
return 0;
|
||||
#endif
|
||||
} else if (LL_USART_IsEnabledIT_TXE(usart->USARTx)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -402,6 +449,7 @@ void stm32_usart_wait_for_tx_dma(const stm32_usart_t* usart)
|
||||
{
|
||||
// TODO: check if everything is properly initialised, this seems to block when
|
||||
// the port has been initialised with a zero baudrate
|
||||
#if !defined(STM32H7RS)
|
||||
if (LL_DMA_IsEnabledStream(usart->txDMA, usart->txDMA_Stream)) {
|
||||
|
||||
switch(usart->txDMA_Stream) {
|
||||
@@ -427,6 +475,7 @@ void stm32_usart_wait_for_tx_dma(const stm32_usart_t* usart)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void stm32_usart_enable_rx(const stm32_usart_t* usart)
|
||||
@@ -494,14 +543,22 @@ uint32_t stm32_usart_get_baudrate(const stm32_usart_t* usart)
|
||||
{
|
||||
auto periphclk = _get_usart_periph_clock(usart->USARTx);
|
||||
auto oversampling = LL_USART_GetOverSampling(usart->USARTx);
|
||||
#if defined(LL_USART_PRESCALER_DIV1)
|
||||
return LL_USART_GetBaudRate(usart->USARTx, periphclk, LL_USART_PRESCALER_DIV1, oversampling);
|
||||
#else
|
||||
return LL_USART_GetBaudRate(usart->USARTx, periphclk, oversampling);
|
||||
#endif
|
||||
}
|
||||
|
||||
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);
|
||||
#if defined(LL_USART_PRESCALER_DIV1)
|
||||
LL_USART_SetBaudRate(usart->USARTx, periphclk, LL_USART_PRESCALER_DIV1, oversampling, baudrate);
|
||||
#else
|
||||
LL_USART_SetBaudRate(usart->USARTx, periphclk, oversampling, baudrate);
|
||||
#endif
|
||||
}
|
||||
|
||||
void stm32_usart_set_hw_option(const stm32_usart_t* usart, uint32_t option)
|
||||
@@ -520,19 +577,34 @@ void stm32_usart_set_hw_option(const stm32_usart_t* usart, uint32_t option)
|
||||
}
|
||||
}
|
||||
|
||||
#define USART_FLAG_ERRORS \
|
||||
(LL_USART_SR_ORE | LL_USART_SR_NE | LL_USART_SR_FE | LL_USART_SR_PE)
|
||||
#if defined(STM32H7) || defined(STM32H7RS)
|
||||
# define USART_STATUS_REG ISR
|
||||
# define USART_IDLE USART_ISR_IDLE
|
||||
# define USART_TXE USART_ISR_TXFE
|
||||
# define USART_TC USART_ISR_TC
|
||||
# define USART_RXNE USART_ISR_RXNE_RXFNE
|
||||
# define USART_FLAG_ERRORS \
|
||||
(USART_ISR_ORE | USART_ISR_NE | USART_ISR_FE | USART_ISR_PE)
|
||||
#else
|
||||
# define USART_STATUS_REG SR
|
||||
# define USART_IDLE USART_SR_IDLE
|
||||
# define USART_TXE USART_SR_TXE
|
||||
# define USART_TC USART_SR_TC
|
||||
# define USART_RXNE USART_SR_RXNE
|
||||
# define USART_FLAG_ERRORS \
|
||||
(USART_SR_ORE | USART_SR_NE | USART_SR_FE | USART_SR_PE)
|
||||
#endif
|
||||
|
||||
void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
|
||||
{
|
||||
uint32_t status = LL_USART_ReadReg(usart->USARTx, SR);
|
||||
uint32_t status = LL_USART_ReadReg(usart->USARTx, USART_STATUS_REG);
|
||||
|
||||
// cache these first, as RXNE might clear SR
|
||||
uint32_t idle = (status & LL_USART_SR_IDLE);
|
||||
uint32_t txe = (status & LL_USART_SR_TXE);
|
||||
// cache these first, as RXNE might clear ISR
|
||||
uint32_t idle = (status & USART_IDLE);
|
||||
uint32_t txe = (status & USART_TXE);
|
||||
|
||||
// TC is only enabled with 2-wire half-duplex when TX DMA was in use
|
||||
if (LL_USART_IsEnabledIT_TC(usart->USARTx) && (status & LL_USART_SR_TC)) {
|
||||
if (LL_USART_IsEnabledIT_TC(usart->USARTx) && (status & USART_TC)) {
|
||||
|
||||
// disable TC IRQ
|
||||
LL_USART_DisableIT_TC(usart->USARTx);
|
||||
@@ -541,9 +613,9 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
|
||||
_half_duplex_input(usart);
|
||||
|
||||
// and drain RX side first
|
||||
while (status & LL_USART_SR_RXNE) {
|
||||
status = LL_USART_ReadReg(usart->USARTx, DR);
|
||||
status = LL_USART_ReadReg(usart->USARTx, SR);
|
||||
while (status & USART_RXNE) {
|
||||
status = LL_USART_ReceiveData8(usart->USARTx);
|
||||
status = LL_USART_ReadReg(usart->USARTx, USART_STATUS_REG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -551,22 +623,25 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
|
||||
if (LL_USART_IsEnabledIT_RXNE(usart->USARTx)) {
|
||||
|
||||
// Drain RX
|
||||
while (status & (LL_USART_SR_RXNE | USART_FLAG_ERRORS)) {
|
||||
while (status & (USART_RXNE | USART_FLAG_ERRORS)) {
|
||||
|
||||
// This will clear the RXNE/error bits in USART_SR register
|
||||
uint8_t data = LL_USART_ReadReg(usart->USARTx, DR);
|
||||
uint8_t data = LL_USART_ReceiveData8(usart->USARTx);
|
||||
|
||||
if (status & USART_FLAG_ERRORS) {
|
||||
#if defined(STM32H7) || defined(STM32H7RS)
|
||||
WRITE_REG(usart->USARTx->ICR, status & USART_FLAG_ERRORS);
|
||||
#endif
|
||||
if (cb->on_error)
|
||||
cb->on_error();
|
||||
}
|
||||
|
||||
if (status & LL_USART_SR_RXNE) {
|
||||
if (status & USART_RXNE) {
|
||||
if (cb->on_receive)
|
||||
cb->on_receive(data);
|
||||
}
|
||||
|
||||
status = LL_USART_ReadReg(usart->USARTx, SR);
|
||||
status = LL_USART_ReadReg(usart->USARTx, USART_STATUS_REG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,8 +657,9 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
|
||||
}
|
||||
|
||||
if (LL_USART_IsEnabledIT_IDLE(usart->USARTx) && idle) {
|
||||
// SR clear sequence
|
||||
status = LL_USART_ReadReg(usart->USARTx, DR);
|
||||
// ISR clear sequence
|
||||
status = LL_USART_ReceiveData8(usart->USARTx);
|
||||
LL_USART_ClearFlag_IDLE(usart->USARTx);
|
||||
if (cb->on_idle) cb->on_idle(cb->on_idle_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,519 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32h7xx_hal_conf_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief HAL configuration template file.
|
||||
* This file should be copied to the application folder and renamed
|
||||
* to stm32h7xx_hal_conf.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef STM32H7xx_HAL_CONF_H
|
||||
#define STM32H7xx_HAL_CONF_H
|
||||
|
||||
// Include common definitions for Cortex MCUs
|
||||
#include "stm32h7xx_hal_cortex.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
// #define HAL_MODULE_ENABLED
|
||||
// #define HAL_ADC_MODULE_ENABLED
|
||||
// #define HAL_CEC_MODULE_ENABLED
|
||||
// #define HAL_COMP_MODULE_ENABLED
|
||||
// #define HAL_CORDIC_MODULE_ENABLED
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
// #define HAL_CRC_MODULE_ENABLED
|
||||
// #define HAL_CRYP_MODULE_ENABLED
|
||||
// #define HAL_DAC_MODULE_ENABLED
|
||||
// #define HAL_DCMI_MODULE_ENABLED
|
||||
// #define HAL_DFSDM_MODULE_ENABLED
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
#define HAL_DMA2D_MODULE_ENABLED
|
||||
// #define HAL_DTS_MODULE_ENABLED
|
||||
#define HAL_DSI_MODULE_ENABLED
|
||||
// #define HAL_ETH_MODULE_ENABLED
|
||||
// #define HAL_EXTI_MODULE_ENABLED
|
||||
// #define HAL_FDCAN_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
// #define HAL_GFXMMU_MODULE_ENABLED
|
||||
// #define HAL_FMAC_MODULE_ENABLED
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
// #define HAL_HASH_MODULE_ENABLED
|
||||
// #define HAL_HCD_MODULE_ENABLED
|
||||
// #define HAL_HRTIM_MODULE_ENABLED
|
||||
// #define HAL_HSEM_MODULE_ENABLED
|
||||
#define HAL_I2C_MODULE_ENABLED
|
||||
// #define HAL_I2S_MODULE_ENABLED
|
||||
// #define HAL_IRDA_MODULE_ENABLED
|
||||
// #define HAL_IWDG_MODULE_ENABLED
|
||||
//#define HAL_JPEG_MODULE_ENABLED
|
||||
//#define HAL_LPTIM_MODULE_ENABLED
|
||||
#define HAL_LTDC_MODULE_ENABLED
|
||||
// #define HAL_MDIOS_MODULE_ENABLED
|
||||
#define HAL_MDMA_MODULE_ENABLED
|
||||
// #define HAL_MMC_MODULE_ENABLED
|
||||
// #define HAL_NAND_MODULE_ENABLED
|
||||
// #define HAL_NOR_MODULE_ENABLED
|
||||
// #define HAL_OPAMP_MODULE_ENABLED
|
||||
// #define HAL_OSPI_MODULE_ENABLED
|
||||
// #define HAL_OTFDEC_MODULE_ENABLED
|
||||
#define HAL_PCD_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
// #define HAL_PSSI_MODULE_ENABLED
|
||||
#define HAL_QSPI_MODULE_ENABLED
|
||||
// #define HAL_RAMECC_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
// #define HAL_RNG_MODULE_ENABLED
|
||||
#define HAL_RTC_MODULE_ENABLED
|
||||
// #define HAL_SAI_MODULE_ENABLED
|
||||
#define HAL_SD_MODULE_ENABLED
|
||||
#define HAL_SDRAM_MODULE_ENABLED
|
||||
// #define HAL_SMARTCARD_MODULE_ENABLED
|
||||
// #define HAL_SMBUS_MODULE_ENABLED
|
||||
// #define HAL_SPDIFRX_MODULE_ENABLED
|
||||
#define HAL_SPI_MODULE_ENABLED
|
||||
// #define HAL_SRAM_MODULE_ENABLED
|
||||
// #define HAL_SWPMI_MODULE_ENABLED
|
||||
// #define HAL_TIM_MODULE_ENABLED
|
||||
// #define HAL_UART_MODULE_ENABLED
|
||||
// #define HAL_USART_MODULE_ENABLED
|
||||
// #define HAL_WWDG_MODULE_ENABLED
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE (25000000UL) /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal oscillator (CSI) default value.
|
||||
* This value is the default CSI value after Reset.
|
||||
*/
|
||||
#if !defined (CSI_VALUE)
|
||||
#define CSI_VALUE (4000000UL) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* CSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE (64000000UL) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE (32768UL) /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */
|
||||
#endif /* LSE_STARTUP_TIMEOUT */
|
||||
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature.*/
|
||||
|
||||
/**
|
||||
* @brief External clock source for I2S peripheral
|
||||
* This value is used by the I2S HAL module to compute the I2S clock source
|
||||
* frequency, this source is inserted directly through I2S_CKIN pad.
|
||||
*/
|
||||
#if !defined (EXTERNAL_CLOCK_VALUE)
|
||||
#define EXTERNAL_CLOCK_VALUE 12288000UL /*!< Value of the External clock in Hz*/
|
||||
#endif /* EXTERNAL_CLOCK_VALUE */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY (0x0FUL) /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0
|
||||
#if defined(SD_SDIO_HAS_TRANSCEIVER)
|
||||
# define USE_SD_TRANSCEIVER 1U /*!< use uSD Transceiver */
|
||||
#else
|
||||
# define USE_SD_TRANSCEIVER 0U /*!< use uSD Transceiver */
|
||||
#endif
|
||||
#define USE_SPI_CRC 1U /*!< use CRC in SPI */
|
||||
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
|
||||
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
|
||||
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U /* COMP register callback disabled */
|
||||
#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U /* CORDIC register callback disabled */
|
||||
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
|
||||
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */
|
||||
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */
|
||||
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */
|
||||
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */
|
||||
#define USE_HAL_DTS_REGISTER_CALLBACKS 0U /* DTS register callback disabled */
|
||||
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
|
||||
#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U /* FDCAN register callback disabled */
|
||||
#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U /* FMAC register callback disabled */
|
||||
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
|
||||
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
|
||||
#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */
|
||||
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
|
||||
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
|
||||
#define USE_HAL_GFXMMU_REGISTER_CALLBACKS 0U /* GFXMMU register callback disabled */
|
||||
#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U /* HRTIM register callback disabled */
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
|
||||
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
|
||||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
|
||||
#define USE_HAL_JPEG_REGISTER_CALLBACKS 0U /* JPEG register callback disabled */
|
||||
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */
|
||||
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */
|
||||
#define USE_HAL_MDIOS_REGISTER_CALLBACKS 0U /* MDIO register callback disabled */
|
||||
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
|
||||
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U /* MDIO register callback disabled */
|
||||
#define USE_HAL_OSPI_REGISTER_CALLBACKS 0U /* OSPI register callback disabled */
|
||||
#define USE_HAL_OTFDEC_REGISTER_CALLBACKS 0U /* OTFDEC register callback disabled */
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
|
||||
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */
|
||||
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
|
||||
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */
|
||||
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
|
||||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
|
||||
#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */
|
||||
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
|
||||
#define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U /* SWPMI register callback disabled */
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
|
||||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
|
||||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
|
||||
|
||||
/* ########################### Ethernet Configuration ######################### */
|
||||
#define ETH_TX_DESC_CNT 4U /* number of Ethernet Tx DMA descriptors */
|
||||
#define ETH_RX_DESC_CNT 4U /* number of Ethernet Rx DMA descriptors */
|
||||
|
||||
#define ETH_MAC_ADDR0 (0x02UL)
|
||||
#define ETH_MAC_ADDR1 (0x00UL)
|
||||
#define ETH_MAC_ADDR2 (0x00UL)
|
||||
#define ETH_MAC_ADDR3 (0x00UL)
|
||||
#define ETH_MAC_ADDR4 (0x00UL)
|
||||
#define ETH_MAC_ADDR5 (0x00UL)
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1 */
|
||||
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MDMA_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_mdma.h"
|
||||
#endif /* HAL_MDMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_hash.h"
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DCMI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_dcmi.h"
|
||||
#endif /* HAL_DCMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA2D_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_dma2d.h"
|
||||
#endif /* HAL_DMA2D_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DSI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_dsi.h"
|
||||
#endif /* HAL_DSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DFSDM_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_dfsdm.h"
|
||||
#endif /* HAL_DFSDM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DTS_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_dts.h"
|
||||
#endif /* HAL_DTS_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ETH_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_eth.h"
|
||||
#endif /* HAL_ETH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FDCAN_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_fdcan.h"
|
||||
#endif /* HAL_FDCAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CEC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_cec.h"
|
||||
#endif /* HAL_CEC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_COMP_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_comp.h"
|
||||
#endif /* HAL_COMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORDIC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_cordic.h"
|
||||
#endif /* HAL_CORDIC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRYP_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_cryp.h"
|
||||
#endif /* HAL_CRYP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GFXMMU_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_gfxmmu.h"
|
||||
#endif /* HAL_GFXMMU_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FMAC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_fmac.h"
|
||||
#endif /* HAL_FMAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HRTIM_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_hrtim.h"
|
||||
#endif /* HAL_HRTIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HSEM_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_hsem.h"
|
||||
#endif /* HAL_HSEM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2S_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_i2s.h"
|
||||
#endif /* HAL_I2S_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_JPEG_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_jpeg.h"
|
||||
#endif /* HAL_JPEG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MDIOS_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_mdios.h"
|
||||
#endif /* HAL_MDIOS_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_mmc.h"
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_lptim.h"
|
||||
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LTDC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_ltdc.h"
|
||||
#endif /* HAL_LTDC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OPAMP_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_opamp.h"
|
||||
#endif /* HAL_OPAMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OSPI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_ospi.h"
|
||||
#endif /* HAL_OSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OTFDEC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_otfdec.h"
|
||||
#endif /* HAL_OTFDEC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PSSI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_pssi.h"
|
||||
#endif /* HAL_PSSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_QSPI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_qspi.h"
|
||||
#endif /* HAL_QSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RAMECC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_ramecc.h"
|
||||
#endif /* HAL_RAMECC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_rng.h"
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SAI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_sai.h"
|
||||
#endif /* HAL_SAI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SDRAM_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_sdram.h"
|
||||
#endif /* HAL_SDRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPDIFRX_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_spdifrx.h"
|
||||
#endif /* HAL_SPDIFRX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SWPMI_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_swpmi.h"
|
||||
#endif /* HAL_SWPMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMBUS_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_smbus.h"
|
||||
#endif /* HAL_SMBUS_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32h7xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t *file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* STM32H7xx_HAL_CONF_H */
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ static volatile uint32_t _ms_ticks;
|
||||
static void _init_1ms_timer()
|
||||
{
|
||||
stm32_timer_enable_clock(MS_TIMER);
|
||||
if ((MS_TIMER->CR1 & TIM_CR1_CEN) == TIM_CR1_CEN) return;
|
||||
|
||||
_ms_ticks = 0;
|
||||
MS_TIMER->ARR = 999; // 1mS in uS
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
#include "hal/watchdog_driver.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
|
||||
#ifdef IWDG1
|
||||
#define IWDG IWDG1
|
||||
#endif
|
||||
|
||||
void watchdogInit(unsigned int duration)
|
||||
{
|
||||
LL_IWDG_EnableWriteAccess(IWDG);
|
||||
|
||||
Reference in New Issue
Block a user