Merge branch 'master' into develop

This commit is contained in:
hathach 2020-03-28 15:31:39 +07:00
commit 69698ed2e0
21 changed files with 127 additions and 98 deletions

View File

@ -1,6 +1,6 @@
name: Build
on: [pull_request, push]
on: [pull_request, push, repository_dispatch]
jobs:
unit-test:

View File

@ -53,7 +53,8 @@ static struct pbuf *received_frame;
/* this is used by this code, ./class/net/net_driver.c, and usb_descriptors.c */
/* ideally speaking, this should be generated from the hardware's unique ID (if available) */
const uint8_t tud_network_mac_address[6] = {0x20,0x89,0x84,0x6A,0x96,0x00};
/* it is suggested that the first two bytes are 0x02,0x02 to indicate a link-local address */
const uint8_t tud_network_mac_address[6] = {0x02,0x02,0x84,0x6A,0x96,0x00};
/* network parameters of this MCU */
static const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(192, 168, 7, 1);
@ -124,8 +125,11 @@ static void init_lwip(void)
struct netif *netif = &netif_data;
lwip_init();
/* the lwip virtual MAC address must be different from the host's; to ensure this, we toggle the LSbit */
netif->hwaddr_len = sizeof(tud_network_mac_address);
memcpy(netif->hwaddr, tud_network_mac_address, sizeof(tud_network_mac_address));
netif->hwaddr[5] ^= 0x01;
netif = netif_add(netif, &ipaddr, &netmask, &gateway, NULL, netif_init_cb, ip_input);
netif_set_default(netif);

View File

@ -112,7 +112,7 @@ uint8_t const desc_configuration[] =
#if CFG_TUD_NET == OPT_NET_ECM
// Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size.
TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, 0x81, 8, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU),
TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, 0x81, 64, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU),
#elif CFG_TUD_NET == OPT_NET_RNDIS
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_RNDIS_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, 0x81, 8, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE),

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32f0xx.h"
#include "stm32f0xx_hal_conf.h"
#include "stm32f0xx_hal.h"
#define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_5
@ -57,10 +56,7 @@ static void all_rcc_clk_enable(void)
void board_init(void)
{
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#endif
/* Configure the system clock to 48 MHz */
RCC_ClkInitTypeDef RCC_ClkInitStruct;
@ -90,10 +86,13 @@ void board_init(void)
(void)HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) ;
// Notify runtime of frequency change.
SystemCoreClockUpdate();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#endif
// LED
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = LED_PIN;

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32f0xx.h"
#include "stm32f0xx_hal_conf.h"
#include "stm32f0xx_hal.h"
#define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_6
@ -95,16 +94,14 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#endif
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();
// LED
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = LED_PIN;

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32f1xx.h"
#include "stm32f1xx_hal_conf.h"
#include "stm32f1xx_hal.h"
#define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_13
@ -85,16 +84,14 @@ void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
#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;

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32f2xx.h"
#include "stm32f2xx_hal_conf.h"
#include "stm32f2xx_hal.h"
#define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_14
@ -93,13 +92,13 @@ void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#endif
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32f3xx.h"
#include "stm32f3xx_hal_conf.h"
#include "stm32f3xx_hal.h"
#define LED_PORT GPIOE
#define LED_PIN GPIO_PIN_9
@ -89,16 +88,13 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
#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_GPIOE_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;

View File

@ -100,6 +100,9 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
@ -107,11 +110,7 @@ void board_init(void)
// 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();
SystemCoreClockUpdate();
all_rcc_clk_enable();
GPIO_InitTypeDef GPIO_InitStruct;
// LED

View File

