本帖最后由 比神乐 于 2022-12-4 11:40 编辑
今天捣鼓了一下USB实验:
代码:
- #include <stddef.h> // Defines NULL
- #include <stdbool.h> // Defines true
- #include <stdlib.h> // Defines EXIT_FAILURE
- #include "definitions.h" // SYS function prototypes
- // *****************************************************************************
- // *****************************************************************************
- // Section: Main Entry Point
- // *****************************************************************************
- // *****************************************************************************
- int main ( void )
- {
- /* Initialize all modules */
- SYS_Initialize ( NULL );
- while ( true )
- {
- /* Maintain state machines of all polled MPLAB Harmony modules. */
- SYS_Tasks ( );
- }
- /* Execution should not come here during normal operation */
- return ( EXIT_FAILURE );
- }
- /*******************************************************************************
- End of File
- */
APP.C
- /*******************************************************************************
- MPLAB Harmony Application Source File
- Company:
- Microchip Technology Inc.
- File Name:
- app.c
- Summary:
- This file contains the source code for the MPLAB Harmony application.
- Description:
- This file contains the source code for the MPLAB Harmony application. It
- implements the logic of the application's state machine and it may call
- API routines of other MPLAB Harmony modules in the system, such as drivers,
- system services, and middleware. However, it does not call any of the
- system interfaces (such as the "Initialize" and "Tasks" functions) of any of
- the modules in the system or make any assumptions about when those functions
- are called. That is the responsibility of the configuration-specific system
- files.
- *******************************************************************************/
-
- /*******************************************************************************
- * Copyright (C) 2020 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.
- *******************************************************************************/
- // *****************************************************************************
- // *****************************************************************************
- // Section: Included Files
- // *****************************************************************************
- // *****************************************************************************
- #include "app.h"
- #include "definitions.h"
- // *****************************************************************************
- // *****************************************************************************
- // Section: Global Data Definitions
- // *****************************************************************************
- // *****************************************************************************
- // *****************************************************************************
- /* Application Data
- Summary:
- Holds application data
- Description:
- This structure holds the application's data.
- Remarks:
- This structure should be initialized by the APP_Initialize function.
- Application strings and buffers are be defined outside this structure.
- */
- APP_DATA appData;
- // *****************************************************************************
- // *****************************************************************************
- // Section: Application Callback Functions
- // *****************************************************************************
- // *****************************************************************************
- /* TODO: Add any necessary callback functions.
- */
- // *****************************************************************************
- // *****************************************************************************
- // Section: Application Local Functions
- // *****************************************************************************
- // *****************************************************************************
- #define BTL_TRIGGER_PATTERN (0x5048434DUL)
- static uint32_t *ramStart = (uint32_t *)BTL_TRIGGER_RAM_START;
- bool bootloader_Trigger(void)
- {
- uint32_t i;
- // Cheap delay. This should give at leat 1 ms delay.
- for (i = 0; i < 2000; i++)
- {
- asm("nop");
- }
- /* Check for Bootloader Trigger Pattern in first 16 Bytes of RAM to enter
- * Bootloader.
- */
- if (BTL_TRIGGER_PATTERN == ramStart[0] && BTL_TRIGGER_PATTERN == ramStart[1] &&
- BTL_TRIGGER_PATTERN == ramStart[2] && BTL_TRIGGER_PATTERN == ramStart[3])
- {
- ramStart[0] = 0;
- DCACHE_CLEAN_BY_ADDR(ramStart, 4);
- return true;
- }
- /* Check for Switch press to enter Bootloader */
- if (SWITCH_GET() == SWITCH_PRESSED)
- {
- return true;
- }
- return false;
- }
- // *****************************************************************************
- // *****************************************************************************
- // Section: Application Initialization and State Machine Functions
- // *****************************************************************************
- // *****************************************************************************
- /*******************************************************************************
- Function:
- void APP_Initialize ( void )
- Remarks:
- See prototype in app.h.
- */
- void APP_Initialize ( void )
- {
- /* Place the App state machine in its initial state. */
- appData.state = APP_STATE_INIT;
- }
- /******************************************************************************
- Function:
- void APP_Tasks ( void )
- Remarks:
- See prototype in app.h.
- */
- void APP_Tasks ( void )
- {
- /* Check the application's current state. */
- switch ( appData.state )
- {
- /* Application's initial state. */
- case APP_STATE_INIT:
- {
- LED_ON();
- break;
- }
- /* The default state should never be executed. */
- default:
- {
- /* TODO: Handle error in application's state machine. */
- break;
- }
- }
- }
- /*******************************************************************************
- End of File
- */
下载了一个USB BUS HOUND
安装以后打开
不接板子显示:
接上板子显示
选择USB MASS Storage Device
点击send commands命令按钮
点击运行按钮:
选择第三项 5 Bulk in,点击运行按钮
|