作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试尽快切换 STM32H743 上的 IO。我正在使用外部 10MHz 时钟,供电电压为 3.3V,我确信我的主时钟运行在 400MHz,与 GPIO (AHB4) 通信的总线时钟运行在 200MHz。这是我用来配置芯片和切换 IO 的一些示例代码:
RCC_ClkInitTypeDef clock;
RCC_OscInitTypeDef osc;
MODIFY_REG(PWR->CR3, PWR_CR3_SCUEN, 0);
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
// External 10.000MHz oscillator
osc.OscillatorType = RCC_OSCILLATORTYPE_HSE;
osc.HSEState = RCC_HSE_ON;
osc.HSIState = RCC_HSI_OFF;
osc.CSIState = RCC_CSI_OFF;
osc.PLL.PLLState = RCC_PLL_ON;
osc.PLL.PLLSource = RCC_PLLSOURCE_HSE;
// ((10 / 5) * 400 ) / 2 = 400
osc.PLL.PLLM = 5;
osc.PLL.PLLN = 400;
osc.PLL.PLLP = 2;
osc.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
osc.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
HAL_RCC_OscConfig(&osc);
// Sysclk source is PLL
clock.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 |
RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1);
clock.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
clock.SYSCLKDivider = RCC_SYSCLK_DIV1;
// HCLK = SYSCLK / 2 = 200
clock.AHBCLKDivider = RCC_HCLK_DIV2;
clock.APB3CLKDivider = RCC_APB3_DIV2;
clock.APB1CLKDivider = RCC_APB1_DIV2;
clock.APB2CLKDivider = RCC_APB2_DIV2;
clock.APB4CLKDivider = RCC_APB4_DIV2;
HAL_RCC_ClockConfig(&clock, FLASH_LATENCY_4);
__HAL_RCC_CSI_ENABLE();
__HAL_RCC_SYSCFG_CLK_ENABLE();
HAL_EnableCompensationCell();
// GPIOC0 is pin I'm toggling
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef gpio;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
gpio.Pull = GPIO_NOPULL;
gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio.Pin = GPIO_PIN_0;
HAL_GPIO_Init(GPIOC, &gpio);
// Configure GPIOC9 as SYSCLK/2 (200MHz)
gpio.Mode = GPIO_MODE_AF_PP;
gpio.Alternate = GPIO_AF0_MCO;
gpio.Pull = GPIO_NOPULL;
gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio.Pin = GPIO_PIN_9;
HAL_GPIO_Init(GPIOC, &gpio);
HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_2);
while (1)
{
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
GPIOC->ODR = 0;
GPIOC->ODR = 1;
}
...
str r1, [r3, #20]
str r2, [r3, #20]
str r1, [r3, #20]
str r2, [r3, #20]
str r1, [r3, #20]
str r2, [r3, #20]
str r1, [r3, #20]
str r2, [r3, #20]
str r1, [r3, #20]
str r2, [r3, #20]
str r1, [r3, #20]
...
#include <stm32h7xx_hal.h>
#include <stdint.h>
DMA_HandleTypeDef dma;
void SysTick_Handler(void)
{
HAL_IncTick();
}
static void ClockConfig(void)
{
RCC_ClkInitTypeDef clock;
RCC_OscInitTypeDef osc;
MODIFY_REG(PWR->CR3, PWR_CR3_SCUEN, 0);
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
osc.OscillatorType = RCC_OSCILLATORTYPE_CSI;
osc.CSIState = RCC_CSI_ON;
osc.CSICalibrationValue = 16;
osc.PLL.PLLState = RCC_PLL_ON;
osc.PLL.PLLSource = RCC_PLLSOURCE_CSI;
osc.PLL.PLLM = 1;
osc.PLL.PLLN = 200;
osc.PLL.PLLP = 2;
osc.PLL.PLLQ = 2;
osc.PLL.PLLR = 2;
osc.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
osc.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
osc.PLL.PLLFRACN = 0;
HAL_RCC_OscConfig(&osc);
clock.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1);
clock.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
clock.SYSCLKDivider = RCC_SYSCLK_DIV1;
clock.AHBCLKDivider = RCC_HCLK_DIV2;
clock.APB3CLKDivider = RCC_APB3_DIV2;
clock.APB1CLKDivider = RCC_APB1_DIV2;
clock.APB2CLKDivider = RCC_APB2_DIV2;
clock.APB4CLKDivider = RCC_APB4_DIV2;
HAL_RCC_ClockConfig(&clock, FLASH_LATENCY_4);
__HAL_RCC_CSI_ENABLE();
__HAL_RCC_SYSCFG_CLK_ENABLE();
HAL_EnableCompensationCell();
HAL_SYSTICK_Config(SystemCoreClock / 1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
void GpioConfig(void)
{
__GPIOC_CLK_ENABLE();
GPIO_InitTypeDef gpio;
gpio.Pin = GPIO_PIN_0;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &gpio);
gpio.Pin = GPIO_PIN_1;
gpio.Mode = GPIO_MODE_OUTPUT_PP;
gpio.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &gpio);
gpio.Mode = GPIO_MODE_AF_PP;
gpio.Alternate = GPIO_AF0_MCO;
gpio.Pull = GPIO_NOPULL;
gpio.Speed = GPIO_SPEED_FAST;
gpio.Pin = GPIO_PIN_9;
HAL_GPIO_Init(GPIOC, &gpio);
HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_2);
}
uint8_t complete = 0;
void DmaComplete(DMA_HandleTypeDef *handle)
{
complete = 1;
}
void DmaError(DMA_HandleTypeDef *handle)
{
complete = 1;
}
void DmaConfig(void)
{
__HAL_RCC_BDMA_CLK_ENABLE();
dma.Instance = BDMA_Channel0;
dma.Init.Request = DMA_REQUEST_MEM2MEM;
dma.Init.Direction = DMA_MEMORY_TO_MEMORY;
dma.Init.PeriphInc = DMA_PINC_ENABLE;
dma.Init.MemInc = DMA_MINC_DISABLE;
dma.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
dma.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
dma.Init.Mode = DMA_NORMAL;
dma.Init.Priority = DMA_PRIORITY_VERY_HIGH;
HAL_DMA_Init(&dma);
HAL_DMA_RegisterCallback(&dma, HAL_DMA_XFER_CPLT_CB_ID, DmaComplete);
HAL_DMA_RegisterCallback(&dma, HAL_DMA_XFER_ERROR_CB_ID, DmaError);
HAL_NVIC_SetPriority(BDMA_Channel0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(BDMA_Channel0_IRQn);
}
void BDMA_Channel0_IRQHandler(void)
{
HAL_DMA_IRQHandler(&dma);
}
void HardFault_Handler(void)
{
__NOP();
}
__attribute__((section(".ram_d3")))
static uint16_t src[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int main(void)
{
HAL_Init();
ClockConfig();
GpioConfig();
DmaConfig();
while (1)
{
complete = 0;
HAL_DMA_Start_IT(&dma, (uint32_t)&src, (uint32_t)&GPIOC->ODR, 10);
while (complete == 0) ;
}
}
最佳答案
你的假设是错误的。 GPIO 速度不是由核心指令时序决定的,而是由外设的物理特性决定的。请参阅 DS 中的表格,其中静态和动态 GPIO 端口特性。最大速度取决于许多参数。
关于arm - STM32H7xx 尽可能快地切换 IO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51736591/
我知道在 KDB 中,如果您有一个列表,例如... l:`apples`oranges`pears` 您可以像下面这样进行 N 次随机选择: 9?l 但是如何尽可能均匀地选择列表中的每个项目? 最佳答
我真的厌倦了它。我有一个高级 Web 应用程序依赖于大量 Javascript 库(jQuery、jQueryUI、OpenLayers、highcharts、EJSChart 等等)。不用说,Int
我是一名优秀的程序员,十分优秀!