Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Allwinner F1C100s family #1220

Merged
merged 24 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dba5921
usbd: supress "statement is unreachable" warning on ARMCC
t123yh Nov 30, 2021
ac20605
Ignore certain compiler options on ARMCC
t123yh Nov 30, 2021
a6929cf
Add support for Keil RTX4 OS abstraction layer
t123yh Nov 30, 2021
bb7d1fa
Add support for Allwinner F1Cx00s family
t123yh Nov 30, 2021
dff54d8
Modify sunxi_musb code
t123yh Dec 4, 2021
68ca62d
Add BSP support for F1C100s
t123yh Dec 4, 2021
28fb51c
Add TODO to README
t123yh Dec 4, 2021
fa0e4d9
Save current EP before querying other EPs
t123yh Dec 5, 2021
64b81fd
Close all EPs upon reset
t123yh Dec 5, 2021
702698e
Add FIFO size check
t123yh Dec 5, 2021
f308603
Fix a typo that leads to incorrect RX handling
t123yh Dec 5, 2021
1ffc366
Change FIFO size to 4KB (not sure)
t123yh Dec 5, 2021
96979a2
Fix handling of RXRDY bit
t123yh Dec 6, 2021
75f7fb3
Add mksunxi tool to make flashable image
t123yh Dec 7, 2021
43621ab
Update README
t123yh Dec 7, 2021
527036b
Initialize MMU if we are executing from DDR
t123yh Dec 8, 2021
30aba24
Merge branch 'master' of https://github.com/t123yh/tinyusb into t123y…
hathach Dec 29, 2021
2d13ecd
add allwinnner driver as submodule
hathach Dec 29, 2021
b943a53
update allwinner submodule
hathach Dec 29, 2021
84e2f6e
skip freertos example for f1c100s
hathach Dec 29, 2021
5f280b3
add license to dcd file, slightly update readme
hathach Dec 29, 2021
adb848f
update docs
hathach Dec 29, 2021
c5d2c82
fix unreachable warnings with keil
hathach Dec 30, 2021
7de1663
Merge branch 'master' into master
hathach Jan 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@
[submodule "hw/mcu/infineon/mtb-xmclib-cat3"]
path = hw/mcu/infineon/mtb-xmclib-cat3
url = https://github.com/Infineon/mtb-xmclib-cat3.git
[submodule "hw/mcu/allwinner"]
path = hw/mcu/allwinner
url = https://github.com/hathach/allwinner_driver.git
6 changes: 6 additions & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ Notable contributors
- Add new class driver for DFU Runtime


`Tian Yunhao <https://github.com/t123yh>`__
-------------------------------------------

- Add new DCD port for Allwinner F1C100S/F1C200S
- Add support for osal_rtx4

`Timon Skerutsch <https://github.com/PTS93>`__
----------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Supported MCUs

The stack supports the following MCUs:

- **Allwinner:** F1C100s/F1C200s
- **Broadcom:** BCM2837, BCM2711
- **Dialog:** DA1469x
- **Espressif:** ESP32-S2, ESP32-S3
Expand Down
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions examples/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ flash-jlink: $(BUILD)/$(PROJECT).hex
flash-stlink: $(BUILD)/$(PROJECT).elf
STM32_Programmer_CLI --connect port=swd --write $< --go

$(BUILD)/$(PROJECT)-sunxi.bin: $(BUILD)/$(PROJECT).bin
$(PYTHON) $(TOP)/tools/mksunxi.py $< $@

flash-xfel: $(BUILD)/$(PROJECT)-sunxi.bin
xfel spinor write 0 $<
xfel reset

# Flash using pyocd
PYOCD_OPTION ?=
flash-pyocd: $(BUILD)/$(PROJECT).hex
Expand Down
20 changes: 20 additions & 0 deletions hw/bsp/f1c100s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# BSP support for F1Cx00s boards

This folder contains necessary file and scripts to run TinyUSB examples on F1Cx00s boards.

Currently tested on:

- Lichee Pi Nano (F1C100s)
- [Widora Tiny200 v2 (also called MangoPi-R3c)](https://mangopi.org/tiny200)

## Flashing

There are two options to put your code into the MCU: `flash` and `exec`. Both modes require you to install [xfel](https://github.com/xboot/xfel) tool to your PATH. You must enter FEL mode before any operation can be done. To enter FEL mode, press BOOT button, then press RESET once, and release BOOT button. You will find VID/PID=1f3a:efe8 on your PC.

Exec: `make BOARD=f1c100s exec` will just upload the image to the DDR ram and execute it. It will not touch anything in the SPI flash.

Flash: `make BOARD=f1c100s flash` will write the image to SPI flash, and then reset the chip to execute it.

## TODO

* Add F1C100s to `#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX` high speed MCU check in examples (maybe we should extract the logic?)
1 change: 1 addition & 0 deletions hw/bsp/f1c100s/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Nothing valuable here
52 changes: 52 additions & 0 deletions hw/bsp/f1c100s/board.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
DEPS_SUBMODULES += hw/mcu/allwinner

DEFINES += -D__ARM32_ARCH__=5 -D__ARM926EJS__

CFLAGS += \
-ffreestanding \
-std=gnu99 \
-march=armv5te \
-mtune=arm926ej-s \
-mfloat-abi=soft \
-marm \
-mno-thumb-interwork \
-Wno-unused-parameter \
-Wno-float-equal \
-DCFG_TUSB_MCU=OPT_MCU_F1C100S \
-Wno-error=cast-align \
-Wno-error=address-of-packed-member \
$(DEFINES)

LD_FILE = hw/mcu/allwinner/f1c100s/f1c100s.ld
LDFLAGS += -nostdlib -lgcc
MCU_DIR = hw/mcu/allwinner/f1c100s

SRC_C += \
src/portable/sunxi/dcd_sunxi_musb.c \
$(MCU_DIR)/machine/sys-uart.c \
$(MCU_DIR)/machine/exception.c \
$(MCU_DIR)/machine/sys-clock.c \
$(MCU_DIR)/machine/sys-copyself.c \
$(MCU_DIR)/machine/sys-dram.c \
$(MCU_DIR)/machine/sys-mmu.c \
$(MCU_DIR)/machine/sys-spi-flash.c \
$(MCU_DIR)/machine/f1c100s-intc.c \
$(MCU_DIR)/lib/malloc.c \
$(MCU_DIR)/lib/printf.c

SRC_S += \
$(MCU_DIR)/machine/start.S \
$(MCU_DIR)/lib/memcpy.S \
$(MCU_DIR)/lib/memset.S

INC += \
$(TOP)/$(MCU_DIR)/include \
$(TOP)/$(BOARD_PATH)

# flash target using xfel
flash: flash-xfel

exec: $(BUILD)/$(PROJECT).bin
xfel ddr
xfel write 0x80000000 $<
xfel exec 0x80000000
130 changes: 130 additions & 0 deletions hw/bsp/f1c100s/f1c100s.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* 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 <stdint.h>
#include <malloc.h>
#include <irqflags.h>
#include <f1c100s-irq.h>
#include "bsp/board.h"
#include "board.h"

extern void sys_uart_putc(char c);

//--------------------------------------------------------------------+
// Board porting API
//--------------------------------------------------------------------+

static void timer_init(void);

void board_init(void)
{
arch_local_irq_disable();
do_init_mem_pool();
f1c100s_intc_init();
timer_init();
printf("Timer INIT done\n");
arch_local_irq_enable();
}

// No LED, no button
void board_led_write(bool state)
{

}

uint32_t board_button_read(void)
{
return 0;
}

int board_uart_read(uint8_t* buf, int len)
{
return 0;
}

int board_uart_write(void const * buf, int len)
{
int txsize = len;
while (txsize--) {
sys_uart_putc(*(uint8_t const*)buf);
buf++;
}
return len;
}

#if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0;

uint32_t board_millis(void)
{
return system_ticks;
}

static void timer_handler(void)
{
volatile uint32_t *temp_addr = (uint32_t *)(0x01C20C00 + 0x04);

/* clear timer */
*temp_addr |= 0x01;

system_ticks++;
}

static void timer_init(void) {
uint32_t temp;
volatile uint32_t *temp_addr;

/* reload value */
temp = 12000000 / 1000;
temp_addr = (uint32_t *)(0x01C20C00 + 0x14);
*temp_addr = temp;

/* continuous | /2 | 24Mhz | reload*/
temp = (0x00 << 7) | (0x01 << 4) | (0x01 << 2) | (0x00 << 1);
temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
*temp_addr &= 0xffffff00;
*temp_addr |= temp;

/* open timer irq */
temp = 0x01 << 0;
temp_addr = (uint32_t *)(0x01C20C00);
*temp_addr |= temp;

/* set init value */
temp_addr = (uint32_t *)(0x01C20C00 + 0x18);
*temp_addr = 0;

/* begin run timer */
temp = 0x01 << 0;
temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
*temp_addr |= temp;

f1c100s_intc_set_isr(F1C100S_IRQ_TIMER0, timer_handler);
f1c100s_intc_enable_irq(F1C100S_IRQ_TIMER0);
}
#else
static void timer_init(void) { }
#endif
1 change: 1 addition & 0 deletions hw/mcu/allwinner
Submodule allwinner added at 8e5e89
4 changes: 3 additions & 1 deletion src/common/tusb_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@
#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
#define TU_BSWAP32(u32) (__builtin_bswap32(u32))

#ifndef __ARMCC_VERSION
// List of obsolete callback function that is renamed and should not be defined.
// Put it here since only gcc support this pragma
#pragma GCC poison tud_vendor_control_request_cb
#pragma GCC poison tud_vendor_control_request_cb
#endif

#elif defined(__TI_COMPILER_VERSION__)
#define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))
Expand Down
4 changes: 2 additions & 2 deletions src/device/dcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ typedef struct TU_ATTR_ALIGNED(4)
void dcd_init (uint8_t rhport);

// Interrupt Handler
#if __GNUC__
#if __GNUC__ && !defined(__ARMCC_VERSION)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
#endif
void dcd_int_handler(uint8_t rhport);
#if __GNUC__
#if __GNUC__ && !defined(__ARMCC_VERSION)
#pragma GCC diagnostic pop
#endif

Expand Down
4 changes: 4 additions & 0 deletions src/device/dcd_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@
#elif TU_CHECK_MCU(OPT_MCU_FT93X)
#define DCD_ATTR_ENDPOINT_MAX 16

//------------ Allwinner -------------//
#elif TU_CHECK_MCU(OPT_MCU_F1C100S)
#define DCD_ATTR_ENDPOINT_MAX 4

#else
#warning "DCD_ATTR_ENDPOINT_MAX is not defined for this MCU, default to 8"
#define DCD_ATTR_ENDPOINT_MAX 8
Expand Down
10 changes: 5 additions & 5 deletions src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
return tud_control_xfer(rhport, p_request, desc_device, sizeof(tusb_desc_device_t));
}
}
break;
// break; // unreachable

