Skip to content

Commit eea19da

Browse files
authored
Merge pull request #1220 from t123yh/master
Add support for Allwinner F1C100s family
2 parents a592282 + 7de1663 commit eea19da

File tree

21 files changed

+2313
-10
lines changed

21 files changed

+2313
-10
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,6 @@
137137
[submodule "hw/mcu/infineon/mtb-xmclib-cat3"]
138138
path = hw/mcu/infineon/mtb-xmclib-cat3
139139
url = https://github.com/Infineon/mtb-xmclib-cat3.git
140+
[submodule "hw/mcu/allwinner"]
141+
path = hw/mcu/allwinner
142+
url = https://github.com/hathach/allwinner_driver.git

CONTRIBUTORS.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ Notable contributors
153153
- Add new class driver for DFU Runtime
154154

155155

156+
`Tian Yunhao <https://github.com/t123yh>`__
157+
-------------------------------------------
158+
159+
- Add new DCD port for Allwinner F1C100S/F1C200S
160+
- Add support for osal_rtx4
161+
156162
`Timon Skerutsch <https://github.com/PTS93>`__
157163
----------------------------------------------
158164

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Supported MCUs
3232

3333
The stack supports the following MCUs:
3434

35+
- **Allwinner:** F1C100s/F1C200s
3536
- **Broadcom:** BCM2837, BCM2711
3637
- **Dialog:** DA1469x
3738
- **Espressif:** ESP32-S2, ESP32-S3

examples/device/cdc_msc_freertos/.skip.MCU_F1C100S

Whitespace-only changes.

examples/device/hid_composite_freertos/.skip.MCU_F1C100S

Whitespace-only changes.

examples/rules.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ flash-jlink: $(BUILD)/$(PROJECT).hex
188188
flash-stlink: $(BUILD)/$(PROJECT).elf
189189
STM32_Programmer_CLI --connect port=swd --write $< --go
190190

191+
$(BUILD)/$(PROJECT)-sunxi.bin: $(BUILD)/$(PROJECT).bin
192+
$(PYTHON) $(TOP)/tools/mksunxi.py $< $@
193+
194+
flash-xfel: $(BUILD)/$(PROJECT)-sunxi.bin
195+
xfel spinor write 0 $<
196+
xfel reset
197+
191198
# Flash using pyocd
192199
PYOCD_OPTION ?=
193200
flash-pyocd: $(BUILD)/$(PROJECT).hex

hw/bsp/f1c100s/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# BSP support for F1Cx00s boards
2+
3+
This folder contains necessary file and scripts to run TinyUSB examples on F1Cx00s boards.
4+
5+
Currently tested on:
6+
7+
- Lichee Pi Nano (F1C100s)
8+
- [Widora Tiny200 v2 (also called MangoPi-R3c)](https://mangopi.org/tiny200)
9+
10+
## Flashing
11+
12+
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.
13+
14+
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.
15+
16+
Flash: `make BOARD=f1c100s flash` will write the image to SPI flash, and then reset the chip to execute it.
17+
18+
## TODO
19+
20+
* 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?)

hw/bsp/f1c100s/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Nothing valuable here

hw/bsp/f1c100s/board.mk

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
DEPS_SUBMODULES += hw/mcu/allwinner
2+
3+
DEFINES += -D__ARM32_ARCH__=5 -D__ARM926EJS__
4+
5+
CFLAGS += \
6+
-ffreestanding \
7+
-std=gnu99 \
8+
-march=armv5te \
9+
-mtune=arm926ej-s \
10+
-mfloat-abi=soft \
11+
-marm \
12+
-mno-thumb-interwork \
13+
-Wno-unused-parameter \
14+
-Wno-float-equal \
15+
-DCFG_TUSB_MCU=OPT_MCU_F1C100S \
16+
-Wno-error=cast-align \
17+
-Wno-error=address-of-packed-member \
18+
$(DEFINES)
19+
20+
LD_FILE = hw/mcu/allwinner/f1c100s/f1c100s.ld
21+
LDFLAGS += -nostdlib -lgcc
22+
MCU_DIR = hw/mcu/allwinner/f1c100s
23+
24+
SRC_C += \
25+
src/portable/sunxi/dcd_sunxi_musb.c \
26+
$(MCU_DIR)/machine/sys-uart.c \
27+
$(MCU_DIR)/machine/exception.c \
28+
$(MCU_DIR)/machine/sys-clock.c \
29+
$(MCU_DIR)/machine/sys-copyself.c \
30+
$(MCU_DIR)/machine/sys-dram.c \
31+
$(MCU_DIR)/machine/sys-mmu.c \
32+
$(MCU_DIR)/machine/sys-spi-flash.c \
33+
$(MCU_DIR)/machine/f1c100s-intc.c \
34+
$(MCU_DIR)/lib/malloc.c \
35+
$(MCU_DIR)/lib/printf.c
36+
37+
SRC_S += \
38+
$(MCU_DIR)/machine/start.S \
39+
$(MCU_DIR)/lib/memcpy.S \
40+
$(MCU_DIR)/lib/memset.S
41+
42+
INC += \
43+
$(TOP)/$(MCU_DIR)/include \
44+
$(TOP)/$(BOARD_PATH)
45+
46+
# flash target using xfel
47+
flash: flash-xfel
48+
49+
exec: $(BUILD)/$(PROJECT).bin
50+
xfel ddr
51+
xfel write 0x80000000 $<
52+
xfel exec 0x80000000