@ -19,6 +19,7 @@ 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_uart.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_rcc.c \
$(ST_HAL_DRIVER)/Src/stm32f4xx_hal_gpio.c

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32f4xx.h"
#include "stm32f4xx_hal_conf.h"
#include "stm32f4xx_hal.h"
#define LED_PORT GPIOD
#define LED_PIN GPIO_PIN_14
@ -38,11 +37,22 @@
#define BUTTON_STATE_ACTIVE 1
// Enable PA2 as the debug log UART
// It is not routed to the ST/Link on the Discovery board.
#define UARTx USART2
#define UART_GPIO_PORT GPIOA
#define UART_GPIO_AF GPIO_AF7_USART2
#define UART_TX_PIN GPIO_PIN_2
#define UART_RX_PIN GPIO_PIN_3
UART_HandleTypeDef UartHandle;
// enable all LED, Button, Uart, USB clock
static void all_rcc_clk_enable(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE(); // USB D+, D-, Button
__HAL_RCC_GPIOD_CLK_ENABLE(); // LED
__HAL_RCC_USART2_CLK_ENABLE(); // Uart module
}
/**
@ -101,6 +111,9 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
@ -109,10 +122,6 @@ void board_init(void)
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();
GPIO_InitTypeDef GPIO_InitStruct;
// LED
@ -155,6 +164,25 @@ void board_init(void)
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = UART_TX_PIN | UART_RX_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = UART_GPIO_AF;
HAL_GPIO_Init(UART_GPIO_PORT, &GPIO_InitStruct);
UartHandle = (UART_HandleTypeDef){
.Instance = UARTx,
.Init.BaudRate = CFG_BOARD_UART_BAUDRATE,
.Init.WordLength = UART_WORDLENGTH_8B,
.Init.StopBits = UART_STOPBITS_1,
.Init.Parity = UART_PARITY_NONE,
.Init.HwFlowCtl = UART_HWCONTROL_NONE,
.Init.Mode = UART_MODE_TX_RX,
.Init.OverSampling = UART_OVERSAMPLING_16
};
HAL_UART_Init(&UartHandle);
// Enable USB OTG clock
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
@ -185,8 +213,8 @@ int board_uart_read(uint8_t* buf, int len)
int board_uart_write(void const * buf, int len)
{
(void) buf; (void) len;
return 0;
HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff);
return len;
}
#if CFG_TUSB_OS == OPT_OS_NONE

View File

@ -79,7 +79,7 @@
/* #define HAL_SD_MODULE_ENABLED */
// #define HAL_SPI_MODULE_ENABLED
/* #define HAL_TIM_MODULE_ENABLED */
/* #define HAL_UART_MODULE_ENABLED */
#define HAL_UART_MODULE_ENABLED
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32f4xx.h"
#include "stm32f4xx_hal_conf.h"
#include "stm32f4xx_hal.h"
#define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_13
@ -100,6 +99,9 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
@ -108,10 +110,6 @@ void board_init(void)
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();
GPIO_InitTypeDef GPIO_InitStruct;
// LED

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32f4xx.h"
#include "stm32f4xx_hal_conf.h"
#include "stm32f4xx_hal.h"
#define LED_PORT GPIOD
#define LED_PIN GPIO_PIN_13
@ -100,6 +99,9 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
@ -108,10 +110,6 @@ void board_init(void)
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();
GPIO_InitTypeDef GPIO_InitStruct;
// LED

View File

@ -122,7 +122,6 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE

View File

