[PIC32/SAM] ATSAMD51 EVK评估板评测3串口发送

[复制链接]
681|5
 楼主| 比神乐 发表于 2022-12-3 15:29 | 显示全部楼层 |阅读模式
今天装了MPLABX和XC32编译器,搞了个串口发送的程序。
代码:
  1. /*******************************************************************************
  2. * Copyright (C) 2019 Microchip Technology Inc. and its subsidiaries.
  3. *
  4. * Subject to your compliance with these terms, you may use Microchip software
  5. * and any derivatives exclusively with Microchip products. It is your
  6. * responsibility to comply with third party license terms applicable to your
  7. * use of third party software (including open source software) that may
  8. * accompany Microchip software.
  9. *
  10. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
  11. * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
  12. * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
  13. * PARTICULAR PURPOSE.
  14. *
  15. * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
  16. * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
  17. * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
  18. * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
  19. * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
  20. * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  21. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  22. *******************************************************************************/

  23. /*******************************************************************************
  24.   Main Source File

  25.   Company:
  26.     Microchip Technology Inc.

  27.   File Name:
  28.     main.c

  29.   Summary:
  30.     This file contains the "main" function for a project.

  31.   Description:
  32.     This file contains the "main" function for a project.  The
  33.     "main" function calls the "SYS_Initialize" function to initialize the state
  34.     machines of all modules in the system
  35. *******************************************************************************/

  36. // *****************************************************************************
  37. // *****************************************************************************
  38. // Section: Included Files
  39. // *****************************************************************************
  40. // *****************************************************************************

  41. #include <stddef.h>                     // Defines NULL
  42. #include <stdbool.h>                    // Defines true
  43. #include <stdlib.h>                     // Defines EXIT_FAILURE
  44. #include "definitions.h"                // SYS function prototypes
  45. #include <string.h>

  46. #define LED_ON                      LED_Clear
  47. #define LED_OFF                     LED_Set
  48. #define LED_TOGGLE                  LED_Toggle

  49. /* Define the NVMCTRL_SEESBLK_MASK_BITS to extract the NVMCTRL_SEESBLK bits(35:32) from NVM User Page Mapping(0x00804000) */
  50. #define NVMCTRL_SEESBLK_MASK_BITS   0x0F

  51. /* Define the NVMCTRL_SEEPSZ_MASK_BITS to extract the NVMCTRL_SEEPSZ bits(38:36) from NVM User Page Mapping(0x00804000) */
  52. #define NVMCTRL_SEEPSZ_MASK_BITS    0x07

  53. /* A specific byte pattern stored at the begining of SmartEEPROM data area.
  54. * When the application comes from a reset, if it finds this signature,
  55. * the assumption is that the SmartEEPROM has some valid data.
  56. */
  57. #define SMEE_CUSTOM_SIG         0x5a5a5a5a

  58. /* Define the number of bytes to be read when a read request comes */
  59. #define MAX_BUFF_SIZE          256

  60. /* The application toggles SmartEEPROM data at the following address
  61. * each time the device is reset. This address must be within the total
  62. * number of EEPROM data bytes ( Defined by SBLK and PSZ fuse values).
  63. */
  64. #define SEEP_TEST_ADDR          32

  65. /* This example demo assumes fuses SBLK = 1 and PSZ = 3, thus total size is 4096 bytes */
  66. #define SEEP_FINAL_BYTE_INDEX   4095

  67. /* Define a pointer to access SmartEEPROM as bytes */
  68. uint8_t *SmartEEPROM8       = (uint8_t *)SEEPROM_ADDR;

  69. /* Define a pointer to access SmartEEPROM as words (32-bits) */
  70. uint32_t *SmartEEPROM32     = (uint32_t *)SEEPROM_ADDR;

  71. uint8_t menu[]              = "\r\n******** uart send test ******** \r\n";
  72. typedef enum {ReadSmartEEPROM = '1', WriteSmartEEPROM = '2', ResetDevice = '3', NoSelection = 0} MenuOptions;
  73. uint8_t data_8;
  74. uint8_t eeprom_data_buffer[MAX_BUFF_SIZE] = {0};


  75. /**
  76. * \brief Invert a byte in SmartEEPROM
  77. *
  78. * To invert the data at the given index in SmartEEPROM
  79. */
  80. void invert_seep_byte(uint8_t index)
  81. {
  82.         /* Wait till the SmartEEPROM is free */
  83.         while (NVMCTRL_SmartEEPROM_IsBusy());

  84.         /* Read the data, invert it, and write it back */
  85.         data_8              = SmartEEPROM8[index];
  86.         printf("\r\nData at test address %d is = %d\r\n", index, (int)data_8);
  87.         SmartEEPROM8[index] = !data_8;
  88.         printf("\r\nInverted the data at test address and written\r\n");
  89. }

  90. /**
  91. * \brief Verify the custom data in SmartEEPROM
  92. *
  93. * Verify the custom data at initial 4 bytes of SmartEEPROM
  94. */
  95. int8_t verify_seep_signature(void)
  96. {
  97.     uint32_t        NVMCTRL_SEESBLK_FuseConfig    = ((*(uint32_t *)(USER_PAGE_ADDR + 4)) >> 0) & NVMCTRL_SEESBLK_MASK_BITS;
  98.         int8_t          ret_val                       = 0;

  99.         /* If SBLK fuse is not configured, inform the user and wait here */
  100.         if (!NVMCTRL_SEESBLK_FuseConfig)
  101.     {
  102.                 printf("\r\nPlease configure SBLK fuse to allocate SmartEEPROM area\r\n");
  103.                 while (1);
  104.         }

  105.         if (SMEE_CUSTOM_SIG != SmartEEPROM32[0])
  106.     {
  107.                 ret_val = 0x4;
  108.         }

  109.         return ret_val;
  110. }

  111. /**
  112. * \brief Print a buffer as hex values
  113. *
  114. * Print a given array as a hex values
  115. */
  116. void print_hex_array(void *mem, uint16_t len)
  117. {
  118.         unsigned char *p = (unsigned char *)mem;

  119.         for(uint32_t i = 0; i < len; i++)
  120.     {
  121.                 if ((i != 0) && (!(i & 0x7)))
  122.         {
  123.                         printf("\r\n");
  124.         }
  125.                 printf("%03d ", p[i]);
  126.         }
  127.         printf("\r\n");
  128. }

  129. // *****************************************************************************
  130. // *****************************************************************************
  131. // Section: Main Entry Point
  132. // *****************************************************************************
  133. // *****************************************************************************

  134. int main ( void )
  135. {
  136.     //uint32_t    NVMCTRL_SEESBLK_FuseConfig  = ((*(uint32_t *)(USER_PAGE_ADDR + 4)) >> 0) & NVMCTRL_SEESBLK_MASK_BITS;
  137.     //uint32_t    NVMCTRL_SEEPSZ_FuseConfig   = ((*(uint32_t *)(USER_PAGE_ADDR + 4)) >> 4) & NVMCTRL_SEEPSZ_MASK_BITS;
  138.         //MenuOptions user_selection              = NoSelection;
  139.     uint32_t    i=0;
  140. //        uint32_t    num_of_bytes_to_read        = 0;
  141. //        uint32_t    eeprom_data                 = 0;
  142. //        uint32_t    eeprom_addr                 = 0;
  143. //        uint32_t    eeprom_data_buf_start_index = 0;
  144.     long int temp=0;
  145.     /* Initialize all modules */
  146.     // <editor-fold defaultstate="collapsed" desc="comment">
  147.     SYS_Initialize( NULL );

  148.        
  149.        
  150.        
  151.     printf("%s", menu);
  152.     while ( true )
  153.     {
  154.                
  155.         printf("temp=%ld\r\n",temp);
  156.                 temp++;
  157.         for(i=0;i<50000000;i++);
  158.                
  159.     }

  160.     /* Execution should not come here during normal operation */

  161.     return ( EXIT_FAILURE );
  162. }


  163. /*******************************************************************************
  164. End of File
  165. */

效果图:

另外说明一下,我装的是MPLABX IDE V5.30,需要设置一下才能下载程序。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
chenjun89 发表于 2022-12-3 18:11 来自手机 | 显示全部楼层
听说V5.3版本不好用?
 楼主| 比神乐 发表于 2022-12-4 08:47 | 显示全部楼层
chenjun89 发表于 2022-12-3 18:11
听说V5.3版本不好用?

感觉还行,V5.4版没用过
 楼主| 比神乐 发表于 2022-12-4 08:47 | 显示全部楼层
chenjun89 发表于 2022-12-3 18:11
听说V5.3版本不好用?

感觉还行,V5.4版没用过
 楼主| 比神乐 发表于 2022-12-4 08:48 | 显示全部楼层
感觉还行,V5.4版没用过
 楼主| 比神乐 发表于 2022-12-4 08:48 | 显示全部楼层
怎么回复了两遍,网络有问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则

470

主题

3537

帖子

7

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