hw/bsp/f1c100s/f1c100s.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#include <stdint.h>
28+
#include <malloc.h>
29+
#include <irqflags.h>
30+
#include <f1c100s-irq.h>
31+
#include "bsp/board.h"
32+
#include "board.h"
33+
34+
extern void sys_uart_putc(char c);
35+
36+
//--------------------------------------------------------------------+
37+
// Board porting API
38+
//--------------------------------------------------------------------+
39+
40+
static void timer_init(void);
41+
42+
void board_init(void)
43+
{
44+
arch_local_irq_disable();
45+
do_init_mem_pool();
46+
f1c100s_intc_init();
47+
timer_init();
48+
printf("Timer INIT done\n");
49+
arch_local_irq_enable();
50+
}
51+
52+
// No LED, no button
53+
void board_led_write(bool state)
54+
{
55+
56+
}
57+
58+
uint32_t board_button_read(void)
59+
{
60+
return 0;
61+
}
62+
63+
int board_uart_read(uint8_t* buf, int len)
64+
{
65+
return 0;
66+
}
67+
68+
int board_uart_write(void const * buf, int len)
69+
{
70+
int txsize = len;
71+
while (txsize--) {
72+
sys_uart_putc(*(uint8_t const*)buf);
73+
buf++;
74+
}
75+
return len;
76+
}
77+
78+
#if CFG_TUSB_OS == OPT_OS_NONE
79+
volatile uint32_t system_ticks = 0;
80+
81+
uint32_t board_millis(void)
82+
{
83+
return system_ticks;
84+
}
85+
86+
static void timer_handler(void)
87+
{
88+
volatile uint32_t *temp_addr = (uint32_t *)(0x01C20C00 + 0x04);
89+
90+
/* clear timer */
91+
*temp_addr |= 0x01;
92+
93+
system_ticks++;
94+
}
95+
96+
static void timer_init(void) {
97+
uint32_t temp;
98+
volatile uint32_t *temp_addr;
99+
100+
/* reload value */
101+
temp = 12000000 / 1000;
102+
temp_addr = (uint32_t *)(0x01C20C00 + 0x14);
103+
*temp_addr = temp;
104+
105+
/* continuous | /2 | 24Mhz | reload*/
106+
temp = (0x00 << 7) | (0x01 << 4) | (0x01 << 2) | (0x00 << 1);
107+
temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
108+
*temp_addr &= 0xffffff00;
109+
*temp_addr |= temp;
110+
111+
/* open timer irq */
112+
temp = 0x01 << 0;
113+
temp_addr = (uint32_t *)(0x01C20C00);
114+
*temp_addr |= temp;
115+
116+
/* set init value */
117+
temp_addr = (uint32_t *)(0x01C20C00 + 0x18);
118+
*temp_addr = 0;
119+
120+
/* begin run timer */
121+
temp = 0x01 << 0;
122+
temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
123+
*temp_addr |= temp;
124+
125+
f1c100s_intc_set_isr(F1C100S_IRQ_TIMER0, timer_handler);
126+
f1c100s_intc_enable_irq(F1C100S_IRQ_TIMER0);
127+
}
128+
#else
129+
static void timer_init(void) { }
130+
#endif

