本帖最后由 HuaWng 于 2024-10-11 21:53 编辑
STM32H7S78-DK是目前ST比较新的一款高性能开发板,虽然自带的FLASH比较小,但是扩展了NOR Flash。启动在片内FLASH,然后通过BOOT跳转到片外FLASH运行。
板载了4个RGB小灯,一个复位按键,一个用户按键,还有WIFI扩展接口,一个800*480分辨率RGB接口屏幕;背面还扩展了Arduino Uno R3接口。总体来讲是功能非常丰富,主打的应用应该是人机交互与处理中枢的角色。
下面介绍一下开发环境:
STM32CubeIde,版本:1.16.0
STM32CubeMx, 版本:6.12.0
STM32CubeProgrammer,版本:2.17.0
推荐大家使用最新的版本,因为最新的板卡往往在最新的版本得到更好的支持,比如最新的bug修复以及更快的编译速度等。
在STM32CubeIde里面,选择New -> STME32 PROJECT
之后在Example Selector里面选择Example Selector,然后选择GPIO Toggle,选择保存位置即可。
对于驱动GPIO,首先需要进行引脚初始化:
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOM_CLK_ENABLE();
__HAL_RCC_GPIOO_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOM, LD4_Pin|LD3_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOO, LD1_Pin|LD2_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : LD4_Pin LD3_Pin */
GPIO_InitStruct.Pin = LD4_Pin|LD3_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOM, &GPIO_InitStruct);
/*Configure GPIO pins : LD1_Pin LD2_Pin */
GPIO_InitStruct.Pin = LD1_Pin|LD2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOO, &GPIO_InitStruct);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
接下来可以可以调用HAL_GPIO_WritePin来控制引脚电平的高低,进而控制LED小灯的亮灭。
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Set or clear the selected data port bit.
* [url=home.php?mod=space&uid=536309]@NOTE[/url] This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
* accesses. In this way, there is no risk of an IRQ occurring between
* the read and the modify access.
* @param GPIOx where x can be (A..H and M..P) to select the GPIO peripheral for STM32H7RSxx family
* @param GPIO_Pin specifies the port bit to be written.
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
* @param PinState specifies the value to be written to the selected bit.
* This parameter can be one of the GPIO_PinState enum values:
* [url=home.php?mod=space&uid=2817080]@ARG[/url] GPIO_PIN_RESET: to clear the port pin
* [url=home.php?mod=space&uid=2817080]@ARG[/url] GPIO_PIN_SET: to set the port pin
* @retval None
*/
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
{
/* Check the parameters */
assert_param(IS_GPIO_PIN(GPIO_Pin));
assert_param(IS_GPIO_PIN_ACTION(PinState));
if (PinState != GPIO_PIN_RESET)
{
GPIOx->BSRR = (uint32_t)GPIO_Pin;
}
else
{
GPIOx->BRR = (uint32_t)GPIO_Pin;
}
}
本次实验在主循环中以此翻转小灯状态:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_GPIO_TogglePin(LD1_GPIO_PORT, LD1_Pin);
/* Insert delay 100 ms */
HAL_Delay(100);
HAL_GPIO_TogglePin(LD2_GPIO_PORT, LD2_PIN);
/* Insert delay 100 ms */
HAL_Delay(100);
HAL_GPIO_TogglePin(LD3_GPIO_PORT, LD3_PIN);
/* Insert delay 100 ms */
HAL_Delay(100);
HAL_GPIO_TogglePin(LD4_GPIO_PORT, LD4_PIN);
/* Insert delay 100 ms */
HAL_Delay(100);
}
编译使用的是arm-none-eabi-gcc工具链:
arm-none-eabi-size GPIO_IOToggle_Appli.elf
arm-none-eabi-objdump -h -S GPIO_IOToggle_Appli.elf > "GPIO_IOToggle_Appli.list"
text data bss dec hex filename
4644 12 1568 6224 1850 GPIO_IOToggle_Appli.elf
Finished building: default.size.stdout
Finished building: GPIO_IOToggle_Appli.list
21:33:09 Build Finished. 0 errors, 0 warnings. (took 6s.118ms)
烧录,查看效果:
|