news 2026/3/19 3:34:40

[STM32L5] 【STM32L562 DK试用】基础外设体验

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
[STM32L5] 【STM32L562 DK试用】基础外设体验

开发板自带了一块240*240分辨率的触摸屏:



本次基于官方demo进行修改,从而在屏幕上显示相应的文字。首先进行系统和时钟的初始化:

复制

  1. HAL_StatusTypeDef HAL_Init(void)
  2. {
  3. HAL_StatusTypeDef status = HAL_OK;
  4. /* Set Interrupt Group Priority */
  5. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
  6. /* Insure time base clock coherency */
  7. SystemCoreClockUpdate();
  8. /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */
  9. if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
  10. {
  11. status = HAL_ERROR;
  12. }
  13. else
  14. {
  15. /* Init the low level hardware */
  16. HAL_MspInit();
  17. }
  18. /* Return function status */
  19. return status;
  20. }

然后进行相关HMI设备和LED等的初始化:

复制

  1. static void SystemHardwareInit(void)
  2. {
  3. /* Init LEDs */
  4. if (LedInitialized != SET)
  5. {
  6. if (BSP_LED_Init(LED9) != BSP_ERROR_NONE)
  7. {
  8. Error_Handler();
  9. }
  10. if (BSP_LED_Init(LED10) != BSP_ERROR_NONE)
  11. {
  12. Error_Handler();
  13. }
  14. LedInitialized = SET;
  15. }
  16. /* Init User push-button in EXTI Mode */
  17. if (ButtonInitialized != SET)
  18. {
  19. if (BSP_PB_Init(BUTTON_USER, BUTTON_MODE_EXTI) != BSP_ERROR_NONE)
  20. {
  21. Error_Handler();
  22. }
  23. ButtonInitialized = SET;
  24. }
  25. /* Initialize the LCD */
  26. if (LcdInitialized != SET)
  27. {
  28. LCD_UTILS_Drv_t lcdDrv;
  29. /* Initialize the LCD */
  30. if (BSP_LCD_Init(0, LCD_ORIENTATION_PORTRAIT) != BSP_ERROR_NONE)
  31. {
  32. Error_Handler();
  33. }
  34. /* Set UTIL_LCD functions */
  35. lcdDrv.DrawBitmap = BSP_LCD_DrawBitmap;
  36. lcdDrv.FillRGBRect = BSP_LCD_FillRGBRect;
  37. lcdDrv.DrawHLine = BSP_LCD_DrawHLine;
  38. lcdDrv.DrawVLine = BSP_LCD_DrawVLine;
  39. lcdDrv.FillRect = BSP_LCD_FillRect;
  40. lcdDrv.GetPixel = BSP_LCD_ReadPixel;
  41. lcdDrv.SetPixel = BSP_LCD_WritePixel;
  42. lcdDrv.GetXSize = BSP_LCD_GetXSize;
  43. lcdDrv.GetYSize = BSP_LCD_GetYSize;
  44. lcdDrv.SetLayer = BSP_LCD_SetActiveLayer;
  45. lcdDrv.GetFormat = BSP_LCD_GetFormat;
  46. UTIL_LCD_SetFuncDriver(&lcdDrv);
  47. /* Clear the LCD */
  48. UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
  49. /* Set the display on */
  50. if (BSP_LCD_DisplayOn(0) != BSP_ERROR_NONE)
  51. {
  52. Error_Handler();
  53. }
  54. LcdInitialized = SET;
  55. }
  56. /* Initialize the TouchScreen */
  57. if (TsInitialized != SET)
  58. {
  59. TS_Init_t TsInit;
  60. /* Initialize the TouchScreen */
  61. TsInit.Width = 240;
  62. TsInit.Height = 240;
  63. TsInit.Orientation = TS_ORIENTATION_PORTRAIT;
  64. TsInit.Accuracy = 10;
  65. if (BSP_TS_Init(0, &TsInit) != BSP_ERROR_NONE)
  66. {
  67. Error_Handler();
  68. }
  69. /* Configure TS interrupt */
  70. if (BSP_TS_EnableIT(0) != BSP_ERROR_NONE)
  71. {
  72. Error_Handler();
  73. }
  74. TsInitialized = SET;
  75. }
  76. }



