[DemoCode下载] 这个米你的例子怎么理解

[复制链接]
777|12
 楼主| jiekou001 发表于 2018-10-26 23:54 | 显示全部楼层 |阅读模式
TE, se, ni, TI, UART
  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. * $Revision: 5 $
  5. * $Date: 15/10/06 11:04a $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Show hard fault information when hard fault happened
  7. *
  8. * @note
  9. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/

  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <stdint.h>
  15. #include "Mini51Series.h"


  16. /*---------------------------------------------------------------------------------------------------------*/
  17. /* Global variables                                                                                        */
  18. /*---------------------------------------------------------------------------------------------------------*/


  19. /*---------------------------------------------------------------------------------------------------------*/
  20. /* Define functions prototype                                                                              */
  21. /*---------------------------------------------------------------------------------------------------------*/
  22. int32_t main(void);


  23. void SYS_Init(void)
  24. {
  25.     /*---------------------------------------------------------------------------------------------------------*/
  26.     /* Init System Clock                                                                                       */
  27.     /*---------------------------------------------------------------------------------------------------------*/
  28.     /* Unlock protected registers */
  29.     SYS_UnlockReg();

  30.     /* Set P5 multi-function pins for XTAL1 and XTAL2 */
  31.     SYS->P5_MFP &= ~(SYS_MFP_P50_Msk | SYS_MFP_P51_Msk);
  32.     SYS->P5_MFP |= (SYS_MFP_P50_XTAL1 | SYS_MFP_P51_XTAL2);

  33.     /* Enable External XTAL (4~24 MHz) */
  34.     CLK->PWRCON &= ~CLK_PWRCON_XTLCLK_EN_Msk;
  35.     CLK->PWRCON |= (0x1 << CLK_PWRCON_XTLCLK_EN_Pos); // XTAL12M (HXT) Enabled

  36.     /* Waiting for 12MHz clock ready */
  37.     CLK_WaitClockReady( CLK_CLKSTATUS_XTL_STB_Msk);

  38.     /* Switch HCLK clock source to XTAL */
  39.     CLK->CLKSEL0 &= ~CLK_CLKSEL0_HCLK_S_Msk;
  40.     CLK->CLKSEL0 |= CLK_CLKSEL0_HCLK_S_XTAL;

  41.     /* Enable IP clock */
  42.     CLK->APBCLK |= CLK_APBCLK_UART_EN_Msk; // UART Clock Enable

  43.     /* Select IP clock source */
  44.     CLK->CLKSEL1 &= ~CLK_CLKSEL1_UART_S_Msk;
  45.     CLK->CLKSEL1 |= (0x0 << CLK_CLKSEL1_UART_S_Pos);// Clock source from external 12 MHz or 32 KHz crystal clock

  46.     /* Update System Core Clock */
  47.     /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
  48.     SystemCoreClockUpdate();

  49.     /*---------------------------------------------------------------------------------------------------------*/
  50.     /* Init I/O Multi-function                                                                                 */
  51.     /*---------------------------------------------------------------------------------------------------------*/
  52.     /* Set P1 multi-function pins for UART RXD and TXD  */
  53.     SYS->P0_MFP &= ~(SYS_MFP_P00_Msk | SYS_MFP_P01_Msk);
  54.     SYS->P0_MFP = SYS_MFP_P00_TXD | SYS_MFP_P01_RXD;

  55.     /* Lock protected registers */
  56.     SYS_LockReg();

  57. }

  58. void UART_Init()
  59. {
  60.     /*---------------------------------------------------------------------------------------------------------*/
  61.     /* Init UART                                                                                               */
  62.     /*---------------------------------------------------------------------------------------------------------*/
  63.     UART_Open(UART, 115200);
  64. }

  65. /*---------------------------------------------------------------------------------------------------------*/
  66. /* MAIN function                                                                                           */
  67. /*---------------------------------------------------------------------------------------------------------*/

  68. int main(void)
  69. {
  70.     char *tmp = 0;

  71.     /* Init System, IP clock and multi-function I/O */
  72.     SYS_Init();
  73.     /* Init UART for printf */
  74.     UART_Init();

  75.     strcpy(tmp,"HardFaultTest");

  76.     while(1);

  77. }






 楼主| jiekou001 发表于 2018-10-26 23:55 | 显示全部楼层
有朋友能看懂怎么回事吗
643757107 发表于 2018-10-27 00:02 | 显示全部楼层
将字符串拷贝到指定的地址,不懂。s
mintspring 发表于 2018-10-27 00:07 | 显示全部楼层
字符串拷贝操作
huangcunxiake 发表于 2018-10-28 13:10 | 显示全部楼层
看头文件啊,C的标准库而已,拷贝字符串到指定地址。
huangcunxiake 发表于 2018-10-28 13:11 | 显示全部楼层
不过这个程序的主题,感觉跟这个对不上号,莫非是敲代码的不会,耍滑头了?
xinxianshi 发表于 2018-10-28 22:59 | 显示全部楼层
一个简单的操作。
 楼主| jiekou001 发表于 2018-11-15 10:35 | 显示全部楼层
还是不懂啊,一个拷贝的程序,怎么说是硬件错误测试
tuoxieshu 发表于 2018-11-19 21:57 来自手机 | 显示全部楼层
strcpy 不检查拷贝前后的地址是否越界,这里定义了一个空指针没有为它申请内存,所以会导致未知错误。
huangcunxiake 发表于 2018-11-20 23:40 | 显示全部楼层
楼上高人啊,原来是指针为空,导致拷贝时候找不到真实地址,发生错误
huangcunxiake 发表于 2018-11-20 23:49 | 显示全部楼层
  1. int add(int a , int b)
  2. {
  3.     return a + b;
  4. }

  5. int main(void)
  6. {
  7.     int num = 97;
  8.     float score = 10.00F;
  9.     int arr[3] = {1,2,3};

  10.     //-----------------------

  11.     int* p_num = &num;
  12.     float* p_score = &score;
  13.     int (*p_arr)[3] = &arr;           
  14.     int (*fp_add)(int ,int )  = add;  //p_add是指向函数add的函数指针
  15.     return 0;
  16. }


指针的正确操作,那个本来要给个地址的,结果给的是个0,所以就后面出错了。
huangcunxiake 发表于 2018-11-20 23:50 | 显示全部楼层
而地址0,肯定会已经填充了重要内容,如果这个时候破坏肯定就发生错误了
tuoxieshu 发表于 2018-11-21 17:38 来自手机 | 显示全部楼层
huangcunxiake 发表于 2018-11-20 23:50
而地址0,肯定会已经填充了重要内容,如果这个时候破坏肯定就发生错误了

对头☺️
您需要登录后才可以回帖 登录 | 注册

本版积分规则

147

主题

1539

帖子

2

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