[PIC32/SAM] ATSAMD51 EVK评估板评测5USB实验

[复制链接]
1577|24
 楼主| 比神乐 发表于 2022-12-4 10:31 | 显示全部楼层 |阅读模式
本帖最后由 比神乐 于 2022-12-4 11:40 编辑

今天捣鼓了一下USB实验:
代码:
  1. #include <stddef.h>                     // Defines NULL
  2. #include <stdbool.h>                    // Defines true
  3. #include <stdlib.h>                     // Defines EXIT_FAILURE
  4. #include "definitions.h"                // SYS function prototypes


  5. // *****************************************************************************
  6. // *****************************************************************************
  7. // Section: Main Entry Point
  8. // *****************************************************************************
  9. // *****************************************************************************

  10. int main ( void )
  11. {
  12.     /* Initialize all modules */
  13.     SYS_Initialize ( NULL );

  14.     while ( true )
  15.     {
  16.         /* Maintain state machines of all polled MPLAB Harmony modules. */
  17.         SYS_Tasks ( );
  18.     }

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

  20.     return ( EXIT_FAILURE );
  21. }


  22. /*******************************************************************************
  23. End of File
  24. */

APP.C
  1. /*******************************************************************************
  2.   MPLAB Harmony Application Source File

  3.   Company:
  4.     Microchip Technology Inc.

  5.   File Name:
  6.     app.c

  7.   Summary:
  8.     This file contains the source code for the MPLAB Harmony application.

  9.   Description:
  10.     This file contains the source code for the MPLAB Harmony application.  It
  11.     implements the logic of the application's state machine and it may call
  12.     API routines of other MPLAB Harmony modules in the system, such as drivers,
  13.     system services, and middleware.  However, it does not call any of the
  14.     system interfaces (such as the "Initialize" and "Tasks" functions) of any of
  15.     the modules in the system or make any assumptions about when those functions
  16.     are called.  That is the responsibility of the configuration-specific system
  17.     files.
  18. *******************************************************************************/

  19. /*******************************************************************************
  20. * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries.
  21. *
  22. * Subject to your compliance with these terms, you may use Microchip software
  23. * and any derivatives exclusively with Microchip products. It is your
  24. * responsibility to comply with third party license terms applicable to your
  25. * use of third party software (including open source software) that may
  26. * accompany Microchip software.
  27. *
  28. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
  29. * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
  30. * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
  31. * PARTICULAR PURPOSE.
  32. *
  33. * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
  34. * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
  35. * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
  36. * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
  37. * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
  38. * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  39. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  40. *******************************************************************************/

  41. // *****************************************************************************
  42. // *****************************************************************************
  43. // Section: Included Files
  44. // *****************************************************************************
  45. // *****************************************************************************

  46. #include "app.h"
  47. #include "definitions.h"

  48. // *****************************************************************************
  49. // *****************************************************************************
  50. // Section: Global Data Definitions
  51. // *****************************************************************************
  52. // *****************************************************************************

  53. // *****************************************************************************
  54. /* Application Data

  55.   Summary:
  56.     Holds application data

  57.   Description:
  58.     This structure holds the application's data.

  59.   Remarks:
  60.     This structure should be initialized by the APP_Initialize function.

  61.     Application strings and buffers are be defined outside this structure.
  62. */

  63. APP_DATA appData;

  64. // *****************************************************************************
  65. // *****************************************************************************
  66. // Section: Application Callback Functions
  67. // *****************************************************************************
  68. // *****************************************************************************

  69. /* TODO:  Add any necessary callback functions.
  70. */

  71. // *****************************************************************************
  72. // *****************************************************************************
  73. // Section: Application Local Functions
  74. // *****************************************************************************
  75. // *****************************************************************************

  76. #define BTL_TRIGGER_PATTERN (0x5048434DUL)

  77. static uint32_t *ramStart = (uint32_t *)BTL_TRIGGER_RAM_START;

  78. bool bootloader_Trigger(void)
  79. {
  80.     uint32_t i;

  81.     // Cheap delay. This should give at leat 1 ms delay.
  82.     for (i = 0; i < 2000; i++)
  83.     {
  84.         asm("nop");
  85.     }

  86.     /* Check for Bootloader Trigger Pattern in first 16 Bytes of RAM to enter
  87.      * Bootloader.
  88.      */
  89.     if (BTL_TRIGGER_PATTERN == ramStart[0] && BTL_TRIGGER_PATTERN == ramStart[1] &&
  90.         BTL_TRIGGER_PATTERN == ramStart[2] && BTL_TRIGGER_PATTERN == ramStart[3])
  91.     {
  92.         ramStart[0] = 0;

  93.         DCACHE_CLEAN_BY_ADDR(ramStart, 4);

  94.         return true;
  95.     }

  96.     /* Check for Switch press to enter Bootloader */
  97.     if (SWITCH_GET() == SWITCH_PRESSED)
  98.     {
  99.         return true;
  100.     }

  101.     return false;
  102. }


  103. // *****************************************************************************
  104. // *****************************************************************************
  105. // Section: Application Initialization and State Machine Functions
  106. // *****************************************************************************
  107. // *****************************************************************************

  108. /*******************************************************************************
  109.   Function:
  110.     void APP_Initialize ( void )

  111.   Remarks:
  112.     See prototype in app.h.
  113. */

  114. void APP_Initialize ( void )
  115. {
  116.     /* Place the App state machine in its initial state. */
  117.     appData.state = APP_STATE_INIT;

  118. }


  119. /******************************************************************************
  120.   Function:
  121.     void APP_Tasks ( void )

  122.   Remarks:
  123.     See prototype in app.h.
  124. */

  125. void APP_Tasks ( void )
  126. {

  127.     /* Check the application's current state. */
  128.     switch ( appData.state )
  129.     {
  130.         /* Application's initial state. */
  131.         case APP_STATE_INIT:
  132.         {
  133.             LED_ON();
  134.             break;
  135.         }

  136.         /* The default state should never be executed. */
  137.         default:
  138.         {
  139.             /* TODO: Handle error in application's state machine. */
  140.             break;
  141.         }
  142.     }
  143. }


  144. /*******************************************************************************
  145. End of File
  146. */
