mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-15 21:40:18 +00:00
Merge remote-tracking branch 'origin' into msp430f5529
This commit is contained in:
commit
5ee1070c16
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,3 +15,7 @@ latex
|
||||
test_old/
|
||||
tests_obsolete/
|
||||
_build
|
||||
# coverity intermediate files
|
||||
cov-int
|
||||
# cppcheck build directories
|
||||
*-build-dir
|
||||
|
@ -1,5 +1,5 @@
|
||||
language: c
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
|
26
README.md
26
README.md
@ -21,6 +21,17 @@ TinyUSB is an open-source cross-platform USB Host/Device stack for embedded syst
|
||||
└── tools # Files used internally
|
||||
```
|
||||
|
||||
## Supported MCUs
|
||||
|
||||
The stack supports the following MCUs
|
||||
|
||||
- **Nordic:** nRF52840
|
||||
- **NXP:** LPC Series: 11Uxx, 13xx, 175x_6x, 177x_8x, 18xx, 40xx, 43xx, 51Uxx
|
||||
- **MicroChip:** SAMD21, SAMD51 (device only)
|
||||
- **ST:** STM32 series: L0, F0, F1, F2, F3, F4, F7, H7 (device only)
|
||||
|
||||
[Here is the list of supported Boards](docs/boards.md) that can be used with provided examples.
|
||||
|
||||
## Device Stack
|
||||
|
||||
Support multiple device configurations by dynamically changing usb descriptors. Low power functions such as suspend, resume and remote wakeup. Following device classes are supported:
|
||||
@ -42,23 +53,12 @@ Support multiple device configurations by dynamically changing usb descriptors.
|
||||
|
||||
## OS Abtraction layer
|
||||
|
||||
Currently the following OS are supported with tinyusb out of the box with a simple change of **CFG_TUSB_OS** macro.
|
||||
TinyUSB is completely thread-safe by pushing all ISR events into a central queue, then process it later in the non-ISR context. It also uses semphore/mutex to access shared resource such as CDC FIFO. Therefore the stack needs to use some of OS's basic APIs. Following OSes are already supported out of the box.
|
||||
|
||||
- **No OS**
|
||||
- **No OS** : Disabling USB IRQ is used as way to provide mutex
|
||||
- **FreeRTOS**
|
||||
- **Mynewt** Due to the newt package build system, Mynewt examples are better to be on its [own repo](https://github.com/hathach/mynewt-tinyusb-example)
|
||||
|
||||
## Supported MCUs
|
||||
|
||||
The stack supports the following MCUs
|
||||
|
||||
- **Nordic:** nRF52840
|
||||
- **NXP:** LPC11Uxx, LPC13xx, LPC175x_6x, LPC177x_8x, LPC18xx, LPC40xx, LPC43xx, LPC51Uxx
|
||||
- **MicroChip:** SAMD21, SAMD51 (device only)
|
||||
- **ST:** STM32F0, STM32F3, STM32F4, STM32F7, STM32H7 (device only)
|
||||
|
||||
[Here is the list of supported Boards](docs/boards.md)
|
||||
|
||||
## Compiler & IDE
|
||||
|
||||
The stack is developed with GCC compiler, and should be compilable with others. Folder `examples` provide Makefile and Segger Embedded Studio build support. [Here is instruction to build example](examples/readme.md).
|
||||
|
@ -9,6 +9,14 @@ The board support code is only used for self-contained examples and testing. It
|
||||
|
||||
This code base already had supported for a handful of following boards
|
||||
|
||||
### MicroChip SAMD
|
||||
|
||||
- [Adafruit Circuit Playground Express](https://www.adafruit.com/product/3333)
|
||||
- [Adafruit Feather M0 Express](https://www.adafruit.com/product/3403)
|
||||
- [Adafruit Metro M0 Express](https://www.adafruit.com/product/3505)
|
||||
- [Adafruit Feather M4 Express](https://www.adafruit.com/product/3857)
|
||||
- [Adafruit Metro M4 Express](https://www.adafruit.com/product/3382)
|
||||
|
||||
### Nordic nRF5x
|
||||
|
||||
- [Adafruit Feather nRF52840 Express](https://www.adafruit.com/product/4062)
|
||||
@ -31,24 +39,21 @@ This code base already had supported for a handful of following boards
|
||||
- [LPCXpresso 54114](https://www.nxp.com/design/microcontrollers-developer-resources/lpcxpresso-boards/lpcxpresso54114-board:OM13089)
|
||||
- [LPCXpresso 55s69 EVK](https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/lpc5500-cortex-m33/lpcxpresso55s69-development-board:LPC55S69-EVK)
|
||||
|
||||
### MicroChip SAMD
|
||||
|
||||
- [Adafruit Circuit Playground Express](https://www.adafruit.com/product/3333)
|
||||
- [Adafruit Feather M0 Express](https://www.adafruit.com/product/3403)
|
||||
- [Adafruit Metro M0 Express](https://www.adafruit.com/product/3505)
|
||||
- [Adafruit Feather M4 Express](https://www.adafruit.com/product/3857)
|
||||
- [Adafruit Metro M4 Express](https://www.adafruit.com/product/3382)
|
||||
|
||||
### ST STM32
|
||||
|
||||
- [STM32F070rb Nucleo](https://www.st.com/en/evaluation-tools/nucleo-f070rb.html)
|
||||
- [STM32F072rb Discovery](https://www.st.com/en/evaluation-tools/32f072bdiscovery.html)
|
||||
- [STM32F303vc Discovery](https://www.st.com/en/evaluation-tools/stm32f3discovery.html)
|
||||
- [STM32F407vg Discovery](https://www.st.com/en/evaluation-tools/stm32f4discovery.html)
|
||||
- [STM32F411ve Discovery](https://www.st.com/en/evaluation-tools/32f411ediscovery.html)
|
||||
- [STM32F412zg Discovery](https://www.st.com/en/evaluation-tools/32f412gdiscovery.html)
|
||||
- [Nucleo STM32F767zi](https://www.st.com/en/evaluation-tools/nucleo-f767zi.html)
|
||||
- [Nucleo H743zi](https://www.st.com/en/evaluation-tools/nucleo-h743zi.html)
|
||||
- Adafruit Feather STM32F405
|
||||
- [Micro Python PyBoard v1.1](https://store.micropython.org/product/PYBv1.1)
|
||||
- [STM32 L035c8 Discovery](https://www.st.com/en/evaluation-tools/32l0538discovery.html)
|
||||
- [STM32 F070rb Nucleo](https://www.st.com/en/evaluation-tools/nucleo-f070rb.html)
|
||||
- [STM32 F072rb Discovery](https://www.st.com/en/evaluation-tools/32f072bdiscovery.html)
|
||||
- STM32 F103c Blue Pill
|
||||
- [STM32 F207zg Nucleo](https://www.st.com/en/evaluation-tools/nucleo-f207zg.html)
|
||||
- [STM32 F303vc Discovery](https://www.st.com/en/evaluation-tools/stm32f3discovery.html)
|
||||
- [STM32 F407vg Discovery](https://www.st.com/en/evaluation-tools/stm32f4discovery.html)
|
||||
- [STM32 F411ve Discovery](https://www.st.com/en/evaluation-tools/32f411ediscovery.html)
|
||||
- [STM32 F412zg Discovery](https://www.st.com/en/evaluation-tools/32f412gdiscovery.html)
|
||||
- [STM32 F767zi Nucleo](https://www.st.com/en/evaluation-tools/nucleo-f767zi.html)
|
||||
- [STM32 H743zi Nucleo](https://www.st.com/en/evaluation-tools/nucleo-h743zi.html)
|
||||
|
||||
## Add your own board
|
||||
|
||||
|
36
docs/concurrency.md
Normal file
36
docs/concurrency.md
Normal file
@ -0,0 +1,36 @@
|
||||
# Concurrency
|
||||
|
||||
The TinyUSB library is designed to operate on single-core MCUs with multi-threaded applications in mind. Interaction with interrupts is especially important to pay attention to.
|
||||
It is compatible with optionally using a RTOS.
|
||||
|
||||
## General
|
||||
|
||||
When writing code, keep in mind that the OS (if using a RTOS) may swap out your code at any time. Also, your code can be preempted by an interrupt at any time.
|
||||
|
||||
## Application Code
|
||||
|
||||
The USB core does not execute application callbacks while in an interrupt context. Calls to application code are from within the USB core task context. Note that the application core will call class drivers from within their own task.
|
||||
|
||||
## Class Drivers
|
||||
|
||||
Class driver code should never be called from an interrupt context by the USB core, though the application is allowed to call class driver functions from interrupts. USB core functions may be called simultaneously by multiple tasks. Use care that proper locking is used to guard the USBD core functions from this case.
|
||||
|
||||
Class drivers are allowed to call `usbd_*` functions, but not `dcd_*` functions.
|
||||
|
||||
## USB Core
|
||||
|
||||
All functions that may be called from an (USB core) interrupt context have a `bool in_isr` parameter to remind the implementer that special care must be taken.
|
||||
|
||||
Interrupt handlers must not directly call class driver code, they must pass a message to the USB core's task.
|
||||
|
||||
`usbd_*` functions may be called from interrupts without any notice. They may also be called simultaneously by multiple tasks.
|
||||
|
||||
## Device Drivers
|
||||
|
||||
Much of the processing of the USB stack is done in an interrupt context, and care must be taken in order to ensure variables are handled in the appropriate ways by the compiler and optimizer.
|
||||
|
||||
In particular:
|
||||
|
||||
- Ensure that all memory-mapped registers (including packet memory) are marked as volatile. GCC's optimizer will even combine memory access (like two 16-bit to be a 32-bit) if you don't mark the pointers as volatile. On some architectures, this can use macros like `_I`, `_O`, or `_IO'.
|
||||
- All defined global variables are marked as `static`.
|
||||
|
12
examples/device/usbtmc/Makefile
Normal file
12
examples/device/usbtmc/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
include ../../../tools/top.mk
|
||||
include ../../make.mk
|
||||
|
||||
INC += \
|
||||
src \
|
||||
$(TOP)/hw \
|
||||
|
||||
# Example source
|
||||
EXAMPLE_SOURCE += $(wildcard src/*.c)
|
||||
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
|
||||
|
||||
include ../../rules.mk
|
143
examples/device/usbtmc/src/main.c
Normal file
143
examples/device/usbtmc/src/main.c
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bsp/board.h"
|
||||
#include "tusb.h"
|
||||
#include "usbtmc_app.h"
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/* Blink pattern
|
||||
* - 250 ms : device not mounted
|
||||
* - 0 ms : device mounted
|
||||
* - 2500 ms : device is suspended
|
||||
*/
|
||||
enum {
|
||||
BLINK_NOT_MOUNTED = 250,
|
||||
BLINK_MOUNTED = 0,
|
||||
BLINK_SUSPENDED = 2500,
|
||||
};
|
||||
|
||||
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||
|
||||
void led_blinking_task(void);
|
||||
|
||||
/*------------- MAIN -------------*/
|
||||
int main(void)
|
||||
{
|
||||
board_init();
|
||||
|
||||
tusb_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
tud_task(); // tinyusb device task
|
||||
led_blinking_task();
|
||||
usbtmc_app_task_iter();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Device callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when device is mounted
|
||||
void tud_mount_cb(void)
|
||||
{
|
||||
blink_interval_ms = BLINK_MOUNTED;
|
||||
}
|
||||
|
||||
// Invoked when device is unmounted
|
||||
void tud_umount_cb(void)
|
||||
{
|
||||
blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||
}
|
||||
|
||||
// Invoked when usb bus is suspended
|
||||
// remote_wakeup_en : if host allow us to perform remote wakeup
|
||||
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
|
||||
void tud_suspend_cb(bool remote_wakeup_en)
|
||||
{
|
||||
(void) remote_wakeup_en;
|
||||
blink_interval_ms = BLINK_SUSPENDED;
|
||||
}
|
||||
|
||||
// Invoked when usb bus is resumed
|
||||
void tud_resume_cb(void)
|
||||
{
|
||||
blink_interval_ms = BLINK_MOUNTED;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// BLINKING TASK + Indicator pulse
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
volatile uint8_t doPulse = false;
|
||||
// called from USB context
|
||||
void led_indicator_pulse(void) {
|
||||
doPulse = true;
|
||||
}
|
||||
|
||||
void led_blinking_task(void)
|
||||
{
|
||||
static uint32_t start_ms = 0;
|
||||
static bool led_state = false;
|
||||
if(blink_interval_ms == BLINK_MOUNTED) // Mounted
|
||||
{
|
||||
if(doPulse)
|
||||
{
|
||||
led_state = true;
|
||||
board_led_write(true);
|
||||
start_ms = board_millis();
|
||||
doPulse = false;
|
||||
}
|
||||
else if (led_state == true)
|
||||
{
|
||||
if ( board_millis() - start_ms < 750) //Spec says blink must be between 500 and 1000 ms.
|
||||
{
|
||||
return; // not enough time
|
||||
}
|
||||
led_state = false;
|
||||
board_led_write(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Blink every interval ms
|
||||
if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
|
||||
start_ms += blink_interval_ms;
|
||||
|
||||
board_led_write(led_state);
|
||||
led_state = 1 - led_state; // toggle
|
||||
}
|
||||
}
|
5
examples/device/usbtmc/src/main.h
Normal file
5
examples/device/usbtmc/src/main.h
Normal file
@ -0,0 +1,5 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
void led_indicator_pulse(void);
|
||||
|
||||
#endif
|
66
examples/device/usbtmc/src/tusb_config.h
Normal file
66
examples/device/usbtmc/src/tusb_config.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* tusb_config.h
|
||||
*
|
||||
* Created on: Sep 5, 2019
|
||||
* Author: nconrad
|
||||
*/
|
||||
|
||||
#ifndef TUSB_CONFIG_H_
|
||||
#define TUSB_CONFIG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// COMMON CONFIGURATION
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
// defined by compiler flags for flexibility
|
||||
#ifndef CFG_TUSB_MCU
|
||||
#error CFG_TUSB_MCU must be defined
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX
|
||||
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED)
|
||||
#else
|
||||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
|
||||
#endif
|
||||
|
||||
#define CFG_TUSB_OS OPT_OS_NONE
|
||||
|
||||
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
|
||||
// #define CFG_TUSB_DEBUG 0
|
||||
|
||||
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
|
||||
* Tinyusb use follows macros to declare transferring memory so that they can be put
|
||||
* into those specific section.
|
||||
* e.g
|
||||
* - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
|
||||
* - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
|
||||
*/
|
||||
#ifndef CFG_TUSB_MEM_SECTION
|
||||
#define CFG_TUSB_MEM_SECTION
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUSB_MEM_ALIGN
|
||||
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// DEVICE CONFIGURATION
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
#define CFG_TUD_ENDPOINT0_SIZE 64
|
||||
|
||||
//------------- CLASS -------------//
|
||||
|
||||
#define CFG_TUD_USBTMC 1
|
||||
#define CFG_TUD_USBTMC_ENABLE_INT_EP 1
|
||||
#define CFG_TUD_USBTMC_ENABLE_488 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TUSB_CONFIG_H_ */
|
252
examples/device/usbtmc/src/usb_descriptors.c
Normal file
252
examples/device/usbtmc/src/usb_descriptors.c
Normal file
@ -0,0 +1,252 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tusb.h"
|
||||
#include "class/usbtmc/usbtmc.h"
|
||||
#include "class/usbtmc/usbtmc_device.h"
|
||||
|
||||
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
|
||||
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
|
||||
*
|
||||
* Auto ProductID layout's Bitmap:
|
||||
* [MSB] HID | MSC | CDC [LSB]
|
||||
*/
|
||||
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
|
||||
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
|
||||
_PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_desc_device_t const desc_device =
|
||||
{
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = 0x0200,
|
||||
|
||||
#if CFG_TUD_CDC
|
||||
// Use Interface Association Descriptor (IAD) for CDC
|
||||
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
|
||||
.bDeviceClass = TUSB_CLASS_MISC,
|
||||
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
||||
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
||||
#else
|
||||
.bDeviceClass = 0x00,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
#endif
|
||||
|
||||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
||||
|
||||
.idVendor = 0xCafe,
|
||||
.idProduct = USB_PID,
|
||||
.bcdDevice = 0x0100,
|
||||
|
||||
.iManufacturer = 0x01,
|
||||
.iProduct = 0x02,
|
||||
.iSerialNumber = 0x03,
|
||||
|
||||
.bNumConfigurations = 0x01
|
||||
};
|
||||
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
return (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HID Report Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUD_HID
|
||||
|
||||
uint8_t const desc_hid_report[] =
|
||||
{
|
||||
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ),
|
||||
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), )
|
||||
};
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_hid_descriptor_report_cb(void)
|
||||
{
|
||||
return desc_hid_report;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if defined(CFG_TUD_USBTMC)
|
||||
|
||||
# define TUD_USBTMC_DESC_MAIN(_itfnum,_bNumEndpoints) \
|
||||
TUD_USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints, /*_stridx = */ 4u, TUD_USBTMC_PROTOCOL_USB488), \
|
||||
TUD_USBTMC_BULK_DESCRIPTORS(/* OUT = */0x01, /* IN = */ 0x81, /* packet size = */USBTMCD_MAX_PACKET_SIZE)
|
||||
|
||||
#if defined(CFG_TUD_USBTMC_ENABLE_INT_EP)
|
||||
// Interrupt endpoint should be 2 bytes on a FS USB link
|
||||
# define TUD_USBTMC_DESC(_itfnum) \
|
||||
TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3), \
|
||||
TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x82, /* epMaxSize = */ 2, /* bInterval = */16u )
|
||||
# define USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN + TUD_USBTMC_INT_DESCRIPTOR_LEN)
|
||||
|
||||
#else
|
||||
|
||||
# define USBTMC_DESC(_itfnum) \
|
||||
USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 2u)
|
||||
# define USBTMC_DESC_LEN (USBTMC_IF_DESCRIPTOR_LEN + USBTMC_BULK_DESCRIPTORS_LEN)
|
||||
|
||||
#endif /* CFG_TUD_USBTMC_ENABLE_INT_EP */
|
||||
|
||||
#else
|
||||
# define USBTMC_DESC_LEN (0)
|
||||
#endif /* CFG_TUD_USBTMC */
|
||||
|
||||
enum
|
||||
{
|
||||
#if CFG_TUD_CDC
|
||||
ITF_NUM_CDC = 0,
|
||||
ITF_NUM_CDC_DATA,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
ITF_NUM_MSC,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
ITF_NUM_HID,
|
||||
#endif
|
||||
#if CFG_TUD_USBTMC
|
||||
ITF_NUM_USBTMC,
|
||||
#endif
|
||||
ITF_NUM_TOTAL
|
||||
};
|
||||
|
||||
|
||||
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + \
|
||||
CFG_TUD_HID*TUD_HID_DESC_LEN + (CFG_TUD_USBTMC)*USBTMC_DESC_LEN)
|
||||
|
||||
#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
|
||||
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
|
||||
// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
|
||||
// Note: since CDC EP ( 1 & 2), HID (4) are spot-on, thus we only need to force
|
||||
// endpoint number for MSC to 5
|
||||
#define EPNUM_MSC 0x05
|
||||
#else
|
||||
#define EPNUM_MSC 0x03
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t const desc_configuration[] =
|
||||
{
|
||||
// Interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||
|
||||
#if CFG_TUD_CDC
|
||||
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 1, 0x81, 8, 0x02, 0x82, 64),
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_USBTMC
|
||||
TUD_USBTMC_DESC(ITF_NUM_USBTMC),
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
// Interface number, string index, EP Out & EP In address, EP size
|
||||
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC, 0x80 | EPNUM_MSC, (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HIGH_SPEED) ? 512 : 64),
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
|
||||
TUD_HID_DESCRIPTOR(ITF_NUM_HID, 6, HID_PROTOCOL_NONE, sizeof(desc_hid_report), 0x84, 16, 10)
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
||||
{
|
||||
(void) index; // for multiple configurations
|
||||
return desc_configuration;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// String Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// array of pointer to string descriptors
|
||||
char const* string_desc_arr [] =
|
||||
{
|
||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||
"TinyUSB", // 1: Manufacturer
|
||||
"TinyUSB Device", // 2: Product
|
||||
"123456", // 3: Serials, should use chip ID
|
||||
"TinyUSB USBTMC", // 4: USBTMC
|
||||
};
|
||||
|
||||
static uint16_t _desc_str[32];
|
||||
|
||||
// Invoked when received GET STRING DESCRIPTOR request
|
||||
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
|
||||
uint16_t const* tud_descriptor_string_cb(uint8_t index)
|
||||
{
|
||||
size_t chr_count;
|
||||
|
||||
if ( index == 0)
|
||||
{
|
||||
memcpy(&_desc_str[1], string_desc_arr[0], 2);
|
||||
chr_count = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert ASCII string into UTF-16
|
||||
|
||||
if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
|
||||
|
||||
const char* str = string_desc_arr[index];
|
||||
|
||||
// Cap at max char
|
||||
chr_count = strlen(str);
|
||||
if ( chr_count > 31 ) {
|
||||
chr_count = 31;
|
||||
}
|
||||
|
||||
for(uint8_t i=0; i<chr_count; i++)
|
||||
{
|
||||
_desc_str[1+i] = str[i];
|
||||
}
|
||||
}
|
||||
|
||||
// first byte is length (including header), second byte is string type
|
||||
_desc_str[0] = (uint16_t)((((uint16_t)TUSB_DESC_STRING) << 8 ) | (2u*chr_count + 2u));
|
||||
|
||||
return _desc_str;
|
||||
}
|
329
examples/device/usbtmc/src/usbtmc_app.c
Normal file
329
examples/device/usbtmc/src/usbtmc_app.c
Normal file
@ -0,0 +1,329 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Nathan Conrad
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <stdlib.h> /* atoi */
|
||||
#include "tusb.h"
|
||||
#include "bsp/board.h"
|
||||
#include "main.h"
|
||||
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
static usbtmc_response_capabilities_488_t const
|
||||
#else
|
||||
static usbtmc_response_capabilities_t const
|
||||
#endif
|
||||
tud_usbtmc_app_capabilities =
|
||||
{
|
||||
.USBTMC_status = USBTMC_STATUS_SUCCESS,
|
||||
.bcdUSBTMC = USBTMC_VERSION,
|
||||
.bmIntfcCapabilities =
|
||||
{
|
||||
.listenOnly = 0,
|
||||
.talkOnly = 0,
|
||||
.supportsIndicatorPulse = 1
|
||||
},
|
||||
.bmDevCapabilities = {
|
||||
.canEndBulkInOnTermChar = 0
|
||||
},
|
||||
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
.bcdUSB488 = USBTMC_488_VERSION,
|
||||
.bmIntfcCapabilities488 =
|
||||
{
|
||||
.supportsTrigger = 1,
|
||||
.supportsREN_GTL_LLO = 0,
|
||||
.is488_2 = 1
|
||||
},
|
||||
.bmDevCapabilities488 =
|
||||
{
|
||||
.SCPI = 1,
|
||||
.SR1 = 0,
|
||||
.RL1 = 0,
|
||||
.DT1 =0,
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#define IEEE4882_STB_QUESTIONABLE (0x08u)
|
||||
#define IEEE4882_STB_MAV (0x10u)
|
||||
#define IEEE4882_STB_SER (0x20u)
|
||||
#define IEEE4882_STB_SRQ (0x40u)
|
||||
|
||||
static const char idn[] = "TinyUSB,ModelNumber,SerialNumber,FirmwareVer123456\r\n";
|
||||
//static const char idn[] = "TinyUSB,ModelNumber,SerialNumber,FirmwareVer and a bunch of other text to make it longer than a packet, perhaps? lets make it three transfers...\n";
|
||||
static volatile uint8_t status;
|
||||
|
||||
// 0=not query, 1=queried, 2=delay,set(MAV), 3=delay 4=ready?
|
||||
// (to simulate delay)
|
||||
static volatile uint16_t queryState = 0;
|
||||
static volatile uint32_t queryDelayStart;
|
||||
static volatile uint32_t bulkInStarted;
|
||||
static volatile uint32_t idnQuery;
|
||||
|
||||
static uint32_t resp_delay = 125u; // Adjustable delay, to allow for better testing
|
||||
static size_t buffer_len;
|
||||
static size_t buffer_tx_ix; // for transmitting using multiple transfers
|
||||
static uint8_t buffer[225]; // A few packets long should be enough.
|
||||
|
||||
|
||||
static usbtmc_msg_dev_dep_msg_in_header_t rspMsg = {
|
||||
.bmTransferAttributes =
|
||||
{
|
||||
.EOM = 1,
|
||||
.UsingTermChar = 0
|
||||
}
|
||||
};
|
||||
|
||||
void tud_usbtmc_open_cb(uint8_t interface_id)
|
||||
{
|
||||
(void)interface_id;
|
||||
tud_usbtmc_start_bus_read();
|
||||
}
|
||||
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
usbtmc_response_capabilities_488_t const *
|
||||
#else
|
||||
usbtmc_response_capabilities_t const *
|
||||
#endif
|
||||
tud_usbtmc_get_capabilities_cb()
|
||||
{
|
||||
return &tud_usbtmc_app_capabilities;
|
||||
}
|
||||
|
||||
|
||||
bool tud_usbtmc_msg_trigger_cb(usbtmc_msg_generic_t* msg) {
|
||||
(void)msg;
|
||||
// Let trigger set the SRQ
|
||||
status |= IEEE4882_STB_SRQ;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_usbtmc_msgBulkOut_start_cb(usbtmc_msg_request_dev_dep_out const * msgHeader)
|
||||
{
|
||||
(void)msgHeader;
|
||||
buffer_len = 0;
|
||||
if(msgHeader->TransferSize > sizeof(buffer))
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_usbtmc_msg_data_cb(void *data, size_t len, bool transfer_complete)
|
||||
{
|
||||
// If transfer isn't finished, we just ignore it (for now)
|
||||
|
||||
if(len + buffer_len < sizeof(buffer))
|
||||
{
|
||||
memcpy(&(buffer[buffer_len]), data, len);
|
||||
buffer_len += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // buffer overflow!
|
||||
}
|
||||
queryState = transfer_complete;
|
||||
idnQuery = 0;
|
||||
|
||||
if(transfer_complete && (len >=4) && !strncasecmp("*idn?",data,4))
|
||||
{
|
||||
idnQuery = 1;
|
||||
}
|
||||
if(transfer_complete && !strncasecmp("delay ",data,5))
|
||||
{
|
||||
queryState = 0;
|
||||
int d = atoi((char*)data + 5);
|
||||
if(d > 10000)
|
||||
d = 10000;
|
||||
if(d<0)
|
||||
d=0;
|
||||
resp_delay = (uint32_t)d;
|
||||
}
|
||||
tud_usbtmc_start_bus_read();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_usbtmc_msgBulkIn_complete_cb()
|
||||
{
|
||||
if((buffer_tx_ix == buffer_len) || idnQuery) // done
|
||||
{
|
||||
status &= (uint8_t)~(IEEE4882_STB_MAV); // clear MAV
|
||||
queryState = 0;
|
||||
bulkInStarted = 0;
|
||||
buffer_tx_ix = 0;
|
||||
}
|
||||
tud_usbtmc_start_bus_read();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static unsigned int msgReqLen;
|
||||
|
||||
bool tud_usbtmc_msgBulkIn_request_cb(usbtmc_msg_request_dev_dep_in const * request)
|
||||
{
|
||||
rspMsg.header.MsgID = request->header.MsgID,
|
||||
rspMsg.header.bTag = request->header.bTag,
|
||||
rspMsg.header.bTagInverse = request->header.bTagInverse;
|
||||
msgReqLen = request->TransferSize;
|
||||
|
||||
#ifdef xDEBUG
|
||||
uart_tx_str_sync("MSG_IN_DATA: Requested!\r\n");
|
||||
#endif
|
||||
if(queryState == 0 || (buffer_tx_ix == 0))
|
||||
{
|
||||
TU_ASSERT(bulkInStarted == 0);
|
||||
bulkInStarted = 1;
|
||||
|
||||
// > If a USBTMC interface receives a Bulk-IN request prior to receiving a USBTMC command message
|
||||
// that expects a response, the device must NAK the request (*not stall*)
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t txlen = tu_min32(buffer_len-buffer_tx_ix,msgReqLen);
|
||||
tud_usbtmc_transmit_dev_msg_data(&buffer[buffer_tx_ix], txlen,
|
||||
(buffer_tx_ix+txlen) == buffer_len, false);
|
||||
buffer_tx_ix += txlen;
|
||||
}
|
||||
// Always return true indicating not to stall the EP.
|
||||
return true;
|
||||
}
|
||||
|
||||
void usbtmc_app_task_iter(void) {
|
||||
switch(queryState) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
queryDelayStart = board_millis();
|
||||
queryState = 2;
|
||||
break;
|
||||
case 2:
|
||||
if( (board_millis() - queryDelayStart) > resp_delay) {
|
||||
queryDelayStart = board_millis();
|
||||
queryState=3;
|
||||
status |= 0x10u; // MAV
|
||||
status |= 0x40u; // SRQ
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if( (board_millis() - queryDelayStart) > resp_delay) {
|
||||
queryState = 4;
|
||||
}
|
||||
break;
|
||||
case 4: // time to transmit;
|
||||
if(bulkInStarted && (buffer_tx_ix == 0)) {
|
||||
if(idnQuery)
|
||||
{
|
||||
tud_usbtmc_transmit_dev_msg_data(idn, tu_min32(sizeof(idn)-1,msgReqLen),true,false);
|
||||
queryState = 0;
|
||||
bulkInStarted = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer_tx_ix = tu_min32(buffer_len,msgReqLen);
|
||||
tud_usbtmc_transmit_dev_msg_data(buffer, buffer_tx_ix, buffer_tx_ix == buffer_len, false);
|
||||
}
|
||||
// MAV is cleared in the transfer complete callback.
|
||||
}
|
||||
break;
|
||||
default:
|
||||
TU_ASSERT(false,);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool tud_usbtmc_initiate_clear_cb(uint8_t *tmcResult)
|
||||
{
|
||||
*tmcResult = USBTMC_STATUS_SUCCESS;
|
||||
queryState = 0;
|
||||
bulkInStarted = false;
|
||||
status = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_usbtmc_check_clear_cb(usbtmc_get_clear_status_rsp_t *rsp)
|
||||
{
|
||||
queryState = 0;
|
||||
bulkInStarted = false;
|
||||
status = 0;
|
||||
buffer_tx_ix = 0u;
|
||||
buffer_len = 0u;
|
||||
rsp->USBTMC_status = USBTMC_STATUS_SUCCESS;
|
||||
rsp->bmClear.BulkInFifoBytes = 0u;
|
||||
return true;
|
||||
}
|
||||
bool tud_usbtmc_initiate_abort_bulk_in_cb(uint8_t *tmcResult)
|
||||
{
|
||||
bulkInStarted = 0;
|
||||
*tmcResult = USBTMC_STATUS_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
bool tud_usbtmc_check_abort_bulk_in_cb(usbtmc_check_abort_bulk_rsp_t *rsp)
|
||||
{
|
||||
(void)rsp;
|
||||
tud_usbtmc_start_bus_read();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tud_usbtmc_initiate_abort_bulk_out_cb(uint8_t *tmcResult)
|
||||
{
|
||||
*tmcResult = USBTMC_STATUS_SUCCESS;
|
||||
return true;
|
||||
|
||||
}
|
||||
bool tud_usbtmc_check_abort_bulk_out_cb(usbtmc_check_abort_bulk_rsp_t *rsp)
|
||||
{
|
||||
(void)rsp;
|
||||
tud_usbtmc_start_bus_read();
|
||||
return true;
|
||||
}
|
||||
|
||||
void tud_usbtmc_bulkIn_clearFeature_cb(void)
|
||||
{
|
||||
}
|
||||
void tud_usmtmc_bulkOut_clearFeature_cb(void)
|
||||
{
|
||||
tud_usbtmc_start_bus_read();
|
||||
}
|
||||
|
||||
// Return status byte, but put the transfer result status code in the rspResult argument.
|
||||
uint8_t tud_usbtmc_get_stb_cb(uint8_t *tmcResult)
|
||||
{
|
||||
uint8_t old_status = status;
|
||||
status = (uint8_t)(status & ~(IEEE4882_STB_SRQ)); // clear SRQ
|
||||
|
||||
*tmcResult = USBTMC_STATUS_SUCCESS;
|
||||
// Increment status so that we see different results on each read...
|
||||
|
||||
return old_status;
|
||||
}
|
||||
|
||||
bool tud_usbtmc_indicator_pulse_cb(tusb_control_request_t const * msg, uint8_t *tmcResult)
|
||||
{
|
||||
(void)msg;
|
||||
led_indicator_pulse();
|
||||
*tmcResult = USBTMC_STATUS_SUCCESS;
|
||||
return true;
|
||||
}
|
7
examples/device/usbtmc/src/usbtmc_app.h
Normal file
7
examples/device/usbtmc/src/usbtmc_app.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef USBTMC_APP_H
|
||||
#define USBTMC_APP_H
|
||||
|
||||
void usbtmc_app_task_iter(void);
|
||||
|
||||
#endif
|
209
examples/device/usbtmc/visaQuery.py
Normal file
209
examples/device/usbtmc/visaQuery.py
Normal file
@ -0,0 +1,209 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import visa
|
||||
import time
|
||||
import sys
|
||||
|
||||
|
||||
def test_idn():
|
||||
idn = inst.query("*idn?");
|
||||
assert (idn == "TinyUSB,ModelNumber,SerialNumber,FirmwareVer123456\r\n")
|
||||
assert (inst.is_4882_compliant)
|
||||
|
||||
def test_echo(m,n):
|
||||
longstr = "0123456789abcdefghijklmnopqrstuvwxyz" * 50
|
||||
t0 = time.monotonic()
|
||||
|
||||
#Next try echo from 1 to 175 characters (200 is max buffer size on DUT)
|
||||
for i in range(m,n):
|
||||
#print(i)
|
||||
x = longstr[0:i]
|
||||
xt = x + inst.write_termination
|
||||
y = inst.query(x)
|
||||
#print(x)
|
||||
#print (":".join("{:02x}".format(ord(c)) for c in xt))
|
||||
#print (":".join("{:02x}".format(ord(c)) for c in y))
|
||||
assert(xt == y), f"failed i={i}"
|
||||
#inst.read_stb();# Just to make USB logging easier by sending a control query (bad thing is that this made things slow)
|
||||
t = time.monotonic() - t0
|
||||
print(f" elapsed: {t:0.3} sec")
|
||||
|
||||
def test_trig():
|
||||
# clear SRQ
|
||||
inst.read_stb()
|
||||
assert (inst.read_stb() == 0)
|
||||
inst.assert_trigger()
|
||||
time.sleep(0.3) # SRQ may have some delay
|
||||
assert (inst.read_stb() & 0x40), "SRQ not set after 0.3 seconds"
|
||||
assert (inst.read_stb() == 0)
|
||||
|
||||
|
||||
def test_mav():
|
||||
inst.write("delay 50")
|
||||
inst.read_stb() # clear STB
|
||||
assert (inst.read_stb() == 0)
|
||||
inst.write("123")
|
||||
time.sleep(0.3)
|
||||
assert (inst.read_stb() & 0x10), "MAV not set after 0.5 seconds"
|
||||
|
||||
rsp = inst.read()
|
||||
assert(rsp == "123\r\n")
|
||||
|
||||
|
||||
def test_srq():
|
||||
assert (inst.read_stb() == 0)
|
||||
inst.write("123")
|
||||
|
||||
#inst.enable_event(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
|
||||
#waitrsp = inst.wait_on_event(visa.constants.VI_EVENT_SERVICE_REQ, 5000)
|
||||
#inst.discard_events(visa.constants.VI_EVENT_SERVICE_REQ, visa.constants.VI_QUEUE)
|
||||
#inst.wait_for_srq()
|
||||
time.sleep(0.3)
|
||||
stb = inst.read_stb()
|
||||
msg = "SRQ not set after 0.5 seconds, was {:02x}".format(stb)
|
||||
assert (stb == 0x50),msg
|
||||
|
||||
assert (inst.read_stb() == 0x10), "SRQ set at second read!"
|
||||
|
||||
rsp = inst.read()
|
||||
assert(rsp == "123\r\n")
|
||||
|
||||
def test_read_timeout():
|
||||
inst.timeout = 500
|
||||
# First read with no MAV
|
||||
inst.read_stb()
|
||||
assert (inst.read_stb() == 0)
|
||||
inst.write("delay 500")
|
||||
t0 = time.monotonic()
|
||||
try:
|
||||
rsp = inst.read()
|
||||
assert(false), "Read should have resulted in timeout"
|
||||
except visa.VisaIOError:
|
||||
print(" Got expected exception")
|
||||
t = time.monotonic() - t0
|
||||
assert ((t*1000.0) > (inst.timeout - 300))
|
||||
assert ((t*1000.0) < (inst.timeout + 300))
|
||||
print(f"Delay was {t:0.3}")
|
||||
# Response is still in queue, so send a clear (to be more helpful to the next test)
|
||||
inst.clear()
|
||||
time.sleep(0.3)
|
||||
assert(0 == (inst.read_stb() & 0x10)), "MAV not reset after clear"
|
||||
|
||||
def test_abort_in():
|
||||
inst.timeout = 200
|
||||
# First read with no MAV
|
||||
inst.read_stb()
|
||||
assert (inst.read_stb() == 0)
|
||||
inst.write("delay 500")
|
||||
inst.write("xxx")
|
||||
t0 = time.monotonic()
|
||||
try:
|
||||
rsp = inst.read()
|
||||
assert(false), "Read should have resulted in timeout"
|
||||
except visa.VisaIOError:
|
||||
print(" Got expected exception")
|
||||
t = time.monotonic() - t0
|
||||
assert ((t*1000.0) > (inst.timeout - 300))
|
||||
assert ((t*1000.0) < (inst.timeout + 300))
|
||||
print(f" Delay was {t:0.3}")
|
||||
# Response is still in queue, so send a clear (to be more helpful to the next test)
|
||||
inst.timeout = 800
|
||||
y = inst.read()
|
||||
assert(y == "xxx\r\n")
|
||||
|
||||
def test_indicate():
|
||||
# perform indicator pulse
|
||||
usb_iface = inst.get_visa_attribute(visa.constants.VI_ATTR_USB_INTFC_NUM)
|
||||
retv = inst.control_in(request_type_bitmap_field=0xA1, request_id=64, request_value=0x0000, index=usb_iface, length=0x0001)
|
||||
assert((retv[1] == visa.constants.StatusCode(0)) and (retv[0] == b'\x01')), f"indicator pulse failed: retv={retv}"
|
||||
|
||||
|
||||
def test_multi_read():
|
||||
old_chunk_size = inst.chunk_size
|
||||
longstr = "0123456789abcdefghijklmnopqrstuvwxyz" * 10
|
||||
timeout = 10
|
||||
x = longstr[0:174]
|
||||
inst.chunk_size = 50 # Seems chunk size only applies to read but not write
|
||||
inst.write(x)
|
||||
# I'm not sure how to request just the remaining bit using a max count... so just read it all.
|
||||
y = inst.read()
|
||||
assert (x + "\r\n" == y)
|
||||
#inst.chunk_size = old_chunk_size
|
||||
|
||||
def test_stall_ep0():
|
||||
usb_iface = inst.get_visa_attribute(visa.constants.VI_ATTR_USB_INTFC_NUM)
|
||||
inst.read_stb()
|
||||
# This is an invalid request, should create stall.
|
||||
try:
|
||||
retv = inst.control_in(request_type_bitmap_field=0xA1, request_id=60, request_value=0x0000, index=usb_iface, length=0x0001)
|
||||
assert false
|
||||
except visa.VisaIOError:
|
||||
pass
|
||||
|
||||
assert (inst.read_stb() == 0)
|
||||
|
||||
|
||||
rm = visa.ResourceManager("/c/Windows/system32/visa64.dll")
|
||||
reslist = rm.list_resources("USB?::?*::INSTR")
|
||||
print(reslist)
|
||||
|
||||
if (len(reslist) == 0):
|
||||
sys.exit()
|
||||
|
||||
inst = rm.open_resource(reslist[0]);
|
||||
inst.timeout = 3000
|
||||
|
||||
inst.clear()
|
||||
|
||||
print("+ IDN")
|
||||
test_idn()
|
||||
|
||||
print("+test abort in")
|
||||
test_abort_in()
|
||||
|
||||
|
||||
inst.timeout = 2000
|
||||
|
||||
print("+ multi read")
|
||||
test_multi_read()
|
||||
|
||||
|
||||
print("+ echo delay=0")
|
||||
inst.write("delay 0")
|
||||
test_echo(1,175)
|
||||
|
||||
print("+ echo delay=2")
|
||||
inst.write("delay 2")
|
||||
test_echo(1,175)
|
||||
|
||||
print("+ echo delay=150")
|
||||
inst.write("delay 150")
|
||||
test_echo(53,76)
|
||||
test_echo(165,170)
|
||||
|
||||
print("+ Read timeout (no MAV)")
|
||||
test_read_timeout()
|
||||
|
||||
print("+ Test EP0 stall recovery")
|
||||
test_stall_ep0()
|
||||
|
||||
print("+ MAV")
|
||||
test_mav()
|
||||
|
||||
print("+ SRQ")
|
||||
test_srq()
|
||||
|
||||
print("+ indicate")
|
||||
test_indicate()
|
||||
|
||||
print("+ TRIG")
|
||||
test_trig()
|
||||
|
||||
# Untested:
|
||||
# abort bulk out
|
||||
# LLO, GTL, etc
|
||||
# Throughput rate?
|
||||
# Transmitting a message using multiple transfers
|
||||
|
||||
inst.close()
|
||||
print("Test complete")
|
@ -60,8 +60,10 @@ CFLAGS += \
|
||||
-Wno-endif-labels \
|
||||
-Wstrict-prototypes \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Werror \
|
||||
-Werror-implicit-function-declaration \
|
||||
-Wfatal-errors \
|
||||
-Wfloat-equal \
|
||||
-Wundef \
|
||||
-Wshadow \
|
||||
|
@ -15,6 +15,7 @@ SRC_C += \
|
||||
src/class/cdc/cdc_device.c \
|
||||
src/class/hid/hid_device.c \
|
||||
src/class/midi/midi_device.c \
|
||||
src/class/usbtmc/usbtmc_device.c \
|
||||
src/class/vendor/vendor_device.c \
|
||||
src/portable/$(VENDOR)/$(CHIP_FAMILY)/dcd_$(CHIP_FAMILY).c
|
||||
|
||||
|
@ -78,7 +78,7 @@ int board_uart_write(void const * buf, int len);
|
||||
{
|
||||
return os_time_ticks_to_ms32( os_time_get() );
|
||||
}
|
||||
#elif
|
||||
#else
|
||||
#error "Need to implement board_millis() for this OS"
|
||||
#endif
|
||||
|
||||
|
@ -9,7 +9,13 @@ CFLAGS += \
|
||||
-DCONFIG_GPIO_AS_PINRESET
|
||||
|
||||
# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49
|
||||
CFLAGS += -Wno-error=undef
|
||||
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter
|
||||
|
||||
# due to tusb_hal_nrf_power_event
|
||||
GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion)))
|
||||
ifeq ($(shell expr $(GCCVERSION) \>= 8), 1)
|
||||
CFLAGS += -Wno-error=cast-function-type
|
||||
endif
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/circuitplayground_bluefruit/nrf52840_s140_v6.ld
|
||||
|
@ -8,8 +8,8 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM2")))' \
|
||||
-D__USE_LPCOPEN
|
||||
|
||||
# lpc_types.h cause following errors
|
||||
CFLAGS += -Wno-error=strict-prototypes
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=strict-prototypes -Wno-error=unused-parameter
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpc_driver/lpc40xx/lpc_chip_40xx
|
||||
|
||||
|
@ -7,8 +7,8 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC43XX \
|
||||
-D__USE_LPCOPEN
|
||||
|
||||
# lpc_types.h cause following errors
|
||||
CFLAGS += -Wno-error=strict-prototypes
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter -Wno-error=strict-prototypes
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpc_driver/lpc43xx/lpc_chip_43xx
|
||||
|
||||
|
@ -9,7 +9,13 @@ CFLAGS += \
|
||||
-DCONFIG_GPIO_AS_PINRESET
|
||||
|
||||
# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49
|
||||
CFLAGS += -Wno-error=undef
|
||||
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter
|
||||
|
||||
# due to tusb_hal_nrf_power_event
|
||||
GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion)))
|
||||
ifeq ($(shell expr $(GCCVERSION) \>= 8), 1)
|
||||
CFLAGS += -Wno-error=cast-function-type
|
||||
endif
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/feather_nrf52840_express/nrf52840_s140_v6.ld
|
||||
|
189
hw/bsp/feather_stm32f405/STM32F405RGTx_FLASH.ld
Normal file
189
hw/bsp/feather_stm32f405/STM32F405RGTx_FLASH.ld
Normal file
@ -0,0 +1,189 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
**
|
||||
|
||||
** File : LinkerScript.ld
|
||||
**
|
||||
** Abstract : Linker script for STM32F405RGTx Device with
|
||||
** 1024KByte FLASH, 128KByte RAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
**
|
||||
** Distribution: The file is distributed as is, without any warranty
|
||||
** of any kind.
|
||||
**
|
||||
** (c)Copyright Ac6.
|
||||
** You may use this file as-is or modify it according to the needs of your
|
||||
** project. Distribution of this file (unmodified or modified) is not
|
||||
** permitted. Ac6 permit registered System Workbench for MCU users the
|
||||
** rights to distribute the assembled, compiled & linked contents of this
|
||||
** file as part of an application binary file, provided that it is built
|
||||
** using the System Workbench for MCU toolchain.
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x20020000; /* end of RAM */
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0x200; /* required amount of heap */
|
||||
_Min_Stack_Size = 0x400; /* required amount of stack */
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
|
||||
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
.isr_vector :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
/* Constant data goes into FLASH */
|
||||
.rodata :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} >FLASH
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >FLASH
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >FLASH
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >RAM AT> FLASH
|
||||
|
||||
_siccmram = LOADADDR(.ccmram);
|
||||
|
||||
/* CCM-RAM section
|
||||
*
|
||||
* IMPORTANT NOTE!
|
||||
* If initialized variables will be placed in this section,
|
||||
* the startup code needs to be modified to copy the init-values.
|
||||
*/
|
||||
.ccmram :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sccmram = .; /* create a global symbol at ccmram start */
|
||||
*(.ccmram)
|
||||
*(.ccmram*)
|
||||
|
||||
. = ALIGN(4);
|
||||
_eccmram = .; /* create a global symbol at ccmram end */
|
||||
} >CCMRAM AT> FLASH
|
||||
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE ( end = . );
|
||||
PROVIDE ( _end = . );
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Min_Stack_Size;
|
||||
. = ALIGN(8);
|
||||
} >RAM
|
||||
|
||||
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
|
||||
|
50
hw/bsp/feather_stm32f405/board.mk
Normal file
50
hw/bsp/feather_stm32f405/board.mk
Normal file
@ -0,0 +1,50 @@
|
||||
CFLAGS += \
|
||||
-DHSE_VALUE=12000000 \
|
||||
-DSTM32F405xx \
|
||||
-mthumb \
|
||||
-mabi=aapcs \
|
||||
-mcpu=cortex-m4 \
|
||||
-mfloat-abi=hard \
|
||||
-mfpu=fpv4-sp-d16 \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F4
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F4xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/pyboardv11/STM32F405RGTx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32f4xx.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_cortex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c
|
||||
|
||||
SRC_S += \
|
||||
$(ST_CMSIS)/Source/Templates/gcc/startup_stm32f405xx.s
|
||||
|
||||
INC += \
|
||||
$(TOP)/hw/mcu/st/st_driver/CMSIS/Include \
|
||||
$(TOP)/$(ST_CMSIS)/Include \
|
||||
$(TOP)/$(ST_HAL_DRIVER)/Inc \
|
||||
$(TOP)/hw/bsp/$(BOARD)
|
||||
|
||||
# For TinyUSB port source
|
||||
VENDOR = st
|
||||
CHIP_FAMILY = synopsys
|
||||
|
||||
# For freeRTOS port source
|
||||
FREERTOS_PORT = ARM_CM4F
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32f405rg
|
||||
JLINK_IF = swd
|
||||
|
||||
# Path to STM32 Cube Programmer CLI, should be added into system path
|
||||
STM32Prog = STM32_Programmer_CLI
|
||||
|
||||
# flash target using on-board stlink
|
||||
flash: $(BUILD)/$(BOARD)-firmware.elf
|
||||
$(STM32Prog) --connect port=swd --write $< --go
|
198
hw/bsp/feather_stm32f405/feather_stm32f405.c
Normal file
198
hw/bsp/feather_stm32f405/feather_stm32f405.c
Normal file
@ -0,0 +1,198 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include "../board.h"
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_hal_conf.h"
|
||||
|
||||
// Blue LED is chosen because the other LEDs are connected to ST-LINK lines.
|
||||
#define LED_PORT GPIOC
|
||||
#define LED_PIN GPIO_PIN_4
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
// Pin D5
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_7
|
||||
#define BUTTON_STATE_ACTIVE 0
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* The system Clock is configured as follow :
|
||||
* System Clock source = PLL (HSE)
|
||||
* SYSCLK(Hz) = 168000000
|
||||
* HCLK(Hz) = 168000000
|
||||
* AHB Prescaler = 1
|
||||
* APB1 Prescaler = 4
|
||||
* APB2 Prescaler = 2
|
||||
* HSE Frequency(Hz) = 12000000
|
||||
* PLL_M = 12
|
||||
* PLL_N = 336
|
||||
* PLL_P = 2
|
||||
* PLL_Q = 7
|
||||
* VDD(V) = 3.3
|
||||
* Main regulator output voltage = Scale1 mode
|
||||
* Flash Latency(WS) = 5
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SystemClock_Config(void)
|
||||
{
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
|
||||
/* Enable Power Control clock */
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* The voltage scaling allows optimizing the power consumption when the device is
|
||||
clocked below the maximum system frequency, to update the voltage scaling value
|
||||
regarding system frequency refer to product datasheet. */
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
|
||||
/* Enable HSE Oscillator and activate PLL with HSE as source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 12;
|
||||
RCC_OscInitStruct.PLL.PLLN = 336;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 7;
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
|
||||
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
||||
clocks dividers */
|
||||
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
|
||||
}
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
// 1ms tick timer
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
|
||||
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
|
||||
#endif
|
||||
|
||||
SystemClock_Config();
|
||||
|
||||
// Notify runtime of frequency change.
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
// LED
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = LED_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
||||
|
||||
board_led_write(false);
|
||||
|
||||
// Button
|
||||
//__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
|
||||
|
||||
// Enable USB OTG clock
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
|
||||
// USB Pin Init
|
||||
// PA9- VUSB, PA10- ID, PA11- DM, PA12- DP
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
/* Configure DM DP Pins */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Configure VBUS Pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* This for ID line debug */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Board porting API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void)
|
||||
{
|
||||
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
void SysTick_Handler (void)
|
||||
{
|
||||
system_ticks++;
|
||||
}
|
||||
|
||||
uint32_t board_millis(void)
|
||||
{
|
||||
return system_ticks;
|
||||
}
|
||||
#endif
|
||||
|
||||
void HardFault_Handler (void)
|
||||
{
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
// Required by __libc_init_array in startup code if we are compiling using
|
||||
// -nostdlib/-nostartfiles.
|
||||
void _init(void)
|
||||
{
|
||||
|
||||
}
|
489
hw/bsp/feather_stm32f405/stm32f4xx_hal_conf.h
Normal file
489
hw/bsp/feather_stm32f405/stm32f4xx_hal_conf.h
Normal file
@ -0,0 +1,489 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f4xx_hal_conf.h
|
||||
* @brief HAL configuration file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2019 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F4xx_HAL_CONF_H
|
||||
#define __STM32F4xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
#define HAL_MODULE_ENABLED
|
||||
|
||||
/* #define HAL_ADC_MODULE_ENABLED */
|
||||
/* #define HAL_CRYP_MODULE_ENABLED */
|
||||
/* #define HAL_CAN_MODULE_ENABLED */
|
||||
/* #define HAL_CRC_MODULE_ENABLED */
|
||||
/* #define HAL_CRYP_MODULE_ENABLED */
|
||||
/* #define HAL_DAC_MODULE_ENABLED */
|
||||
/* #define HAL_DCMI_MODULE_ENABLED */
|
||||
/* #define HAL_DMA2D_MODULE_ENABLED */
|
||||
/* #define HAL_ETH_MODULE_ENABLED */
|
||||
/* #define HAL_NAND_MODULE_ENABLED */
|
||||
/* #define HAL_NOR_MODULE_ENABLED */
|
||||
/* #define HAL_PCCARD_MODULE_ENABLED */
|
||||
/* #define HAL_SRAM_MODULE_ENABLED */
|
||||
/* #define HAL_SDRAM_MODULE_ENABLED */
|
||||
/* #define HAL_HASH_MODULE_ENABLED */
|
||||
/* #define HAL_I2C_MODULE_ENABLED */
|
||||
/* #define HAL_I2S_MODULE_ENABLED */
|
||||
/* #define HAL_IWDG_MODULE_ENABLED */
|
||||
/* #define HAL_LTDC_MODULE_ENABLED */
|
||||
/* #define HAL_RNG_MODULE_ENABLED */
|
||||
/* #define HAL_RTC_MODULE_ENABLED */
|
||||
/* #define HAL_SAI_MODULE_ENABLED */
|
||||
/* #define HAL_SD_MODULE_ENABLED */
|
||||
/* #define HAL_MMC_MODULE_ENABLED */
|
||||
/* #define HAL_SPI_MODULE_ENABLED */
|
||||
/* #define HAL_TIM_MODULE_ENABLED */
|
||||
/* #define HAL_UART_MODULE_ENABLED */
|
||||
/* #define HAL_USART_MODULE_ENABLED */
|
||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||
#define HAL_PCD_MODULE_ENABLED
|
||||
/* #define HAL_HCD_MODULE_ENABLED */
|
||||
/* #define HAL_DSI_MODULE_ENABLED */
|
||||
/* #define HAL_QSPI_MODULE_ENABLED */
|
||||
/* #define HAL_QSPI_MODULE_ENABLED */
|
||||
/* #define HAL_CEC_MODULE_ENABLED */
|
||||
/* #define HAL_FMPI2C_MODULE_ENABLED */
|
||||
/* #define HAL_SPDIFRX_MODULE_ENABLED */
|
||||
/* #define HAL_DFSDM_MODULE_ENABLED */
|
||||
/* #define HAL_LPTIM_MODULE_ENABLED */
|
||||
/* #define HAL_EXTI_MODULE_ENABLED */
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
|
||||
/* ########################## HSE/HSI Values adaptation ##################### */
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE ((uint32_t)12000000U) /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE ((uint32_t)32000U) /*!< LSI Typical Value in Hz*/
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature.*/
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External Low Speed oscillator in Hz */
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
|
||||
#endif /* LSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief External clock source for I2S peripheral
|
||||
* This value is used by the I2S HAL module to compute the I2S clock source
|
||||
* frequency, this source is inserted directly through I2S_CKIN pad.
|
||||
*/
|
||||
#if !defined (EXTERNAL_CLOCK_VALUE)
|
||||
#define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000U) /*!< Value of the External audio frequency in Hz*/
|
||||
#endif /* EXTERNAL_CLOCK_VALUE */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 1U
|
||||
#define INSTRUCTION_CACHE_ENABLE 1U
|
||||
#define DATA_CACHE_ENABLE 1U
|
||||
|
||||
/* Copied over manually- STM32Cube didn't generate these for some reason. */
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
|
||||
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
|
||||
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U /* COMP register callback disabled */
|
||||
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
|
||||
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */
|
||||
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */
|
||||
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */
|
||||
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */
|
||||
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
|
||||
#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U /* FDCAN register callback disabled */
|
||||
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
|
||||
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
|
||||
#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */
|
||||
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
|
||||
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
|
||||
#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U /* HRTIM register callback disabled */
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
|
||||
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
|
||||
#define USE_HAL_JPEG_REGISTER_CALLBACKS 0U /* JPEG register callback disabled */
|
||||
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */
|
||||
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */
|
||||
#define USE_HAL_MDIOS_REGISTER_CALLBACKS 0U /* MDIO register callback disabled */
|
||||
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U /* MDIO register callback disabled */
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
|
||||
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */
|
||||
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
|
||||
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */
|
||||
#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */
|
||||
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
|
||||
#define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U /* SWPMI register callback disabled */
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## Ethernet peripheral configuration ##################### */
|
||||
|
||||
/* Section 1 : Ethernet peripheral configuration */
|
||||
|
||||
/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
|
||||
#define MAC_ADDR0 2U
|
||||
#define MAC_ADDR1 0U
|
||||
#define MAC_ADDR2 0U
|
||||
#define MAC_ADDR3 0U
|
||||
#define MAC_ADDR4 0U
|
||||
#define MAC_ADDR5 0U
|
||||
|
||||
/* Definition of the Ethernet driver buffers size and count */
|
||||
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
|
||||
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
|
||||
#define ETH_RXBUFNB ((uint32_t)4U) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
|
||||
#define ETH_TXBUFNB ((uint32_t)4U) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
|
||||
|
||||
/* Section 2: PHY configuration section */
|
||||
|
||||
/* DP83848_PHY_ADDRESS Address*/
|
||||
#define DP83848_PHY_ADDRESS 0x01U
|
||||
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
|
||||
#define PHY_RESET_DELAY ((uint32_t)0x000000FFU)
|
||||
/* PHY Configuration delay */
|
||||
#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFFU)
|
||||
|
||||
#define PHY_READ_TO ((uint32_t)0x0000FFFFU)
|
||||
#define PHY_WRITE_TO ((uint32_t)0x0000FFFFU)
|
||||
|
||||
/* Section 3: Common PHY Registers */
|
||||
|
||||
#define PHY_BCR ((uint16_t)0x0000U) /*!< Transceiver Basic Control Register */
|
||||
#define PHY_BSR ((uint16_t)0x0001U) /*!< Transceiver Basic Status Register */
|
||||
|
||||
#define PHY_RESET ((uint16_t)0x8000U) /*!< PHY Reset */
|
||||
#define PHY_LOOPBACK ((uint16_t)0x4000U) /*!< Select loop-back mode */
|
||||
#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100U) /*!< Set the full-duplex mode at 100 Mb/s */
|
||||
#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000U) /*!< Set the half-duplex mode at 100 Mb/s */
|
||||
#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100U) /*!< Set the full-duplex mode at 10 Mb/s */
|
||||
#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000U) /*!< Set the half-duplex mode at 10 Mb/s */
|
||||
#define PHY_AUTONEGOTIATION ((uint16_t)0x1000U) /*!< Enable auto-negotiation function */
|
||||
#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200U) /*!< Restart auto-negotiation function */
|
||||
#define PHY_POWERDOWN ((uint16_t)0x0800U) /*!< Select the power down mode */
|
||||
#define PHY_ISOLATE ((uint16_t)0x0400U) /*!< Isolate PHY from MII */
|
||||
|
||||
#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020U) /*!< Auto-Negotiation process completed */
|
||||
#define PHY_LINKED_STATUS ((uint16_t)0x0004U) /*!< Valid link established */
|
||||
#define PHY_JABBER_DETECTION ((uint16_t)0x0002U) /*!< Jabber condition detected */
|
||||
|
||||
/* Section 4: Extended PHY Registers */
|
||||
#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */
|
||||
|
||||
#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */
|
||||
#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 0U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRYP_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_cryp.h"
|
||||
#endif /* HAL_CRYP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA2D_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_dma2d.h"
|
||||
#endif /* HAL_DMA2D_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DCMI_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_dcmi.h"
|
||||
#endif /* HAL_DCMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ETH_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_eth.h"
|
||||
#endif /* HAL_ETH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCCARD_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_pccard.h"
|
||||
#endif /* HAL_PCCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SDRAM_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_sdram.h"
|
||||
#endif /* HAL_SDRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_hash.h"
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2S_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_i2s.h"
|
||||
#endif /* HAL_I2S_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LTDC_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_ltdc.h"
|
||||
#endif /* HAL_LTDC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_rng.h"
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SAI_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_sai.h"
|
||||
#endif /* HAL_SAI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_MMC_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_mmc.h"
|
||||
#endif /* HAL_MMC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DSI_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_dsi.h"
|
||||
#endif /* HAL_DSI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_QSPI_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_qspi.h"
|
||||
#endif /* HAL_QSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CEC_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_cec.h"
|
||||
#endif /* HAL_CEC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FMPI2C_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_fmpi2c.h"
|
||||
#endif /* HAL_FMPI2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPDIFRX_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_spdifrx.h"
|
||||
#endif /* HAL_SPDIFRX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DFSDM_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_dfsdm.h"
|
||||
#endif /* HAL_DFSDM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||
#include "stm32f4xx_hal_lptim.h"
|
||||
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F4xx_HAL_CONF_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -10,8 +10,8 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM2")))' \
|
||||
-DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))'
|
||||
|
||||
# startup.c and lpc_types.h cause following errors
|
||||
CFLAGS += -Wno-error=nested-externs -Wno-error=strict-prototypes
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=nested-externs -Wno-error=strict-prototypes -Wno-error=unused-parameter
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpc_driver/lpc11uxx/lpc_chip_11uxx
|
||||
|
||||
|
@ -7,8 +7,8 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MEM_SECTION='__attribute__((section(".data")))' \
|
||||
-DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))'
|
||||
|
||||
# system_LPC51U68.c cause following errors
|
||||
CFLAGS += -Wno-error=nested-externs
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=nested-externs -Wno-error=unused-parameter
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpc_driver/lpc51u6x/devices/LPC51U68
|
||||
|
||||
|
@ -9,6 +9,9 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MEM_SECTION='__attribute__((section(".data")))' \
|
||||
-DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))'
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpc_driver/lpc54xxx/devices/LPC54114
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
|
@ -7,10 +7,10 @@ CFLAGS += \
|
||||
-DCPU_LPC55S69JBD100_cm33_core0 \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC55XX \
|
||||
-DCFG_TUSB_MEM_SECTION='__attribute__((section(".data")))' \
|
||||
-DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))'
|
||||
-DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))'
|
||||
|
||||
# system_LPC55S69_cm33_core0.c cause following errors
|
||||
CFLAGS += -Wno-error=float-equal -Wno-error=nested-externs
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter -Wno-error=float-equal -Wno-error=nested-externs
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpc_driver/lpc55xx/devices/LPC55S69
|
||||
|
||||
|
@ -7,8 +7,8 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC18XX \
|
||||
-D__USE_LPCOPEN
|
||||
|
||||
# lpc_types.h cause following errors
|
||||
CFLAGS += -Wno-error=strict-prototypes
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter -Wno-error=strict-prototypes
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpc_driver/lpc18xx/lpc_chip_18xx
|
||||
|
||||
|
@ -7,8 +7,8 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_LPC43XX \
|
||||
-D__USE_LPCOPEN
|
||||
|
||||
# lpc_types.h cause following errors
|
||||
CFLAGS += -Wno-error=strict-prototypes
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=strict-prototypes -Wno-error=unused-parameter
|
||||
|
||||
MCU_DIR = hw/mcu/nxp/lpc_driver/lpc43xx/lpc_chip_43xx
|
||||
|
||||
|
@ -9,7 +9,13 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_NRF5X
|
||||
|
||||
# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49
|
||||
CFLAGS += -Wno-error=undef
|
||||
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter
|
||||
|
||||
# due to tusb_hal_nrf_power_event
|
||||
GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion)))
|
||||
ifeq ($(shell expr $(GCCVERSION) \>= 8), 1)
|
||||
CFLAGS += -Wno-error=cast-function-type
|
||||
endif
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/mcu/nordic/nrfx/mdk/nrf52840_xxaa.ld
|
||||
|
@ -96,7 +96,8 @@ void board_init(void)
|
||||
nrfx_power_init(&pwr_cfg);
|
||||
|
||||
// Register tusb function as USB power handler
|
||||
const nrfx_power_usbevt_config_t config = { .handler = (nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event };
|
||||
// cause cast-function-type warning
|
||||
const nrfx_power_usbevt_config_t config = { .handler = ((nrfx_power_usb_event_handler_t) tusb_hal_nrf_power_event) };
|
||||
nrfx_power_usbevt_init(&config);
|
||||
|
||||
nrfx_power_usbevt_enable();
|
||||
|
@ -9,7 +9,13 @@ CFLAGS += \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_NRF5X
|
||||
|
||||
# nrfx issue undef _ARMCC_VERSION usage https://github.com/NordicSemiconductor/nrfx/issues/49
|
||||
CFLAGS += -Wno-error=undef
|
||||
CFLAGS += -Wno-error=undef -Wno-error=unused-parameter
|
||||
|
||||
# due to tusb_hal_nrf_power_event
|
||||
GCCVERSION = $(firstword $(subst ., ,$(shell arm-none-eabi-gcc -dumpversion)))
|
||||
ifeq ($(shell expr $(GCCVERSION) \>= 8), 1)
|
||||
CFLAGS += -Wno-error=cast-function-type
|
||||
endif
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/$(BOARD)/$(BOARD).ld
|
||||
|
@ -39,7 +39,7 @@ CHIP_FAMILY = synopsys
|
||||
FREERTOS_PORT = ARM_CM4F
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32f407vg
|
||||
JLINK_DEVICE = stm32f405rg
|
||||
JLINK_IF = swd
|
||||
|
||||
# Path to STM32 Cube Programmer CLI, should be added into system path
|
||||
|
@ -9,11 +9,14 @@ CFLAGS += \
|
||||
-DCFG_EXAMPLE_MSC_READONLY \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F0
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F0xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F0xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/stm32f070rbnucleo/stm32F070rbtx_flash.ld
|
||||
LD_FILE = hw/bsp/$(BOARD)/stm32F070rbtx_flash.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32f0xx.c \
|
||||
|
@ -29,13 +29,13 @@
|
||||
#include "stm32f0xx.h"
|
||||
#include "stm32f0xx_hal_conf.h"
|
||||
|
||||
#define LED_PORT GPIOC
|
||||
#define LED_PIN GPIO_PIN_13
|
||||
#define LED_PORT GPIOA
|
||||
#define LED_PIN GPIO_PIN_5
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_5
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 0
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
@ -75,7 +75,7 @@ void board_init(void)
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
// LED
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Pin = LED_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
@ -84,7 +84,7 @@ void board_init(void)
|
||||
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
||||
|
||||
// Button
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
|
@ -9,6 +9,9 @@ CFLAGS += \
|
||||
-DCFG_EXAMPLE_MSC_READONLY \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F0
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F0xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F0xx
|
||||
|
||||
|
53
hw/bsp/stm32f103bluepill/board.mk
Normal file
53
hw/bsp/stm32f103bluepill/board.mk
Normal file
@ -0,0 +1,53 @@
|
||||
CFLAGS += \
|
||||
-DHSE_VALUE=8000000 \
|
||||
-DSTM32F103xB \
|
||||
-mthumb \
|
||||
-mabi=aapcs \
|
||||
-mcpu=cortex-m3 \
|
||||
-mfloat-abi=soft \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F1
|
||||
|
||||
# mcu driver cause following warnings
|
||||
#CFLAGS += -Wno-error=unused-parameter
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F1xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F1xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = $(ST_CMSIS)/Source/Templates/gcc/linker/STM32F103XB_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32f1xx.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f1xx_hal.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f1xx_hal_cortex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f1xx_hal_rcc.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f1xx_hal_rcc_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f1xx_hal_gpio.c
|
||||
|
||||
SRC_S += \
|
||||
$(ST_CMSIS)/Source/Templates/gcc/startup_stm32f103xb.s
|
||||
|
||||
INC += \
|
||||
$(TOP)/hw/mcu/st/st_driver/CMSIS/Include \
|
||||
$(TOP)/$(ST_CMSIS)/Include \
|
||||
$(TOP)/$(ST_HAL_DRIVER)/Inc \
|
||||
$(TOP)/hw/bsp/$(BOARD)
|
||||
|
||||
# For TinyUSB port source
|
||||
VENDOR = st
|
||||
CHIP_FAMILY = stm32_fsdev
|
||||
|
||||
# For freeRTOS port source
|
||||
FREERTOS_PORT = ARM_CM3
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32f303vc
|
||||
JLINK_IF = swd
|
||||
|
||||
# Path to STM32 Cube Programmer CLI, should be added into system path
|
||||
STM32Prog = STM32_Programmer_CLI
|
||||
|
||||
# flash target using on-board stlink
|
||||
flash: $(BUILD)/$(BOARD)-firmware.elf
|
||||
$(STM32Prog) --connect port=swd --write $< --go
|
182
hw/bsp/stm32f103bluepill/stm32f103bluepill.c
Normal file
182
hw/bsp/stm32f103bluepill/stm32f103bluepill.c
Normal file
@ -0,0 +1,182 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include "../board.h"
|
||||
|
||||
#include "stm32f1xx.h"
|
||||
#include "stm32f1xx_hal_conf.h"
|
||||
|
||||
#define LED_PORT GPIOC
|
||||
#define LED_PIN GPIO_PIN_13
|
||||
#define LED_STATE_ON 0
|
||||
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_0
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* The system Clock is configured as follow :
|
||||
* System Clock source = PLL (HSE)
|
||||
* SYSCLK(Hz) = 72000000
|
||||
* HCLK(Hz) = 72000000
|
||||
* AHB Prescaler = 1
|
||||
* APB1 Prescaler = 2
|
||||
* APB2 Prescaler = 1
|
||||
* HSE Frequency(Hz) = 8000000
|
||||
* HSE PREDIV1 = 1
|
||||
* PLLMUL = 9
|
||||
* Flash Latency(WS) = 2
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_ClkInitTypeDef clkinitstruct = {0};
|
||||
RCC_OscInitTypeDef oscinitstruct = {0};
|
||||
RCC_PeriphCLKInitTypeDef rccperiphclkinit = {0};
|
||||
|
||||
/* Enable HSE Oscillator and activate PLL with HSE as source */
|
||||
oscinitstruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
oscinitstruct.HSEState = RCC_HSE_ON;
|
||||
oscinitstruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
||||
oscinitstruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||
oscinitstruct.PLL.PLLState = RCC_PLL_ON;
|
||||
oscinitstruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
HAL_RCC_OscConfig(&oscinitstruct);
|
||||
|
||||
/* USB clock selection */
|
||||
rccperiphclkinit.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||
rccperiphclkinit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
|
||||
HAL_RCCEx_PeriphCLKConfig(&rccperiphclkinit);
|
||||
|
||||
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
|
||||
clkinitstruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
||||
clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||
clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2);
|
||||
}
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
// 1ms tick timer
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
#endif
|
||||
|
||||
SystemClock_Config();
|
||||
|
||||
// Notify runtime of frequency change.
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
// LED
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Pin = LED_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
||||
|
||||
// Button
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
|
||||
|
||||
// USB Pins
|
||||
// Configure USB DM and DP pins.
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// USB Clock enable
|
||||
__HAL_RCC_USB_CLK_ENABLE();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Board porting API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void)
|
||||
{
|
||||
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
void SysTick_Handler (void)
|
||||
{
|
||||
system_ticks++;
|
||||
}
|
||||
|
||||
uint32_t board_millis(void)
|
||||
{
|
||||
return system_ticks;
|
||||
}
|
||||
#endif
|
||||
|
||||
void HardFault_Handler (void)
|
||||
{
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(char *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User can add his own implementation to report the file name and line number,
|
||||
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
// Required by __libc_init_array in startup code if we are compiling using
|
||||
// -nostdlib/-nostartfiles.
|
||||
void _init(void)
|
||||
{
|
||||
|
||||
}
|
379
hw/bsp/stm32f103bluepill/stm32f1xx_hal_conf.h
Normal file
379
hw/bsp/stm32f103bluepill/stm32f1xx_hal_conf.h
Normal file
@ -0,0 +1,379 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file USB_Device/HID_Standalone/Inc/stm32f1xx_hal_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief HAL configuration template file.
|
||||
* This file should be copied to the application folder and renamed
|
||||
* to stm32f1xx_hal_conf.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F1xx_HAL_CONF_H
|
||||
#define __STM32F1xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
#define HAL_MODULE_ENABLED
|
||||
/* #define HAL_ADC_MODULE_ENABLED */
|
||||
/* #define HAL_CAN_MODULE_ENABLED */
|
||||
/* #define HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
#define HAL_CORTEX_MODULE_ENABLED */
|
||||
/* #define HAL_CRC_MODULE_ENABLED */
|
||||
/* #define HAL_DAC_MODULE_ENABLED */
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
#define HAL_EXTI_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
/* #define HAL_I2C_MODULE_ENABLED */
|
||||
/* #define HAL_I2S_MODULE_ENABLED */
|
||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||
/* #define HAL_IWDG_MODULE_ENABLED */
|
||||
/* #define HAL_NOR_MODULE_ENABLED */
|
||||
/* #define HAL_PCCARD_MODULE_ENABLED */
|
||||
#define HAL_PCD_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
/* #define HAL_RTC_MODULE_ENABLED */
|
||||
/* #define HAL_SD_MODULE_ENABLED */
|
||||
/* #define HAL_SDRAM_MODULE_ENABLED */
|
||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/* #define HAL_SPI_MODULE_ENABLED */
|
||||
/* #define HAL_SRAM_MODULE_ENABLED */
|
||||
/* #define HAL_TIM_MODULE_ENABLED */
|
||||
#define HAL_UART_MODULE_ENABLED
|
||||
/* #define HAL_USART_MODULE_ENABLED */
|
||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#if defined(USE_STM3210C_EVAL)
|
||||
#define HSE_VALUE 25000000U /*!< Value of the External oscillator in Hz */
|
||||
#else
|
||||
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
|
||||
#endif
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 8000000U /*!< Value of the Internal oscillator in Hz */
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE 40000U /*!< LSI Typical Value in Hz */
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature. */
|
||||
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
|
||||
#endif /* LSE_STARTUP_TIMEOUT */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY 0x00U /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 1U
|
||||
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
|
||||
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
|
||||
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
|
||||
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
|
||||
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
|
||||
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
|
||||
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
|
||||
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
|
||||
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
|
||||
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
|
||||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
|
||||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
|
||||
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
|
||||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
|
||||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## Ethernet peripheral configuration ##################### */
|
||||
|
||||
/* Section 1 : Ethernet peripheral configuration */
|
||||
|
||||
/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
|
||||
#define MAC_ADDR0 2U
|
||||
#define MAC_ADDR1 0U
|
||||
#define MAC_ADDR2 0U
|
||||
#define MAC_ADDR3 0U
|
||||
#define MAC_ADDR4 0U
|
||||
#define MAC_ADDR5 0U
|
||||
|
||||
/* Definition of the Ethernet driver buffers size and count */
|
||||
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
|
||||
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
|
||||
#define ETH_RXBUFNB 8U /* 8 Rx buffers of size ETH_RX_BUF_SIZE */
|
||||
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
|
||||
|
||||
/* Section 2: PHY configuration section */
|
||||
|
||||
/* DP83848 PHY Address*/
|
||||
#define DP83848_PHY_ADDRESS 0x01U
|
||||
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
|
||||
#define PHY_RESET_DELAY 0x000000FFU
|
||||
/* PHY Configuration delay */
|
||||
#define PHY_CONFIG_DELAY 0x00000FFFU
|
||||
|
||||
#define PHY_READ_TO 0x0000FFFFU
|
||||
#define PHY_WRITE_TO 0x0000FFFFU
|
||||
|
||||
/* Section 3: Common PHY Registers */
|
||||
|
||||
#define PHY_BCR ((uint16_t)0x0000) /*!< Transceiver Basic Control Register */
|
||||
#define PHY_BSR ((uint16_t)0x0001) /*!< Transceiver Basic Status Register */
|
||||
|
||||
#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
|
||||
#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
|
||||
#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
|
||||
#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
|
||||
#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
|
||||
#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
|
||||
#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
|
||||
#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
|
||||
#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
|
||||
#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
|
||||
|
||||
#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
|
||||
#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
|
||||
#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
|
||||
|
||||
/* Section 4: Extended PHY Registers */
|
||||
|
||||
#define PHY_SR ((uint16_t)0x0010) /*!< PHY status register Offset */
|
||||
#define PHY_MICR ((uint16_t)0x0011) /*!< MII Interrupt Control Register */
|
||||
#define PHY_MISR ((uint16_t)0x0012) /*!< MII Interrupt Status and Misc. Control Register */
|
||||
|
||||
#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
|
||||
#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
|
||||
#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
|
||||
|
||||
#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
|
||||
#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
|
||||
|
||||
#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
|
||||
#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 1U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
|
||||
#include "Legacy/stm32f1xx_hal_can_legacy.h"
|
||||
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2S_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_i2s.h"
|
||||
#endif /* HAL_I2S_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCCARD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pccard.h"
|
||||
#endif /* HAL_PCCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SDRAM_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_sdram.h"
|
||||
#endif /* HAL_SDRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32f1xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F1xx_HAL_CONF_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
169
hw/bsp/stm32f207nucleo/STM32F207ZGTx_FLASH.ld
Normal file
169
hw/bsp/stm32f207nucleo/STM32F207ZGTx_FLASH.ld
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
**
|
||||
|
||||
** File : LinkerScript.ld
|
||||
**
|
||||
** Abstract : Linker script for STM32F207IGHx Device with
|
||||
** 1024KByte FLASH, 128KByte RAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
**
|
||||
** Distribution: The file is distributed as is, without any warranty
|
||||
** of any kind.
|
||||
**
|
||||
** (c)Copyright Ac6.
|
||||
** You may use this file as-is or modify it according to the needs of your
|
||||
** project. Distribution of this file (unmodified or modified) is not
|
||||
** permitted. Ac6 permit registered System Workbench for MCU users the
|
||||
** rights to distribute the assembled, compiled & linked contents of this
|
||||
** file as part of an application binary file, provided that it is built
|
||||
** using the System Workbench for MCU toolchain.
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x20020000; /* end of RAM */
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0x200; /* required amount of heap */
|
||||
_Min_Stack_Size = 0x400; /* required amount of stack */
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
.isr_vector :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
/* Constant data goes into FLASH */
|
||||
.rodata :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} >FLASH
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >FLASH
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >FLASH
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >RAM AT> FLASH
|
||||
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE ( end = . );
|
||||
PROVIDE ( _end = . );
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Min_Stack_Size;
|
||||
. = ALIGN(8);
|
||||
} >RAM
|
||||
|
||||
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
|
||||
|
53
hw/bsp/stm32f207nucleo/board.mk
Normal file
53
hw/bsp/stm32f207nucleo/board.mk
Normal file
@ -0,0 +1,53 @@
|
||||
CFLAGS += \
|
||||
-DHSE_VALUE=8000000 \
|
||||
-DSTM32F207xx \
|
||||
-mthumb \
|
||||
-mabi=aapcs \
|
||||
-mcpu=cortex-m3 \
|
||||
-mfloat-abi=soft \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F2
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=sign-compare
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F2xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F2xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/$(BOARD)/STM32F207ZGTx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32f2xx.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f2xx_hal.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f2xx_hal_cortex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f2xx_hal_rcc.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f2xx_hal_rcc_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32f2xx_hal_gpio.c
|
||||
|
||||
SRC_S += \
|
||||
$(ST_CMSIS)/Source/Templates/gcc/startup_stm32f207xx.s
|
||||
|
||||
INC += \
|
||||
$(TOP)/hw/mcu/st/st_driver/CMSIS/Include \
|
||||
$(TOP)/$(ST_CMSIS)/Include \
|
||||
$(TOP)/$(ST_HAL_DRIVER)/Inc \
|
||||
$(TOP)/hw/bsp/$(BOARD)
|
||||
|
||||
# For TinyUSB port source
|
||||
VENDOR = st
|
||||
CHIP_FAMILY = synopsys
|
||||
|
||||
# For freeRTOS port source
|
||||
FREERTOS_PORT = ARM_CM3
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32f207zg
|
||||
JLINK_IF = swd
|
||||
|
||||
# Path to STM32 Cube Programmer CLI, should be added into system path
|
||||
STM32Prog = STM32_Programmer_CLI
|
||||
|
||||
# flash target using on-board stlink
|
||||
flash: $(BUILD)/$(BOARD)-firmware.elf
|
||||
$(STM32Prog) --connect port=swd --write $< --go
|
178
hw/bsp/stm32f207nucleo/stm32f207nucleo.c
Normal file
178
hw/bsp/stm32f207nucleo/stm32f207nucleo.c
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include "../board.h"
|
||||
|
||||
#include "stm32f2xx.h"
|
||||
#include "stm32f2xx_hal_conf.h"
|
||||
|
||||
#define LED_PORT GPIOB
|
||||
#define LED_PIN GPIO_PIN_14
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BUTTON_PORT GPIOC
|
||||
#define BUTTON_PIN GPIO_PIN_13
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* The system Clock is configured as follow :
|
||||
* System Clock source = PLL (HSE)
|
||||
* SYSCLK(Hz) = 120000000
|
||||
* HCLK(Hz) = 120000000
|
||||
* AHB Prescaler = 1
|
||||
* APB1 Prescaler = 4
|
||||
* APB2 Prescaler = 2
|
||||
* HSE Frequency(Hz) = 8000000
|
||||
* PLL_M = 8
|
||||
* PLL_N = 240
|
||||
* PLL_P = 2
|
||||
* PLL_Q = 5
|
||||
* VDD(V) = 3.3
|
||||
* Flash Latency(WS) = 3
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
|
||||
/* Enable HSE Oscillator and activate PLL with HSE as source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = 8;
|
||||
RCC_OscInitStruct.PLL.PLLN = 240;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 5;
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
|
||||
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
||||
clocks dividers */
|
||||
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3);
|
||||
}
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
// 1ms tick timer
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
#endif
|
||||
|
||||
SystemClock_Config();
|
||||
|
||||
// Notify runtime of frequency change.
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
// LED
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
GPIO_InitStruct.Pin = LED_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
||||
|
||||
// Button
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
|
||||
|
||||
/* Configure DM DP Pins */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Configure VBUS Pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_9;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Configure ID pin */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Enable USB FS Clocks */
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Board porting API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void)
|
||||
{
|
||||
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
void SysTick_Handler (void)
|
||||
{
|
||||
system_ticks++;
|
||||
}
|
||||
|
||||
uint32_t board_millis(void)
|
||||
{
|
||||
return system_ticks;
|
||||
}
|
||||
#endif
|
||||
|
||||
void HardFault_Handler (void)
|
||||
{
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
// Required by __libc_init_array in startup code if we are compiling using
|
||||
// -nostdlib/-nostartfiles.
|
||||
void _init(void)
|
||||
{
|
||||
|
||||
}
|
407
hw/bsp/stm32f207nucleo/stm32f2xx_hal_conf.h
Normal file
407
hw/bsp/stm32f207nucleo/stm32f2xx_hal_conf.h
Normal file
@ -0,0 +1,407 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32f2xx_hal_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief HAL configuration file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32F2xx_HAL_CONF_H
|
||||
#define __STM32F2xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
#define HAL_MODULE_ENABLED
|
||||
/* #define HAL_ADC_MODULE_ENABLED */
|
||||
/* #define HAL_CAN_MODULE_ENABLED */
|
||||
/* #define HAL_CRC_MODULE_ENABLED */
|
||||
/* #define HAL_CRYP_MODULE_ENABLED */
|
||||
/* #define HAL_DAC_MODULE_ENABLED */
|
||||
/* #define HAL_DCMI_MODULE_ENABLED */
|
||||
/* #define HAL_DMA_MODULE_ENABLED */
|
||||
/* #define HAL_ETH_MODULE_ENABLED */
|
||||
#define HAL_EXTI_MODULE_ENABLED
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
/* #define HAL_NAND_MODULE_ENABLED */
|
||||
/* #define HAL_NOR_MODULE_ENABLED */
|
||||
/* #define HAL_PCCARD_MODULE_ENABLED */
|
||||
/* #define HAL_SRAM_MODULE_ENABLED */
|
||||
/* #define HAL_HASH_MODULE_ENABLED */
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
/* #define HAL_I2C_MODULE_ENABLED */
|
||||
/* #define HAL_I2S_MODULE_ENABLED */
|
||||
/* #define HAL_IWDG_MODULE_ENABLED */
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
/* #define HAL_RNG_MODULE_ENABLED */
|
||||
/* #define HAL_RTC_MODULE_ENABLED */
|
||||
/* #define HAL_SD_MODULE_ENABLED */
|
||||
/* #define HAL_SPI_MODULE_ENABLED */
|
||||
/* #define HAL_TIM_MODULE_ENABLED */
|
||||
/* #define HAL_UART_MODULE_ENABLED */
|
||||
/* #define HAL_USART_MODULE_ENABLED */
|
||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
#define HAL_PCD_MODULE_ENABLED
|
||||
/* #define HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
|
||||
/* ########################## HSE/HSI Values adaptation ##################### */
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature.*/
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE 32768U /*!< Value of the External Low Speed oscillator in Hz */
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
|
||||
#endif /* LSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief External clock source for I2S peripheral
|
||||
* This value is used by the I2S HAL module to compute the I2S clock source
|
||||
* frequency, this source is inserted directly through I2S_CKIN pad.
|
||||
*/
|
||||
#if !defined (EXTERNAL_CLOCK_VALUE)
|
||||
#define EXTERNAL_CLOCK_VALUE 12288000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* EXTERNAL_CLOCK_VALUE */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY 0x0FU /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 1U
|
||||
#define INSTRUCTION_CACHE_ENABLE 1U
|
||||
#define DATA_CACHE_ENABLE 1U
|
||||
|
||||
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
|
||||
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
|
||||
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */
|
||||
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
|
||||
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */
|
||||
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
|
||||
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */
|
||||
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
|
||||
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
|
||||
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
|
||||
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
|
||||
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
|
||||
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
|
||||
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
|
||||
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
|
||||
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
|
||||
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */
|
||||
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
|
||||
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
|
||||
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
|
||||
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
|
||||
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
|
||||
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
|
||||
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
|
||||
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
|
||||
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## Ethernet peripheral configuration for NUCLEO 144 board ##################### */
|
||||
|
||||
/* Section 1 : Ethernet peripheral configuration */
|
||||
|
||||
/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
|
||||
#define MAC_ADDR0 2U
|
||||
#define MAC_ADDR1 0U
|
||||
#define MAC_ADDR2 0U
|
||||
#define MAC_ADDR3 0U
|
||||
#define MAC_ADDR4 0U
|
||||
#define MAC_ADDR5 0U
|
||||
|
||||
/* Definition of the Ethernet driver buffers size and count */
|
||||
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
|
||||
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
|
||||
#define ETH_RXBUFNB 5U /* 5 Rx buffers of size ETH_RX_BUF_SIZE */
|
||||
#define ETH_TXBUFNB 5U /* 5 Tx buffers of size ETH_TX_BUF_SIZE */
|
||||
|
||||
/* Section 2: PHY configuration section */
|
||||
|
||||
/* LAN8742A PHY Address*/
|
||||
#define LAN8742A_PHY_ADDRESS 0x00U
|
||||
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
|
||||
#define PHY_RESET_DELAY 0x000000FFU
|
||||
/* PHY Configuration delay */
|
||||
#define PHY_CONFIG_DELAY 0x00000FFFU
|
||||
|
||||
#define PHY_READ_TO 0x0000FFFFU
|
||||
#define PHY_WRITE_TO 0x0000FFFFU
|
||||
|
||||
/* Section 3: Common PHY Registers */
|
||||
|
||||
#define PHY_BCR ((uint16_t)0x0000) /*!< Transceiver Basic Control Register */
|
||||
#define PHY_BSR ((uint16_t)0x0001) /*!< Transceiver Basic Status Register */
|
||||
|
||||
#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
|
||||
#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
|
||||
#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
|
||||
#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
|
||||
#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
|
||||
#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
|
||||
#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
|
||||
#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
|
||||
#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
|
||||
#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
|
||||
|
||||
#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
|
||||
#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
|
||||
#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
|
||||
|
||||
/* Section 4: Extended PHY Registers */
|
||||
|
||||
#define PHY_SR ((uint16_t)0x1F) /*!< PHY special control/ status register Offset */
|
||||
|
||||
#define PHY_SPEED_STATUS ((uint16_t)0x0004) /*!< PHY Speed mask */
|
||||
#define PHY_DUPLEX_STATUS ((uint16_t)0x0010) /*!< PHY Duplex mask */
|
||||
|
||||
|
||||
#define PHY_ISFR ((uint16_t)0x1D) /*!< PHY Interrupt Source Flag register Offset */
|
||||
#define PHY_ISFR_INT4 ((uint16_t)0x0010) /*!< PHY Link down inturrupt */
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 1U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_EXTI_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_exti.h"
|
||||
#endif /* HAL_EXTI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRYP_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_cryp.h"
|
||||
#endif /* HAL_CRYP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DCMI_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_dcmi.h"
|
||||
#endif /* HAL_DCMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ETH_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_eth.h"
|
||||
#endif /* HAL_ETH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCCARD_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_pccard.h"
|
||||
#endif /* HAL_PCCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HASH_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_hash.h"
|
||||
#endif /* HAL_HASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2S_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_i2s.h"
|
||||
#endif /* HAL_I2S_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_rng.h"
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32f2xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t* file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F2xx_HAL_CONF_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -9,11 +9,14 @@ CFLAGS += \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F3
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F3xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F3xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/stm32f303disco/STM32F303VCTx_FLASH.ld
|
||||
LD_FILE = hw/bsp/$(BOARD)/STM32F303VCTx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32f3xx.c \
|
||||
|
@ -13,7 +13,7 @@ ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F4xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/stm32f407disco/STM32F407VGTx_FLASH.ld
|
||||
LD_FILE = hw/bsp/$(BOARD)/STM32F407VGTx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32f4xx.c \
|
||||
|
@ -13,7 +13,7 @@ ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F4xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/stm32f411disco/STM32F411VETx_FLASH.ld
|
||||
LD_FILE = hw/bsp/$(BOARD)/STM32F411VETx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32f4xx.c \
|
||||
|
@ -9,11 +9,14 @@ CFLAGS += \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F4
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=maybe-uninitialized
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F4xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F4xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/stm32f412disco/STM32F412ZGTx_FLASH.ld
|
||||
LD_FILE = hw/bsp/$(BOARD)/STM32F412ZGTx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32f4xx.c \
|
||||
|
@ -9,8 +9,8 @@ CFLAGS += \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32F7
|
||||
|
||||
# The -Wno-error=sign-compare line is required due to STM32F7xx_HAL_Driver.
|
||||
CFLAGS += -Wno-error=shadow
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=shadow
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32F7xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32F7xx
|
||||
|
@ -174,15 +174,16 @@ uint32_t board_button_read(void)
|
||||
|
||||
int board_uart_read(uint8_t* buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
void SysTick_Handler (void)
|
||||
|
@ -9,11 +9,14 @@ CFLAGS += \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32H7
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=maybe-uninitialized
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32H7xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32H7xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/stm32h743nucleo/STM32H743ZITx_FLASH.ld
|
||||
LD_FILE = hw/bsp/$(BOARD)/STM32H743ZITx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32h7xx.c \
|
||||
|
@ -197,11 +197,13 @@ uint32_t board_button_read(void)
|
||||
|
||||
int board_uart_read(uint8_t* buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
169
hw/bsp/stm32l0538disco/STM32L053C8Tx_FLASH.ld
Normal file
169
hw/bsp/stm32l0538disco/STM32L053C8Tx_FLASH.ld
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
**
|
||||
|
||||
** File : LinkerScript.ld
|
||||
**
|
||||
** Abstract : Linker script for STM32L053C8Tx Device with
|
||||
** 64KByte FLASH, 8KByte RAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
**
|
||||
** Distribution: The file is distributed as is, without any warranty
|
||||
** of any kind.
|
||||
**
|
||||
** (c)Copyright Ac6.
|
||||
** You may use this file as-is or modify it according to the needs of your
|
||||
** project. Distribution of this file (unmodified or modified) is not
|
||||
** permitted. Ac6 permit registered System Workbench for MCU users the
|
||||
** rights to distribute the assembled, compiled & linked contents of this
|
||||
** file as part of an application binary file, provided that it is built
|
||||
** using the System Workbench for MCU toolchain.
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x20002000; /* end of RAM */
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0x200; /* required amount of heap */
|
||||
_Min_Stack_Size = 0x200; /* required amount of stack */
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
.isr_vector :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
/* Constant data goes into FLASH */
|
||||
.rodata :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
. = ALIGN(4);
|
||||
} >FLASH
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} >FLASH
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >FLASH
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >FLASH
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
|
||||
. = ALIGN(4);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >RAM AT> FLASH
|
||||
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE ( end = . );
|
||||
PROVIDE ( _end = . );
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Min_Stack_Size;
|
||||
. = ALIGN(8);
|
||||
} >RAM
|
||||
|
||||
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
|
||||
|
54
hw/bsp/stm32l0538disco/board.mk
Normal file
54
hw/bsp/stm32l0538disco/board.mk
Normal file
@ -0,0 +1,54 @@
|
||||
CFLAGS += \
|
||||
-DHSE_VALUE=8000000 \
|
||||
-DSTM32L053xx \
|
||||
-mthumb \
|
||||
-mabi=aapcs \
|
||||
-mcpu=cortex-m0plus \
|
||||
-mfloat-abi=soft \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_EXAMPLE_MSC_READONLY \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32L0
|
||||
|
||||
# mcu driver cause following warnings
|
||||
CFLAGS += -Wno-error=unused-parameter -Wno-error=maybe-uninitialized
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32L0xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32L0xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/$(BOARD)/STM32L053C8Tx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32l0xx.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l0xx_hal.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l0xx_hal_cortex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l0xx_hal_rcc.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l0xx_hal_rcc_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l0xx_hal_gpio.c
|
||||
|
||||
SRC_S += \
|
||||
$(ST_CMSIS)/Source/Templates/gcc/startup_stm32l053xx.s
|
||||
|
||||
INC += \
|
||||
$(TOP)/hw/mcu/st/st_driver/CMSIS/Include \
|
||||
$(TOP)/$(ST_CMSIS)/Include \
|
||||
$(TOP)/$(ST_HAL_DRIVER)/Inc \
|
||||
$(TOP)/hw/bsp/$(BOARD)
|
||||
|
||||
# For TinyUSB port source
|
||||
VENDOR = st
|
||||
CHIP_FAMILY = stm32_fsdev
|
||||
|
||||
# For freeRTOS port source
|
||||
FREERTOS_PORT = ARM_CM0
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = STM32L053R8
|
||||
JLINK_IF = swd
|
||||
|
||||
# Path to STM32 Cube Programmer CLI, should be added into system path
|
||||
STM32Prog = STM32_Programmer_CLI
|
||||
|
||||
# flash target using on-board stlink
|
||||
flash: $(BUILD)/$(BOARD)-firmware.elf
|
||||
$(STM32Prog) --connect port=swd --write $< --go
|
187
hw/bsp/stm32l0538disco/stm32l0538disco.c
Normal file
187
hw/bsp/stm32l0538disco/stm32l0538disco.c
Normal file
@ -0,0 +1,187 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include "../board.h"
|
||||
|
||||
#include "stm32l0xx.h"
|
||||
#include "stm32l0xx_hal_conf.h"
|
||||
|
||||
#define LED_PORT GPIOA
|
||||
#define LED_PIN GPIO_PIN_5
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_0
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* The system Clock is configured as follow:
|
||||
* HSI48 used as USB clock source
|
||||
* - System Clock source = HSI
|
||||
* - HSI Frequency(Hz) = 16000000
|
||||
* - SYSCLK(Hz) = 16000000
|
||||
* - HCLK(Hz) = 16000000
|
||||
* - AHB Prescaler = 1
|
||||
* - APB1 Prescaler = 1
|
||||
* - APB2 Prescaler = 1
|
||||
* - Flash Latency(WS) = 0
|
||||
* - Main regulator output voltage = Scale1 mode
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SystemClock_Config(void)
|
||||
{
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
||||
static RCC_CRSInitTypeDef RCC_CRSInitStruct;
|
||||
|
||||
/* Enable HSI Oscillator to be used as System clock source
|
||||
Enable HSI48 Oscillator to be used as USB clock source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSI48;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
|
||||
/* Select HSI48 as USB clock source */
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;
|
||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
||||
|
||||
/* Select HSI as system clock source and configure the HCLK, PCLK1 and PCLK2
|
||||
clock dividers */
|
||||
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
|
||||
|
||||
/*Configure the clock recovery system (CRS)**********************************/
|
||||
|
||||
/*Enable CRS Clock*/
|
||||
__HAL_RCC_CRS_CLK_ENABLE();
|
||||
|
||||
/* Default Synchro Signal division factor (not divided) */
|
||||
RCC_CRSInitStruct.Prescaler = RCC_CRS_SYNC_DIV1;
|
||||
/* Set the SYNCSRC[1:0] bits according to CRS_Source value */
|
||||
RCC_CRSInitStruct.Source = RCC_CRS_SYNC_SOURCE_USB;
|
||||
/* HSI48 is synchronized with USB SOF at 1KHz rate */
|
||||
RCC_CRSInitStruct.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000, 1000);
|
||||
RCC_CRSInitStruct.ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT;
|
||||
/* Set the TRIM[5:0] to the default value*/
|
||||
RCC_CRSInitStruct.HSI48CalibrationValue = 0x20;
|
||||
/* Start automatic synchronization */
|
||||
HAL_RCCEx_CRSConfig (&RCC_CRSInitStruct);
|
||||
}
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
// 1ms tick timer
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
|
||||
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
|
||||
#endif
|
||||
|
||||
SystemClock_Config();
|
||||
|
||||
// Notify runtime of frequency change.
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
// LED
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = LED_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
||||
|
||||
board_led_write(false);
|
||||
|
||||
// Button
|
||||
//__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
|
||||
|
||||
// USB
|
||||
/* Configure DM DP Pins */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Enable USB FS Clock */
|
||||
__HAL_RCC_USB_CLK_ENABLE();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Board porting API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void)
|
||||
{
|
||||
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
void SysTick_Handler (void)
|
||||
{
|
||||
system_ticks++;
|
||||
}
|
||||
|
||||
uint32_t board_millis(void)
|
||||
{
|
||||
return system_ticks;
|
||||
}
|
||||
#endif
|
||||
|
||||
void HardFault_Handler (void)
|
||||
{
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
// Required by __libc_init_array in startup code if we are compiling using
|
||||
// -nostdlib/-nostartfiles.
|
||||
void _init(void)
|
||||
{
|
||||
|
||||
}
|
331
hw/bsp/stm32l0538disco/stm32l0xx_hal_conf.h
Normal file
331
hw/bsp/stm32l0538disco/stm32l0xx_hal_conf.h
Normal file
@ -0,0 +1,331 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l0xx_hal_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief HAL configuration file.
|
||||
******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2016 STMicroelectronics International N.V. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted, provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistribution of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of other
|
||||
* contributors to this software may be used to endorse or promote products
|
||||
* derived from this software without specific written permission.
|
||||
* 4. This software, including modifications and/or derivative works of this
|
||||
* software, must execute solely and exclusively on microcontroller or
|
||||
* microprocessor devices manufactured by or for STMicroelectronics.
|
||||
* 5. Redistribution and use of this software other than as permitted under
|
||||
* this license is void and will automatically terminate your rights under
|
||||
* this license.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||||
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||||
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32L0xx_HAL_CONF_H
|
||||
#define __STM32L0xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
#define HAL_MODULE_ENABLED
|
||||
// #define HAL_ADC_MODULE_ENABLED
|
||||
/* #define HAL_COMP_MODULE_ENABLED */
|
||||
/* #define HAL_CRC_MODULE_ENABLED */
|
||||
/* #define HAL_CRYP_MODULE_ENABLED */
|
||||
/* #define HAL_DAC_MODULE_ENABLED */
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
/* #define HAL_FIREWALL_MODULE_ENABLED */
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
/* #define HAL_I2C_MODULE_ENABLED */
|
||||
/* #define HAL_I2S_MODULE_ENABLED */
|
||||
/* #define HAL_IWDG_MODULE_ENABLED */
|
||||
/* #define HAL_LCD_MODULE_ENABLED */
|
||||
/* #define HAL_LPTIM_MODULE_ENABLED */
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
//#define HAL_RNG_MODULE_ENABLED
|
||||
/* #define HAL_RTC_MODULE_ENABLED */
|
||||
//#define HAL_SPI_MODULE_ENABLED
|
||||
/* #define HAL_TIM_MODULE_ENABLED */
|
||||
/* #define HAL_TSC_MODULE_ENABLED */
|
||||
/* #define HAL_UART_MODULE_ENABLED */
|
||||
/* #define HAL_USART_MODULE_ENABLED */
|
||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/* #define HAL_SMBUS_MODULE_ENABLED */
|
||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||
//#define HAL_PCD_MODULE_ENABLED
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
/* #define HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE ((uint32_t)8000000U) /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT ((uint32_t)100U) /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal Multiple Speed oscillator (MSI) default value.
|
||||
* This value is the default MSI range value after Reset.
|
||||
*/
|
||||
#if !defined (MSI_VALUE)
|
||||
#define MSI_VALUE ((uint32_t)2097152U) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* MSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE ((uint32_t)16000000U) /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator for USB (HSI48) value.
|
||||
*/
|
||||
#if !defined (HSI48_VALUE)
|
||||
#define HSI48_VALUE ((uint32_t)48000000U) /*!< Value of the Internal High Speed oscillator for USB in Hz.
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature. */
|
||||
#endif /* HSI48_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE ((uint32_t)37000U) /*!< LSI Typical Value in Hz*/
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature.*/
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE ((uint32_t)32768U) /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Time out for LSE start up value in ms.
|
||||
*/
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000U) /*!< Time out for LSE start up, in ms */
|
||||
#endif /* LSE_STARTUP_TIMEOUT */
|
||||
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE ((uint32_t)3300U) /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY ((uint32_t)0U) /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 1U
|
||||
#define PREREAD_ENABLE 1U
|
||||
#define BUFFER_CACHE_DISABLE 0U
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1 */
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 1U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_COMP_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_comp.h"
|
||||
#endif /* HAL_COMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRYP_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_cryp.h"
|
||||
#endif /* HAL_CRYP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FIREWALL_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_firewall.h"
|
||||
#endif /* HAL_FIREWALL_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2S_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_i2s.h"
|
||||
#endif /* HAL_I2S_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LCD_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_lcd.h"
|
||||
#endif /* HAL_LCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_lptim.h"
|
||||
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_rng.h"
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TSC_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_tsc.h"
|
||||
#endif /* HAL_TSC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMBUS_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_smbus.h"
|
||||
#endif /* HAL_SMBUS_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32l0xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t *file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32L0xx_HAL_CONF_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
183
hw/bsp/stm32l476disco/STM32L476VGTx_FLASH.ld
Normal file
183
hw/bsp/stm32l476disco/STM32L476VGTx_FLASH.ld
Normal file
@ -0,0 +1,183 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
**
|
||||
|
||||
** File : LinkerScript.ld
|
||||
**
|
||||
** Abstract : Linker script for STM32L476VGTx Device with
|
||||
** 1024KByte FLASH, 96KByte RAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
**
|
||||
** Distribution: The file is distributed as is, without any warranty
|
||||
** of any kind.
|
||||
**
|
||||
** (c)Copyright Ac6.
|
||||
** You may use this file as-is or modify it according to the needs of your
|
||||
** project. Distribution of this file (unmodified or modified) is not
|
||||
** permitted. Ac6 permit registered System Workbench for MCU users the
|
||||
** rights to distribute the assembled, compiled & linked contents of this
|
||||
** file as part of an application binary file, provided that it is built
|
||||
** using the System Workbench for MCU toolchain.
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x20018000; /* end of RAM */
|
||||
/* Generate a link error if heap and stack don't fit into RAM */
|
||||
_Min_Heap_Size = 0x500; /* required amount of heap */
|
||||
_Min_Stack_Size = 0x1000; /* required amount of stack */
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
.isr_vector :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(8);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
/* Constant data goes into FLASH */
|
||||
.rodata :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
|
||||
.ARM.extab :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
.ARM : {
|
||||
. = ALIGN(8);
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
|
||||
.init_array :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
.fini_array :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
|
||||
. = ALIGN(8);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >RAM AT> FLASH
|
||||
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
PROVIDE ( end = . );
|
||||
PROVIDE ( _end = . );
|
||||
. = . + _Min_Heap_Size;
|
||||
. = . + _Min_Stack_Size;
|
||||
. = ALIGN(8);
|
||||
} >RAM
|
||||
|
||||
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
|
||||
|
53
hw/bsp/stm32l476disco/board.mk
Normal file
53
hw/bsp/stm32l476disco/board.mk
Normal file
@ -0,0 +1,53 @@
|
||||
CFLAGS += \
|
||||
-DHSE_VALUE=8000000 \
|
||||
-DSTM32L476xx \
|
||||
-mthumb \
|
||||
-mabi=aapcs \
|
||||
-mcpu=cortex-m4 \
|
||||
-mfloat-abi=hard \
|
||||
-mfpu=fpv4-sp-d16 \
|
||||
-nostdlib -nostartfiles \
|
||||
-DCFG_TUSB_MCU=OPT_MCU_STM32L4
|
||||
|
||||
ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32L4xx_HAL_Driver
|
||||
ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32L4xx
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = hw/bsp/$(BOARD)/STM32L476VGTx_FLASH.ld
|
||||
|
||||
SRC_C += \
|
||||
$(ST_CMSIS)/Source/Templates/system_stm32l4xx.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l4xx_hal.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l4xx_hal_cortex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l4xx_hal_rcc.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l4xx_hal_rcc_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l4xx_hal_pwr.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l4xx_hal_pwr_ex.c \
|
||||
$(ST_HAL_DRIVER)/Src/stm32l4xx_hal_gpio.c
|
||||
|
||||
SRC_S += \
|
||||
$(ST_CMSIS)/Source/Templates/gcc/startup_stm32l476xx.s
|
||||
|
||||
INC += \
|
||||
$(TOP)/hw/mcu/st/st_driver/CMSIS/Include \
|
||||
$(TOP)/$(ST_CMSIS)/Include \
|
||||
$(TOP)/$(ST_HAL_DRIVER)/Inc \
|
||||
$(TOP)/hw/bsp/$(BOARD)
|
||||
|
||||
# For TinyUSB port source
|
||||
VENDOR = st
|
||||
CHIP_FAMILY = synopsys
|
||||
|
||||
# For freeRTOS port source
|
||||
FREERTOS_PORT = ARM_CM4F
|
||||
|
||||
# For flash-jlink target
|
||||
JLINK_DEVICE = stm32l476vg
|
||||
JLINK_IF = swd
|
||||
|
||||
# Path to STM32 Cube Programmer CLI, should be added into system path
|
||||
STM32Prog = STM32_Programmer_CLI
|
||||
|
||||
# flash target using on-board stlink
|
||||
flash: $(BUILD)/$(BOARD)-firmware.elf
|
||||
$(STM32Prog) --connect port=swd --write $< --go
|
217
hw/bsp/stm32l476disco/stm32l476disco.c
Normal file
217
hw/bsp/stm32l476disco/stm32l476disco.c
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#include "../board.h"
|
||||
|
||||
#include "stm32l4xx.h"
|
||||
#include "stm32l4xx_hal_conf.h"
|
||||
|
||||
#define LED_PORT GPIOB
|
||||
#define LED_PIN GPIO_PIN_2
|
||||
#define LED_STATE_ON 1
|
||||
|
||||
#define BUTTON_PORT GPIOA
|
||||
#define BUTTON_PIN GPIO_PIN_0
|
||||
#define BUTTON_STATE_ACTIVE 1
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* The system Clock is configured as follow :
|
||||
*
|
||||
* If define USB_USE_LSE_MSI_CLOCK enabled:
|
||||
* System Clock source = PLL (MSI)
|
||||
* SYSCLK(Hz) = 80000000
|
||||
* HCLK(Hz) = 80000000
|
||||
* AHB Prescaler = 1
|
||||
* APB1 Prescaler = 1
|
||||
* APB2 Prescaler = 2
|
||||
* MSI Frequency(Hz) = 4800000
|
||||
* LSE Frequency(Hz) = 32768
|
||||
* PLL_M = 6
|
||||
* PLL_N = 40
|
||||
* PLL_P = 7
|
||||
* PLL_Q = 4
|
||||
* PLL_R = 4
|
||||
* Flash Latency(WS) = 4
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void SystemClock_Config(void)
|
||||
{
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
||||
|
||||
/* Enable the LSE Oscilator */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
|
||||
/* Enable the CSS interrupt in case LSE signal is corrupted or not present */
|
||||
HAL_RCCEx_DisableLSECSS();
|
||||
|
||||
/* Enable MSI Oscillator and activate PLL with MSI as source */
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
|
||||
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
|
||||
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_11;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
|
||||
RCC_OscInitStruct.PLL.PLLM = 6;
|
||||
RCC_OscInitStruct.PLL.PLLN = 40;
|
||||
RCC_OscInitStruct.PLL.PLLP = 7;
|
||||
RCC_OscInitStruct.PLL.PLLQ = 4;
|
||||
RCC_OscInitStruct.PLL.PLLR = 4;
|
||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
||||
|
||||
/* Enable MSI Auto-calibration through LSE */
|
||||
HAL_RCCEx_EnableMSIPLLMode();
|
||||
|
||||
/* Select MSI output as USB clock source */
|
||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
|
||||
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_MSI;
|
||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
|
||||
|
||||
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
||||
clocks dividers */
|
||||
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
|
||||
}
|
||||
|
||||
void board_init(void)
|
||||
{
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
// 1ms tick timer
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
|
||||
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
|
||||
#endif
|
||||
|
||||
SystemClock_Config();
|
||||
|
||||
HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_MSI, RCC_MCODIV_1);//RCC_MCO1SOURCE_SYSCLK
|
||||
|
||||
/* Enable Power Clock*/
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
|
||||
/* Enable USB power on Pwrctrl CR2 register */
|
||||
HAL_PWREx_EnableVddUSB();
|
||||
|
||||
// Notify runtime of frequency change.
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
// LED
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = LED_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
HAL_GPIO_Init(LED_PORT, &GPIO_InitStruct);
|
||||
|
||||
board_led_write(false);
|
||||
|
||||
// Button
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = BUTTON_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
||||
HAL_GPIO_Init(BUTTON_PORT, &GPIO_InitStruct);
|
||||
|
||||
// USB
|
||||
/* Configure DM DP Pins */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Configure VBUS Pin */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_11;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* This for ID line */
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_12;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* Enable USB FS Clock */
|
||||
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Board porting API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
void board_led_write(bool state)
|
||||
{
|
||||
HAL_GPIO_WritePin(LED_PORT, LED_PIN, state ? LED_STATE_ON : (1-LED_STATE_ON));
|
||||
}
|
||||
|
||||
uint32_t board_button_read(void)
|
||||
{
|
||||
return BUTTON_STATE_ACTIVE == HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN);
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
volatile uint32_t system_ticks = 0;
|
||||
void SysTick_Handler (void)
|
||||
{
|
||||
system_ticks++;
|
||||
}
|
||||
|
||||
uint32_t board_millis(void)
|
||||
{
|
||||
return system_ticks;
|
||||
}
|
||||
#endif
|
||||
|
||||
void HardFault_Handler (void)
|
||||
{
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
// Required by __libc_init_array in startup code if we are compiling using
|
||||
// -nostdlib/-nostartfiles.
|
||||
void _init(void)
|
||||
{
|
||||
|
||||
}
|
380
hw/bsp/stm32l476disco/stm32l4xx_hal_conf.h
Normal file
380
hw/bsp/stm32l476disco/stm32l4xx_hal_conf.h
Normal file
@ -0,0 +1,380 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32l4xx_hal_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief HAL configuration template file.
|
||||
* This file should be copied to the application folder and renamed
|
||||
* to stm32l4xx_hal_conf.h.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __STM32L4xx_HAL_CONF_H
|
||||
#define __STM32L4xx_HAL_CONF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/* ########################## Module Selection ############################## */
|
||||
/**
|
||||
* @brief This is the list of modules to be used in the HAL driver
|
||||
*/
|
||||
#define HAL_MODULE_ENABLED
|
||||
/* #define HAL_ADC_MODULE_ENABLED */
|
||||
/* #define HAL_CAN_MODULE_ENABLED */
|
||||
/* #define HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
/* #define HAL_COMP_MODULE_ENABLED */
|
||||
#define HAL_CORTEX_MODULE_ENABLED
|
||||
/* #define HAL_CRC_MODULE_ENABLED */
|
||||
/* #define HAL_CRYP_MODULE_ENABLED */
|
||||
/* #define HAL_DAC_MODULE_ENABLED */
|
||||
/* #define HAL_DFSDM_MODULE_ENABLED */
|
||||
#define HAL_DMA_MODULE_ENABLED
|
||||
/* #define HAL_FIREWALL_MODULE_ENABLED */
|
||||
#define HAL_FLASH_MODULE_ENABLED
|
||||
/* #define HAL_NAND_MODULE_ENABLED */
|
||||
#define HAL_NOR_MODULE_ENABLED
|
||||
#define HAL_SRAM_MODULE_ENABLED
|
||||
/* #define HAL_HCD_MODULE_ENABLED */
|
||||
#define HAL_GPIO_MODULE_ENABLED
|
||||
//#define HAL_I2C_MODULE_ENABLED
|
||||
/* #define HAL_IRDA_MODULE_ENABLED */
|
||||
/* #define HAL_IWDG_MODULE_ENABLED */
|
||||
//#define HAL_LCD_MODULE_ENABLED
|
||||
/* #define HAL_LPTIM_MODULE_ENABLED */
|
||||
/* #define HAL_OPAMP_MODULE_ENABLED */
|
||||
//#define HAL_PCD_MODULE_ENABLED
|
||||
#define HAL_PWR_MODULE_ENABLED
|
||||
/* #define HAL_QSPI_MODULE_ENABLED */
|
||||
#define HAL_RCC_MODULE_ENABLED
|
||||
/* #define HAL_RNG_MODULE_ENABLED */
|
||||
/* #define HAL_RTC_MODULE_ENABLED */
|
||||
//#define HAL_SAI_MODULE_ENABLED
|
||||
//#define HAL_SD_MODULE_ENABLED
|
||||
/* #define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/* #define HAL_SMBUS_MODULE_ENABLED */
|
||||
/* #define HAL_SPI_MODULE_ENABLED */
|
||||
/* #define HAL_SWPMI_MODULE_ENABLED */
|
||||
/* #define HAL_TIM_MODULE_ENABLED */
|
||||
/* #define HAL_TSC_MODULE_ENABLED */
|
||||
//#define HAL_UART_MODULE_ENABLED
|
||||
/* #define HAL_USART_MODULE_ENABLED */
|
||||
/* #define HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
|
||||
/* ########################## Oscillator Values adaptation ####################*/
|
||||
/**
|
||||
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSE is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSE_VALUE)
|
||||
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
|
||||
#endif /* HSE_VALUE */
|
||||
|
||||
#if !defined (HSE_STARTUP_TIMEOUT)
|
||||
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief Internal Multiple Speed oscillator (MSI) default value.
|
||||
* This value is the default MSI range value after Reset.
|
||||
*/
|
||||
#if !defined (MSI_VALUE)
|
||||
#define MSI_VALUE 4000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* MSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI) value.
|
||||
* This value is used by the RCC HAL module to compute the system frequency
|
||||
* (when HSI is used as system clock source, directly or through the PLL).
|
||||
*/
|
||||
#if !defined (HSI_VALUE)
|
||||
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal High Speed oscillator (HSI48) value for USB FS, SDMMC and RNG.
|
||||
* This internal oscillator is mainly dedicated to provide a high precision clock to
|
||||
* the USB peripheral by means of a special Clock Recovery System (CRS) circuitry.
|
||||
* When the CRS is not used, the HSI48 RC oscillator runs on it default frequency
|
||||
* which is subject to manufacturing process variations.
|
||||
*/
|
||||
#if !defined (HSI48_VALUE)
|
||||
#define HSI48_VALUE 48000000U /*!< Value of the Internal High Speed oscillator for USB FS/SDMMC/RNG in Hz.
|
||||
The real value my vary depending on manufacturing process variations.*/
|
||||
#endif /* HSI48_VALUE */
|
||||
|
||||
/**
|
||||
* @brief Internal Low Speed oscillator (LSI) value.
|
||||
*/
|
||||
#if !defined (LSI_VALUE)
|
||||
#define LSI_VALUE 32000U /*!< LSI Typical Value in Hz*/
|
||||
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
|
||||
The real value may vary depending on the variations
|
||||
in voltage and temperature.*/
|
||||
/**
|
||||
* @brief External Low Speed oscillator (LSE) value.
|
||||
* This value is used by the UART, RTC HAL module to compute the system frequency
|
||||
*/
|
||||
#if !defined (LSE_VALUE)
|
||||
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
|
||||
#endif /* LSE_VALUE */
|
||||
|
||||
#if !defined (LSE_STARTUP_TIMEOUT)
|
||||
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
|
||||
#endif /* HSE_STARTUP_TIMEOUT */
|
||||
|
||||
/**
|
||||
* @brief External clock source for SAI1 peripheral
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* frequency.
|
||||
*/
|
||||
#if !defined (EXTERNAL_SAI1_CLOCK_VALUE)
|
||||
#define EXTERNAL_SAI1_CLOCK_VALUE 48000U /*!< Value of the SAI1 External clock source in Hz*/
|
||||
#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
|
||||
|
||||
/**
|
||||
* @brief External clock source for SAI2 peripheral
|
||||
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
|
||||
* frequency.
|
||||
*/
|
||||
#if !defined (EXTERNAL_SAI2_CLOCK_VALUE)
|
||||
#define EXTERNAL_SAI2_CLOCK_VALUE 48000U /*!< Value of the SAI2 External clock source in Hz*/
|
||||
#endif /* EXTERNAL_SAI2_CLOCK_VALUE */
|
||||
|
||||
/* Tip: To avoid modifying this file each time you need to use different HSE,
|
||||
=== you can define the HSE value in your toolchain compiler preprocessor. */
|
||||
|
||||
/* ########################### System Configuration ######################### */
|
||||
/**
|
||||
* @brief This is the HAL system configuration section
|
||||
*/
|
||||
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
|
||||
#define TICK_INT_PRIORITY 0U /*!< tick interrupt priority */
|
||||
#define USE_RTOS 0U
|
||||
#define PREFETCH_ENABLE 0U
|
||||
#define INSTRUCTION_CACHE_ENABLE 1U
|
||||
#define DATA_CACHE_ENABLE 1U
|
||||
|
||||
/* ########################## Assert Selection ############################## */
|
||||
/**
|
||||
* @brief Uncomment the line below to expanse the "assert_param" macro in the
|
||||
* HAL drivers code
|
||||
*/
|
||||
/* #define USE_FULL_ASSERT 1U */
|
||||
|
||||
/* ################## SPI peripheral configuration ########################## */
|
||||
|
||||
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
|
||||
* Activated: CRC code is present inside driver
|
||||
* Deactivated: CRC code cleaned from driver
|
||||
*/
|
||||
|
||||
#define USE_SPI_CRC 1U
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Include module's header file
|
||||
*/
|
||||
|
||||
#ifdef HAL_RCC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rcc.h"
|
||||
#endif /* HAL_RCC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_GPIO_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_gpio.h"
|
||||
#endif /* HAL_GPIO_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DMA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dma.h"
|
||||
#endif /* HAL_DMA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DFSDM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dfsdm.h"
|
||||
#endif /* HAL_DFSDM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CORTEX_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_cortex.h"
|
||||
#endif /* HAL_CORTEX_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_ADC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_adc.h"
|
||||
#endif /* HAL_ADC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_can.h"
|
||||
#endif /* HAL_CAN_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
|
||||
#include "Legacy/stm32l4xx_hal_can_legacy.h"
|
||||
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_COMP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_comp.h"
|
||||
#endif /* HAL_COMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_crc.h"
|
||||
#endif /* HAL_CRC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_CRYP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_cryp.h"
|
||||
#endif /* HAL_CRYP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_DAC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_dac.h"
|
||||
#endif /* HAL_DAC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FIREWALL_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_firewall.h"
|
||||
#endif /* HAL_FIREWALL_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_FLASH_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_flash.h"
|
||||
#endif /* HAL_FLASH_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SRAM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sram.h"
|
||||
#endif /* HAL_SRAM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NOR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nor.h"
|
||||
#endif /* HAL_NOR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_NAND_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_nand.h"
|
||||
#endif /* HAL_NAND_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_I2C_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_i2c.h"
|
||||
#endif /* HAL_I2C_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_iwdg.h"
|
||||
#endif /* HAL_IWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lcd.h"
|
||||
#endif /* HAL_LCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_LPTIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_lptim.h"
|
||||
#endif /* HAL_LPTIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_OPAMP_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_opamp.h"
|
||||
#endif /* HAL_OPAMP_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PWR_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pwr.h"
|
||||
#endif /* HAL_PWR_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_QSPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_qspi.h"
|
||||
#endif /* HAL_QSPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RNG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rng.h"
|
||||
#endif /* HAL_RNG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_RTC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_rtc.h"
|
||||
#endif /* HAL_RTC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SAI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sai.h"
|
||||
#endif /* HAL_SAI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_sd.h"
|
||||
#endif /* HAL_SD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMBUS_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smbus.h"
|
||||
#endif /* HAL_SMBUS_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SPI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_spi.h"
|
||||
#endif /* HAL_SPI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SWPMI_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_swpmi.h"
|
||||
#endif /* HAL_SWPMI_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TIM_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_tim.h"
|
||||
#endif /* HAL_TIM_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_TSC_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_tsc.h"
|
||||
#endif /* HAL_TSC_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_UART_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_uart.h"
|
||||
#endif /* HAL_UART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_USART_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_usart.h"
|
||||
#endif /* HAL_USART_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_IRDA_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_irda.h"
|
||||
#endif /* HAL_IRDA_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_smartcard.h"
|
||||
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_WWDG_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_wwdg.h"
|
||||
#endif /* HAL_WWDG_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_PCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_pcd.h"
|
||||
#endif /* HAL_PCD_MODULE_ENABLED */
|
||||
|
||||
#ifdef HAL_HCD_MODULE_ENABLED
|
||||
#include "stm32l4xx_hal_hcd.h"
|
||||
#endif /* HAL_HCD_MODULE_ENABLED */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief The assert_param macro is used for function's parameters check.
|
||||
* @param expr: If expr is false, it calls assert_failed function
|
||||
* which reports the name of the source file and the source
|
||||
* line number of the call that failed.
|
||||
* If expr is true, it returns no value.
|
||||
* @retval None
|
||||
*/
|
||||
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
void assert_failed(uint8_t *file, uint32_t line);
|
||||
#else
|
||||
#define assert_param(expr) ((void)0U)
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __STM32L4xx_HAL_CONF_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
@ -1,52 +0,0 @@
|
||||
This README describes the layout of system files and headers for
|
||||
microcontrollers supported by tinyusb from the vendor [ST](www.st.com).
|
||||
|
||||
The CMSIS by ARM is an attempt to unify how system initialization and headers
|
||||
for ARM microcontrollers are handled across vendors. A vendor is expected to
|
||||
provide a number of files, including vendor-specific device headers,
|
||||
vendor-specific system init code (in C), vendor-specific startup code (coded in
|
||||
assembly _and_ meant to make writing C interrupt handlers easy), and ARM
|
||||
architecture-specific headers. In practice, it's actually difficult to find all
|
||||
these files in one place.
|
||||
|
||||
* stm32cube generates a self-contained application. All the relevant headers,
|
||||
system init, and startup code are under `Drivers/CMSIS`. The linker script is
|
||||
stored at the root of your project, _along_ with a copy of the startup code.
|
||||
Relative to `Drivers/CMSIS`:
|
||||
* Device header files are stored under `Device/ST/$family/Include`.
|
||||
* Arm-provided CMSIS headers are stored under `Include`.
|
||||
* The portable C portion of the startup code, called `system_$family.c`, is
|
||||
stored under `Device/ST/$family/Source/Templates`. This "system init" code
|
||||
is required by CMSIS.
|
||||
* The assembly portion of the startup code, called `startup_$device.c`, is
|
||||
stored under `Device\ST\STM32F4xx\Source\Templates\gcc`.
|
||||
|
||||
* Micropython maintains [a repo](https://github.com/micropython/stm32lib)
|
||||
with _only_ the device header files. We use that
|
||||
repo and provide the remaining files ourselves.
|
||||
* Micropython keeps the linker script and assembly portion of the startup
|
||||
code under the
|
||||
[boards](https://github.com/micropython/micropython/tree/master/ports/stm32/boards)
|
||||
directory in the stm32 port (but the code is board agnostic).
|
||||
* Micropython also embeds its own
|
||||
[copy](https://github.com/micropython/micropython/tree/master/lib/cmsis/inc)
|
||||
of CMSIS headers for all ARM targets into the repo.
|
||||
* Micropython indeed _does_ use their own custom C startup code (CMSIS system
|
||||
init) for
|
||||
[stm32](https://github.com/micropython/micropython/blob/master/ports/stm32/system_stm32.c)
|
||||
targets. It is
|
||||
[missing](https://github.com/micropython/micropython/commit/fdbc22e4d27b9d1c686647c9c67a32206f7bc83a)
|
||||
the `SystemCoreClockUpdate` function.
|
||||
|
||||
* TinyUSB uses Micropython's [stm32lib](stm32lib) as a submodule to provide
|
||||
device headers. The remaining system files can be found in the following
|
||||
directories:
|
||||
* C system init code is in the [system-init](system-init) directory.
|
||||
* Assembly startup code is in the [startup](startup) directory. Each family
|
||||
gets its own subdirectory under startup (e.g. [stm32f4](startup/stm32f4)).
|
||||
* ARM-provided headers are stored in the [cmsis](cmsis) directory.
|
||||
* The linker script for the STM32F4-DISCOVERY board demo is supplied as
|
||||
part of TinyUSB's
|
||||
[Board Support Packages](../../bsp/stm32f407disco/STM32F407VGTx_FLASH.ld).
|
||||
The above files were extracted from a dummy stm32cube project in February
|
||||
2019.
|
@ -46,12 +46,13 @@ typedef struct
|
||||
uint8_t boot_protocol; // Boot mouse or keyboard
|
||||
bool boot_mode; // default = false (Report)
|
||||
uint8_t idle_rate; // up to application to handle idle rate
|
||||
uint16_t reprot_desc_len;
|
||||
uint16_t report_desc_len;
|
||||
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_HID_BUFSIZE];
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_HID_BUFSIZE];
|
||||
|
||||
}hidd_interface_t;
|
||||
tusb_hid_descriptor_hid_t const * hid_descriptor;
|
||||
} hidd_interface_t;
|
||||
|
||||
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID];
|
||||
|
||||
@ -73,7 +74,7 @@ bool tud_hid_ready(void)
|
||||
{
|
||||
uint8_t itf = 0;
|
||||
uint8_t const ep_in = _hidd_itf[itf].ep_in;
|
||||
return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
|
||||
return tud_ready() && (ep_in != 0) && usbd_edpt_ready(TUD_OPT_RHPORT, ep_in);
|
||||
}
|
||||
|
||||
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
||||
@ -167,8 +168,8 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
|
||||
|
||||
//------------- HID descriptor -------------//
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||
TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType);
|
||||
p_hid->hid_descriptor = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||
TU_ASSERT(HID_DESC_TYPE_HID == p_hid->hid_descriptor->bDescriptorType);
|
||||
|
||||
//------------- Endpoint Descriptor -------------//
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
@ -178,7 +179,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
|
||||
|
||||
p_hid->boot_mode = false; // default mode is REPORT
|
||||
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
||||
memcpy(&p_hid->reprot_desc_len, &desc_hid->wReportLength, 2);
|
||||
memcpy(&p_hid->report_desc_len, &(p_hid->hid_descriptor->wReportLength), 2);
|
||||
|
||||
*p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
@ -192,6 +193,10 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
|
||||
// return false to stall control endpoint (e.g unsupported request)
|
||||
bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
if (p_request->bmRequestType_bit.recipient != TUSB_REQ_RCPT_INTERFACE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex );
|
||||
TU_ASSERT(p_hid);
|
||||
|
||||
@ -202,11 +207,17 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
|
||||
uint8_t const desc_index = tu_u16_low (p_request->wValue);
|
||||
(void) desc_index;
|
||||
|
||||
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_HID)
|
||||
{
|
||||
TU_VERIFY(p_hid->hid_descriptor != NULL);
|
||||
TU_VERIFY(tud_control_xfer(rhport, p_request, (void*) p_hid->hid_descriptor, p_hid->hid_descriptor->bLength));
|
||||
}
|
||||
else if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||
{
|
||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb();
|
||||
tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->reprot_desc_len);
|
||||
}else
|
||||
tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->report_desc_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // stall unsupported request
|
||||
}
|
||||
@ -251,7 +262,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
|
||||
|
||||
case HID_REQ_CONTROL_GET_PROTOCOL:
|
||||
{
|
||||
uint8_t protocol = 1-p_hid->boot_mode; // 0 is Boot, 1 is Report protocol
|
||||
uint8_t protocol = (uint8_t)(1-p_hid->boot_mode); // 0 is Boot, 1 is Report protocol
|
||||
tud_control_xfer(rhport, p_request, &protocol, 1);
|
||||
}
|
||||
break;
|
||||
|
@ -86,16 +86,19 @@ bool tud_midi_n_mounted (uint8_t itf)
|
||||
//--------------------------------------------------------------------+
|
||||
uint32_t tud_midi_n_available(uint8_t itf, uint8_t jack_id)
|
||||
{
|
||||
(void) jack_id;
|
||||
return tu_fifo_count(&_midid_itf[itf].rx_ff);
|
||||
}
|
||||
|
||||
uint32_t tud_midi_n_read(uint8_t itf, uint8_t jack_id, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
(void) jack_id;
|
||||
return tu_fifo_read_n(&_midid_itf[itf].rx_ff, buffer, bufsize);
|
||||
}
|
||||
|
||||
void tud_midi_n_read_flush (uint8_t itf, uint8_t jack_id)
|
||||
{
|
||||
(void) jack_id;
|
||||
tu_fifo_clear(&_midid_itf[itf].rx_ff);
|
||||
}
|
||||
|
||||
@ -128,6 +131,8 @@ void midi_rx_done_cb(midid_interface_t* midi, uint8_t const* buffer, uint32_t bu
|
||||
|
||||
static bool maybe_transmit(midid_interface_t* midi, uint8_t itf_index)
|
||||
{
|
||||
(void) itf_index;
|
||||
|
||||
// skip if previous transfer not complete
|
||||
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, midi->ep_in) );
|
||||
|
||||
@ -309,11 +314,15 @@ bool midid_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc,
|
||||
|
||||
bool midid_control_complete(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
return false;
|
||||
(void) rhport;
|
||||
(void) p_request;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool midid_control_request(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
//------------- Class Specific Request -------------//
|
||||
if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return false;
|
||||
|
||||
@ -322,6 +331,8 @@ bool midid_control_request(uint8_t rhport, tusb_control_request_t const * p_requ
|
||||
|
||||
bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) result;
|
||||
|
||||
// TODO Support multiple interfaces
|
||||
uint8_t const itf = 0;
|
||||
midid_interface_t* p_midi = &_midid_itf[itf];
|
||||
|
316
src/class/usbtmc/usbtmc.h
Normal file
316
src/class/usbtmc/usbtmc.h
Normal file
@ -0,0 +1,316 @@
|
||||
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 N Conrad
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
#ifndef _TUSB_USBTMC_H__
|
||||
#define _TUSB_USBTMC_H__
|
||||
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
|
||||
/* Implements USBTMC Revision 1.0, April 14, 2003
|
||||
|
||||
String descriptors must have a "LANGID=0x409"/US English string.
|
||||
Characters must be 0x20 (' ') to 0x7E ('~') ASCII,
|
||||
But MUST not contain: "/:?\*
|
||||
Also must not have leading or trailing space (' ')
|
||||
Device descriptor must state USB version 0x0200 or greater
|
||||
|
||||
If USB488DeviceCapabilites.D2 = 1 (SR1), then there must be a INT endpoint.
|
||||
*/
|
||||
|
||||
#define USBTMC_VERSION 0x0100
|
||||
#define USBTMC_488_VERSION 0x0100
|
||||
|
||||
typedef enum {
|
||||
USBTMC_MSGID_DEV_DEP_MSG_OUT = 1u,
|
||||
USBTMC_MSGID_DEV_DEP_MSG_IN = 2u,
|
||||
USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT = 126u,
|
||||
USBTMC_MSGID_VENDOR_SPECIFIC_IN = 127u,
|
||||
USBTMC_MSGID_USB488_TRIGGER = 128u,
|
||||
} usbtmc_msgid_enum;
|
||||
|
||||
/// \brief Message header (For BULK OUT and BULK IN); 4 bytes
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t MsgID ; ///< Message type ID (usbtmc_msgid_enum)
|
||||
uint8_t bTag ; ///< Transfer ID 1<=bTag<=255
|
||||
uint8_t bTagInverse ; ///< Complement of the tag
|
||||
uint8_t _reserved ; ///< Must be 0x00
|
||||
} usbtmc_msg_header_t;
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
usbtmc_msg_header_t header;
|
||||
uint8_t data[8];
|
||||
} usbtmc_msg_generic_t;
|
||||
|
||||
/* Uses on the bulk-out endpoint: */
|
||||
// Next 8 bytes are message-specific
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
usbtmc_msg_header_t header ; ///< Header
|
||||
uint32_t TransferSize ; ///< Transfer size; LSB first
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int EOM : 1 ; ///< EOM set on last byte
|
||||
} bmTransferAttributes;
|
||||
uint8_t _reserved[3];
|
||||
} usbtmc_msg_request_dev_dep_out;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_out) == 12u, "struct wrong length");
|
||||
|
||||
// Next 8 bytes are message-specific
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
usbtmc_msg_header_t header ; ///< Header
|
||||
uint32_t TransferSize ; ///< Transfer size; LSB first
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int TermCharEnabled : 1 ; ///< "The Bulk-IN transfer must terminate on the specified TermChar."; CAPABILITIES must list TermChar
|
||||
} bmTransferAttributes;
|
||||
uint8_t TermChar;
|
||||
uint8_t _reserved[2];
|
||||
} usbtmc_msg_request_dev_dep_in;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_in) == 12u, "struct wrong length");
|
||||
|
||||
/* Bulk-in headers */
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
usbtmc_msg_header_t header;
|
||||
uint32_t TransferSize;
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t EOM: 1; ///< Last byte of transfer is the end of the message
|
||||
uint8_t UsingTermChar: 1; ///< Support TermChar && Request.TermCharEnabled && last char in transfer is TermChar
|
||||
} bmTransferAttributes;
|
||||
uint8_t _reserved[3];
|
||||
} usbtmc_msg_dev_dep_msg_in_header_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_msg_dev_dep_msg_in_header_t) == 12u, "struct wrong length");
|
||||
|
||||
/* Unsupported vendor things.... Are these ever used?*/
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
usbtmc_msg_header_t header ; ///< Header
|
||||
uint32_t TransferSize ; ///< Transfer size; LSB first
|
||||
uint8_t _reserved[4];
|
||||
} usbtmc_msg_request_vendor_specific_out;
|
||||
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_vendor_specific_out) == 12u, "struct wrong length");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
usbtmc_msg_header_t header ; ///< Header
|
||||
uint32_t TransferSize ; ///< Transfer size; LSB first
|
||||
uint8_t _reserved[4];
|
||||
} usbtmc_msg_request_vendor_specific_in;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_vendor_specific_in) == 12u, "struct wrong length");
|
||||
|
||||
// Control request type should use tusb_control_request_t
|
||||
|
||||
/*
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
struct {
|
||||
unsigned int Recipient : 5 ; ///< EOM set on last byte
|
||||
unsigned int Type : 2 ; ///< EOM set on last byte
|
||||
unsigned int DirectionToHost : 1 ; ///< 0 is OUT, 1 is IN
|
||||
} bmRequestType;
|
||||
uint8_t bRequest ; ///< If bmRequestType.Type = Class, see usmtmc_request_type_enum
|
||||
uint16_t wValue ;
|
||||
uint16_t wIndex ;
|
||||
uint16_t wLength ; // Number of bytes in data stage
|
||||
} usbtmc_class_specific_control_req;
|
||||
|
||||
*/
|
||||
// bulk-in protocol errors
|
||||
enum {
|
||||
USBTMC_BULK_IN_ERR_INCOMPLETE_HEADER = 1u,
|
||||
USBTMC_BULK_IN_ERR_UNSUPPORTED = 2u,
|
||||
USBTMC_BULK_IN_ERR_BAD_PARAMETER = 3u,
|
||||
USBTMC_BULK_IN_ERR_DATA_TOO_SHORT = 4u,
|
||||
USBTMC_BULK_IN_ERR_DATA_TOO_LONG = 5u,
|
||||
};
|
||||
// bult-in halt errors
|
||||
enum {
|
||||
USBTMC_BULK_IN_ERR = 1u, ///< receives a USBTMC command message that expects a response while a
|
||||
/// Bulk-IN transfer is in progress
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
USBTMC_bREQUEST_INITIATE_ABORT_BULK_OUT = 1u,
|
||||
USBTMC_bREQUEST_CHECK_ABORT_BULK_OUT_STATUS = 2u,
|
||||
USBTMC_bREQUEST_INITIATE_ABORT_BULK_IN = 3u,
|
||||
USBTMC_bREQUEST_CHECK_ABORT_BULK_IN_STATUS = 4u,
|
||||
USBTMC_bREQUEST_INITIATE_CLEAR = 5u,
|
||||
USBTMC_bREQUEST_CHECK_CLEAR_STATUS = 6u,
|
||||
USBTMC_bREQUEST_GET_CAPABILITIES = 7u,
|
||||
|
||||
USBTMC_bREQUEST_INDICATOR_PULSE = 64u, // Optional
|
||||
|
||||
/****** USBTMC 488 *************/
|
||||
USB488_bREQUEST_READ_STATUS_BYTE = 128u,
|
||||
USB488_bREQUEST_REN_CONTROL = 160u,
|
||||
USB488_bREQUEST_GO_TO_LOCAL = 161u,
|
||||
USB488_bREQUEST_LOCAL_LOCKOUT = 162u,
|
||||
|
||||
} usmtmc_request_type_enum;
|
||||
|
||||
typedef enum {
|
||||
USBTMC_STATUS_SUCCESS = 0x01,
|
||||
USBTMC_STATUS_PENDING = 0x02,
|
||||
USBTMC_STATUS_FAILED = 0x80,
|
||||
USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS = 0x81,
|
||||
USBTMC_STATUS_SPLIT_NOT_IN_PROGRESS = 0x82,
|
||||
USBTMC_STATUS_SPLIT_IN_PROGRESS = 0x83
|
||||
} usbtmc_status_enum;
|
||||
|
||||
/************************************************************
|
||||
* Control Responses
|
||||
*/
|
||||
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
uint8_t USBTMC_status; ///< usbtmc_status_enum
|
||||
uint8_t _reserved;
|
||||
uint16_t bcdUSBTMC; ///< USBTMC_VERSION
|
||||
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int listenOnly :1;
|
||||
unsigned int talkOnly :1;
|
||||
unsigned int supportsIndicatorPulse :1;
|
||||
} bmIntfcCapabilities;
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int canEndBulkInOnTermChar :1;
|
||||
} bmDevCapabilities;
|
||||
uint8_t _reserved2[6];
|
||||
uint8_t _reserved3[12];
|
||||
} usbtmc_response_capabilities_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_response_capabilities_t) == 0x18, "struct wrong length");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t USBTMC_status;
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int BulkInFifoBytes :1;
|
||||
} bmClear;
|
||||
} usbtmc_get_clear_status_rsp_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_get_clear_status_rsp_t) == 2u, "struct wrong length");
|
||||
|
||||
// Used for both abort bulk IN and bulk OUT
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t USBTMC_status;
|
||||
uint8_t bTag;
|
||||
} usbtmc_initiate_abort_rsp_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_get_clear_status_rsp_t) == 2u, "struct wrong length");
|
||||
|
||||
// Used for both check_abort_bulk_in_status and check_abort_bulk_out_status
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t USBTMC_status;
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int BulkInFifoBytes : 1; ///< Has queued data or a short packet that is queued
|
||||
} bmAbortBulkIn;
|
||||
uint8_t _reserved[2]; ///< Must be zero
|
||||
uint32_t NBYTES_RXD_TXD;
|
||||
} usbtmc_check_abort_bulk_rsp_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_check_abort_bulk_rsp_t) == 8u, "struct wrong length");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t USBTMC_status; ///< usbtmc_status_enum
|
||||
uint8_t _reserved;
|
||||
uint16_t bcdUSBTMC; ///< USBTMC_VERSION
|
||||
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int listenOnly :1;
|
||||
unsigned int talkOnly :1;
|
||||
unsigned int supportsIndicatorPulse :1;
|
||||
} bmIntfcCapabilities;
|
||||
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int canEndBulkInOnTermChar :1;
|
||||
} bmDevCapabilities;
|
||||
|
||||
uint8_t _reserved2[6];
|
||||
uint16_t bcdUSB488;
|
||||
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int is488_2 :1;
|
||||
unsigned int supportsREN_GTL_LLO :1;
|
||||
unsigned int supportsTrigger :1;
|
||||
} bmIntfcCapabilities488;
|
||||
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int SCPI :1;
|
||||
unsigned int SR1 :1;
|
||||
unsigned int RL1 :1;
|
||||
unsigned int DT1 :1;
|
||||
} bmDevCapabilities488;
|
||||
uint8_t _reserved3[8];
|
||||
} usbtmc_response_capabilities_488_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_response_capabilities_488_t) == 0x18, "struct wrong length");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
uint8_t USBTMC_status;
|
||||
uint8_t bTag;
|
||||
uint8_t statusByte;
|
||||
} usbtmc_read_stb_rsp_488_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_read_stb_rsp_488_t) == 3u, "struct wrong length");
|
||||
|
||||
typedef struct TU_ATTR_PACKED
|
||||
{
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
unsigned int bTag : 7;
|
||||
unsigned int one : 1;
|
||||
} bNotify1;
|
||||
uint8_t StatusByte;
|
||||
} usbtmc_read_stb_interrupt_488_t;
|
||||
|
||||
TU_VERIFY_STATIC(sizeof(usbtmc_read_stb_interrupt_488_t) == 2u, "struct wrong length");
|
||||
|
||||
#endif
|
||||
|
863
src/class/usbtmc/usbtmc_device.c
Normal file
863
src/class/usbtmc/usbtmc_device.c
Normal file
@ -0,0 +1,863 @@
|
||||
/*
|
||||
* usbtmc.c
|
||||
*
|
||||
* Created on: Sep 9, 2019
|
||||
* Author: nconrad
|
||||
*/
|
||||
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Nathan Conrad
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This library is not fully reentrant, though it is reentrant from the view
|
||||
* of either the application layer or the USB stack. Due to its locking,
|
||||
* it is not safe to call its functions from interrupts.
|
||||
*
|
||||
* The one exception is that its functions may not be called from the application
|
||||
* until the USB stack is initialized. This should not be a problem since the
|
||||
* device shouldn't be sending messages until it receives a request from the
|
||||
* host.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* In the case of single-CPU "no OS", this task is never preempted other than by
|
||||
* interrupts, and the USBTMC code isn't called by interrupts, so all is OK. For "no OS",
|
||||
* the mutex structure's main effect is to disable the USB interrupts.
|
||||
* With an OS, this class driver uses the OSAL to perform locking. The code uses a single lock
|
||||
* and does not call outside of this class with a lock held, so deadlocks won't happen.
|
||||
*/
|
||||
|
||||
//Limitations:
|
||||
// "vendor-specific" commands are not handled.
|
||||
// Dealing with "termchar" must be handled by the application layer,
|
||||
// though additional error checking is does in this module.
|
||||
// talkOnly and listenOnly are NOT supported. They're not permitted
|
||||
// in USB488, anyway.
|
||||
|
||||
/* Supported:
|
||||
*
|
||||
* Notification pulse
|
||||
* Trigger
|
||||
* Read status byte (both by interrupt endpoint and control message)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// TODO:
|
||||
// USBTMC 3.2.2 error conditions not strictly followed
|
||||
// No local lock-out, REN, or GTL.
|
||||
// Clear message available status byte at the correct time? (488 4.3.1.3)
|
||||
|
||||
|
||||
#include "tusb_option.h"
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_USBTMC)
|
||||
|
||||
#include <string.h>
|
||||
#include "usbtmc.h"
|
||||
#include "usbtmc_device.h"
|
||||
#include "device/dcd.h"
|
||||
#include "device/usbd.h"
|
||||
#include "osal/osal.h"
|
||||
|
||||
// FIXME: I shouldn't need to include _pvt headers, but it is necessary for usbd_edpt_xfer, _stall, and _busy
|
||||
#include "device/usbd_pvt.h"
|
||||
|
||||
#ifdef xDEBUG
|
||||
#include "uart_util.h"
|
||||
static char logMsg[150];
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The state machine does not allow simultaneous reading and writing. This is
|
||||
* consistent with USBTMC.
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
STATE_CLOSED, // Endpoints have not yet been opened since USB reset
|
||||
STATE_NAK, // Bulk-out endpoint is in NAK state.
|
||||
STATE_IDLE, // Bulk-out endpoint is waiting for CMD.
|
||||
STATE_RCV, // Bulk-out is receiving DEV_DEP message
|
||||
STATE_TX_REQUESTED,
|
||||
STATE_TX_INITIATED,
|
||||
STATE_TX_SHORTED,
|
||||
STATE_CLEARING,
|
||||
STATE_ABORTING_BULK_IN,
|
||||
STATE_ABORTING_BULK_IN_SHORTED, // aborting, and short packet has been queued for transmission
|
||||
STATE_ABORTING_BULK_IN_ABORTED, // aborting, and short packet has been transmitted
|
||||
STATE_ABORTING_BULK_OUT,
|
||||
STATE_NUM_STATES
|
||||
} usbtmcd_state_enum;
|
||||
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
typedef usbtmc_response_capabilities_488_t usbtmc_capabilities_specific_t;
|
||||
#else
|
||||
typedef usbtmc_response_capabilities_t usbtmc_capabilities_specific_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
volatile usbtmcd_state_enum state;
|
||||
|
||||
uint8_t itf_id;
|
||||
uint8_t rhport;
|
||||
uint8_t ep_bulk_in;
|
||||
uint8_t ep_bulk_out;
|
||||
uint8_t ep_int_in;
|
||||
// IN buffer is only used for first packet, not the remainder
|
||||
// in order to deal with prepending header
|
||||
uint8_t ep_bulk_in_buf[USBTMCD_MAX_PACKET_SIZE];
|
||||
// OUT buffer receives one packet at a time
|
||||
uint8_t ep_bulk_out_buf[USBTMCD_MAX_PACKET_SIZE];
|
||||
uint32_t transfer_size_remaining; // also used for requested length for bulk IN.
|
||||
uint32_t transfer_size_sent; // To keep track of data bytes that have been queued in FIFO (not header bytes)
|
||||
|
||||
uint8_t lastBulkOutTag; // used for aborts (mostly)
|
||||
uint8_t lastBulkInTag; // used for aborts (mostly)
|
||||
|
||||
uint8_t const * devInBuffer; // pointer to application-layer used for transmissions
|
||||
|
||||
usbtmc_capabilities_specific_t const * capabilities;
|
||||
} usbtmc_interface_state_t;
|
||||
|
||||
static usbtmc_interface_state_t usbtmc_state =
|
||||
{
|
||||
.itf_id = 0xFF,
|
||||
};
|
||||
|
||||
// We need all headers to fit in a single packet in this implementation.
|
||||
TU_VERIFY_STATIC(USBTMCD_MAX_PACKET_SIZE >= 32u,"USBTMC dev EP packet size too small");
|
||||
TU_VERIFY_STATIC(
|
||||
(sizeof(usbtmc_state.ep_bulk_in_buf) % USBTMCD_MAX_PACKET_SIZE) == 0,
|
||||
"packet buffer must be a multiple of the packet size");
|
||||
|
||||
static bool handle_devMsgOutStart(uint8_t rhport, void *data, size_t len);
|
||||
static bool handle_devMsgOut(uint8_t rhport, void *data, size_t len, size_t packetLen);
|
||||
|
||||
static uint8_t termChar;
|
||||
static uint8_t termCharRequested = false;
|
||||
|
||||
|
||||
osal_mutex_def_t usbtmcLockBuffer;
|
||||
static osal_mutex_t usbtmcLock;
|
||||
|
||||
// Our own private lock, mostly for the state variable.
|
||||
#define criticalEnter() do {osal_mutex_lock(usbtmcLock,OSAL_TIMEOUT_WAIT_FOREVER); } while (0)
|
||||
#define criticalLeave() do {osal_mutex_unlock(usbtmcLock); } while (0)
|
||||
|
||||
bool atomicChangeState(usbtmcd_state_enum expectedState, usbtmcd_state_enum newState)
|
||||
{
|
||||
bool ret = true;
|
||||
criticalEnter();
|
||||
usbtmcd_state_enum oldState = usbtmc_state.state;
|
||||
if (oldState == expectedState)
|
||||
{
|
||||
usbtmc_state.state = newState;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = false;
|
||||
}
|
||||
criticalLeave();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// called from app
|
||||
// We keep a reference to the buffer, so it MUST not change until the app is
|
||||
// notified that the transfer is complete.
|
||||
// length of data is specified in the hdr.
|
||||
|
||||
// We can't just send the whole thing at once because we need to concatanate the
|
||||
// header with the data.
|
||||
bool tud_usbtmc_transmit_dev_msg_data(
|
||||
const void * data, size_t len,
|
||||
bool endOfMessage,
|
||||
bool usingTermChar)
|
||||
{
|
||||
const unsigned int txBufLen = sizeof(usbtmc_state.ep_bulk_in_buf);
|
||||
|
||||
#ifndef NDEBUG
|
||||
TU_ASSERT(len > 0u);
|
||||
TU_ASSERT(len <= usbtmc_state.transfer_size_remaining);
|
||||
TU_ASSERT(usbtmc_state.transfer_size_sent == 0u);
|
||||
if(usingTermChar)
|
||||
{
|
||||
TU_ASSERT(usbtmc_state.capabilities->bmDevCapabilities.canEndBulkInOnTermChar);
|
||||
TU_ASSERT(termCharRequested);
|
||||
TU_ASSERT(((uint8_t*)data)[len-1u] == termChar);
|
||||
}
|
||||
#endif
|
||||
|
||||
TU_VERIFY(usbtmc_state.state == STATE_TX_REQUESTED);
|
||||
usbtmc_msg_dev_dep_msg_in_header_t *hdr = (usbtmc_msg_dev_dep_msg_in_header_t*)usbtmc_state.ep_bulk_in_buf;
|
||||
tu_varclr(hdr);
|
||||
hdr->header.MsgID = USBTMC_MSGID_DEV_DEP_MSG_IN;
|
||||
hdr->header.bTag = usbtmc_state.lastBulkInTag;
|
||||
hdr->header.bTagInverse = (uint8_t)~(usbtmc_state.lastBulkInTag);
|
||||
hdr->TransferSize = len;
|
||||
hdr->bmTransferAttributes.EOM = endOfMessage;
|
||||
hdr->bmTransferAttributes.UsingTermChar = usingTermChar;
|
||||
|
||||
// Copy in the header
|
||||
const size_t headerLen = sizeof(*hdr);
|
||||
const size_t dataLen = ((headerLen + hdr->TransferSize) <= txBufLen) ?
|
||||
len : (txBufLen - headerLen);
|
||||
const size_t packetLen = headerLen + dataLen;
|
||||
|
||||
memcpy((uint8_t*)(usbtmc_state.ep_bulk_in_buf) + headerLen, data, dataLen);
|
||||
usbtmc_state.transfer_size_remaining = len - dataLen;
|
||||
usbtmc_state.transfer_size_sent = dataLen;
|
||||
usbtmc_state.devInBuffer = (uint8_t*)data + (dataLen);
|
||||
|
||||
bool stateChanged =
|
||||
atomicChangeState(STATE_TX_REQUESTED, (packetLen >= txBufLen) ? STATE_TX_INITIATED : STATE_TX_SHORTED);
|
||||
TU_VERIFY(stateChanged);
|
||||
TU_VERIFY(usbd_edpt_xfer(usbtmc_state.rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf, (uint16_t)packetLen));
|
||||
return true;
|
||||
}
|
||||
|
||||
void usbtmcd_init_cb(void)
|
||||
{
|
||||
usbtmc_state.capabilities = tud_usbtmc_get_capabilities_cb();
|
||||
#ifndef NDEBUG
|
||||
# if CFG_TUD_USBTMC_ENABLE_488
|
||||
if(usbtmc_state.capabilities->bmIntfcCapabilities488.supportsTrigger)
|
||||
TU_ASSERT(&tud_usbtmc_msg_trigger_cb != NULL,);
|
||||
// Per USB488 spec: table 8
|
||||
TU_ASSERT(!usbtmc_state.capabilities->bmIntfcCapabilities.listenOnly,);
|
||||
TU_ASSERT(!usbtmc_state.capabilities->bmIntfcCapabilities.talkOnly,);
|
||||
# endif
|
||||
if(usbtmc_state.capabilities->bmIntfcCapabilities.supportsIndicatorPulse)
|
||||
TU_ASSERT(&tud_usbtmc_indicator_pulse_cb != NULL,);
|
||||
#endif
|
||||
|
||||
usbtmcLock = osal_mutex_create(&usbtmcLockBuffer);
|
||||
}
|
||||
|
||||
bool usbtmcd_open_cb(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
|
||||
{
|
||||
(void)rhport;
|
||||
TU_ASSERT(usbtmc_state.state == STATE_CLOSED);
|
||||
uint8_t const * p_desc;
|
||||
uint8_t found_endpoints = 0;
|
||||
|
||||
#ifndef NDEBUG
|
||||
TU_ASSERT(itf_desc->bInterfaceClass == TUD_USBTMC_APP_CLASS);
|
||||
TU_ASSERT(itf_desc->bInterfaceSubClass == TUD_USBTMC_APP_SUBCLASS);
|
||||
// Only 2 or 3 endpoints are allowed for USBTMC.
|
||||
TU_ASSERT((itf_desc->bNumEndpoints == 2) || (itf_desc->bNumEndpoints ==3));
|
||||
#endif
|
||||
|
||||
// Interface
|
||||
(*p_length) = 0u;
|
||||
p_desc = (uint8_t const *) itf_desc;
|
||||
|
||||
usbtmc_state.itf_id = itf_desc->bInterfaceNumber;
|
||||
usbtmc_state.rhport = rhport;
|
||||
|
||||
while (found_endpoints < itf_desc->bNumEndpoints)
|
||||
{
|
||||
if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE])
|
||||
{
|
||||
tusb_desc_endpoint_t const *ep_desc = (tusb_desc_endpoint_t const *)p_desc;
|
||||
switch(ep_desc->bmAttributes.xfer) {
|
||||
case TUSB_XFER_BULK:
|
||||
TU_ASSERT(ep_desc->wMaxPacketSize.size == USBTMCD_MAX_PACKET_SIZE);
|
||||
if (tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN)
|
||||
{
|
||||
usbtmc_state.ep_bulk_in = ep_desc->bEndpointAddress;
|
||||
} else {
|
||||
usbtmc_state.ep_bulk_out = ep_desc->bEndpointAddress;
|
||||
}
|
||||
|
||||
break;
|
||||
case TUSB_XFER_INTERRUPT:
|
||||
#ifndef NDEBUG
|
||||
TU_ASSERT(tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN);
|
||||
TU_ASSERT(usbtmc_state.ep_int_in == 0);
|
||||
#endif
|
||||
usbtmc_state.ep_int_in = ep_desc->bEndpointAddress;
|
||||
break;
|
||||
default:
|
||||
TU_ASSERT(false);
|
||||
}
|
||||
TU_VERIFY( dcd_edpt_open(rhport, ep_desc));
|
||||
found_endpoints++;
|
||||
}
|
||||
(*p_length) = (uint8_t)((*p_length) + p_desc[DESC_OFFSET_LEN]);
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
// bulk endpoints are required, but interrupt IN is optional
|
||||
#ifndef NDEBUG
|
||||
TU_ASSERT(usbtmc_state.ep_bulk_in != 0);
|
||||
TU_ASSERT(usbtmc_state.ep_bulk_out != 0);
|
||||
if (itf_desc->bNumEndpoints == 2)
|
||||
{
|
||||
TU_ASSERT(usbtmc_state.ep_int_in == 0);
|
||||
}
|
||||
else if (itf_desc->bNumEndpoints == 3)
|
||||
{
|
||||
TU_ASSERT(usbtmc_state.ep_int_in != 0);
|
||||
}
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
if(usbtmc_state.capabilities->bmIntfcCapabilities488.is488_2 ||
|
||||
usbtmc_state.capabilities->bmDevCapabilities488.SR1)
|
||||
{
|
||||
TU_ASSERT(usbtmc_state.ep_int_in != 0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
atomicChangeState(STATE_CLOSED, STATE_NAK);
|
||||
tud_usbtmc_open_cb(itf_desc->iInterface);
|
||||
|
||||
return true;
|
||||
}
|
||||
// Tell USBTMC class to set its bulk-in EP to ACK so that it can
|
||||
// receive USBTMC commands.
|
||||
// Returns false if it was already in an ACK state or is busy
|
||||
// processing a command (such as a clear). Returns true if it was
|
||||
// in the NAK state and successfully transitioned to the ACK wait
|
||||
// state.
|
||||
bool tud_usbtmc_start_bus_read()
|
||||
{
|
||||
usbtmcd_state_enum oldState = usbtmc_state.state;
|
||||
switch(oldState)
|
||||
{
|
||||
// These may transition to IDLE
|
||||
case STATE_NAK:
|
||||
case STATE_ABORTING_BULK_IN_ABORTED:
|
||||
TU_VERIFY(atomicChangeState(oldState, STATE_IDLE));
|
||||
break;
|
||||
// When receiving, let it remain receiving
|
||||
case STATE_RCV:
|
||||
break;
|
||||
default:
|
||||
TU_VERIFY(false);
|
||||
}
|
||||
TU_VERIFY(usbd_edpt_xfer(usbtmc_state.rhport, usbtmc_state.ep_bulk_out, usbtmc_state.ep_bulk_out_buf, 64));
|
||||
return true;
|
||||
}
|
||||
|
||||
void usbtmcd_reset_cb(uint8_t rhport)
|
||||
{
|
||||
(void)rhport;
|
||||
usbtmc_capabilities_specific_t const * capabilities = tud_usbtmc_get_capabilities_cb();
|
||||
|
||||
criticalEnter();
|
||||
tu_varclr(&usbtmc_state);
|
||||
usbtmc_state.capabilities = capabilities;
|
||||
usbtmc_state.itf_id = 0xFFu;
|
||||
criticalLeave();
|
||||
}
|
||||
|
||||
static bool handle_devMsgOutStart(uint8_t rhport, void *data, size_t len)
|
||||
{
|
||||
(void)rhport;
|
||||
// return true upon failure, as we can assume error is being handled elsewhere.
|
||||
TU_VERIFY(atomicChangeState(STATE_IDLE, STATE_RCV), true);
|
||||
usbtmc_state.transfer_size_sent = 0u;
|
||||
|
||||
// must be a header, should have been confirmed before calling here.
|
||||
usbtmc_msg_request_dev_dep_out *msg = (usbtmc_msg_request_dev_dep_out*)data;
|
||||
usbtmc_state.transfer_size_remaining = msg->TransferSize;
|
||||
TU_VERIFY(tud_usbtmc_msgBulkOut_start_cb(msg));
|
||||
|
||||
TU_VERIFY(handle_devMsgOut(rhport, (uint8_t*)data + sizeof(*msg), len - sizeof(*msg), len));
|
||||
usbtmc_state.lastBulkOutTag = msg->header.bTag;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool handle_devMsgOut(uint8_t rhport, void *data, size_t len, size_t packetLen)
|
||||
{
|
||||
(void)rhport;
|
||||
// return true upon failure, as we can assume error is being handled elsewhere.
|
||||
TU_VERIFY(usbtmc_state.state == STATE_RCV,true);
|
||||
|
||||
bool shortPacket = (packetLen < USBTMCD_MAX_PACKET_SIZE);
|
||||
|
||||
// Packet is to be considered complete when we get enough data or at a short packet.
|
||||
bool atEnd = false;
|
||||
if(len >= usbtmc_state.transfer_size_remaining || shortPacket)
|
||||
{
|
||||
atEnd = true;
|
||||
TU_VERIFY(atomicChangeState(STATE_RCV, STATE_NAK));
|
||||
}
|
||||
|
||||
len = tu_min32(len, usbtmc_state.transfer_size_remaining);
|
||||
|
||||
usbtmc_state.transfer_size_remaining -= len;
|
||||
usbtmc_state.transfer_size_sent += len;
|
||||
|
||||
// App may (should?) call the wait_for_bus() command at this point
|
||||
if(!tud_usbtmc_msg_data_cb(data, len, atEnd))
|
||||
{
|
||||
// TODO: Go to an error state upon failure other than just stalling the EP?
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool handle_devMsgIn(void *data, size_t len)
|
||||
{
|
||||
TU_VERIFY(len == sizeof(usbtmc_msg_request_dev_dep_in));
|
||||
usbtmc_msg_request_dev_dep_in *msg = (usbtmc_msg_request_dev_dep_in*)data;
|
||||
bool stateChanged = atomicChangeState(STATE_IDLE, STATE_TX_REQUESTED);
|
||||
TU_VERIFY(stateChanged);
|
||||
usbtmc_state.lastBulkInTag = msg->header.bTag;
|
||||
usbtmc_state.transfer_size_remaining = msg->TransferSize;
|
||||
usbtmc_state.transfer_size_sent = 0u;
|
||||
|
||||
termCharRequested = msg->bmTransferAttributes.TermCharEnabled;
|
||||
termChar = msg->TermChar;
|
||||
|
||||
if(termCharRequested)
|
||||
TU_VERIFY(usbtmc_state.capabilities->bmDevCapabilities.canEndBulkInOnTermChar);
|
||||
|
||||
TU_VERIFY(tud_usbtmc_msgBulkIn_request_cb(msg));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
{
|
||||
TU_VERIFY(result == XFER_RESULT_SUCCESS);
|
||||
//uart_tx_str_sync("TMC XFER CB\r\n");
|
||||
if(usbtmc_state.state == STATE_CLEARING) {
|
||||
return true; /* I think we can ignore everything here */
|
||||
}
|
||||
|
||||
if(ep_addr == usbtmc_state.ep_bulk_out)
|
||||
{
|
||||
usbtmc_msg_generic_t *msg = NULL;
|
||||
|
||||
switch(usbtmc_state.state)
|
||||
{
|
||||
case STATE_IDLE:
|
||||
TU_VERIFY(xferred_bytes >= sizeof(usbtmc_msg_generic_t));
|
||||
msg = (usbtmc_msg_generic_t*)(usbtmc_state.ep_bulk_out_buf);
|
||||
uint8_t invInvTag = (uint8_t)~(msg->header.bTagInverse);
|
||||
TU_VERIFY(msg->header.bTag == invInvTag);
|
||||
TU_VERIFY(msg->header.bTag != 0x00);
|
||||
|
||||
switch(msg->header.MsgID) {
|
||||
case USBTMC_MSGID_DEV_DEP_MSG_OUT:
|
||||
if(!handle_devMsgOutStart(rhport, msg, xferred_bytes))
|
||||
{
|
||||
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
|
||||
TU_VERIFY(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBTMC_MSGID_DEV_DEP_MSG_IN:
|
||||
TU_VERIFY(handle_devMsgIn(msg, xferred_bytes));
|
||||
break;
|
||||
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
case USBTMC_MSGID_USB488_TRIGGER:
|
||||
// Spec says we halt the EP if we didn't declare we support it.
|
||||
TU_VERIFY(usbtmc_state.capabilities->bmIntfcCapabilities488.supportsTrigger);
|
||||
TU_VERIFY(tud_usbtmc_msg_trigger_cb(msg));
|
||||
|
||||
break;
|
||||
#endif
|
||||
case USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT:
|
||||
case USBTMC_MSGID_VENDOR_SPECIFIC_IN:
|
||||
default:
|
||||
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
|
||||
TU_VERIFY(false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
case STATE_RCV:
|
||||
if(!handle_devMsgOut(rhport, usbtmc_state.ep_bulk_out_buf, xferred_bytes, xferred_bytes))
|
||||
{
|
||||
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
|
||||
TU_VERIFY(false);
|
||||
}
|
||||
return true;
|
||||
|
||||
case STATE_ABORTING_BULK_OUT:
|
||||
TU_VERIFY(false);
|
||||
return false; // Should be stalled by now, shouldn't have received a packet.
|
||||
case STATE_TX_REQUESTED:
|
||||
case STATE_TX_INITIATED:
|
||||
case STATE_ABORTING_BULK_IN:
|
||||
case STATE_ABORTING_BULK_IN_SHORTED:
|
||||
case STATE_ABORTING_BULK_IN_ABORTED:
|
||||
default:
|
||||
|
||||
TU_VERIFY(false);
|
||||
}
|
||||
}
|
||||
else if(ep_addr == usbtmc_state.ep_bulk_in)
|
||||
{
|
||||
switch(usbtmc_state.state) {
|
||||
case STATE_TX_SHORTED:
|
||||
TU_VERIFY(atomicChangeState(STATE_TX_SHORTED, STATE_NAK));
|
||||
TU_VERIFY(tud_usbtmc_msgBulkIn_complete_cb());
|
||||
break;
|
||||
|
||||
case STATE_TX_INITIATED:
|
||||
if(usbtmc_state.transfer_size_remaining >=sizeof(usbtmc_state.ep_bulk_in_buf))
|
||||
{
|
||||
// FIXME! This removes const below!
|
||||
TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in,
|
||||
(void*)usbtmc_state.devInBuffer,sizeof(usbtmc_state.ep_bulk_in_buf)));
|
||||
usbtmc_state.devInBuffer += sizeof(usbtmc_state.ep_bulk_in_buf);
|
||||
usbtmc_state.transfer_size_remaining -= sizeof(usbtmc_state.ep_bulk_in_buf);
|
||||
usbtmc_state.transfer_size_sent += sizeof(usbtmc_state.ep_bulk_in_buf);
|
||||
}
|
||||
else // last packet
|
||||
{
|
||||
size_t packetLen = usbtmc_state.transfer_size_remaining;
|
||||
memcpy(usbtmc_state.ep_bulk_in_buf, usbtmc_state.devInBuffer, usbtmc_state.transfer_size_remaining);
|
||||
usbtmc_state.transfer_size_sent += sizeof(usbtmc_state.transfer_size_remaining);
|
||||
usbtmc_state.transfer_size_remaining = 0;
|
||||
usbtmc_state.devInBuffer = NULL;
|
||||
TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf,(uint16_t)packetLen));
|
||||
if(((packetLen % USBTMCD_MAX_PACKET_SIZE) != 0) || (packetLen == 0 ))
|
||||
{
|
||||
usbtmc_state.state = STATE_TX_SHORTED;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case STATE_ABORTING_BULK_IN:
|
||||
// need to send short packet (ZLP?)
|
||||
TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf,(uint16_t)0u));
|
||||
usbtmc_state.state = STATE_ABORTING_BULK_IN_SHORTED;
|
||||
return true;
|
||||
case STATE_ABORTING_BULK_IN_SHORTED:
|
||||
/* Done. :)*/
|
||||
usbtmc_state.state = STATE_ABORTING_BULK_IN_ABORTED;
|
||||
return true;
|
||||
default:
|
||||
TU_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (ep_addr == usbtmc_state.ep_int_in) {
|
||||
// Good?
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool usbtmcd_control_request_cb(uint8_t rhport, tusb_control_request_t const * request) {
|
||||
|
||||
uint8_t tmcStatusCode = USBTMC_STATUS_FAILED;
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
uint8_t bTag;
|
||||
#endif
|
||||
|
||||
if((request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD) &&
|
||||
(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_ENDPOINT) &&
|
||||
(request->bRequest == TUSB_REQ_CLEAR_FEATURE) &&
|
||||
(request->wValue == TUSB_REQ_FEATURE_EDPT_HALT))
|
||||
{
|
||||
uint32_t ep_addr = (request->wIndex);
|
||||
|
||||
if(ep_addr == usbtmc_state.ep_bulk_out)
|
||||
{
|
||||
criticalEnter();
|
||||
usbtmc_state.state = STATE_NAK; // USBD core has placed EP in NAK state for us
|
||||
criticalLeave();
|
||||
tud_usmtmc_bulkOut_clearFeature_cb();
|
||||
}
|
||||
else if (ep_addr == usbtmc_state.ep_bulk_in)
|
||||
{
|
||||
tud_usbtmc_bulkIn_clearFeature_cb();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, we only handle class requests.
|
||||
if(request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verification that we own the interface is unneeded since it's been routed to us specifically.
|
||||
|
||||
switch(request->bRequest)
|
||||
{
|
||||
// USBTMC required requests
|
||||
case USBTMC_bREQUEST_INITIATE_ABORT_BULK_OUT:
|
||||
{
|
||||
usbtmc_initiate_abort_rsp_t rsp = {
|
||||
.bTag = usbtmc_state.lastBulkOutTag,
|
||||
};
|
||||
TU_VERIFY(request->bmRequestType == 0xA2); // in,class,interface
|
||||
TU_VERIFY(request->wLength == sizeof(rsp));
|
||||
TU_VERIFY(request->wIndex == usbtmc_state.ep_bulk_out);
|
||||
|
||||
// wValue is the requested bTag to abort
|
||||
if(usbtmc_state.state != STATE_RCV)
|
||||
{
|
||||
rsp.USBTMC_status = USBTMC_STATUS_FAILED;
|
||||
}
|
||||
else if(usbtmc_state.lastBulkOutTag == (request->wValue & 0x7Fu))
|
||||
{
|
||||
rsp.USBTMC_status = USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
|
||||
// Check if we've queued a short packet
|
||||
criticalEnter();
|
||||
usbtmc_state.state = STATE_ABORTING_BULK_OUT;
|
||||
criticalLeave();
|
||||
TU_VERIFY(tud_usbtmc_initiate_abort_bulk_out_cb(&(rsp.USBTMC_status)));
|
||||
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
|
||||
}
|
||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp,sizeof(rsp)));
|
||||
return true;
|
||||
}
|
||||
|
||||
case USBTMC_bREQUEST_CHECK_ABORT_BULK_OUT_STATUS:
|
||||
{
|
||||
usbtmc_check_abort_bulk_rsp_t rsp = {
|
||||
.USBTMC_status = USBTMC_STATUS_SUCCESS,
|
||||
.NBYTES_RXD_TXD = usbtmc_state.transfer_size_sent
|
||||
};
|
||||
TU_VERIFY(request->bmRequestType == 0xA2); // in,class,EP
|
||||
TU_VERIFY(request->wLength == sizeof(rsp));
|
||||
TU_VERIFY(request->wIndex == usbtmc_state.ep_bulk_out);
|
||||
TU_VERIFY(tud_usbtmc_check_abort_bulk_out_cb(&rsp));
|
||||
TU_VERIFY(usbd_edpt_xfer(rhport, 0u, (void*)&rsp,sizeof(rsp)));
|
||||
return true;
|
||||
}
|
||||
|
||||
case USBTMC_bREQUEST_INITIATE_ABORT_BULK_IN:
|
||||
{
|
||||
usbtmc_initiate_abort_rsp_t rsp = {
|
||||
.bTag = usbtmc_state.lastBulkInTag,
|
||||
};
|
||||
TU_VERIFY(request->bmRequestType == 0xA2); // in,class,interface
|
||||
TU_VERIFY(request->wLength == sizeof(rsp));
|
||||
TU_VERIFY(request->wIndex == usbtmc_state.ep_bulk_in);
|
||||
// wValue is the requested bTag to abort
|
||||
if((usbtmc_state.state == STATE_TX_REQUESTED || usbtmc_state.state == STATE_TX_INITIATED) &&
|
||||
usbtmc_state.lastBulkInTag == (request->wValue & 0x7Fu))
|
||||
{
|
||||
rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
|
||||
usbtmc_state.transfer_size_remaining = 0u;
|
||||
// Check if we've queued a short packet
|
||||
criticalEnter();
|
||||
usbtmc_state.state = ((usbtmc_state.transfer_size_sent % USBTMCD_MAX_PACKET_SIZE) == 0) ?
|
||||
STATE_ABORTING_BULK_IN : STATE_ABORTING_BULK_IN_SHORTED;
|
||||
criticalLeave();
|
||||
if(usbtmc_state.transfer_size_sent == 0)
|
||||
{
|
||||
// Send short packet, nothing is in the buffer yet
|
||||
TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf,(uint16_t)0u));
|
||||
usbtmc_state.state = STATE_ABORTING_BULK_IN_SHORTED;
|
||||
}
|
||||
TU_VERIFY(tud_usbtmc_initiate_abort_bulk_in_cb(&(rsp.USBTMC_status)));
|
||||
}
|
||||
else if((usbtmc_state.state == STATE_TX_REQUESTED || usbtmc_state.state == STATE_TX_INITIATED))
|
||||
{ // FIXME: Unsure how to check if the OUT endpoint fifo is non-empty....
|
||||
rsp.USBTMC_status = USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
rsp.USBTMC_status = USBTMC_STATUS_FAILED;
|
||||
}
|
||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp,sizeof(rsp)));
|
||||
return true;
|
||||
}
|
||||
|
||||
case USBTMC_bREQUEST_CHECK_ABORT_BULK_IN_STATUS:
|
||||
{
|
||||
TU_VERIFY(request->bmRequestType == 0xA2); // in,class,EP
|
||||
TU_VERIFY(request->wLength == 8u);
|
||||
|
||||
usbtmc_check_abort_bulk_rsp_t rsp =
|
||||
{
|
||||
.USBTMC_status = USBTMC_STATUS_FAILED,
|
||||
.bmAbortBulkIn =
|
||||
{
|
||||
.BulkInFifoBytes = (usbtmc_state.state != STATE_ABORTING_BULK_IN_ABORTED)
|
||||
},
|
||||
.NBYTES_RXD_TXD = usbtmc_state.transfer_size_sent,
|
||||
};
|
||||
TU_VERIFY(tud_usbtmc_check_abort_bulk_in_cb(&rsp));
|
||||
criticalEnter();
|
||||
switch(usbtmc_state.state)
|
||||
{
|
||||
case STATE_ABORTING_BULK_IN_ABORTED:
|
||||
rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
|
||||
usbtmc_state.state = STATE_IDLE;
|
||||
break;
|
||||
case STATE_ABORTING_BULK_IN:
|
||||
case STATE_ABORTING_BULK_OUT:
|
||||
rsp.USBTMC_status = USBTMC_STATUS_PENDING;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
criticalLeave();
|
||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp,sizeof(rsp)));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
case USBTMC_bREQUEST_INITIATE_CLEAR:
|
||||
{
|
||||
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
|
||||
TU_VERIFY(request->wLength == sizeof(tmcStatusCode));
|
||||
// After receiving an INITIATE_CLEAR request, the device must Halt the Bulk-OUT endpoint, queue the
|
||||
// control endpoint response shown in Table 31, and clear all input buffers and output buffers.
|
||||
usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
|
||||
usbtmc_state.transfer_size_remaining = 0;
|
||||
criticalEnter();
|
||||
usbtmc_state.state = STATE_CLEARING;
|
||||
criticalLeave();
|
||||
TU_VERIFY(tud_usbtmc_initiate_clear_cb(&tmcStatusCode));
|
||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&tmcStatusCode,sizeof(tmcStatusCode)));
|
||||
return true;
|
||||
}
|
||||
|
||||
case USBTMC_bREQUEST_CHECK_CLEAR_STATUS:
|
||||
{
|
||||
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
|
||||
usbtmc_get_clear_status_rsp_t clearStatusRsp = {0};
|
||||
TU_VERIFY(request->wLength == sizeof(clearStatusRsp));
|
||||
|
||||
if(usbd_edpt_busy(rhport, usbtmc_state.ep_bulk_in))
|
||||
{
|
||||
// Stuff stuck in TX buffer?
|
||||
clearStatusRsp.bmClear.BulkInFifoBytes = 1;
|
||||
clearStatusRsp.USBTMC_status = USBTMC_STATUS_PENDING;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Let app check if it's clear
|
||||
TU_VERIFY(tud_usbtmc_check_clear_cb(&clearStatusRsp));
|
||||
}
|
||||
if(clearStatusRsp.USBTMC_status == USBTMC_STATUS_SUCCESS)
|
||||
{
|
||||
criticalEnter();
|
||||
usbtmc_state.state = STATE_IDLE;
|
||||
criticalLeave();
|
||||
}
|
||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&clearStatusRsp,sizeof(clearStatusRsp)));
|
||||
return true;
|
||||
}
|
||||
|
||||
case USBTMC_bREQUEST_GET_CAPABILITIES:
|
||||
{
|
||||
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
|
||||
TU_VERIFY(request->wLength == sizeof(*(usbtmc_state.capabilities)));
|
||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)usbtmc_state.capabilities, sizeof(*usbtmc_state.capabilities)));
|
||||
return true;
|
||||
}
|
||||
// USBTMC Optional Requests
|
||||
|
||||
case USBTMC_bREQUEST_INDICATOR_PULSE: // Optional
|
||||
{
|
||||
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
|
||||
TU_VERIFY(request->wLength == sizeof(tmcStatusCode));
|
||||
TU_VERIFY(usbtmc_state.capabilities->bmIntfcCapabilities.supportsIndicatorPulse);
|
||||
TU_VERIFY(tud_usbtmc_indicator_pulse_cb(request, &tmcStatusCode));
|
||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&tmcStatusCode, sizeof(tmcStatusCode)));
|
||||
return true;
|
||||
}
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
|
||||
// USB488 required requests
|
||||
case USB488_bREQUEST_READ_STATUS_BYTE:
|
||||
{
|
||||
usbtmc_read_stb_rsp_488_t rsp;
|
||||
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
|
||||
TU_VERIFY(request->wLength == sizeof(rsp)); // in,class,interface
|
||||
|
||||
bTag = request->wValue & 0x7F;
|
||||
TU_VERIFY(request->bmRequestType == 0xA1);
|
||||
TU_VERIFY((request->wValue & (~0x7F)) == 0u); // Other bits are required to be zero
|
||||
TU_VERIFY(bTag >= 0x02 && bTag <= 127);
|
||||
TU_VERIFY(request->wIndex == usbtmc_state.itf_id);
|
||||
TU_VERIFY(request->wLength == 0x0003);
|
||||
rsp.bTag = (uint8_t)bTag;
|
||||
if(usbtmc_state.ep_int_in != 0)
|
||||
{
|
||||
rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
|
||||
rsp.statusByte = 0x00; // Use interrupt endpoint, instead.
|
||||
|
||||
usbtmc_read_stb_interrupt_488_t intMsg =
|
||||
{
|
||||
.bNotify1 = {
|
||||
.one = 1,
|
||||
.bTag = bTag & 0x7Fu,
|
||||
},
|
||||
.StatusByte = tud_usbtmc_get_stb_cb(&(rsp.USBTMC_status))
|
||||
};
|
||||
usbd_edpt_xfer(rhport, usbtmc_state.ep_int_in, (void*)&intMsg, sizeof(intMsg));
|
||||
}
|
||||
else
|
||||
{
|
||||
rsp.statusByte = tud_usbtmc_get_stb_cb(&(rsp.USBTMC_status));
|
||||
}
|
||||
TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp, sizeof(rsp)));
|
||||
return true;
|
||||
}
|
||||
// USB488 optional requests
|
||||
case USB488_bREQUEST_REN_CONTROL:
|
||||
case USB488_bREQUEST_GO_TO_LOCAL:
|
||||
case USB488_bREQUEST_LOCAL_LOCKOUT:
|
||||
{
|
||||
TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
|
||||
TU_VERIFY(false);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
default:
|
||||
TU_VERIFY(false);
|
||||
return false;
|
||||
}
|
||||
TU_VERIFY(false);
|
||||
}
|
||||
|
||||
bool usbtmcd_control_complete_cb(uint8_t rhport, tusb_control_request_t const * request)
|
||||
{
|
||||
(void)rhport;
|
||||
//------------- Class Specific Request -------------//
|
||||
TU_ASSERT (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* CFG_TUD_TSMC */
|
123
src/class/usbtmc/usbtmc_device.h
Normal file
123
src/class/usbtmc/usbtmc_device.h
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* usbtmc_device.h
|
||||
*
|
||||
* Created on: Sep 10, 2019
|
||||
* Author: nconrad
|
||||
*/
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 N Conrad
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* This file is part of the TinyUSB stack.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CLASS_USBTMC_USBTMC_DEVICE_H_
|
||||
#define CLASS_USBTMC_USBTMC_DEVICE_H_
|
||||
|
||||
#include "usbtmc.h"
|
||||
|
||||
// Enable 488 mode by default
|
||||
#if !defined(CFG_TUD_USBTMC_ENABLE_488)
|
||||
#define CFG_TUD_USBTMC_ENABLE_488 (1)
|
||||
#endif
|
||||
|
||||
// USB spec says that full-speed must be 8,16,32, or 64.
|
||||
// However, this driver implementation requires it to be >=32
|
||||
#define USBTMCD_MAX_PACKET_SIZE (64u)
|
||||
|
||||
/***********************************************
|
||||
* Functions to be implemeted by the class implementation
|
||||
*/
|
||||
|
||||
// In order to proceed, app must call call tud_usbtmc_start_bus_read(rhport) during or soon after:
|
||||
// * tud_usbtmc_open_cb
|
||||
// * tud_usbtmc_msg_data_cb
|
||||
// * tud_usbtmc_msgBulkIn_complete_cb
|
||||
// * tud_usbtmc_msg_trigger_cb
|
||||
// * (successful) tud_usbtmc_check_abort_bulk_out_cb
|
||||
// * (successful) tud_usbtmc_check_abort_bulk_in_cb
|
||||
// * (successful) tud_usmtmc_bulkOut_clearFeature_cb
|
||||
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
usbtmc_response_capabilities_488_t const * tud_usbtmc_get_capabilities_cb(void);
|
||||
#else
|
||||
usbtmc_response_capabilities_t const * tud_usbtmc_get_capabilities_cb(void);
|
||||
#endif
|
||||
|
||||
void tud_usbtmc_open_cb(uint8_t interface_id);
|
||||
|
||||
bool tud_usbtmc_msgBulkOut_start_cb(usbtmc_msg_request_dev_dep_out const * msgHeader);
|
||||
// transfer_complete does not imply that a message is complete.
|
||||
bool tud_usbtmc_msg_data_cb( void *data, size_t len, bool transfer_complete);
|
||||
void tud_usmtmc_bulkOut_clearFeature_cb(void); // Notice to clear and abort the pending BULK out transfer
|
||||
|
||||
bool tud_usbtmc_msgBulkIn_request_cb(usbtmc_msg_request_dev_dep_in const * request);
|
||||
bool tud_usbtmc_msgBulkIn_complete_cb(void);
|
||||
void tud_usbtmc_bulkIn_clearFeature_cb(void); // Notice to clear and abort the pending BULK out transfer
|
||||
|
||||
bool tud_usbtmc_initiate_abort_bulk_in_cb(uint8_t *tmcResult);
|
||||
bool tud_usbtmc_initiate_abort_bulk_out_cb(uint8_t *tmcResult);
|
||||
bool tud_usbtmc_initiate_clear_cb(uint8_t *tmcResult);
|
||||
|
||||
bool tud_usbtmc_check_abort_bulk_in_cb(usbtmc_check_abort_bulk_rsp_t *rsp);
|
||||
bool tud_usbtmc_check_abort_bulk_out_cb(usbtmc_check_abort_bulk_rsp_t *rsp);
|
||||
bool tud_usbtmc_check_clear_cb(usbtmc_get_clear_status_rsp_t *rsp);
|
||||
|
||||
// Indicator pulse should be 0.5 to 1.0 seconds long
|
||||
TU_ATTR_WEAK bool tud_usbtmc_indicator_pulse_cb(tusb_control_request_t const * msg, uint8_t *tmcResult);
|
||||
|
||||
#if (CFG_TUD_USBTMC_ENABLE_488)
|
||||
uint8_t tud_usbtmc_get_stb_cb(uint8_t *tmcResult);
|
||||
TU_ATTR_WEAK bool tud_usbtmc_msg_trigger_cb(usbtmc_msg_generic_t* msg);
|
||||
//TU_ATTR_WEAK bool tud_usbtmc_app_go_to_local_cb();
|
||||
#endif
|
||||
|
||||
/*******************************************
|
||||
* Called from app
|
||||
*
|
||||
* We keep a reference to the buffer, so it MUST not change until the app is
|
||||
* notified that the transfer is complete.
|
||||
******************************************/
|
||||
|
||||
bool tud_usbtmc_transmit_dev_msg_data(
|
||||
const void * data, size_t len,
|
||||
bool endOfMessage, bool usingTermChar);
|
||||
|
||||
bool tud_usbtmc_start_bus_read(void);
|
||||
|
||||
|
||||
/* "callbacks" from USB device core */
|
||||
|
||||
bool usbtmcd_open_cb(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
|
||||
void usbtmcd_reset_cb(uint8_t rhport);
|
||||
bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
|
||||
bool usbtmcd_control_request_cb(uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool usbtmcd_control_complete_cb(uint8_t rhport, tusb_control_request_t const * request);
|
||||
void usbtmcd_init_cb(void);
|
||||
|
||||
/************************************************************
|
||||
* USBTMC Descriptor Templates
|
||||
*************************************************************/
|
||||
|
||||
|
||||
#endif /* CLASS_USBTMC_USBTMC_DEVICE_H_ */
|
@ -38,7 +38,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// Macros Helper
|
||||
//--------------------------------------------------------------------+
|
||||
#define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
|
||||
#define TU_ARRAY_SIZE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
|
||||
#define TU_MIN(_x, _y) ( (_x) < (_y) ) ? (_x) : (_y) )
|
||||
#define TU_MAX(_x, _y) ( (_x) > (_y) ) ? (_x) : (_y) )
|
||||
|
||||
|
@ -53,6 +53,9 @@
|
||||
// for declaration of reserved field, make use of _TU_COUNTER_
|
||||
#define TU_RESERVED TU_XSTRCAT(reserved, _TU_COUNTER_)
|
||||
|
||||
#define TU_LITTLE_ENDIAN (0x12u)
|
||||
#define TU_BIG_ENDIAN (0x21u)
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Compiler porting with Attribute and Endian
|
||||
//--------------------------------------------------------------------+
|
||||
@ -67,20 +70,68 @@
|
||||
|
||||
// Endian conversion use well-known host to network (big endian) naming
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define tu_htonl(u32) __builtin_bswap32(u32)
|
||||
#define tu_ntohl(u32) __builtin_bswap32(u32)
|
||||
|
||||
#define tu_htons(u16) __builtin_bswap16(u16)
|
||||
#define tu_ntohs(u16) __builtin_bswap16(u16)
|
||||
#define TU_BYTE_ORDER TU_LITTLE_ENDIAN
|
||||
#else
|
||||
#define tu_htonl(u32) (u32)
|
||||
#define tu_ntohl(u32) (u32)
|
||||
|
||||
#define tu_htons(u16) (u16)
|
||||
#define tu_ntohs(u16) (u16)
|
||||
#define TU_BYTE_ORDER TU_BIG_ENDIAN
|
||||
#endif
|
||||
|
||||
#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
|
||||
#define TU_BSWAP32(u32) (__builtin_bswap32(u32))
|
||||
|
||||
#elif defined(__TI_COMPILER_VERSION__)
|
||||
#define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
|
||||
#define TU_ATTR_SECTION(sec_name) __attribute__ ((section(#sec_name)))
|
||||
#define TU_ATTR_PACKED __attribute__ ((packed))
|
||||
#define TU_ATTR_PREPACKED
|
||||
#define TU_ATTR_WEAK __attribute__ ((weak))
|
||||
#define TU_ATTR_DEPRECATED(mess) __attribute__ ((deprecated(mess))) // warn if function with this attribute is used
|
||||
#define TU_ATTR_UNUSED __attribute__ ((unused)) // Function/Variable is meant to be possibly unused
|
||||
|
||||
// __BYTE_ORDER is defined in the TI ARM compiler, but not MSP430 (which is little endian)
|
||||
#if ((__BYTE_ORDER__) == (__ORDER_LITTLE_ENDIAN__)) || defined(__MSP430__)
|
||||
#define TU_BYTE_ORDER TU_LITTLE_ENDIAN
|
||||
#else
|
||||
#define TU_BYTE_ORDER TU_BIG_ENDIAN
|
||||
#endif
|
||||
|
||||
#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
|
||||
#define TU_BSWAP32(u32) (__builtin_bswap32(u32))
|
||||
|
||||
#else
|
||||
#error "Compiler attribute porting are required"
|
||||
#error "Compiler attribute porting is required"
|
||||
#endif
|
||||
|
||||
#if (TU_BYTE_ORDER == TU_LITTLE_ENDIAN)
|
||||
|
||||
#define tu_htons(u16) (TU_BSWAP16(u16))
|
||||
#define tu_ntohs(u16) (TU_BSWAP16(u16))
|
||||
|
||||
#define tu_htonl(u32) (TU_BSWAP32(u32))
|
||||
#define tu_ntohl(u32) (TU_BSWAP32(u32))
|
||||
|
||||
#define tu_htole16(u16) (u16)
|
||||
#define tu_le16toh(u16) (u16)
|
||||
|
||||
#define tu_htole32(u32) (u32)
|
||||
#define tu_le32toh(u32) (u32)
|
||||
|
||||
#elif (TU_BYTE_ORDER == TU_BIG_ENDIAN)
|
||||
|
||||
#define tu_htons(u16) (u16)
|
||||
#define tu_ntohs(u16) (u16)
|
||||
|
||||
#define tu_htonl(u32) (u32)
|
||||
#define tu_ntohl(u32) (u32)
|
||||
|
||||
|
||||
#define tu_htole16(u16) (tu_bswap16(u16))
|
||||
#define tu_le16toh(u16) (tu_bswap16(u16))
|
||||
|
||||
#define tu_htole32(u32) (tu_bswap32(u32))
|
||||
#define tu_le32toh(u32) (tu_bswap32(u32))
|
||||
|
||||
#else
|
||||
#error Byte order is undefined
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_COMPILER_H_ */
|
||||
|
@ -125,7 +125,8 @@ typedef enum
|
||||
{
|
||||
TUSB_REQ_TYPE_STANDARD = 0,
|
||||
TUSB_REQ_TYPE_CLASS,
|
||||
TUSB_REQ_TYPE_VENDOR
|
||||
TUSB_REQ_TYPE_VENDOR,
|
||||
TUSB_REQ_TYPE_INVALID
|
||||
} tusb_request_type_t;
|
||||
|
||||
typedef enum
|
||||
|
@ -36,10 +36,34 @@
|
||||
* as C++ for the sake of code simplicity. Beware of a headache macro
|
||||
* manipulation that you are told to stay away.
|
||||
*
|
||||
* e.g
|
||||
*
|
||||
* - TU_VERIFY( cond ) will return false if cond is false
|
||||
* - TU_VERIFY( cond, err) will return err instead if cond is false
|
||||
* This contains macros for both VERIFY and ASSERT:
|
||||
*
|
||||
* VERIFY: Used when there is an error condition which is not the
|
||||
* fault of the MCU. For example, bounds checking on data
|
||||
* sent to the micro over USB should use this function.
|
||||
* Another example is checking for buffer overflows, where
|
||||
* returning from the active function causes a NAK.
|
||||
*
|
||||
* ASSERT: Used for error conditions that are caused by MCU firmware
|
||||
* bugs. This is used to discover bugs in the code more
|
||||
* quickly. One example would be adding assertions in library
|
||||
* function calls to confirm a function's (untainted)
|
||||
* parameters are valid.
|
||||
*
|
||||
*
|
||||
* The difference in behaviour is that ASSERT triggers a breakpoint while
|
||||
* verify does not.
|
||||
*
|
||||
* #define TU_VERIFY(cond) if(cond) return false;
|
||||
* #define TU_VERIFY(cond,ret) if(cond) return ret;
|
||||
*
|
||||
* #define TU_VERIFY_HDLR(cond,handler) if(cond) {handler; return false;}
|
||||
* #define TU_VERIFY_HDLR(cond,ret,handler) if(cond) {handler; return ret;}
|
||||
*
|
||||
* #define TU_ASSERT(cond) if(cond) {_MESS_FAILED(); TU_BREAKPOINT(), return false;}
|
||||
* #define TU_ASSERT(cond,ret) if(cond) {_MESS_FAILED(); TU_BREAKPOINT(), return ret;}
|
||||
*
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -52,14 +52,22 @@ typedef struct {
|
||||
uint8_t self_powered : 1; // configuration descriptor's attribute
|
||||
};
|
||||
|
||||
uint8_t ep_busy_map[2]; // bit mask for busy endpoint
|
||||
uint8_t ep_stall_map[2]; // bit map for stalled endpoint
|
||||
|
||||
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
|
||||
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
|
||||
|
||||
struct TU_ATTR_PACKED
|
||||
{
|
||||
volatile bool busy : 1;
|
||||
volatile bool stalled : 1;
|
||||
|
||||
// TODO merge ep2drv here, 4-bit should be sufficient
|
||||
}ep_status[8][2];
|
||||
}usbd_device_t;
|
||||
|
||||
static usbd_device_t _usbd_dev = { 0 };
|
||||
static usbd_device_t _usbd_dev;
|
||||
|
||||
// Invalid driver ID in itf2drv[] ep2drv[][] mapping
|
||||
enum { DRVID_INVALID = 0xFFu };
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver
|
||||
@ -142,9 +150,26 @@ static usbd_class_driver_t const usbd_class_drivers[] =
|
||||
.sof = NULL
|
||||
},
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_USBTMC
|
||||
// Presently USBTMC is the only defined class with the APP_SPECIFIC class code.
|
||||
// We maybe need to add subclass codes here, or a callback to ask if a driver can
|
||||
// handle a particular interface.
|
||||
{
|
||||
.class_code = TUD_USBTMC_APP_CLASS,
|
||||
//.subclass_code = TUD_USBTMC_APP_SUBCLASS
|
||||
.init = usbtmcd_init_cb,
|
||||
.reset = usbtmcd_reset_cb,
|
||||
.open = usbtmcd_open_cb,
|
||||
.control_request = usbtmcd_control_request_cb,
|
||||
.control_complete = usbtmcd_control_complete_cb,
|
||||
.xfer_cb = usbtmcd_xfer_cb,
|
||||
.sof = NULL
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
enum { USBD_CLASS_DRIVER_COUNT = TU_ARRAY_SZIE(usbd_class_drivers) };
|
||||
enum { USBD_CLASS_DRIVER_COUNT = TU_ARRAY_SIZE(usbd_class_drivers) };
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DCD Event
|
||||
@ -213,8 +238,8 @@ static void usbd_reset(uint8_t rhport)
|
||||
{
|
||||
tu_varclr(&_usbd_dev);
|
||||
|
||||
memset(_usbd_dev.itf2drv, 0xff, sizeof(_usbd_dev.itf2drv)); // invalid mapping
|
||||
memset(_usbd_dev.ep2drv , 0xff, sizeof(_usbd_dev.ep2drv )); // invalid mapping
|
||||
memset(_usbd_dev.itf2drv, DRVID_INVALID, sizeof(_usbd_dev.itf2drv)); // invalid mapping
|
||||
memset(_usbd_dev.ep2drv , DRVID_INVALID, sizeof(_usbd_dev.ep2drv )); // invalid mapping
|
||||
|
||||
usbd_control_reset(rhport);
|
||||
|
||||
@ -287,19 +312,19 @@ void tud_task (void)
|
||||
{
|
||||
// Invoke the class callback associated with the endpoint address
|
||||
uint8_t const ep_addr = event.xfer_complete.ep_addr;
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const ep_dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
_usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
_usbd_dev.ep_status[epnum][ep_dir].busy = false;
|
||||
|
||||
if ( 0 == tu_edpt_number(ep_addr) )
|
||||
if ( 0 == epnum )
|
||||
{
|
||||
// control transfer DATA stage callback
|
||||
usbd_control_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t const drv_id = _usbd_dev.ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)];
|
||||
uint8_t const drv_id = _usbd_dev.ep2drv[epnum][ep_dir];
|
||||
TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,);
|
||||
|
||||
usbd_class_drivers[drv_id].xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len);
|
||||
@ -346,6 +371,8 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
{
|
||||
usbd_control_set_complete_callback(NULL);
|
||||
|
||||
TU_ASSERT(p_request->bmRequestType_bit.type < TUSB_REQ_TYPE_INVALID);
|
||||
|
||||
// Vendor request
|
||||
if ( p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR )
|
||||
{
|
||||
@ -435,74 +462,122 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
case TUSB_REQ_RCPT_INTERFACE:
|
||||
{
|
||||
uint8_t const itf = tu_u16_low(p_request->wIndex);
|
||||
uint8_t const drvid = _usbd_dev.itf2drv[itf];
|
||||
TU_VERIFY(itf < TU_ARRAY_SIZE(_usbd_dev.itf2drv));
|
||||
|
||||
uint8_t const drvid = _usbd_dev.itf2drv[itf];
|
||||
TU_VERIFY(drvid < USBD_CLASS_DRIVER_COUNT);
|
||||
|
||||
switch ( p_request->bRequest )
|
||||
if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
|
||||
{
|
||||
case TUSB_REQ_GET_INTERFACE:
|
||||
switch ( p_request->bRequest )
|
||||
{
|
||||
// TODO not support alternate interface yet
|
||||
uint8_t alternate = 0;
|
||||
tud_control_xfer(rhport, p_request, &alternate, 1);
|
||||
case TUSB_REQ_GET_INTERFACE:
|
||||
{
|
||||
// TODO not support alternate interface yet
|
||||
uint8_t alternate = 0;
|
||||
tud_control_xfer(rhport, p_request, &alternate, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_INTERFACE:
|
||||
{
|
||||
uint8_t const alternate = (uint8_t) p_request->wValue;
|
||||
|
||||
// TODO not support alternate interface yet
|
||||
TU_ASSERT(alternate == 0);
|
||||
tud_control_status(rhport, p_request);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// forward to class driver: "STD request to Interface"
|
||||
// GET HID REPORT DESCRIPTOR falls into this case
|
||||
// stall control endpoint if driver return false
|
||||
usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_complete);
|
||||
TU_ASSERT(usbd_class_drivers[drvid].control_request != NULL &&
|
||||
usbd_class_drivers[drvid].control_request(rhport, p_request));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_INTERFACE:
|
||||
{
|
||||
uint8_t alternate = (uint8_t) p_request->wValue;
|
||||
|
||||
// TODO not support alternate interface yet
|
||||
TU_ASSERT(alternate == 0);
|
||||
|
||||
tud_control_status(rhport, p_request);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// forward to class driver
|
||||
// stall control endpoint if driver return false
|
||||
usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_complete);
|
||||
TU_ASSERT(usbd_class_drivers[drvid].control_request(rhport, p_request));
|
||||
break;
|
||||
}else
|
||||
{
|
||||
// forward to class driver: "non-STD request to Interface"
|
||||
// stall control endpoint if driver return false
|
||||
usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_complete);
|
||||
TU_ASSERT(usbd_class_drivers[drvid].control_request != NULL &&
|
||||
usbd_class_drivers[drvid].control_request(rhport, p_request));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//------------- Endpoint Request -------------//
|
||||
case TUSB_REQ_RCPT_ENDPOINT:
|
||||
// Non standard request is not supported
|
||||
TU_VERIFY( TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type );
|
||||
{
|
||||
uint8_t const ep_addr = tu_u16_low(p_request->wIndex);
|
||||
uint8_t const ep_num = tu_edpt_number(ep_addr);
|
||||
uint8_t const ep_dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
switch ( p_request->bRequest )
|
||||
TU_ASSERT(ep_num < TU_ARRAY_SIZE(_usbd_dev.ep2drv) );
|
||||
|
||||
uint8_t const drv_id = _usbd_dev.ep2drv[ep_num][ep_dir];
|
||||
TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT);
|
||||
|
||||
bool ret = false;
|
||||
|
||||
if ( TUSB_REQ_TYPE_STANDARD != p_request->bmRequestType_bit.type )
|
||||
{
|
||||
case TUSB_REQ_GET_STATUS:
|
||||
{
|
||||
uint16_t status = usbd_edpt_stalled(rhport, tu_u16_low(p_request->wIndex)) ? 0x0001 : 0x0000;
|
||||
tud_control_xfer(rhport, p_request, &status, 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_CLEAR_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex));
|
||||
}
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_stall(rhport, tu_u16_low(p_request->wIndex));
|
||||
}
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
// Unknown/Unsupported request
|
||||
default: TU_BREAKPOINT(); return false;
|
||||
// complete callback is also capable of stalling/acking the request
|
||||
usbd_control_set_complete_callback(usbd_class_drivers[drv_id].control_complete);
|
||||
}
|
||||
|
||||
// Then handle if it is standard request
|
||||
if ( TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type )
|
||||
{
|
||||
// force return true for standard request
|
||||
ret = true;
|
||||
|
||||
switch ( p_request->bRequest )
|
||||
{
|
||||
case TUSB_REQ_GET_STATUS:
|
||||
{
|
||||
uint16_t status = usbd_edpt_stalled(rhport, ep_addr) ? 0x0001 : 0x0000;
|
||||
tud_control_xfer(rhport, p_request, &status, 2);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_REQ_CLEAR_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_clear_stall(rhport, ep_addr);
|
||||
}
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
case TUSB_REQ_SET_FEATURE:
|
||||
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
|
||||
{
|
||||
usbd_edpt_stall(rhport, ep_addr);
|
||||
}
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
// Unknown/Unsupported request
|
||||
default: TU_BREAKPOINT(); return false;
|
||||
}
|
||||
}
|
||||
// Some classes such as TMC needs to clear/re-init its buffer when receiving CLEAR_FEATURE request
|
||||
// We will forward all request targeted endpoint to its class driver
|
||||
// For class-type requests: must (call tud_control_status(); return true) or (return false)
|
||||
// For std-type requests: non-std request codes are already discarded.
|
||||
// must not call tud_control_status(), and return value will have no effect
|
||||
// class driver is invoked last, so that EP already has EP stall cleared (in event of clear feature EP halt)
|
||||
|
||||
if ( usbd_class_drivers[drv_id].control_request &&
|
||||
usbd_class_drivers[drv_id].control_request(rhport, p_request))
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
|
||||
// Unknown recipient
|
||||
@ -548,7 +623,7 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num)
|
||||
TU_ASSERT( drv_id < USBD_CLASS_DRIVER_COUNT );
|
||||
|
||||
// Interface number must not be used already TODO alternate interface
|
||||
TU_ASSERT( 0xff == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] );
|
||||
TU_ASSERT( DRVID_INVALID == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] );
|
||||
_usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id;
|
||||
|
||||
uint16_t itf_len=0;
|
||||
@ -581,7 +656,7 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc,
|
||||
ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = driver_id;
|
||||
}
|
||||
|
||||
len += tu_desc_len(p_desc);
|
||||
len = (uint16_t)(len + tu_desc_len(p_desc));
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
}
|
||||
@ -752,7 +827,7 @@ bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count
|
||||
{
|
||||
tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
|
||||
|
||||
TU_VERIFY(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
|
||||
TU_ASSERT(dcd_edpt_open(rhport, desc_ep));
|
||||
|
||||
if ( tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN )
|
||||
@ -794,8 +869,7 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
TU_VERIFY( dcd_edpt_xfer(rhport, ep_addr, buffer, total_bytes) );
|
||||
|
||||
_usbd_dev.ep_busy_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
_usbd_dev.ep_status[epnum][dir].busy = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -807,17 +881,17 @@ bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr)
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
return tu_bit_test(_usbd_dev.ep_busy_map[dir], epnum);
|
||||
return _usbd_dev.ep_status[epnum][dir].busy;
|
||||
}
|
||||
|
||||
|
||||
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_stall(rhport, ep_addr);
|
||||
_usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_set(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
_usbd_dev.ep_status[epnum][dir].stalled = true;
|
||||
_usbd_dev.ep_status[epnum][dir].busy = true;
|
||||
}
|
||||
|
||||
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
@ -826,7 +900,8 @@ void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_clear_stall(rhport, ep_addr);
|
||||
_usbd_dev.ep_stall_map[dir] = (uint8_t) tu_bit_clear(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
_usbd_dev.ep_status[epnum][dir].stalled = false;
|
||||
_usbd_dev.ep_status[epnum][dir].busy = false;
|
||||
}
|
||||
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
|
||||
@ -836,7 +911,7 @@ bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
return tu_bit_test(_usbd_dev.ep_stall_map[dir], epnum);
|
||||
return _usbd_dev.ep_status[epnum][dir].stalled;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -261,6 +261,37 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
|
||||
/* MS Endpoint (connected to embedded jack out) */\
|
||||
5, TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL, 1, 3
|
||||
|
||||
//------------- TUD_USBTMC/USB488 -------------//
|
||||
#define TUD_USBTMC_APP_CLASS (TUSB_CLASS_APPLICATION_SPECIFIC)
|
||||
#define TUD_USBTMC_APP_SUBCLASS 0x03u
|
||||
|
||||
#define TUD_USBTMC_PROTOCOL_STD 0x00u
|
||||
#define TUD_USBTMC_PROTOCOL_USB488 0x01u
|
||||
|
||||
// Interface number, number of endpoints, EP string index, USB_TMC_PROTOCOL*, bulk-out endpoint ID,
|
||||
// bulk-in endpoint ID
|
||||
#define TUD_USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints, _stridx, _itfProtocol) \
|
||||
/* Interface */ \
|
||||
0x09, TUSB_DESC_INTERFACE, _itfnum, 0x00, _bNumEndpoints, TUD_USBTMC_APP_CLASS, TUD_USBTMC_APP_SUBCLASS, _itfProtocol, _stridx
|
||||
|
||||
#define TUD_USBTMC_IF_DESCRIPTOR_LEN 9u
|
||||
|
||||
#define TUD_USBTMC_BULK_DESCRIPTORS(_epout, _epin, _bulk_epsize) \
|
||||
/* Endpoint Out */ \
|
||||
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_bulk_epsize), 0u, \
|
||||
/* Endpoint In */ \
|
||||
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_bulk_epsize), 0u
|
||||
|
||||
#define TUD_USBTMC_BULK_DESCRIPTORS_LEN (7u+7u)
|
||||
|
||||
/* optional interrupt endpoint */ \
|
||||
// _int_pollingInterval : for LS/FS, expressed in frames (1ms each). 16 may be a good number?
|
||||
#define TUD_USBTMC_INT_DESCRIPTOR(_ep_interrupt, _ep_interrupt_size, _int_pollingInterval ) \
|
||||
7, TUSB_DESC_ENDPOINT, _ep_interrupt, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_interrupt_size), 0x16
|
||||
|
||||
#define TUD_USBTMC_INT_DESCRIPTOR_LEN (7u)
|
||||
|
||||
|
||||
//------------- Vendor -------------//
|
||||
#define TUD_VENDOR_DESC_LEN (9+7+7)
|
||||
|
||||
|
@ -122,7 +122,7 @@ bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result
|
||||
}
|
||||
|
||||
_control_state.total_transferred += xferred_bytes;
|
||||
_control_state.buffer += xferred_bytes;
|
||||
_control_state.buffer = ((uint8_t*)_control_state.buffer) + xferred_bytes;
|
||||
|
||||
if ( _control_state.total_len == _control_state.total_transferred || xferred_bytes < CFG_TUD_ENDPOINT0_SIZE )
|
||||
{
|
||||
|
@ -47,10 +47,21 @@ bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
// Check if endpoint transferring is complete
|
||||
bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
// Stall endpoint
|
||||
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
// Clear stalled endpoint
|
||||
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
// Check if endpoint is stalled
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
static inline
|
||||
bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Helper
|
||||
*------------------------------------------------------------------*/
|
||||
|
@ -145,6 +145,8 @@ typedef osal_queue_def_t* osal_queue_t;
|
||||
// lock queue by disable usb isr
|
||||
static inline void _osal_q_lock(osal_queue_t qhdl)
|
||||
{
|
||||
(void) qhdl;
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
if (qhdl->role == OPT_MODE_DEVICE) dcd_int_disable(TUD_OPT_RHPORT);
|
||||
#endif
|
||||
@ -157,6 +159,8 @@ static inline void _osal_q_lock(osal_queue_t qhdl)
|
||||
// unlock queue
|
||||
static inline void _osal_q_unlock(osal_queue_t qhdl)
|
||||
{
|
||||
(void) qhdl;
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED
|
||||
if (qhdl->role == OPT_MODE_DEVICE) dcd_int_enable(TUD_OPT_RHPORT);
|
||||
#endif
|
||||
|
@ -293,7 +293,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
|
||||
break;
|
||||
|
||||
case TUSB_XFER_ISOCHRONOUS:
|
||||
TU_ASSERT((epnum % 3) == 3 && (epnum != 15));
|
||||
TU_ASSERT((epnum % 3) == 0 && (epnum != 0) && (epnum != 15));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -30,13 +30,10 @@
|
||||
|
||||
/**********************************************
|
||||
* This driver has been tested with the following MCUs:
|
||||
*
|
||||
*
|
||||
* STM32F070RB
|
||||
*
|
||||
* - F070, F072, L053
|
||||
*
|
||||
* It also should work with minimal changes for any ST MCU with an "USB A"/"PCD"/"HCD" peripheral. This
|
||||
* covers:
|
||||
* covers:
|
||||
*
|
||||
* F04x, F072, F078, 070x6/B 1024 byte buffer
|
||||
* F102, F103 512 byte buffer; no internal D+ pull-up (maybe many more changes?)
|
||||
@ -46,9 +43,13 @@
|
||||
* L1 512 byte buffer
|
||||
* L4x2, L4x3 1024 byte buffer
|
||||
*
|
||||
* To use this driver, you must:
|
||||
* - Enable USB clock; Perhaps use __HAL_RCC_USB_CLK_ENABLE();
|
||||
* - (Optionally configure GPIO HAL to tell it the USB driver is using the USB pins)
|
||||
* - call tusb_init();
|
||||
* - periodically call tusb_task();
|
||||
*
|
||||
* Assumptions of the driver:
|
||||
* - dcd_fs_irqHandler() is called by the USB interrupt handler
|
||||
* - USB clock enabled before usb_init() is called; Perhaps use __HAL_RCC_USB_CLK_ENABLE();
|
||||
* - You are not using CAN (it must share the packet buffer)
|
||||
* - APB clock is >= 10 MHz
|
||||
* - On some boards, series resistors are required, but not on others.
|
||||
@ -59,7 +60,6 @@
|
||||
* Current driver limitations (i.e., a list of features for you to add):
|
||||
* - STALL handled, but not tested.
|
||||
* - Does it work? No clue.
|
||||
* - Only tested on F070RB; other models will have an #error during compilation
|
||||
* - All EP BTABLE buffers are created as max 64 bytes.
|
||||
* - Smaller can be requested, but it has to be an even number.
|
||||
* - No isochronous endpoints
|
||||
@ -74,7 +74,7 @@
|
||||
* - No DMA
|
||||
* - No provision to control the D+ pull-up using GPIO on devices without an internal pull-up.
|
||||
* - Minimal error handling
|
||||
* - Perhaps error interrupts sholud be reported to the stack, or cause a device reset?
|
||||
* - Perhaps error interrupts should be reported to the stack, or cause a device reset?
|
||||
* - Assumes a single USB peripheral; I think that no hardware has multiple so this is fine.
|
||||
* - Add a callback for enabling/disabling the D+ PU on devices without an internal PU.
|
||||
* - F3 models use three separate interrupts. I think we could only use the LP interrupt for
|
||||
@ -103,14 +103,17 @@
|
||||
|
||||
#include "tusb_option.h"
|
||||
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || \
|
||||
defined(STM32F103x6) || defined(STM32F103xB) || \
|
||||
defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#define STM32F1_FSDEV
|
||||
#endif
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED) && ( \
|
||||
((CFG_TUSB_MCU) == OPT_MCU_STM32F0) || \
|
||||
(((CFG_TUSB_MCU) == OPT_MCU_STM32F1) && ( \
|
||||
defined(stm32f102x6) || defined(stm32f102xb) || \
|
||||
defined(stm32f103x6) || defined(stm32f103xb) || \
|
||||
defined(stm32f103xe) || defined(stm32f103xg) \
|
||||
)) || \
|
||||
((CFG_TUSB_MCU) == OPT_MCU_STM32F3) \
|
||||
(CFG_TUSB_MCU == OPT_MCU_STM32F0 ) || \
|
||||
(CFG_TUSB_MCU == OPT_MCU_STM32F1 && defined(STM32F1_FSDEV)) || \
|
||||
(CFG_TUSB_MCU == OPT_MCU_STM32F3 ) || \
|
||||
(CFG_TUSB_MCU == OPT_MCU_STM32L0 ) \
|
||||
)
|
||||
|
||||
// In order to reduce the dependance on HAL, we undefine this.
|
||||
@ -144,22 +147,12 @@
|
||||
* Checks, structs, defines, function definitions, etc.
|
||||
*/
|
||||
|
||||
#if ((MAX_EP_COUNT) > 8)
|
||||
# error Only 8 endpoints supported on the hardware
|
||||
#endif
|
||||
TU_VERIFY_STATIC((MAX_EP_COUNT) <= STFSDEV_EP_COUNT, "Only 8 endpoints supported on the hardware");
|
||||
|
||||
#if (((DCD_STM32_BTABLE_BASE) + (DCD_STM32_BTABLE_LENGTH))>(PMA_LENGTH))
|
||||
# error BTABLE does not fit in PMA RAM
|
||||
#endif
|
||||
|
||||
#if (((DCD_STM32_BTABLE_BASE) % 8) != 0)
|
||||
// per STM32F3 reference manual
|
||||
#error BTABLE must be aligned to 8 bytes
|
||||
#endif
|
||||
|
||||
// Max size of a USB FS packet is 64...
|
||||
#define MAX_PACKET_SIZE 64
|
||||
TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) + (DCD_STM32_BTABLE_LENGTH))<=(PMA_LENGTH),
|
||||
"BTABLE does not fit in PMA RAM");
|
||||
|
||||
TU_VERIFY_STATIC(((DCD_STM32_BTABLE_BASE) % 8) == 0, "BTABLE base must be aligned to 8 bytes");
|
||||
|
||||
// One of these for every EP IN & OUT, uses a bit of RAM....
|
||||
typedef struct
|
||||
@ -167,24 +160,37 @@ typedef struct
|
||||
uint8_t * buffer;
|
||||
uint16_t total_len;
|
||||
uint16_t queued_len;
|
||||
uint16_t max_packet_size;
|
||||
} xfer_ctl_t;
|
||||
|
||||
static xfer_ctl_t xfer_status[MAX_EP_COUNT][2];
|
||||
#define XFER_CTL_BASE(_epnum, _dir) &xfer_status[_epnum][_dir]
|
||||
static xfer_ctl_t xfer_status[MAX_EP_COUNT][2];
|
||||
|
||||
static inline xfer_ctl_t* xfer_ctl_ptr(uint32_t epnum, uint32_t dir)
|
||||
{
|
||||
return &xfer_status[epnum][dir];
|
||||
}
|
||||
|
||||
static TU_ATTR_ALIGNED(4) uint32_t _setup_packet[6];
|
||||
|
||||
static uint8_t newDADDR; // Used to set the new device address during the CTR IRQ handler
|
||||
static uint8_t remoteWakeCountdown; // When wake is requested
|
||||
|
||||
// EP Buffers assigned from end of memory location, to minimize their chance of crashing
|
||||
// into the stack.
|
||||
static uint16_t ep_buf_ptr;
|
||||
static void dcd_handle_bus_reset(void);
|
||||
static void dcd_write_packet_memory(uint16_t dst, const void *__restrict src, size_t wNBytes);
|
||||
static void dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wNBytes);
|
||||
static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, size_t wNBytes);
|
||||
static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wNBytes);
|
||||
static void dcd_transmit_packet(xfer_ctl_t * xfer, uint16_t ep_ix);
|
||||
static uint16_t dcd_ep_ctr_handler(void);
|
||||
|
||||
|
||||
// Using a function due to better type checks
|
||||
// This seems better than having to do type casts everywhere else
|
||||
static inline void reg16_clear_bits(__IO uint16_t *reg, uint16_t mask) {
|
||||
*reg = (uint16_t)(*reg & ~mask);
|
||||
}
|
||||
|
||||
void dcd_init (uint8_t rhport)
|
||||
{
|
||||
(void)rhport;
|
||||
@ -204,7 +210,7 @@ void dcd_init (uint8_t rhport)
|
||||
{
|
||||
asm("NOP");
|
||||
}
|
||||
USB->CNTR &= ~(USB_CNTR_PDWN);// Remove powerdown
|
||||
reg16_clear_bits(&USB->CNTR, USB_CNTR_PDWN);// Remove powerdown
|
||||
// Wait startup time, for F042 and F070, this is <= 1 us.
|
||||
for(uint32_t i = 0; i<200; i++) // should be a few us
|
||||
{
|
||||
@ -214,21 +220,22 @@ void dcd_init (uint8_t rhport)
|
||||
|
||||
USB->BTABLE = DCD_STM32_BTABLE_BASE;
|
||||
|
||||
USB->ISTR &= ~(USB_ISTR_ALL_EVENTS); // Clear pending interrupts
|
||||
reg16_clear_bits(&USB->ISTR, USB_ISTR_ALL_EVENTS); // Clear pending interrupts
|
||||
|
||||
// Clear all EPREG
|
||||
for(uint16_t i=0; i<8; i++)
|
||||
// Reset endpoints to disabled
|
||||
for(uint32_t i=0; i<STFSDEV_EP_COUNT; i++)
|
||||
{
|
||||
EPREG(0) = 0u;
|
||||
// This doesn't clear all bits since some bits are "toggle", but does set the type to DISABLED.
|
||||
pcd_set_endpoint(USB,i,0u);
|
||||
}
|
||||
|
||||
// Initialize the BTABLE for EP0 at this point (though setting up the EP0R is unneeded)
|
||||
// This is actually not necessary, but helps debugging to start with a blank RAM area
|
||||
for(uint16_t i=0;i<(DCD_STM32_BTABLE_LENGTH>>1); i++)
|
||||
for(uint32_t i=0;i<(DCD_STM32_BTABLE_LENGTH>>1); i++)
|
||||
{
|
||||
pma[PMA_STRIDE*(DCD_STM32_BTABLE_BASE + i)] = 0u;
|
||||
}
|
||||
USB->CNTR |= USB_CNTR_RESETM | USB_CNTR_SOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
|
||||
USB->CNTR |= USB_CNTR_RESETM | USB_CNTR_SOFM | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
|
||||
dcd_handle_bus_reset();
|
||||
|
||||
// And finally enable pull-up, which may trigger the RESET IRQ if the host is connected.
|
||||
@ -245,16 +252,21 @@ void dcd_init (uint8_t rhport)
|
||||
void dcd_int_enable (uint8_t rhport)
|
||||
{
|
||||
(void)rhport;
|
||||
#if defined(STM32F0)
|
||||
NVIC_SetPriority(USB_IRQn, 0);
|
||||
// Member here forces write to RAM before allowing ISR to execute
|
||||
__DSB();
|
||||
__ISB();
|
||||
#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0
|
||||
NVIC_EnableIRQ(USB_IRQn);
|
||||
#elif defined(STM32F3)
|
||||
NVIC_SetPriority(USB_HP_CAN_TX_IRQn, 0);
|
||||
NVIC_SetPriority(USB_LP_CAN_RX0_IRQn, 0);
|
||||
NVIC_SetPriority(USBWakeUp_IRQn, 0);
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32F3
|
||||
NVIC_EnableIRQ(USB_HP_CAN_TX_IRQn);
|
||||
NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);
|
||||
NVIC_EnableIRQ(USBWakeUp_IRQn);
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
|
||||
NVIC_EnableIRQ(USB_HP_CAN1_TX_IRQn);
|
||||
NVIC_EnableIRQ(USB_LP_CAN1_RX0_IRQn);
|
||||
NVIC_EnableIRQ(USBWakeUp_IRQn);
|
||||
#else
|
||||
#error Unknown arch in USB driver
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -262,15 +274,22 @@ void dcd_int_enable (uint8_t rhport)
|
||||
void dcd_int_disable(uint8_t rhport)
|
||||
{
|
||||
(void)rhport;
|
||||
#if defined(STM32F0)
|
||||
|
||||
#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0
|
||||
NVIC_DisableIRQ(USB_IRQn);
|
||||
#elif defined(STM32F3)
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32F3
|
||||
NVIC_DisableIRQ(USB_HP_CAN_TX_IRQn);
|
||||
NVIC_DisableIRQ(USB_LP_CAN_RX0_IRQn);
|
||||
NVIC_DisableIRQ(USBWakeUp_IRQn);
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
|
||||
NVIC_DisableIRQ(USB_HP_CAN1_TX_IRQn);
|
||||
NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
|
||||
NVIC_DisableIRQ(USBWakeUp_IRQn);
|
||||
#else
|
||||
#error Unknown arch in USB driver
|
||||
#error Unknown arch in USB driver
|
||||
#endif
|
||||
|
||||
// CMSIS has a membar after disabling interrupts
|
||||
}
|
||||
|
||||
// Receive Set Address request, mcu port must also include status IN response
|
||||
@ -297,6 +316,9 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
|
||||
void dcd_remote_wakeup(uint8_t rhport)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
USB->CNTR |= (uint16_t) USB_CNTR_RESUME;
|
||||
remoteWakeCountdown = 4u; // required to be 1 to 15 ms, ESOF should trigger every 1ms.
|
||||
}
|
||||
|
||||
// I'm getting a weird warning about missing braces here that I don't
|
||||
@ -319,7 +341,9 @@ static const tusb_desc_endpoint_t ep0IN_desc =
|
||||
.bEndpointAddress = 0x80
|
||||
};
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
static void dcd_handle_bus_reset(void)
|
||||
{
|
||||
@ -327,23 +351,22 @@ static void dcd_handle_bus_reset(void)
|
||||
USB->DADDR = 0u; // disable USB peripheral by clearing the EF flag
|
||||
|
||||
// Clear all EPREG (or maybe this is automatic? I'm not sure)
|
||||
for(uint16_t i=0; i<8; i++)
|
||||
for(uint32_t i=0; i<STFSDEV_EP_COUNT; i++)
|
||||
{
|
||||
EPREG(0) = 0u;
|
||||
pcd_set_endpoint(USB,i,0u);
|
||||
}
|
||||
|
||||
ep_buf_ptr = DCD_STM32_BTABLE_BASE + 8*MAX_EP_COUNT; // 8 bytes per endpoint (two TX and two RX words, each)
|
||||
dcd_edpt_open (0, &ep0OUT_desc);
|
||||
dcd_edpt_open (0, &ep0IN_desc);
|
||||
newDADDR = 0;
|
||||
newDADDR = 0u;
|
||||
USB->DADDR = USB_DADDR_EF; // Set enable flag, and leaving the device address as zero.
|
||||
PCD_SET_EP_RX_STATUS(USB, 0, USB_EP_RX_VALID); // And start accepting SETUP on EP0
|
||||
}
|
||||
|
||||
// FIXME: Defined to return uint16 so that ASSERT can be used, even though a return value is not needed.
|
||||
static uint16_t dcd_ep_ctr_handler(void)
|
||||
{
|
||||
uint16_t count=0U;
|
||||
uint32_t count=0U;
|
||||
uint8_t EPindex;
|
||||
__IO uint16_t wIstr;
|
||||
__IO uint16_t wEPVal = 0U;
|
||||
@ -365,9 +388,9 @@ static uint16_t dcd_ep_ctr_handler(void)
|
||||
{
|
||||
/* DIR = 0 => IN int */
|
||||
/* DIR = 0 implies that (EP_CTR_TX = 1) always */
|
||||
PCD_CLEAR_TX_EP_CTR(USB, 0);
|
||||
pcd_clear_tx_ep_ctr(USB, 0);
|
||||
|
||||
xfer_ctl_t * xfer = XFER_CTL_BASE(EPindex,TUSB_DIR_IN);
|
||||
xfer_ctl_t * xfer = xfer_ctl_ptr(EPindex,TUSB_DIR_IN);
|
||||
|
||||
if((xfer->total_len == xfer->queued_len))
|
||||
{
|
||||
@ -375,13 +398,13 @@ static uint16_t dcd_ep_ctr_handler(void)
|
||||
if((newDADDR != 0) && ( xfer->total_len == 0U))
|
||||
{
|
||||
// Delayed setting of the DADDR after the 0-len DATA packet acking the request is sent.
|
||||
USB->DADDR &= ~USB_DADDR_ADD;
|
||||
USB->DADDR |= newDADDR;
|
||||
reg16_clear_bits(&USB->DADDR, USB_DADDR_ADD);
|
||||
USB->DADDR = (uint16_t)(USB->DADDR | newDADDR); // leave the enable bit set
|
||||
newDADDR = 0;
|
||||
}
|
||||
if(xfer->total_len == 0) // Probably a status message?
|
||||
{
|
||||
PCD_CLEAR_RX_DTOG(USB,EPindex);
|
||||
pcd_clear_rx_dtog(USB,EPindex);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -394,10 +417,10 @@ static uint16_t dcd_ep_ctr_handler(void)
|
||||
/* DIR = 1 & CTR_RX => SETUP or OUT int */
|
||||
/* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
|
||||
|
||||
xfer_ctl_t *xfer = XFER_CTL_BASE(EPindex,TUSB_DIR_OUT);
|
||||
xfer_ctl_t *xfer = xfer_ctl_ptr(EPindex,TUSB_DIR_OUT);
|
||||
|
||||
//ep = &hpcd->OUT_ep[0];
|
||||
wEPVal = PCD_GET_ENDPOINT(USB, EPindex);
|
||||
wEPVal = pcd_get_endpoint(USB, EPindex);
|
||||
|
||||
if ((wEPVal & USB_EP_SETUP) != 0U) // SETUP
|
||||
{
|
||||
@ -405,69 +428,67 @@ static uint16_t dcd_ep_ctr_handler(void)
|
||||
// user memory, to allow for the 32-bit access that memcpy performs.
|
||||
uint8_t userMemBuf[8];
|
||||
/* Get SETUP Packet*/
|
||||
count = PCD_GET_EP_RX_CNT(USB, EPindex);
|
||||
//TU_ASSERT_ERR(count == 8);
|
||||
dcd_read_packet_memory(userMemBuf, *PCD_EP_RX_ADDRESS_PTR(USB,EPindex), 8);
|
||||
count = pcd_get_ep_rx_cnt(USB, EPindex);
|
||||
if(count == 8) // Setup packet should always be 8 bytes. If not, ignore it, and try again.
|
||||
{
|
||||
// Must reset EP to NAK (in case it had been stalling) (though, maybe too late here)
|
||||
pcd_set_ep_rx_status(USB,0u,USB_EP_RX_NAK);
|
||||
pcd_set_ep_tx_status(USB,0u,USB_EP_TX_NAK);
|
||||
dcd_read_packet_memory(userMemBuf, *pcd_ep_rx_address_ptr(USB,EPindex), 8);
|
||||
dcd_event_setup_received(0, (uint8_t*)userMemBuf, true);
|
||||
}
|
||||
/* SETUP bit kept frozen while CTR_RX = 1*/
|
||||
dcd_event_setup_received(0, (uint8_t*)userMemBuf, true);
|
||||
PCD_CLEAR_RX_EP_CTR(USB, EPindex);
|
||||
pcd_clear_rx_ep_ctr(USB, EPindex);
|
||||
}
|
||||
else if ((wEPVal & USB_EP_CTR_RX) != 0U) // OUT
|
||||
{
|
||||
|
||||
PCD_CLEAR_RX_EP_CTR(USB, EPindex);
|
||||
pcd_clear_rx_ep_ctr(USB, EPindex);
|
||||
|
||||
/* Get Control Data OUT Packet */
|
||||
count = PCD_GET_EP_RX_CNT(USB,EPindex);
|
||||
count = pcd_get_ep_rx_cnt(USB,EPindex);
|
||||
|
||||
if (count != 0U)
|
||||
{
|
||||
dcd_read_packet_memory(xfer->buffer, *PCD_EP_RX_ADDRESS_PTR(USB,EPindex), count);
|
||||
dcd_read_packet_memory(xfer->buffer, *pcd_ep_rx_address_ptr(USB,EPindex), count);
|
||||
xfer->queued_len = (uint16_t)(xfer->queued_len + count);
|
||||
}
|
||||
|
||||
/* Process Control Data OUT status Packet*/
|
||||
if(EPindex == 0 && xfer->total_len == 0)
|
||||
{
|
||||
PCD_CLEAR_EP_KIND(USB,0); // Good, so allow non-zero length packets now.
|
||||
}
|
||||
dcd_event_xfer_complete(0, EPindex, xfer->total_len, XFER_RESULT_SUCCESS, true);
|
||||
|
||||
PCD_SET_EP_RX_CNT(USB, EPindex, CFG_TUD_ENDPOINT0_SIZE);
|
||||
if(EPindex == 0 && xfer->total_len == 0)
|
||||
pcd_set_ep_rx_cnt(USB, EPindex, CFG_TUD_ENDPOINT0_SIZE);
|
||||
if(EPindex == 0u && xfer->total_len == 0u)
|
||||
{
|
||||
PCD_SET_EP_RX_STATUS(USB, EPindex, USB_EP_RX_VALID);// Await next SETUP
|
||||
pcd_set_ep_rx_status(USB, EPindex, USB_EP_RX_VALID);// Await next SETUP
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else /* Decode and service non control endpoints interrupt */
|
||||
{
|
||||
|
||||
/* process related endpoint register */
|
||||
wEPVal = PCD_GET_ENDPOINT(USB, EPindex);
|
||||
wEPVal = pcd_get_endpoint(USB, EPindex);
|
||||
if ((wEPVal & USB_EP_CTR_RX) != 0U) // OUT
|
||||
{
|
||||
/* clear int flag */
|
||||
PCD_CLEAR_RX_EP_CTR(USB, EPindex);
|
||||
pcd_clear_rx_ep_ctr(USB, EPindex);
|
||||
|
||||
xfer_ctl_t * xfer = XFER_CTL_BASE(EPindex,TUSB_DIR_OUT);
|
||||
xfer_ctl_t * xfer = xfer_ctl_ptr(EPindex,TUSB_DIR_OUT);
|
||||
|
||||
//ep = &hpcd->OUT_ep[EPindex];
|
||||
|
||||
count = PCD_GET_EP_RX_CNT(USB, EPindex);
|
||||
count = pcd_get_ep_rx_cnt(USB, EPindex);
|
||||
if (count != 0U)
|
||||
{
|
||||
dcd_read_packet_memory(&(xfer->buffer[xfer->queued_len]),
|
||||
*PCD_EP_RX_ADDRESS_PTR(USB,EPindex), count);
|
||||
*pcd_ep_rx_address_ptr(USB,EPindex), count);
|
||||
}
|
||||
|
||||
/*multi-packet on the NON control OUT endpoint */
|
||||
xfer->queued_len = (uint16_t)(xfer->queued_len + count);
|
||||
|
||||
if ((count < 64) || (xfer->queued_len == xfer->total_len))
|
||||
if ((count < xfer->max_packet_size) || (xfer->queued_len == xfer->total_len))
|
||||
{
|
||||
/* RX COMPLETE */
|
||||
dcd_event_xfer_complete(0, EPindex, xfer->queued_len, XFER_RESULT_SUCCESS, true);
|
||||
@ -476,14 +497,14 @@ static uint16_t dcd_ep_ctr_handler(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
uint16_t remaining = (uint16_t)(xfer->total_len - xfer->queued_len);
|
||||
if(remaining >=64) {
|
||||
PCD_SET_EP_RX_CNT(USB, EPindex,64);
|
||||
uint32_t remaining = (uint32_t)xfer->total_len - (uint32_t)xfer->queued_len;
|
||||
if(remaining >= xfer->max_packet_size) {
|
||||
pcd_set_ep_rx_cnt(USB, EPindex,xfer->max_packet_size);
|
||||
} else {
|
||||
PCD_SET_EP_RX_CNT(USB, EPindex,remaining);
|
||||
pcd_set_ep_rx_cnt(USB, EPindex,remaining);
|
||||
}
|
||||
|
||||
PCD_SET_EP_RX_STATUS(USB, EPindex, USB_EP_RX_VALID);
|
||||
pcd_set_ep_rx_status(USB, EPindex, USB_EP_RX_VALID);
|
||||
}
|
||||
|
||||
} /* if((wEPVal & EP_CTR_RX) */
|
||||
@ -491,9 +512,9 @@ static uint16_t dcd_ep_ctr_handler(void)
|
||||
if ((wEPVal & USB_EP_CTR_TX) != 0U) // IN
|
||||
{
|
||||
/* clear int flag */
|
||||
PCD_CLEAR_TX_EP_CTR(USB, EPindex);
|
||||
pcd_clear_tx_ep_ctr(USB, EPindex);
|
||||
|
||||
xfer_ctl_t * xfer = XFER_CTL_BASE(EPindex,TUSB_DIR_IN);
|
||||
xfer_ctl_t * xfer = xfer_ctl_ptr(EPindex,TUSB_DIR_IN);
|
||||
|
||||
if (xfer->queued_len != xfer->total_len) // data remaining in transfer?
|
||||
{
|
||||
@ -507,46 +528,71 @@ static uint16_t dcd_ep_ctr_handler(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dcd_fs_irqHandler(void) {
|
||||
static void dcd_fs_irqHandler(void) {
|
||||
|
||||
uint16_t int_status = USB->ISTR;
|
||||
// unused IRQs: (USB_ISTR_PMAOVR | USB_ISTR_ERR | USB_ISTR_WKUP | USB_ISTR_SUSP | USB_ISTR_ESOF | USB_ISTR_L1REQ )
|
||||
uint32_t int_status = USB->ISTR;
|
||||
//const uint32_t handled_ints = USB_ISTR_CTR | USB_ISTR_RESET | USB_ISTR_WKUP
|
||||
// | USB_ISTR_SUSP | USB_ISTR_SOF | USB_ISTR_ESOF;
|
||||
// unused IRQs: (USB_ISTR_PMAOVR | USB_ISTR_ERR | USB_ISTR_L1REQ )
|
||||
|
||||
// The ST driver loops here on the CTR bit, but that loop has been moved into the
|
||||
// dcd_ep_ctr_handler(), so less need to loop here. The other interrupts shouldn't
|
||||
// be triggered repeatedly.
|
||||
|
||||
if(int_status & USB_ISTR_RESET) {
|
||||
// USBRST is start of reset.
|
||||
reg16_clear_bits(&USB->ISTR, USB_ISTR_RESET);
|
||||
dcd_handle_bus_reset();
|
||||
dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true);
|
||||
return; // Don't do the rest of the things here; perhaps they've been cleared?
|
||||
}
|
||||
|
||||
if (int_status & USB_ISTR_CTR)
|
||||
{
|
||||
/* servicing of the endpoint correct transfer interrupt */
|
||||
/* clear of the CTR flag into the sub */
|
||||
dcd_ep_ctr_handler();
|
||||
USB->ISTR &= ~USB_ISTR_CTR;
|
||||
}
|
||||
if(int_status & USB_ISTR_RESET) {
|
||||
// USBRST is start of reset.
|
||||
USB->ISTR &= ~USB_ISTR_RESET;
|
||||
dcd_handle_bus_reset();
|
||||
dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true);
|
||||
reg16_clear_bits(&USB->ISTR, USB_ISTR_CTR);
|
||||
}
|
||||
|
||||
if (int_status & USB_ISTR_WKUP)
|
||||
{
|
||||
|
||||
USB->CNTR &= ~USB_CNTR_LPMODE;
|
||||
USB->CNTR &= ~USB_CNTR_FSUSP;
|
||||
USB->ISTR &= ~USB_ISTR_WKUP;
|
||||
reg16_clear_bits(&USB->CNTR, USB_CNTR_LPMODE);
|
||||
reg16_clear_bits(&USB->CNTR, USB_CNTR_FSUSP);
|
||||
reg16_clear_bits(&USB->ISTR, USB_ISTR_WKUP);
|
||||
dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
|
||||
}
|
||||
|
||||
if (int_status & USB_ISTR_SUSP)
|
||||
{
|
||||
/* Suspend is asserted for both suspend and unplug events. without Vbus monitoring,
|
||||
* these events cannot be differentiated, so we only trigger suspend. */
|
||||
|
||||
/* Force low-power mode in the macrocell */
|
||||
USB->CNTR |= USB_CNTR_FSUSP;
|
||||
USB->CNTR |= USB_CNTR_LPMODE;
|
||||
|
||||
/* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
|
||||
USB->ISTR &= ~USB_ISTR_SUSP;
|
||||
reg16_clear_bits(&USB->ISTR, USB_ISTR_SUSP);
|
||||
dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
|
||||
}
|
||||
|
||||
if(int_status & USB_ISTR_SOF) {
|
||||
USB->ISTR &= ~USB_ISTR_SOF;
|
||||
reg16_clear_bits(&USB->ISTR, USB_ISTR_SOF);
|
||||
dcd_event_bus_signal(0, DCD_EVENT_SOF, true);
|
||||
}
|
||||
|
||||
if(int_status & USB_ISTR_ESOF) {
|
||||
if(remoteWakeCountdown == 1u)
|
||||
{
|
||||
USB->CNTR &= (uint16_t)(~USB_CNTR_RESUME);
|
||||
}
|
||||
if(remoteWakeCountdown > 0u)
|
||||
{
|
||||
remoteWakeCountdown--;
|
||||
}
|
||||
reg16_clear_bits(&USB->ISTR, USB_ISTR_ESOF);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -561,47 +607,57 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc
|
||||
(void)rhport;
|
||||
uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
|
||||
uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress);
|
||||
|
||||
const uint16_t epMaxPktSize = p_endpoint_desc->wMaxPacketSize.size;
|
||||
// Isochronous not supported (yet), and some other driver assumptions.
|
||||
TU_ASSERT(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
|
||||
TU_ASSERT(p_endpoint_desc->wMaxPacketSize.size <= MAX_PACKET_SIZE);
|
||||
TU_ASSERT(epnum < MAX_EP_COUNT);
|
||||
TU_ASSERT((p_endpoint_desc->wMaxPacketSize.size %2) == 0);
|
||||
|
||||
// __IO uint16_t * const epreg = &(EPREG(epnum));
|
||||
TU_ASSERT(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
|
||||
TU_ASSERT(epnum < MAX_EP_COUNT);
|
||||
|
||||
// Set type
|
||||
switch(p_endpoint_desc->bmAttributes.xfer) {
|
||||
case TUSB_XFER_CONTROL:
|
||||
PCD_SET_EPTYPE(USB, epnum, USB_EP_CONTROL); break;
|
||||
case TUSB_XFER_ISOCHRONOUS:
|
||||
PCD_SET_EPTYPE(USB, epnum, USB_EP_ISOCHRONOUS); break;
|
||||
pcd_set_eptype(USB, epnum, USB_EP_CONTROL);
|
||||
break;
|
||||
#if (0)
|
||||
case TUSB_XFER_ISOCHRONOUS: // FIXME: Not yet supported
|
||||
pcd_set_eptype(USB, epnum, USB_EP_ISOCHRONOUS); break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case TUSB_XFER_BULK:
|
||||
PCD_SET_EPTYPE(USB, epnum, USB_EP_BULK); break;
|
||||
pcd_set_eptype(USB, epnum, USB_EP_BULK);
|
||||
break;
|
||||
|
||||
case TUSB_XFER_INTERRUPT:
|
||||
PCD_SET_EPTYPE(USB, epnum, USB_EP_INTERRUPT); break;
|
||||
pcd_set_eptype(USB, epnum, USB_EP_INTERRUPT);
|
||||
break;
|
||||
|
||||
default:
|
||||
TU_ASSERT(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
PCD_SET_EP_ADDRESS(USB, epnum, epnum);
|
||||
PCD_CLEAR_EP_KIND(USB,0); // Be normal, for now, instead of only accepting zero-byte packets
|
||||
pcd_set_ep_address(USB, epnum, epnum);
|
||||
// Be normal, for now, instead of only accepting zero-byte packets (on control endpoint)
|
||||
// or being double-buffered (bulk endpoints)
|
||||
pcd_clear_ep_kind(USB,0);
|
||||
|
||||
if(dir == TUSB_DIR_IN)
|
||||
{
|
||||
*PCD_EP_TX_ADDRESS_PTR(USB, epnum) = ep_buf_ptr;
|
||||
PCD_SET_EP_RX_CNT(USB, epnum, p_endpoint_desc->wMaxPacketSize.size);
|
||||
PCD_CLEAR_TX_DTOG(USB, epnum);
|
||||
PCD_SET_EP_TX_STATUS(USB,epnum,USB_EP_TX_NAK);
|
||||
*pcd_ep_tx_address_ptr(USB, epnum) = ep_buf_ptr;
|
||||
pcd_set_ep_tx_cnt(USB, epnum, p_endpoint_desc->wMaxPacketSize.size);
|
||||
pcd_clear_tx_dtog(USB, epnum);
|
||||
pcd_set_ep_tx_status(USB,epnum,USB_EP_TX_NAK);
|
||||
}
|
||||
else
|
||||
{
|
||||
*PCD_EP_RX_ADDRESS_PTR(USB, epnum) = ep_buf_ptr;
|
||||
PCD_SET_EP_RX_CNT(USB, epnum, p_endpoint_desc->wMaxPacketSize.size);
|
||||
PCD_CLEAR_RX_DTOG(USB, epnum);
|
||||
PCD_SET_EP_RX_STATUS(USB, epnum, USB_EP_RX_NAK);
|
||||
*pcd_ep_rx_address_ptr(USB, epnum) = ep_buf_ptr;
|
||||
pcd_set_ep_rx_cnt(USB, epnum, p_endpoint_desc->wMaxPacketSize.size);
|
||||
pcd_clear_rx_dtog(USB, epnum);
|
||||
pcd_set_ep_rx_status(USB, epnum, USB_EP_RX_NAK);
|
||||
}
|
||||
|
||||
xfer_ctl_ptr(epnum, dir)->max_packet_size = epMaxPktSize;
|
||||
ep_buf_ptr = (uint16_t)(ep_buf_ptr + p_endpoint_desc->wMaxPacketSize.size); // increment buffer pointer
|
||||
|
||||
return true;
|
||||
@ -613,15 +669,16 @@ static void dcd_transmit_packet(xfer_ctl_t * xfer, uint16_t ep_ix)
|
||||
{
|
||||
uint16_t len = (uint16_t)(xfer->total_len - xfer->queued_len);
|
||||
|
||||
if(len > 64u) // max packet size for FS transfer
|
||||
if(len > xfer->max_packet_size) // max packet size for FS transfer
|
||||
{
|
||||
len = 64u;
|
||||
len = xfer->max_packet_size;
|
||||
}
|
||||
dcd_write_packet_memory(*PCD_EP_TX_ADDRESS_PTR(USB,ep_ix), &(xfer->buffer[xfer->queued_len]), len);
|
||||
uint16_t oldAddr = *pcd_ep_tx_address_ptr(USB,ep_ix);
|
||||
dcd_write_packet_memory(oldAddr, &(xfer->buffer[xfer->queued_len]), len);
|
||||
xfer->queued_len = (uint16_t)(xfer->queued_len + len);
|
||||
|
||||
PCD_SET_EP_TX_CNT(USB,ep_ix,len);
|
||||
PCD_SET_EP_TX_STATUS(USB, ep_ix, USB_EP_TX_VALID);
|
||||
pcd_set_ep_tx_cnt(USB,ep_ix,len);
|
||||
pcd_set_ep_tx_status(USB, ep_ix, USB_EP_TX_VALID);
|
||||
}
|
||||
|
||||
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
|
||||
@ -631,7 +688,7 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum,dir);
|
||||
xfer_ctl_t * xfer = xfer_ctl_ptr(epnum,dir);
|
||||
|
||||
xfer->buffer = buffer;
|
||||
xfer->total_len = total_bytes;
|
||||
@ -644,15 +701,14 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
if (epnum == 0 && buffer == NULL)
|
||||
{
|
||||
xfer->buffer = (uint8_t*)_setup_packet;
|
||||
PCD_SET_EP_KIND(USB,0); // Expect a zero-byte INPUT
|
||||
}
|
||||
if(total_bytes > 64)
|
||||
if(total_bytes > xfer->max_packet_size)
|
||||
{
|
||||
PCD_SET_EP_RX_CNT(USB,epnum,64);
|
||||
pcd_set_ep_rx_cnt(USB,epnum,xfer->max_packet_size);
|
||||
} else {
|
||||
PCD_SET_EP_RX_CNT(USB,epnum,total_bytes);
|
||||
pcd_set_ep_rx_cnt(USB,epnum,total_bytes);
|
||||
}
|
||||
PCD_SET_EP_RX_STATUS(USB, epnum, USB_EP_RX_VALID);
|
||||
pcd_set_ep_rx_status(USB, epnum, USB_EP_RX_VALID);
|
||||
}
|
||||
else // IN
|
||||
{
|
||||
@ -665,41 +721,35 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void)rhport;
|
||||
|
||||
if (ep_addr == 0) { // CTRL EP0 (OUT for setup)
|
||||
PCD_SET_EP_TX_STATUS(USB,ep_addr, USB_EP_TX_STALL);
|
||||
if (ep_addr & 0x80)
|
||||
{ // IN
|
||||
pcd_set_ep_tx_status(USB, ep_addr & 0x7F, USB_EP_TX_STALL);
|
||||
}
|
||||
|
||||
if (ep_addr & 0x80) { // IN
|
||||
ep_addr &= 0x7F;
|
||||
PCD_SET_EP_TX_STATUS(USB,ep_addr, USB_EP_TX_STALL);
|
||||
} else { // OUT
|
||||
PCD_SET_EP_RX_STATUS(USB,ep_addr, USB_EP_RX_STALL);
|
||||
else
|
||||
{ // OUT
|
||||
pcd_set_ep_rx_status(USB, ep_addr, USB_EP_RX_STALL);
|
||||
}
|
||||
}
|
||||
|
||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void)rhport;
|
||||
if (ep_addr == 0)
|
||||
{
|
||||
PCD_SET_EP_TX_STATUS(USB,ep_addr, USB_EP_TX_NAK);
|
||||
}
|
||||
|
||||
if (ep_addr & 0x80)
|
||||
{ // IN
|
||||
ep_addr &= 0x7F;
|
||||
|
||||
PCD_SET_EP_TX_STATUS(USB,ep_addr, USB_EP_TX_NAK);
|
||||
pcd_set_ep_tx_status(USB,ep_addr, USB_EP_TX_NAK);
|
||||
|
||||
/* Reset to DATA0 if clearing stall condition. */
|
||||
PCD_CLEAR_TX_DTOG(USB,ep_addr);
|
||||
pcd_clear_tx_dtog(USB,ep_addr);
|
||||
}
|
||||
else
|
||||
{ // OUT
|
||||
/* Reset to DATA0 if clearing stall condition. */
|
||||
PCD_CLEAR_RX_DTOG(USB,ep_addr);
|
||||
pcd_clear_rx_dtog(USB,ep_addr);
|
||||
|
||||
PCD_SET_EP_RX_STATUS(USB,ep_addr, USB_EP_RX_VALID);
|
||||
pcd_set_ep_rx_status(USB,ep_addr, USB_EP_RX_NAK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -714,19 +764,13 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
* @param wNBytes no. of bytes to be copied.
|
||||
* @retval None
|
||||
*/
|
||||
static void dcd_write_packet_memory(uint16_t dst, const void *__restrict src, size_t wNBytes)
|
||||
static bool dcd_write_packet_memory(uint16_t dst, const void *__restrict src, size_t wNBytes)
|
||||
{
|
||||
uint32_t n = ((uint32_t)((uint32_t)wNBytes + 1U)) >> 1U;
|
||||
uint32_t n = ((uint32_t)wNBytes + 1U) >> 1U;
|
||||
uint32_t i;
|
||||
uint16_t temp1, temp2;
|
||||
const uint8_t * srcVal;
|
||||
|
||||
#ifdef DEBUG
|
||||
if(((dst%2) != 0) ||
|
||||
(dst < DCD_STM32_BTABLE_BASE) ||
|
||||
dst >= (DCD_STM32_BTABLE_BASE + DCD_STM32_BTABLE_LENGTH))
|
||||
while(1) TU_BREAKPOINT();
|
||||
#endif
|
||||
// The GCC optimizer will combine access to 32-bit sizes if we let it. Force
|
||||
// it volatile so that it won't do that.
|
||||
__IO uint16_t *pdwVal;
|
||||
@ -743,6 +787,7 @@ static void dcd_write_packet_memory(uint16_t dst, const void *__restrict src, si
|
||||
pdwVal += PMA_STRIDE;
|
||||
srcVal++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -751,7 +796,7 @@ static void dcd_write_packet_memory(uint16_t dst, const void *__restrict src, si
|
||||
* @param wNBytes no. of bytes to be copied.
|
||||
* @retval None
|
||||
*/
|
||||
static void dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wNBytes)
|
||||
static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wNBytes)
|
||||
{
|
||||
uint32_t n = (uint32_t)wNBytes >> 1U;
|
||||
uint32_t i;
|
||||
@ -760,13 +805,6 @@ static void dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wN
|
||||
__IO const uint16_t *pdwVal;
|
||||
uint32_t temp;
|
||||
|
||||
#ifdef DEBUG
|
||||
if((src%2) != 0 ||
|
||||
(src < DCD_STM32_BTABLE_BASE) ||
|
||||
src >= (DCD_STM32_BTABLE_BASE + DCD_STM32_BTABLE_LENGTH))
|
||||
while(1) TU_BREAKPOINT();
|
||||
#endif
|
||||
|
||||
pdwVal = &pma[PMA_STRIDE*(src>>1)];
|
||||
uint8_t *dstVal = (uint8_t*)dst;
|
||||
|
||||
@ -784,17 +822,18 @@ static void dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wN
|
||||
pdwVal += PMA_STRIDE;
|
||||
*dstVal++ = ((temp >> 0) & 0xFF);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Interrupt handlers
|
||||
#if (CFG_TUSB_MCU) == (OPT_MCU_STM32F0)
|
||||
#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0
|
||||
void USB_IRQHandler(void)
|
||||
{
|
||||
dcd_fs_irqHandler();
|
||||
}
|
||||
|
||||
#elif (CFG_TUSB_MCU) == (OPT_MCU_STM32F1)
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
|
||||
void USB_HP_IRQHandler(void)
|
||||
{
|
||||
dcd_fs_irqHandler();
|
||||
@ -826,14 +865,16 @@ void USB_LP_CAN_RX0_IRQHandler(void)
|
||||
{
|
||||
dcd_fs_irqHandler();
|
||||
}
|
||||
|
||||
// USB wakeup interrupt (Channel 42): Triggered by the wakeup event from the USB
|
||||
// Suspend mode.
|
||||
void USBWakeUp_IRQHandler(void)
|
||||
{
|
||||
dcd_fs_irqHandler();
|
||||
}
|
||||
|
||||
#else
|
||||
#error Which IRQ handler do you need?
|
||||
#error Which IRQ handler do you need?
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -41,51 +41,58 @@
|
||||
#ifndef PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_
|
||||
#define PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_
|
||||
|
||||
#if defined(STM32F042x6) | \
|
||||
defined(STM32F070x6) | defined(STM32F070xB) | \
|
||||
defined(STM32F072xB) | \
|
||||
#if defined(STM32F042x6) || \
|
||||
defined(STM32F070x6) || defined(STM32F070xB) || \
|
||||
defined(STM32F072xB) || \
|
||||
defined(STM32F078xx)
|
||||
#include "stm32f0xx.h"
|
||||
#define PMA_LENGTH 1024
|
||||
// F0x2 models are crystal-less
|
||||
// All have internal D+ pull-up
|
||||
// 070RB: 2 x 16 bits/word memory LPM Support, BCD Support
|
||||
// PMA dedicated to USB (no sharing with CAN)
|
||||
#elif defined(STM32F102x6) | defined(STM32F102x6) | \
|
||||
defined(STM32F103x6) | defined(STM32F103xB) | \
|
||||
defined(STM32F103xE) | defined(STM32F103xB)
|
||||
#include "stm32f1xx.h"
|
||||
#define PMA_LENGTH 512u
|
||||
// NO internal Pull-ups
|
||||
// *B, and *C: 2 x 16 bits/word
|
||||
#error The F102/F103 driver is expected not to work, but it might? Try it?
|
||||
#include "stm32f0xx.h"
|
||||
#define PMA_LENGTH (1024u)
|
||||
// F0x2 models are crystal-less
|
||||
// All have internal D+ pull-up
|
||||
// 070RB: 2 x 16 bits/word memory LPM Support, BCD Support
|
||||
// PMA dedicated to USB (no sharing with CAN)
|
||||
|
||||
#elif defined(STM32F302xB) | defined(STM32F302xC) | \
|
||||
defined(STM32F303xB) | defined(STM32F303xC) | \
|
||||
#elif defined(STM32F1_FSDEV)
|
||||
#include "stm32f1xx.h"
|
||||
#define PMA_LENGTH (512u)
|
||||
// NO internal Pull-ups
|
||||
// *B, and *C: 2 x 16 bits/word
|
||||
|
||||
// F1 names this differently from the rest
|
||||
#define USB_CNTR_LPMODE USB_CNTR_LP_MODE
|
||||
|
||||
#elif defined(STM32F302xB) || defined(STM32F302xC) || \
|
||||
defined(STM32F303xB) || defined(STM32F303xC) || \
|
||||
defined(STM32F373xC)
|
||||
#include "stm32f3xx.h"
|
||||
#define PMA_LENGTH 512u
|
||||
// NO internal Pull-ups
|
||||
// *B, and *C: 1 x 16 bits/word
|
||||
// PMA dedicated to USB (no sharing with CAN)
|
||||
#elif defined(STM32F302x6) | defined(STM32F302x8) | \
|
||||
defined(STM32F302xD) | defined(STM32F302xE) | \
|
||||
defined(STM32F303xD) | defined(STM32F303xE) | \
|
||||
#include "stm32f3xx.h"
|
||||
#define PMA_LENGTH 1024u
|
||||
// NO internal Pull-ups
|
||||
// *6, *8, *D, and *E: 2 x 16 bits/word LPM Support
|
||||
// When CAN clock is enabled, USB can use first 768 bytes ONLY.
|
||||
#include "stm32f3xx.h"
|
||||
#define PMA_LENGTH (512u)
|
||||
// NO internal Pull-ups
|
||||
// *B, and *C: 1 x 16 bits/word
|
||||
// PMA dedicated to USB (no sharing with CAN)
|
||||
|
||||
#elif defined(STM32F302x6) || defined(STM32F302x8) || \
|
||||
defined(STM32F302xD) || defined(STM32F302xE) || \
|
||||
defined(STM32F303xD) || defined(STM32F303xE)
|
||||
#include "stm32f3xx.h"
|
||||
#define PMA_LENGTH (1024u)
|
||||
// NO internal Pull-ups
|
||||
// *6, *8, *D, and *E: 2 x 16 bits/word LPM Support
|
||||
// When CAN clock is enabled, USB can use first 768 bytes ONLY.
|
||||
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32L0
|
||||
#include "stm32l0xx.h"
|
||||
#define PMA_LENGTH (1024u)
|
||||
|
||||
#else
|
||||
#error You are using an untested or unimplemented STM32 variant. Please update the driver.
|
||||
// This includes L0x2, L0x3, L1x0, L1x1, L1x2, L4x2 and L4x3, G1x1, G1x3, and G1x4
|
||||
#error You are using an untested or unimplemented STM32 variant. Please update the driver.
|
||||
// This includes L1x0, L1x1, L1x2, L4x2 and L4x3, G1x1, G1x3, and G1x4
|
||||
#endif
|
||||
|
||||
// For purposes of accessing the packet
|
||||
#if ((PMA_LENGTH) == 512u)
|
||||
# define PMA_STRIDE (2u)
|
||||
#define PMA_STRIDE (2u)
|
||||
#elif ((PMA_LENGTH) == 1024u)
|
||||
# define PMA_STRIDE (1u)
|
||||
#define PMA_STRIDE (1u)
|
||||
#endif
|
||||
|
||||
// And for type-safety create a new macro for the volatile address of PMAADDR
|
||||
@ -93,32 +100,75 @@
|
||||
// Volatile is also needed to prevent the optimizer from changing access to 32-bit (as 32-bit access is forbidden)
|
||||
static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
|
||||
/* SetENDPOINT */
|
||||
#define PCD_SET_ENDPOINT(USBx, bEpNum,wRegValue) (*((__IO uint16_t *)(((uint32_t)(&(USBx)->EP0R + (bEpNum) * 2U))))= (uint16_t)(wRegValue))
|
||||
/* GetENDPOINT */
|
||||
#define PCD_GET_ENDPOINT(USBx, bEpNum) (*((__IO uint16_t *)(((uint32_t)(&(USBx)->EP0R + (bEpNum) * 2U)))))
|
||||
#define PCD_SET_EPTYPE(USBx, bEpNum,wType) (PCD_SET_ENDPOINT((USBx), (bEpNum),\
|
||||
(((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & ((uint32_t)(USB_EP_T_MASK))) | ((uint32_t)(wType))) | USB_EP_CTR_RX | USB_EP_CTR_TX)))
|
||||
#define PCD_GET_EPTYPE(USBx, bEpNum) (((uint16_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EP_T_FIELD)
|
||||
// prototypes
|
||||
static inline __IO uint16_t* pcd_ep_rx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum);
|
||||
static inline __IO uint16_t* pcd_ep_tx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum);
|
||||
static inline void pcd_set_endpoint(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wRegValue);
|
||||
|
||||
|
||||
/* SetENDPOINT */
|
||||
static inline void pcd_set_endpoint(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wRegValue)
|
||||
{
|
||||
__O uint16_t *reg = (__O uint16_t *)((&USBx->EP0R) + bEpNum*2u);
|
||||
*reg = (uint16_t)wRegValue;
|
||||
}
|
||||
|
||||
/* GetENDPOINT */
|
||||
static inline uint16_t pcd_get_endpoint(USB_TypeDef * USBx, uint32_t bEpNum) {
|
||||
__I uint16_t *reg = (__I uint16_t *)((&USBx->EP0R) + bEpNum*2u);
|
||||
return *reg;
|
||||
}
|
||||
|
||||
static inline void pcd_set_eptype(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wType)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= (uint32_t)USB_EP_T_MASK;
|
||||
regVal |= wType;
|
||||
regVal |= USB_EP_CTR_RX | USB_EP_CTR_TX; // These clear on write0, so must set high
|
||||
pcd_set_endpoint(USBx, bEpNum, regVal);
|
||||
}
|
||||
|
||||
static inline uint32_t pcd_get_eptype(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= USB_EP_T_FIELD;
|
||||
return regVal;
|
||||
}
|
||||
/**
|
||||
* @brief Clears bit CTR_RX / CTR_TX in the endpoint register.
|
||||
* @param USBx USB peripheral instance register address.
|
||||
* @param bEpNum Endpoint Number.
|
||||
* @retval None
|
||||
*/
|
||||
#define PCD_CLEAR_RX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum),\
|
||||
PCD_GET_ENDPOINT((USBx), (bEpNum)) & 0x7FFFU & USB_EPREG_MASK))
|
||||
#define PCD_CLEAR_TX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum),\
|
||||
PCD_GET_ENDPOINT((USBx), (bEpNum)) & 0xFF7FU & USB_EPREG_MASK))
|
||||
static inline void pcd_clear_rx_ep_ctr(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= 0x7FFFu & USB_EPREG_MASK;
|
||||
pcd_set_endpoint(USBx, bEpNum, regVal);
|
||||
}
|
||||
static inline void pcd_clear_tx_ep_ctr(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= regVal & 0xFF7FU & USB_EPREG_MASK;
|
||||
pcd_set_endpoint(USBx, bEpNum,regVal);
|
||||
}
|
||||
/**
|
||||
* @brief gets counter of the tx buffer.
|
||||
* @param USBx USB peripheral instance register address.
|
||||
* @param bEpNum Endpoint Number.
|
||||
* @retval Counter value
|
||||
*/
|
||||
#define PCD_GET_EP_TX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_TX_CNT_PTR((USBx), (bEpNum))) & 0x3ffU)
|
||||
#define PCD_GET_EP_RX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_RX_CNT_PTR((USBx), (bEpNum))) & 0x3ffU)
|
||||
static inline uint32_t pcd_get_ep_tx_cnt(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
__I uint16_t *regPtr = pcd_ep_tx_cnt_ptr(USBx, bEpNum);
|
||||
return *regPtr & 0x3ffU;
|
||||
}
|
||||
|
||||
static inline uint32_t pcd_get_ep_rx_cnt(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
__I uint16_t *regPtr = pcd_ep_rx_cnt_ptr(USBx, bEpNum);
|
||||
return *regPtr & 0x3ffU;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets counter of rx buffer with no. of blocks.
|
||||
@ -127,38 +177,30 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
* @param wNBlocks no. of Blocks.
|
||||
* @retval None
|
||||
*/
|
||||
#define PCD_CALC_BLK32(dwReg,wCount,wNBlocks) {\
|
||||
(wNBlocks) = (uint32_t)((wCount) >> 5U);\
|
||||
if(((wCount) & 0x1fU) == 0U)\
|
||||
{ \
|
||||
(wNBlocks)--;\
|
||||
} \
|
||||
*pdwReg = (uint16_t)((uint16_t)((wNBlocks) << 10U) | (uint16_t)0x8000U); \
|
||||
}/* PCD_CALC_BLK32 */
|
||||
|
||||
|
||||
#define PCD_CALC_BLK2(dwReg,wCount,wNBlocks) {\
|
||||
(wNBlocks) = (uint32_t)((wCount) >> 1U); \
|
||||
if(((wCount) & 0x1U) != 0U)\
|
||||
{ \
|
||||
(wNBlocks)++;\
|
||||
} \
|
||||
*pdwReg = (uint16_t)((wNBlocks) << 10U);\
|
||||
}/* PCD_CALC_BLK2 */
|
||||
|
||||
|
||||
#define PCD_SET_EP_CNT_RX_REG(dwReg,wCount) {\
|
||||
uint32_t wNBlocks;\
|
||||
if((wCount) > 62U) \
|
||||
{ \
|
||||
PCD_CALC_BLK32((dwReg),(wCount),wNBlocks) \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PCD_CALC_BLK2((dwReg),(wCount),wNBlocks) \
|
||||
} \
|
||||
}/* PCD_SET_EP_CNT_RX_REG */
|
||||
|
||||
static inline void pcd_set_ep_cnt_rx_reg(__O uint16_t * pdwReg, size_t wCount) {
|
||||
uint32_t wNBlocks;
|
||||
if(wCount > 62u)
|
||||
{
|
||||
wNBlocks = wCount >> 5u;
|
||||
if((wCount & 0x1fU) == 0u)
|
||||
{
|
||||
wNBlocks--;
|
||||
}
|
||||
wNBlocks = wNBlocks << 10u;
|
||||
wNBlocks |= 0x8000u; // Mark block size as 32byte
|
||||
*pdwReg = (uint16_t)wNBlocks;
|
||||
}
|
||||
else
|
||||
{
|
||||
wNBlocks = wCount >> 1u;
|
||||
if((wCount & 0x1U) != 0u)
|
||||
{
|
||||
wNBlocks++;
|
||||
}
|
||||
*pdwReg = (uint16_t)((wNBlocks) << 10u);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -168,23 +210,52 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
* @param bAddr Address.
|
||||
* @retval None
|
||||
*/
|
||||
#define PCD_SET_EP_ADDRESS(USBx, bEpNum,bAddr) PCD_SET_ENDPOINT((USBx), (bEpNum),\
|
||||
USB_EP_CTR_RX|USB_EP_CTR_TX|(((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPREG_MASK) | (bAddr))
|
||||
static inline void pcd_set_ep_address(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t bAddr)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= USB_EPREG_MASK;
|
||||
regVal |= bAddr;
|
||||
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
|
||||
pcd_set_endpoint(USBx, bEpNum,regVal);
|
||||
}
|
||||
|
||||
#define PCD_BTABLE_WORD_PTR(USBx,x) (&(pma[PMA_STRIDE*((((USBx)->BTABLE)>>1) + x)]))
|
||||
static inline __IO uint16_t * pcd_btable_word_ptr(USB_TypeDef * USBx, size_t x)
|
||||
{
|
||||
size_t total_word_offset = (((USBx)->BTABLE)>>1) + x;
|
||||
total_word_offset *= PMA_STRIDE;
|
||||
return &(pma[total_word_offset]);
|
||||
}
|
||||
|
||||
// Pointers to the PMA table entries (using the ARM address space)
|
||||
#define PCD_EP_TX_ADDRESS_PTR(USBx, bEpNum) (PCD_BTABLE_WORD_PTR(USBx,(bEpNum)*4u + 0u))
|
||||
#define PCD_EP_TX_CNT_PTR(USBx, bEpNum) (PCD_BTABLE_WORD_PTR(USBx,(bEpNum)*4u + 1u))
|
||||
static inline __IO uint16_t* pcd_ep_tx_address_ptr(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
return pcd_btable_word_ptr(USBx,(bEpNum)*4u + 0u);
|
||||
}
|
||||
static inline __IO uint16_t* pcd_ep_tx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
return pcd_btable_word_ptr(USBx,(bEpNum)*4u + 1u);
|
||||
}
|
||||
|
||||
#define PCD_EP_RX_ADDRESS_PTR(USBx, bEpNum) (PCD_BTABLE_WORD_PTR(USBx,(bEpNum)*4u + 2u))
|
||||
#define PCD_EP_RX_CNT_PTR(USBx, bEpNum) (PCD_BTABLE_WORD_PTR(USBx,(bEpNum)*4u + 3u))
|
||||
static inline __IO uint16_t* pcd_ep_rx_address_ptr(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
return pcd_btable_word_ptr(USBx,(bEpNum)*4u + 2u);
|
||||
}
|
||||
|
||||
#define PCD_SET_EP_TX_CNT(USBx, bEpNum,wCount) (*PCD_EP_TX_CNT_PTR((USBx), (bEpNum)) = (wCount))
|
||||
#define PCD_SET_EP_RX_CNT(USBx, bEpNum,wCount) do {\
|
||||
__IO uint16_t *pdwReg =PCD_EP_RX_CNT_PTR((USBx),(bEpNum)); \
|
||||
PCD_SET_EP_CNT_RX_REG((pdwReg), (wCount))\
|
||||
} while(0)
|
||||
static inline __IO uint16_t* pcd_ep_rx_cnt_ptr(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
return pcd_btable_word_ptr(USBx,(bEpNum)*4u + 3u);
|
||||
}
|
||||
|
||||
static inline void pcd_set_ep_tx_cnt(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wCount)
|
||||
{
|
||||
*pcd_ep_tx_cnt_ptr(USBx, bEpNum) = (uint16_t)wCount;
|
||||
}
|
||||
|
||||
static inline void pcd_set_ep_rx_cnt(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wCount)
|
||||
{
|
||||
__IO uint16_t *pdwReg = pcd_ep_rx_cnt_ptr((USBx),(bEpNum));
|
||||
pcd_set_ep_cnt_rx_reg(pdwReg, wCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sets the status for tx transfer (bits STAT_TX[1:0]).
|
||||
@ -193,21 +264,24 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
* @param wState new state
|
||||
* @retval None
|
||||
*/
|
||||
#define PCD_SET_EP_TX_STATUS(USBx, bEpNum, wState) { register uint16_t _wRegVal;\
|
||||
\
|
||||
_wRegVal = (uint32_t) (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPTX_DTOGMASK);\
|
||||
/* toggle first bit ? */ \
|
||||
if((USB_EPTX_DTOG1 & (wState))!= 0U)\
|
||||
{ \
|
||||
_wRegVal ^=(uint16_t) USB_EPTX_DTOG1; \
|
||||
} \
|
||||
/* toggle second bit ? */ \
|
||||
if((USB_EPTX_DTOG2 & ((uint32_t)(wState)))!= 0U) \
|
||||
{ \
|
||||
_wRegVal ^=(uint16_t) USB_EPTX_DTOG2; \
|
||||
} \
|
||||
PCD_SET_ENDPOINT((USBx), (bEpNum), (((uint32_t)(_wRegVal)) | USB_EP_CTR_RX|USB_EP_CTR_TX));\
|
||||
} /* PCD_SET_EP_TX_STATUS */
|
||||
static inline void pcd_set_ep_tx_status(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wState)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= USB_EPTX_DTOGMASK;
|
||||
|
||||
/* toggle first bit ? */
|
||||
if((USB_EPTX_DTOG1 & (wState))!= 0U)
|
||||
{
|
||||
regVal ^= USB_EPTX_DTOG1;
|
||||
}
|
||||
/* toggle second bit ? */
|
||||
if((USB_EPTX_DTOG2 & ((uint32_t)(wState)))!= 0U)
|
||||
{
|
||||
regVal ^= USB_EPTX_DTOG2;
|
||||
}
|
||||
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
|
||||
pcd_set_endpoint(USBx, bEpNum, regVal);
|
||||
} /* pcd_set_ep_tx_status */
|
||||
|
||||
/**
|
||||
* @brief sets the status for rx transfer (bits STAT_TX[1:0])
|
||||
@ -216,22 +290,25 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
* @param wState new state
|
||||
* @retval None
|
||||
*/
|
||||
#define PCD_SET_EP_RX_STATUS(USBx, bEpNum,wState) {\
|
||||
register uint16_t _wRegVal; \
|
||||
\
|
||||
_wRegVal = (uint32_t) (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPRX_DTOGMASK);\
|
||||
/* toggle first bit ? */ \
|
||||
if((USB_EPRX_DTOG1 & (wState))!= 0U) \
|
||||
{ \
|
||||
_wRegVal ^= (uint16_t) USB_EPRX_DTOG1; \
|
||||
} \
|
||||
/* toggle second bit ? */ \
|
||||
if((USB_EPRX_DTOG2 & ((uint32_t)(wState)))!= 0U) \
|
||||
{ \
|
||||
_wRegVal ^= (uint16_t) USB_EPRX_DTOG2; \
|
||||
} \
|
||||
PCD_SET_ENDPOINT((USBx), (bEpNum), (((uint32_t)(_wRegVal)) | USB_EP_CTR_RX|USB_EP_CTR_TX)); \
|
||||
} /* PCD_SET_EP_RX_STATUS */
|
||||
|
||||
static inline void pcd_set_ep_rx_status(USB_TypeDef * USBx, uint32_t bEpNum, uint32_t wState)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= USB_EPRX_DTOGMASK;
|
||||
|
||||
/* toggle first bit ? */
|
||||
if((USB_EPRX_DTOG1 & wState)!= 0U)
|
||||
{
|
||||
regVal ^= USB_EPRX_DTOG1;
|
||||
}
|
||||
/* toggle second bit ? */
|
||||
if((USB_EPRX_DTOG2 & wState)!= 0U)
|
||||
{
|
||||
regVal ^= USB_EPRX_DTOG2;
|
||||
}
|
||||
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
|
||||
pcd_set_endpoint(USBx, bEpNum, regVal);
|
||||
} /* pcd_set_ep_rx_status */
|
||||
|
||||
/**
|
||||
* @brief Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
|
||||
@ -239,10 +316,21 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
* @param bEpNum Endpoint Number.
|
||||
* @retval None
|
||||
*/
|
||||
#define PCD_RX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \
|
||||
USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_RX | (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPREG_MASK)))
|
||||
#define PCD_TX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \
|
||||
USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_TX | (((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPREG_MASK)))
|
||||
static inline void pcd_rx_dtog(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= USB_EPREG_MASK;
|
||||
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_RX;
|
||||
pcd_set_endpoint(USBx, bEpNum, regVal);
|
||||
}
|
||||
|
||||
static inline void pcd_tx_dtog(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= USB_EPREG_MASK;
|
||||
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_TX;
|
||||
pcd_set_endpoint(USBx, bEpNum, regVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears DTOG_RX / DTOG_TX bit in the endpoint register.
|
||||
@ -250,14 +338,24 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
* @param bEpNum Endpoint Number.
|
||||
* @retval None
|
||||
*/
|
||||
#define PCD_CLEAR_RX_DTOG(USBx, bEpNum) if((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EP_DTOG_RX) != 0)\
|
||||
{ \
|
||||
PCD_RX_DTOG((USBx),(bEpNum));\
|
||||
}
|
||||
#define PCD_CLEAR_TX_DTOG(USBx, bEpNum) if((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EP_DTOG_TX) != 0)\
|
||||
{\
|
||||
PCD_TX_DTOG((USBx),(bEpNum));\
|
||||
}
|
||||
|
||||
static inline void pcd_clear_rx_dtog(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
if((regVal & USB_EP_DTOG_RX) != 0)
|
||||
{
|
||||
pcd_rx_dtog(USBx,bEpNum);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void pcd_clear_tx_dtog(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
if((regVal & USB_EP_DTOG_TX) != 0)
|
||||
{
|
||||
pcd_tx_dtog(USBx,bEpNum);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set & clear EP_KIND bit.
|
||||
@ -265,14 +363,22 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
* @param bEpNum Endpoint Number.
|
||||
* @retval None
|
||||
*/
|
||||
#define PCD_SET_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \
|
||||
(USB_EP_CTR_RX|USB_EP_CTR_TX|((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) | USB_EP_KIND) & USB_EPREG_MASK))))
|
||||
|
||||
#define PCD_CLEAR_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT((USBx), (bEpNum), \
|
||||
(USB_EP_CTR_RX|USB_EP_CTR_TX|((((uint32_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)))) & USB_EPKIND_MASK)))))
|
||||
|
||||
|
||||
#define EPREG(n) (((__IO uint16_t*)USB_BASE)[n*2])
|
||||
static inline void pcd_set_ep_kind(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal |= USB_EP_KIND;
|
||||
regVal &= USB_EPREG_MASK;
|
||||
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
|
||||
pcd_set_endpoint(USBx, bEpNum, regVal);
|
||||
}
|
||||
static inline void pcd_clear_ep_kind(USB_TypeDef * USBx, uint32_t bEpNum)
|
||||
{
|
||||
uint32_t regVal = pcd_get_endpoint(USBx, bEpNum);
|
||||
regVal &= USB_EPKIND_MASK;
|
||||
regVal |= USB_EP_CTR_RX|USB_EP_CTR_TX;
|
||||
pcd_set_endpoint(USBx, bEpNum, regVal);
|
||||
}
|
||||
|
||||
// This checks if the device has "LPM"
|
||||
#if defined(USB_ISTR_L1REQ)
|
||||
@ -284,5 +390,7 @@ static __IO uint16_t * const pma = (__IO uint16_t*)USB_PMAADDR;
|
||||
#define USB_ISTR_ALL_EVENTS (USB_ISTR_PMAOVR | USB_ISTR_ERR | USB_ISTR_WKUP | USB_ISTR_SUSP | \
|
||||
USB_ISTR_RESET | USB_ISTR_SOF | USB_ISTR_ESOF | USB_ISTR_L1REQ_FORCED )
|
||||
|
||||
// Number of endpoints in hardware
|
||||
#define STFSDEV_EP_COUNT (8u)
|
||||
|
||||
#endif /* PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_ */
|
||||
|
@ -27,29 +27,47 @@
|
||||
|
||||
#include "tusb_option.h"
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_STM32F4 || \
|
||||
CFG_TUSB_MCU == OPT_MCU_STM32H7 || \
|
||||
CFG_TUSB_MCU == OPT_MCU_STM32F7)
|
||||
#if defined (STM32L475xx) || defined (STM32L476xx) || \
|
||||
defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || \
|
||||
defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || \
|
||||
defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
|
||||
#define STM32L4_SYNOPSYS
|
||||
#endif
|
||||
|
||||
#if TUSB_OPT_DEVICE_ENABLED && \
|
||||
( CFG_TUSB_MCU == OPT_MCU_STM32F2 || \
|
||||
CFG_TUSB_MCU == OPT_MCU_STM32F4 || \
|
||||
CFG_TUSB_MCU == OPT_MCU_STM32F7 || \
|
||||
CFG_TUSB_MCU == OPT_MCU_STM32H7 || \
|
||||
(CFG_TUSB_MCU == OPT_MCU_STM32L4 && defined(STM32L4_SYNOPSYS)) \
|
||||
)
|
||||
|
||||
// TODO Support OTG_HS
|
||||
// EP_MAX : Max number of bi-directional endpoints including EP0
|
||||
// EP_FIFO_SIZE : Size of dedicated USB SRAM
|
||||
#if CFG_TUSB_MCU == OPT_MCU_STM32F4
|
||||
#if CFG_TUSB_MCU == OPT_MCU_STM32F2
|
||||
#include "stm32f2xx.h"
|
||||
#define EP_MAX USB_OTG_FS_MAX_IN_ENDPOINTS
|
||||
#define EP_FIFO_SIZE USB_OTG_FS_TOTAL_FIFO_SIZE
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32F4
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
#define EP_MAX USB_OTG_FS_MAX_IN_ENDPOINTS
|
||||
#define EP_FIFO_SIZE USB_OTG_FS_TOTAL_FIFO_SIZE
|
||||
#define EP_MAX USB_OTG_FS_MAX_IN_ENDPOINTS
|
||||
#define EP_FIFO_SIZE USB_OTG_FS_TOTAL_FIFO_SIZE
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32H7
|
||||
#include "stm32h7xx.h"
|
||||
|
||||
#define EP_MAX 9
|
||||
#define EP_FIFO_SIZE 4096
|
||||
#define EP_MAX 9
|
||||
#define EP_FIFO_SIZE 4096
|
||||
// TODO The official name of the USB FS peripheral on H7 is "USB2_OTG_FS".
|
||||
#else
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32F7
|
||||
#include "stm32f7xx.h"
|
||||
|
||||
#define EP_MAX 6
|
||||
#define EP_FIFO_SIZE 1280
|
||||
#define EP_MAX 6
|
||||
#define EP_FIFO_SIZE 1280
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_STM32L4
|
||||
#include "stm32l4xx.h"
|
||||
#define EP_MAX 6
|
||||
#define EP_FIFO_SIZE 1280
|
||||
#else
|
||||
#error "Unsupported MCUs"
|
||||
#endif
|
||||
|
||||
#include "device/dcd.h"
|
||||
@ -57,10 +75,10 @@
|
||||
/*------------------------------------------------------------------*/
|
||||
/* MACRO TYPEDEF CONSTANT ENUM
|
||||
*------------------------------------------------------------------*/
|
||||
#define DEVICE_BASE (USB_OTG_DeviceTypeDef *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_DEVICE_BASE)
|
||||
#define OUT_EP_BASE (USB_OTG_OUTEndpointTypeDef *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_OUT_ENDPOINT_BASE)
|
||||
#define IN_EP_BASE (USB_OTG_INEndpointTypeDef *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_IN_ENDPOINT_BASE)
|
||||
#define FIFO_BASE(_x) (volatile uint32_t *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_FIFO_BASE + (_x) * USB_OTG_FIFO_SIZE)
|
||||
#define DEVICE_BASE (USB_OTG_DeviceTypeDef *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_DEVICE_BASE)
|
||||
#define OUT_EP_BASE (USB_OTG_OUTEndpointTypeDef *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_OUT_ENDPOINT_BASE)
|
||||
#define IN_EP_BASE (USB_OTG_INEndpointTypeDef *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_IN_ENDPOINT_BASE)
|
||||
#define FIFO_BASE(_x) ((volatile uint32_t *) (USB_OTG_FS_PERIPH_BASE + USB_OTG_FIFO_BASE + (_x) * USB_OTG_FIFO_SIZE))
|
||||
|
||||
static TU_ATTR_ALIGNED(4) uint32_t _setup_packet[6];
|
||||
static uint8_t _setup_offs; // We store up to 3 setup packets.
|
||||
@ -251,20 +269,21 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
||||
uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress);
|
||||
uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);
|
||||
|
||||
// Unsupported endpoint numbers/size.
|
||||
if((desc_edpt->wMaxPacketSize.size > 64) || (epnum > EP_MAX)) {
|
||||
return false;
|
||||
}
|
||||
TU_ASSERT(desc_edpt->wMaxPacketSize.size <= 64);
|
||||
TU_ASSERT(epnum < EP_MAX);
|
||||
|
||||
xfer_ctl_t * xfer = XFER_CTL_BASE(epnum, dir);
|
||||
xfer->max_size = desc_edpt->wMaxPacketSize.size;
|
||||
|
||||
if(dir == TUSB_DIR_OUT) {
|
||||
if(dir == TUSB_DIR_OUT)
|
||||
{
|
||||
out_ep[epnum].DOEPCTL |= (1 << USB_OTG_DOEPCTL_USBAEP_Pos) | \
|
||||
desc_edpt->bmAttributes.xfer << USB_OTG_DOEPCTL_EPTYP_Pos | \
|
||||
desc_edpt->wMaxPacketSize.size << USB_OTG_DOEPCTL_MPSIZ_Pos;
|
||||
dev->DAINTMSK |= (1 << (USB_OTG_DAINTMSK_OEPM_Pos + epnum));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// "USB Data FIFOs" section in reference manual
|
||||
// Peripheral FIFO architecture
|
||||
//
|
||||
@ -286,18 +305,22 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
||||
// Since OUT FIFO = GRXFSIZ, FIFO 0 = 16, for simplicity, we equally allocated for the rest of endpoints
|
||||
// - Size : (FIFO_SIZE/4 - GRXFSIZ - 16) / (EP_MAX-1)
|
||||
// - Offset: GRXFSIZ + 16 + Size*(epnum-1)
|
||||
// - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
|
||||
|
||||
in_ep[epnum].DIEPCTL |= (1 << USB_OTG_DIEPCTL_USBAEP_Pos) | \
|
||||
(epnum - 1) << USB_OTG_DIEPCTL_TXFNUM_Pos | \
|
||||
epnum << USB_OTG_DIEPCTL_TXFNUM_Pos | \
|
||||
desc_edpt->bmAttributes.xfer << USB_OTG_DIEPCTL_EPTYP_Pos | \
|
||||
(desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? USB_OTG_DOEPCTL_SD0PID_SEVNFRM : 0) | \
|
||||
desc_edpt->wMaxPacketSize.size << USB_OTG_DIEPCTL_MPSIZ_Pos;
|
||||
dev->DAINTMSK |= (1 << (USB_OTG_DAINTMSK_IEPM_Pos + epnum));
|
||||
|
||||
// Both TXFD and TXSA are in unit of 32-bit words
|
||||
// Both TXFD and TXSA are in unit of 32-bit words.
|
||||
// IN FIFO 0 was configured during enumeration, hence the "+ 16".
|
||||
uint16_t const allocated_size = (USB_OTG_FS->GRXFSIZ & 0x0000ffff) + 16;
|
||||
uint16_t const fifo_size = (EP_FIFO_SIZE/4 - allocated_size) / (EP_MAX-1);
|
||||
uint32_t const fifo_offset = allocated_size + fifo_size*(epnum-1);
|
||||
|
||||
// DIEPTXF starts at FIFO #1.
|
||||
USB_OTG_FS->DIEPTXF[epnum - 1] = (fifo_size << USB_OTG_DIEPTXF_INEPTXFD_Pos) | fifo_offset;
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,10 @@
|
||||
#if CFG_TUD_VENDOR
|
||||
#include "class/vendor/vendor_device.h"
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_USBTMC
|
||||
#include "class/usbtmc/usbtmc_device.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -35,6 +35,8 @@
|
||||
/** \defgroup group_mcu Supported MCU
|
||||
* \ref CFG_TUSB_MCU must be defined to one of these
|
||||
* @{ */
|
||||
|
||||
// LPC
|
||||
#define OPT_MCU_LPC11UXX 1 ///< NXP LPC11Uxx
|
||||
#define OPT_MCU_LPC13XX 3 ///< NXP LPC13xx
|
||||
#define OPT_MCU_LPC175X_6X 4 ///< NXP LPC175x, LPC176x
|
||||
@ -46,12 +48,14 @@
|
||||
#define OPT_MCU_LPC54XXX 10 ///< NXP LPC54xxx
|
||||
#define OPT_MCU_LPC55XX 11 ///< NXP LPC55xx
|
||||
|
||||
// NRF
|
||||
#define OPT_MCU_NRF5X 100 ///< Nordic nRF5x series
|
||||
|
||||
// SAM
|
||||
#define OPT_MCU_SAMD21 200 ///< MicroChip SAMD21
|
||||
#define OPT_MCU_SAMD51 201 ///< MicroChip SAMD51
|
||||
|
||||
// ST Synopsis OTG devices
|
||||
// STM32
|
||||
#define OPT_MCU_STM32F0 300 ///< ST STM32F0
|
||||
#define OPT_MCU_STM32F1 301 ///< ST STM32F1
|
||||
#define OPT_MCU_STM32F2 302 ///< ST STM32F2
|
||||
@ -59,6 +63,9 @@
|
||||
#define OPT_MCU_STM32F4 304 ///< ST STM32F4
|
||||
#define OPT_MCU_STM32F7 305 ///< ST STM32F7
|
||||
#define OPT_MCU_STM32H7 306 ///< ST STM32H7
|
||||
#define OPT_MCU_STM32L0 307 ///< ST STM32L0
|
||||
#define OPT_MCU_STM32L1 308 ///< ST STM32L1
|
||||
#define OPT_MCU_STM32L4 309 ///< ST STM32L4
|
||||
|
||||
#define OPT_MCU_MSP430x5xx 400 ///< TI MSP430x5xx
|
||||
|
||||
@ -177,6 +184,10 @@
|
||||
#define CFG_TUD_VENDOR 0
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_USBTMC
|
||||
#define CFG_TUD_USBTMC 0
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// HOST OPTIONS
|
||||
|
@ -46,13 +46,13 @@ for example in all_examples:
|
||||
build_result = build_example(example, board)
|
||||
build_duration = time.monotonic() - start_time
|
||||
|
||||
if build_result.returncode != 0:
|
||||
if build_result.returncode == 0:
|
||||
success = "\033[32msucceeded\033[0m"
|
||||
success_count += 1
|
||||
else:
|
||||
exit_status = build_result.returncode
|
||||
success = "\033[31mfailed\033[0m "
|
||||
fail_count += 1
|
||||
else:
|
||||
success = "\033[32msucceeded\033[0m"
|
||||
success_count += 1
|
||||
|
||||
if travis:
|
||||
print('travis_fold:start:build-{}-{}\\r'.format(example, board))
|
||||
|
Loading…
x
Reference in New Issue
Block a user