打印
[PIC32/SAM]

ATSAMD51 EVK评估板评测3串口发送

[复制链接]
443|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
今天装了MPLABX和XC32编译器,搞了个串口发送的程序。
代码:
/*******************************************************************************
* Copyright (C) 2019 Microchip Technology Inc. and its subsidiaries.
*
* Subject to your compliance with these terms, you may use Microchip software
* and any derivatives exclusively with Microchip products. It is your
* responsibility to comply with third party license terms applicable to your
* use of third party software (including open source software) that may
* accompany Microchip software.
*
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
* FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
* ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*******************************************************************************/

/*******************************************************************************
  Main Source File

  Company:
    Microchip Technology Inc.

  File Name:
    main.c

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

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

// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************

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

#define LED_ON                      LED_Clear
#define LED_OFF                     LED_Set
#define LED_TOGGLE                  LED_Toggle

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

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

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

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

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

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

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

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

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


/**
* \brief Invert a byte in SmartEEPROM
*
* To invert the data at the given index in SmartEEPROM
*/
void invert_seep_byte(uint8_t index)
{
        /* Wait till the SmartEEPROM is free */
        while (NVMCTRL_SmartEEPROM_IsBusy());

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

/**
* \brief Verify the custom data in SmartEEPROM
*
* Verify the custom data at initial 4 bytes of SmartEEPROM
*/
int8_t verify_seep_signature(void)
{
    uint32_t        NVMCTRL_SEESBLK_FuseConfig    = ((*(uint32_t *)(USER_PAGE_ADDR + 4)) >> 0) & NVMCTRL_SEESBLK_MASK_BITS;
        int8_t          ret_val                       = 0;

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

        if (SMEE_CUSTOM_SIG != SmartEEPROM32[0])
    {
                ret_val = 0x4;
        }

        return ret_val;
}

/**
* \brief Print a buffer as hex values
*
* Print a given array as a hex values
*/
void print_hex_array(void *mem, uint16_t len)
{
        unsigned char *p = (unsigned char *)mem;

        for(uint32_t i = 0; i < len; i++)
    {
                if ((i != 0) && (!(i & 0x7)))
        {
                        printf("\r\n");
        }
                printf("%03d ", p[i]);
        }
        printf("\r\n");
}

// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************

int main ( void )
{
    //uint32_t    NVMCTRL_SEESBLK_FuseConfig  = ((*(uint32_t *)(USER_PAGE_ADDR + 4)) >> 0) & NVMCTRL_SEESBLK_MASK_BITS;
    //uint32_t    NVMCTRL_SEEPSZ_FuseConfig   = ((*(uint32_t *)(USER_PAGE_ADDR + 4)) >> 4) & NVMCTRL_SEEPSZ_MASK_BITS;
        //MenuOptions user_selection              = NoSelection;
    uint32_t    i=0;
//        uint32_t    num_of_bytes_to_read        = 0;
//        uint32_t    eeprom_data                 = 0;
//        uint32_t    eeprom_addr                 = 0;
//        uint32_t    eeprom_data_buf_start_index = 0;
    long int temp=0;
    /* Initialize all modules */
    // <editor-fold defaultstate="collapsed" desc="comment">
    SYS_Initialize( NULL );

       
       
       
    printf("%s", menu);
    while ( true )
    {
               
        printf("temp=%ld\r\n",temp);
                temp++;
        for(i=0;i<50000000;i++);
               
    }

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

    return ( EXIT_FAILURE );
}


/*******************************************************************************
End of File
*/

效果图:

另外说明一下,我装的是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版没用过

使用特权

评论回复
5
比神乐|  楼主 | 2022-12-4 08:48 | 只看该作者
感觉还行,V5.4版没用过

使用特权

评论回复
6
比神乐|  楼主 | 2022-12-4 08:48 | 只看该作者
怎么回复了两遍,网络有问题

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

438

主题

3433

帖子

7

粉丝