下载了一个USB BUS HOUND
安装以后打开
不接板子显示:

接上板子显示

选择USB MASS Storage Device
点击send commands命令按钮

点击运行按钮:

选择第三项 5  Bulk in,点击运行按钮


本帖子中包含更多资源

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

×
wangjiahao88 发表于 2022-12-4 12:17 | 显示全部楼层
这种开发板 官方会搞活动领取吗?

SAME SAMD系列的
 楼主| 比神乐 发表于 2022-12-5 09:25 | 显示全部楼层
wangjiahao88 发表于 2022-12-4 12:17
这种开发板 官方会搞活动领取吗?

SAME SAMD系列的

好像可以
tpgf 发表于 2023-1-3 12:10 | 显示全部楼层
做usb试验的时候还需要安装相关底层的驱动吗
 楼主| 比神乐 发表于 2023-1-3 12:12 | 显示全部楼层
tpgf 发表于 2023-1-3 12:10
做usb试验的时候还需要安装相关底层的驱动吗

要下载一些文件包吧
qcliu 发表于 2023-1-3 12:51 | 显示全部楼层
如果电脑一直不能识别usb设备 那么一般来说是时序有问题是吗
drer 发表于 2023-1-3 13:36 | 显示全部楼层
如何设置才能保证usb设备支持热拔插呢
coshi 发表于 2023-1-3 13:42 | 显示全部楼层
wangjiahao88 发表于 2022-12-4 12:17
这种开发板 官方会搞活动领取吗?

SAME SAMD系列的

这种开发板说不好 但是官方经常性的会有一些申请活动
kxsi 发表于 2023-1-3 13:52 | 显示全部楼层
在什么情况下会导致就是一接上usb就让格式化呢
wiba 发表于 2023-1-3 14:09 | 显示全部楼层
带usb的功能的现成的开发板不知道会不会缩短上手时间
 楼主| 比神乐 发表于 2023-1-3 15:01 | 显示全部楼层
qcliu 发表于 2023-1-3 12:51
如果电脑一直不能识别usb设备 那么一般来说是时序有问题是吗

不好说,我搞USB也是二把刀
 楼主| 比神乐 发表于 2023-1-3 15:02 | 显示全部楼层
drer 发表于 2023-1-3 13:36
如何设置才能保证usb设备支持热拔插呢

不清楚,一般都支持热插拔吧
geraldbetty 发表于 2023-1-5 14:06 | 显示全部楼层
这个usb可以实现的功能就比较多了。
zerorobert 发表于 2023-1-5 16:37 | 显示全部楼层
现在对usb的开发还没有入门,需要学习一下的。
 楼主| 比神乐 发表于 2023-1-6 11:45 | 显示全部楼层
kxsi 发表于 2023-1-3 13:52
在什么情况下会导致就是一接上usb就让格式化呢

不清楚,程序有问题吧
jackcat 发表于 2023-1-6 20:53 | 显示全部楼层
ATSAMD51有几个端点可以识别?
 楼主| 比神乐 发表于 2023-1-7 10:54 | 显示全部楼层
jackcat 发表于 2023-1-6 20:53
ATSAMD51有几个端点可以识别?

不清楚
mollylawrence 发表于 2023-1-9 14:21 | 显示全部楼层
需要开发电脑的驱动程序的吗?              
 楼主| 比神乐 发表于 2023-1-9 14:54 | 显示全部楼层
mollylawrence 发表于 2023-1-9 14:21
需要开发电脑的驱动程序的吗?

不需要
cashrwood 发表于 2023-1-11 22:37 | 显示全部楼层
官网提供的usb代码吗?
              
您需要登录后才可以回帖 登录 | 注册

本版积分规则

470

主题

3537

帖子

7

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