[DemoCode下载] M091半主机测试示例

[复制链接]
1493|4
 楼主| xinxianshi 发表于 2023-11-25 21:50 | 显示全部楼层 |阅读模式
TE, 测试, ID, ck, ST, se
  1. /******************************************************************************
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
  4. * [url=home.php?mod=space&uid=247401]@brief[/url]    Show how to print and get character with IDE console window.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * [url=home.php?mod=space&uid=17282]@CopyRight[/url] (C) 2016 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #include <stdio.h>
  10. #include "NuMicro.h"

  11. # if defined (__GNUC__)
  12. extern void initialise_monitor_handles(void);
  13. #endif

  14. #define PLL_CLOCK           96000000

  15. /**
  16. *  @brief  Init system clock and I/O multi function .
  17. *  @param  None
  18. *  [url=home.php?mod=space&uid=266161]@return[/url] None
  19. */
  20. void SYS_Init(void)
  21. {
  22.     /*---------------------------------------------------------------------------------------------------------*/
  23.     /* Init System Clock                                                                                       */
  24.     /*---------------------------------------------------------------------------------------------------------*/
  25.     /* Unlock protected registers */
  26.     SYS_UnlockReg();

  27.     /* Enable HIRC clock (Internal RC 48MHz) */
  28.     CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

  29.     /* Wait for HIRC clock ready */
  30.     CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

  31.     /* Select HCLK clock source as HIRC and HCLK source divider as 1 */
  32.     CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

  33.     /* Set PCLK0/PCLK1 to HCLK/2 */
  34.     CLK->PCLKDIV = CLK_PCLKDIV_APB0DIV_DIV1 | CLK_PCLKDIV_APB1DIV_DIV1;


  35.     /* Update System Core Clock */
  36.     /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
  37.     SystemCoreClockUpdate();


  38.     /* Lock protected registers */
  39.     SYS_LockReg();

  40. }


  41. int32_t main()
  42. {
  43.     int8_t item;

  44.     /* Init System, IP clock and multi-function I/O */
  45.     SYS_Init();

  46. #if defined (__GNUC__) && !defined(__ARMCC_VERSION) && defined(OS_USE_SEMIHOSTING)
  47.     initialise_monitor_handles();
  48. #endif

  49.     printf("\n Start SEMIHOST test: \n");

  50.     while(1)
  51.     {
  52.         item = getchar();
  53.         printf("%c\n",item);
  54.     }

  55. }





  56. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/





小灵通2018 发表于 2023-11-26 21:35 | 显示全部楼层
半主机是干什么用的。
蝶弄美人簪 发表于 2025-9-27 15:30 | 显示全部楼层
M091 半主机测试示例:配置调试环境,编写输出字符代码,通过半主机模式将数据发送到调试器,实现 printf 功能测试。
小岛西岸来信 发表于 2025-9-28 11:53 | 显示全部楼层
M091 半主机测试可借助 Keil MDK,通过半主机模式实现调试信息输出。示例:启用半主机功能,包含stdio.h,用printf输出调试信息。配置调试器为半主机模式,下载程序后,调试时串口助手可接收打印内容,无需硬件 UART,简化初期调试,适合验证代码逻辑与变量状态。
灰色与青 发表于 2025-10-9 21:28 | 显示全部楼层
M091 半主机测试可借助 Keil MDK 或 IAR 等工具实现,需先配置调试环境,使芯片与调试器(如 J-Link)连接。示例代码中,通过调用printf等半主机函数输出调试信息,无需外接串口模块。编译时需启用半主机模式,调试时信息会实时显示在 IDE 的调试终端,方便监测变量值、程序运行流程,快速定位 bug,适合 M091 初期开发阶段的低成本、高效调试。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

102

主题

1019

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部