hw/mcu/allwinner

Submodule allwinner added at 8e5e89e

src/common/tusb_compiler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@
137137
#define TU_BSWAP16(u16) (__builtin_bswap16(u16))
138138
#define TU_BSWAP32(u32) (__builtin_bswap32(u32))
139139

140+
#ifndef __ARMCC_VERSION
140141
// List of obsolete callback function that is renamed and should not be defined.
141142
// Put it here since only gcc support this pragma
142-
#pragma GCC poison tud_vendor_control_request_cb
143+
#pragma GCC poison tud_vendor_control_request_cb
144+
#endif
143145

144146
#elif defined(__TI_COMPILER_VERSION__)
145147
#define TU_ATTR_ALIGNED(Bytes) __attribute__ ((aligned(Bytes)))

src/device/dcd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ typedef struct TU_ATTR_ALIGNED(4)
106106
void dcd_init (uint8_t rhport);
107107

108108
// Interrupt Handler
109-
#if __GNUC__
109+
#if __GNUC__ && !defined(__ARMCC_VERSION)
110110
#pragma GCC diagnostic push
111111
#pragma GCC diagnostic ignored "-Wredundant-decls"
112112
#endif
113113
void dcd_int_handler(uint8_t rhport);
114-
#if __GNUC__
114+
#if __GNUC__ && !defined(__ARMCC_VERSION)
115115
#pragma GCC diagnostic pop
116116
#endif
117117

src/device/dcd_attr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@
208208
#elif TU_CHECK_MCU(OPT_MCU_FT93X)
209209
#define DCD_ATTR_ENDPOINT_MAX 16
210210

211+
//------------ Allwinner -------------//
212+
#elif TU_CHECK_MCU(OPT_MCU_F1C100S)
213+
#define DCD_ATTR_ENDPOINT_MAX 4
214+
211215
#else
212216
#warning "DCD_ATTR_ENDPOINT_MAX is not defined for this MCU, default to 8"
213217
#define DCD_ATTR_ENDPOINT_MAX 8

src/device/usbd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
10081008
return tud_control_xfer(rhport, p_request, desc_device, sizeof(tusb_desc_device_t));
10091009
}
10101010
}
1011-
break;
1011+
// break; // unreachable
10121012

10131013
case TUSB_DESC_BOS:
10141014
{
@@ -1025,7 +1025,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
10251025

10261026
return tud_control_xfer(rhport, p_request, (void*) desc_bos, total_len);
10271027
}
1028-
break;
1028+
// break; // unreachable
10291029

10301030
case TUSB_DESC_CONFIGURATION:
10311031
case TUSB_DESC_OTHER_SPEED_CONFIG:
@@ -1051,7 +1051,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
10511051

10521052
return tud_control_xfer(rhport, p_request, (void*) desc_config, total_len);
10531053
}
1054-
break;
1054+
// break; // unreachable
10551055

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

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

10831083
default: return false;
10841084
}

src/osal/osal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ typedef void (*osal_task_func_t)( void * );
5757
#include "osal_pico.h"
5858
#elif CFG_TUSB_OS == OPT_OS_RTTHREAD
5959
#include "osal_rtthread.h"
60+
#elif CFG_TUSB_OS == OPT_OS_RTX4
61+
#include "osal_rtx4.h"
6062
#elif CFG_TUSB_OS == OPT_OS_CUSTOM
6163
#include "tusb_os_custom.h" // implemented by application
6264
#else
@@ -67,7 +69,7 @@ typedef void (*osal_task_func_t)( void * );
6769
// OSAL Porting API
6870
//--------------------------------------------------------------------+
6971

70-
#if __GNUC__
72+
#if __GNUC__ && !defined(__ARMCC_VERSION)
7173
#pragma GCC diagnostic push
7274
#pragma GCC diagnostic ignored "-Wredundant-decls"
7375
#endif
@@ -88,7 +90,7 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
8890
static inline bool osal_queue_receive(osal_queue_t qhdl, void* data);
8991
static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr);
9092
static inline bool osal_queue_empty(osal_queue_t qhdl);
91-
#if __GNUC__
93+
#if __GNUC__ && !defined(__ARMCC_VERSION)
9294
#pragma GCC diagnostic pop
9395
#endif
9496

0 commit comments

Comments
 (0)