@ -27,8 +27,7 @@
#include "../board.h"
#include "stm32f7xx.h"
#include "stm32f7xx_hal_conf.h"
#include "stm32f7xx_hal.h"
#define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_14
@ -121,16 +120,16 @@ void SystemClock_Config(void)
void board_init(void)
{
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#endif
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#endif
GPIO_InitTypeDef GPIO_InitStruct;
// LED

View File

@ -27,8 +27,7 @@
#include "../board.h"
#include "stm32h7xx.h"
#include "stm32h7xx_hal_conf.h"
#include "stm32h7xx_hal.h"
#define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_0
@ -98,6 +97,7 @@ static void SystemClock_Config(void)
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 7;
RCC_OscInitStruct.PLL.PLLR = 2; /* Unused */
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_0;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
@ -134,15 +134,14 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
#endif
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();
GPIO_InitTypeDef GPIO_InitStruct;
// LED

View File

@ -26,8 +26,7 @@
#include "../board.h"
#include "stm32l0xx.h"
#include "stm32l0xx_hal_conf.h"
#include "stm32l0xx_hal.h"
#define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_5
@ -101,6 +100,8 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
@ -109,11 +110,6 @@ void board_init(void)
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif
SystemClock_Config();
// Notify runtime of frequency change.
SystemCoreClockUpdate();
GPIO_InitTypeDef GPIO_InitStruct;
// LED

View File

@ -26,8 +26,6 @@
#include "../board.h"
#include "stm32l4xx.h"
#include "stm32l4xx_hal_conf.h"
#include "stm32l4xx_hal.h"
#define LED_PORT GPIOB
@ -118,6 +116,9 @@ static void SystemClock_Config(void)
void board_init(void)
{
SystemClock_Config();
all_rcc_clk_enable();
#if CFG_TUSB_OS == OPT_OS_NONE
// 1ms tick timer
SysTick_Config(SystemCoreClock / 1000);
@ -126,10 +127,6 @@ void board_init(void)
//NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif
SystemClock_Config();
SystemCoreClockUpdate();
all_rcc_clk_enable();
/* Enable Power Clock*/
__HAL_RCC_PWR_CLK_ENABLE();

View File

@ -63,7 +63,15 @@ typedef struct
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t received[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t transmitted[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
#if CFG_TUD_NET == OPT_NET_RNDIS
#if CFG_TUD_NET == OPT_NET_ECM
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static tusb_control_request_t notify =
{
.bmRequestType = 0x21,
.bRequest = 0 /* NETWORK_CONNECTION */,
.wValue = 1 /* Connected */,
.wLength = 0,
};
#elif CFG_TUD_NET == OPT_NET_RNDIS
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t rndis_buf[120];
#endif
@ -197,7 +205,15 @@ bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request
TU_VERIFY (_netd_itf.itf_num == request->wIndex);
#if CFG_TUD_NET == OPT_NET_RNDIS
#if CFG_TUD_NET == OPT_NET_ECM
/* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest)
{
tud_control_xfer(rhport, request, NULL, 0);
notify.wIndex = request->wIndex;
usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_notif, (uint8_t *)&notify, sizeof(notify));
}
#elif CFG_TUD_NET == OPT_NET_RNDIS
if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
{
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)rndis_buf;

View File

@ -101,22 +101,29 @@ static bool _data_stage_xact(uint8_t rhport)
return dcd_edpt_xfer(rhport, ep_addr, xact_len ? _usbd_ctrl_buf : NULL, xact_len);
}
// Transmit data to/from the control endpoint.
//
// If the request's wLength is zero, a status packet is sent instead.
bool tud_control_xfer(uint8_t rhport, tusb_control_request_t const * request, void* buffer, uint16_t len)
{
_ctrl_xfer.request = (*request);
_ctrl_xfer.buffer = (uint8_t*) buffer;
_ctrl_xfer.total_xferred = 0;
_ctrl_xfer.total_xferred = 0U;
_ctrl_xfer.data_len = tu_min16(len, request->wLength);
if ( _ctrl_xfer.data_len )
if (request->wLength > 0U)
{
TU_ASSERT(buffer);
if(_ctrl_xfer.data_len > 0U)
{
TU_ASSERT(buffer);
}
TU_LOG2(" XFER Endpoint: 0x%02X, Bytes: %d\r\n", request->bmRequestType_bit.direction ? EDPT_CTRL_IN : EDPT_CTRL_OUT, _ctrl_xfer.data_len);
// Data stage
TU_ASSERT( _data_stage_xact(rhport) );
}else
}
else
{
// Status stage
TU_ASSERT( _status_stage_xact(rhport, request) );