case TUSB_DESC_BOS:
{
Expand All @@ -1025,7 +1025,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const

return tud_control_xfer(rhport, p_request, (void*) desc_bos, total_len);
}
break;
// break; // unreachable

case TUSB_DESC_CONFIGURATION:
case TUSB_DESC_OTHER_SPEED_CONFIG:
Expand All @@ -1051,7 +1051,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const

return tud_control_xfer(rhport, p_request, (void*) desc_config, total_len);
}
break;
// break; // unreachable

case TUSB_DESC_STRING:
{
Expand All @@ -1064,7 +1064,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
// first byte of descriptor is its size
return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_str, tu_desc_len(desc_str));
}
break;
// break; // unreachable

case TUSB_DESC_DEVICE_QUALIFIER:
{
Expand All @@ -1078,7 +1078,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
// first byte of descriptor is its size
return tud_control_xfer(rhport, p_request, (void*) (uintptr_t) desc_qualifier, tu_desc_len(desc_qualifier));
}
break;
// break; // unreachable

default: return false;
}
Expand Down
6 changes: 4 additions & 2 deletions src/osal/osal.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ typedef void (*osal_task_func_t)( void * );
#include "osal_pico.h"
#elif CFG_TUSB_OS == OPT_OS_RTTHREAD
#include "osal_rtthread.h"
#elif CFG_TUSB_OS == OPT_OS_RTX4
#include "osal_rtx4.h"
#elif CFG_TUSB_OS == OPT_OS_CUSTOM
#include "tusb_os_custom.h" // implemented by application
#else
Expand All @@ -67,7 +69,7 @@ typedef void (*osal_task_func_t)( void * );
// OSAL Porting API
//--------------------------------------------------------------------+

#if __GNUC__
#if __GNUC__ && !defined(__ARMCC_VERSION)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
#endif
Expand All @@ -88,7 +90,7 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
static inline bool osal_queue_receive(osal_queue_t qhdl, void* data);
static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr);
static inline bool osal_queue_empty(osal_queue_t qhdl);
#if __GNUC__
#if __GNUC__ && !defined(__ARMCC_VERSION)
#pragma GCC diagnostic pop
#endif

Expand Down
Loading