调用屏幕API进行显示:

复制

  1. static void Display_DemoDescription(void)
  2. {
  3. char desc[60];
  4. /* Set font */
  5. UTIL_LCD_SetFont(&Font20);
  6. /* Clear the LCD */
  7. UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
  8. /* Set the LCD Text Color */
  9. UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_DARKBLUE);
  10. UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  11. /* Display LCD messages */
  12. UTIL_LCD_DisplayStringAt(0, 10, (uint8_t *)"STM32L562E-DK BSP", CENTER_MODE);
  13. UTIL_LCD_DisplayStringAt(0, 35, (uint8_t *)"drivers example", CENTER_MODE);
  14. /* Draw Bitmap */
  15. UTIL_LCD_DrawBitmap(80, 65, (uint8_t *)st**);
  16. UTIL_LCD_SetFont(&Font8);
  17. UTIL_LCD_DisplayStringAt(0, 220, (uint8_t *)"Copyright (c) STMicroelectronics 2019", CENTER_MODE);
  18. UTIL_LCD_SetFont(&Font12);
  19. UTIL_LCD_FillRect(0, 145, 240, 50, UTIL_LCD_COLOR_BLUE);
  20. UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_WHITE);
  21. UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_BLUE);
  22. UTIL_LCD_DisplayStringAt(0, 135, (uint8_t *)"Hello 21IC", CENTER_MODE);
  23. UTIL_LCD_DisplayStringAt(0, 150, (uint8_t *)"Press User push-button", CENTER_MODE);
  24. UTIL_LCD_DisplayStringAt(0, 165, (uint8_t *)"to start :", CENTER_MODE);
  25. sprintf(desc,"%s example", BSP_examples[DemoIndex].DemoName);
  26. UTIL_LCD_DisplayStringAt(0, 180, (uint8_t *)desc, CENTER_MODE);
  27. }



显示效果:



---------------------
作者:lishuihua
链接:https://bbs.21ic.com/forum.php?mod=viewthread&tid=3437260
来源:21ic.com
此文章已获得原创/原创奖标签,著作权归21ic所有,任何人未经允许禁止转载。

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/18 11:56:57

[STM32L5] STM32L562E-DK开发板的BSP学习

该工程所在位置 STM32Cube_FW_L5_V1.5.0\Projects\STM32L562E-DK\Examples\BSP\MDK-ARM 打开工程,找到main.c的main函数,查看硬件初始化函数复制static void SystemHardwareInit(void){ /* Init LEDs */ if (LedInitialized ! SET) { if (BSP_L…

作者头像 李华
网站建设 2026/3/16 23:33:49

AI教材写作必备:掌握这些技巧,低查重教材轻松搞定

不少教材编写者常常感到沮丧,他们辛辛苦苦打磨出来的正文内容,却因为缺乏必要的配套资源而影响了教学效果。课后练习的题型设计需要层次分明,但往往缺少创新的想法;教学课件想要生动形象,却因技术限制而无法实现&#…

作者头像 李华
网站建设 2026/3/16 17:39:35

【OptisLang】设计优化

【OptisLang】设计优化 引言 正文 设计优化的三个重点 Author: JiJi \textrm{Author: JiJi} Author: JiJi Created Time: 2026.02.06 \textrm{Created Time: 2026.02.06} Created Time: 2026.02.06

作者头像 李华
网站建设 2026/3/18 17:26:18

【小程序毕设源码分享】基于springboot+小程序的在线答题微信小程序的设计与实现(程序+文档+代码讲解+一条龙定制)

博主介绍:✌️码农一枚 ,专注于大学生项目实战开发、讲解和毕业🚢文撰写修改等。全栈领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围:&am…

作者头像 李华
网站建设 2026/3/18 2:42:35

当人类Delta化:AI时代的智能基线与意义重构

在人工智能技术迭代的浪潮中,我们正站在一个前所未有的临界点上。当多智能体协作系统(Agent Teams)开始展现出惊人的涌现能力时,一个深刻的转变正在发生:智能不再是人类的专属特权,而是变成了可以被拆解、组…

作者头像 李华