Skip to content

Commit b03a688

Browse files
authored
Merge pull request #1768 from ftdigdm/port-ft90x
Port ft90x
2 parents 7166bb3 + 770de31 commit b03a688

File tree

10 files changed

+350
-147
lines changed

10 files changed

+350
-147
lines changed

examples/device/cdc_dual_ports/src/usb_descriptors.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ enum
108108
#define EPNUM_CDC_1_OUT 0x05
109109
#define EPNUM_CDC_1_IN 0x86
110110

111+
#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
112+
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
113+
// e.g EP1 OUT & EP1 IN cannot exist together
114+
#define EPNUM_CDC_0_NOTIF 0x81
115+
#define EPNUM_CDC_0_OUT 0x02
116+
#define EPNUM_CDC_0_IN 0x83
117+
118+
#define EPNUM_CDC_1_NOTIF 0x84
119+
#define EPNUM_CDC_1_OUT 0x05
120+
#define EPNUM_CDC_1_IN 0x86
121+
111122
#else
112123
#define EPNUM_CDC_0_NOTIF 0x81
113124
#define EPNUM_CDC_0_OUT 0x02

examples/device/dynamic_configuration/src/usb_descriptors.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ enum
145145
#define EPNUM_1_MSC_OUT 0x01
146146
#define EPNUM_1_MSC_IN 0x82
147147

148+
#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
149+
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
150+
// e.g EP1 OUT & EP1 IN cannot exist together
151+
#define EPNUM_0_CDC_NOTIF 0x81
152+
#define EPNUM_0_CDC_OUT 0x02
153+
#define EPNUM_0_CDC_IN 0x83
154+
155+
#define EPNUM_0_MIDI_OUT 0x04
156+
#define EPNUM_0_MIDI_IN 0x85
157+
158+
#define EPNUM_1_MSC_OUT 0x01
159+
#define EPNUM_1_MSC_IN 0x82
160+
148161
#else
149162
#define EPNUM_0_CDC_NOTIF 0x81
150163
#define EPNUM_0_CDC_OUT 0x02

examples/device/msc_dual_lun/src/usb_descriptors.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ enum
9090
#define EPNUM_MSC_OUT 0x01
9191
#define EPNUM_MSC_IN 0x82
9292

93+
#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
94+
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
95+
// e.g EP1 OUT & EP1 IN cannot exist together
96+
#define EPNUM_MSC_OUT 0x01
97+
#define EPNUM_MSC_IN 0x82
98+
9399
#else
94100
#define EPNUM_MSC_OUT 0x01
95101
#define EPNUM_MSC_IN 0x81

examples/device/uac2_headset/src/usb_descriptors.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ uint8_t const * tud_descriptor_device_cb(void)
9393
#define EPNUM_AUDIO_IN 0x01
9494
#define EPNUM_AUDIO_OUT 0x02
9595

96+
#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
97+
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
98+
// e.g EP1 OUT & EP1 IN cannot exist together
99+
#define EPNUM_AUDIO_IN 0x01
100+
#define EPNUM_AUDIO_OUT 0x02
101+
96102
#else
97103
#define EPNUM_AUDIO_IN 0x01
98104
#define EPNUM_AUDIO_OUT 0x01

examples/device/webusb_serial/src/usb_descriptors.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ enum
9797
#define EPNUM_CDC_OUT 3
9898
#define EPNUM_VENDOR_IN 4
9999
#define EPNUM_VENDOR_OUT 5
100+
#elif CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X
101+
// FT9XX doesn't support a same endpoint number with different direction IN and OUT
102+
// e.g EP1 OUT & EP1 IN cannot exist together
103+
#define EPNUM_CDC_IN 2
104+
#define EPNUM_CDC_OUT 3
105+
#define EPNUM_VENDOR_IN 4
106+
#define EPNUM_VENDOR_OUT 5
100107
#else
101108
#define EPNUM_CDC_IN 2
102109
#define EPNUM_CDC_OUT 2

hw/bsp/brtmm90x/boards/mm900evxb/board.h

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,53 @@
2727
#ifndef BOARD_H_
2828
#define BOARD_H_
2929

30-
// Note: This definition file covers all MM900EV1B, MM900EV2B, and MM900EV3B boards.
30+
// Note: This definition file covers all MM900EV1B, MM900EV2B, MM900EV3B,
31+
// MM900EV-Lite boards.
3132
// Each of these boards has an FT900 device.
3233

3334
#ifdef __cplusplus
3435
extern "C" {
3536
#endif
3637

37-
#define GPIO_UART0_TX 48
38-
#define GPIO_UART0_RX 49
39-
#define GPIO_ETH_LED0 61
40-
#define GPIO_ETH_LED1 62
41-
#define GPIO_REMOTE_WAKEUP_PIN 18
42-
#define USBD_VBUS_DTC_PIN 3
38+
// UART to use on this board.
39+
#ifndef BOARD_UART
40+
#define BOARD_UART UART0
41+
#endif
42+
43+
// UART is on connector CN1.
44+
#ifndef BOARD_GPIO_UART0_TX
45+
#define BOARD_GPIO_UART0_TX 48 // Pin 4 of CN1.
46+
#endif
47+
#ifndef BOARD_GPIO_UART0_RX
48+
#define BOARD_GPIO_UART0_RX 49 // Pin 6 of CN1.
49+
#endif
50+
51+
// LED is connected to pins 17 (signal) and 15 (GND) of CN1.
52+
#ifndef BOARD_GPIO_LED
53+
#define BOARD_GPIO_LED 35
54+
#endif
55+
#ifndef BOARD_GPIO_LED_STATE_ON
56+
#define BOARD_GPIO_LED_STATE_ON 1
57+
#endif
58+
// Button is connected to pins 13 (signal) and 15 (GND) of CN1.
59+
#ifndef BOARD_GPIO_BUTTON
60+
#define BOARD_GPIO_BUTTON 56
61+
#endif
62+
// Button is pulled up and grounded for active.
63+
#ifndef BOARD_GPIO_BUTTON_STATE_ACTIVE
64+
#define BOARD_GPIO_BUTTON_STATE_ACTIVE 0
65+
#endif
4366

44-
#define GPIO_REMOTE_WAKEUP
67+
// Enable the Remote Wakeup signalling.
68+
// Remote wakeup is wired to pin 40 of CN1.
69+
#ifndef BOARD_GPIO_REMOTE_WAKEUP
70+
#define BOARD_GPIO_REMOTE_WAKEUP 18
71+
#endif
72+
73+
// USB VBus signal is connected directly to the FT900.
74+
#ifndef BOARD_USBD_VBUS_DTC_PIN
75+
#define BOARD_USBD_VBUS_DTC_PIN 3
76+
#endif
4577

4678
#ifdef __cplusplus
4779
}

hw/bsp/brtmm90x/family.c

Lines changed: 76 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
#include "bsp/board.h"
2828
#include "board.h"
2929

30-
#include <registers/ft900_registers.h>
3130
#include <ft900.h>
31+
#include <registers/ft900_registers.h>
3232

3333
#if CFG_TUD_ENABLED
34-
int8_t board_ft90x_vbus(void); // Board specific implementation of VBUS detection for USB device.
35-
extern void ft90x_usbd_pm_ISR(uint16_t pmcfg); // Interrupt handler for USB device power management
34+
int8_t board_ft9xx_vbus(void); // Board specific implementation of VBUS detection for USB device.
35+
extern void ft9xx_usbd_pm_ISR(uint16_t pmcfg); // Interrupt handler for USB device power management
3636
#endif
3737

38-
#ifdef GPIO_REMOTE_WAKEUP
38+
#ifdef BOARD_GPIO_REMOTE_WAKEUP
3939
void gpio_ISR(void);
4040
#endif
4141
void timer_ISR(void);
@@ -49,12 +49,17 @@ void board_pm_ISR(void);
4949
void board_init(void)
5050
{
5151
sys_reset_all();
52+
5253
// Enable the UART Device.
5354
sys_enable(sys_device_uart0);
54-
// Set UART0 GPIO functions to UART0_TXD and UART0_RXD.
55-
gpio_function(GPIO_UART0_TX, pad_uart0_txd); /* UART0 TXD */
56-
gpio_function(GPIO_UART0_RX, pad_uart0_rxd); /* UART0 RXD */
57-
uart_open(UART0, /* Device */
55+
// Set BOARD_UART GPIO function pins for TXD and RXD.
56+
#ifdef BOARD_GPIO_UART_TX
57+
gpio_function(BOARD_GPIO_UART_TX, pad_uart0_txd); /* UART0 TXD */
58+
#endif
59+
#ifdef BOARD_GPIO_UART_RX
60+
gpio_function(BOARD_GPIO_UART_RX, pad_uart0_rxd); /* UART0 RXD */
61+
#endif
62+
uart_open(BOARD_UART, /* Device */
5863
1, /* Prescaler = 1 */
5964
UART_DIVIDER_19200_BAUD, /* Divider = 1302 */
6065
uart_data_bits_8, /* No. Data Bits */
@@ -64,12 +69,17 @@ void board_init(void)
6469
// Use sizeof to avoid pulling in strlen unnecessarily.
6570
board_uart_write(WELCOME_MSG, sizeof(WELCOME_MSG));
6671

67-
#if 0
68-
// Ethernet LEDs
69-
gpio_function(GPIO_ETH_LED0, pad_gpio4); /* ETH LED0 */
70-
gpio_dir(GPIO_ETH_LED0, pad_dir_open_drain);
71-
gpio_function(GPIO_ETH_LED1, pad_gpio5); /* ETH LED1 */
72-
gpio_dir(GPIO_ETH_LED1, pad_dir_output);
72+
#ifdef BOARD_GPIO_LED
73+
gpio_function(BOARD_GPIO_LED, pad_func_0);
74+
gpio_idrive(BOARD_GPIO_LED, pad_drive_12mA);
75+
gpio_dir(BOARD_GPIO_LED, pad_dir_output);
76+
#endif
77+
78+
#ifdef BOARD_GPIO_BUTTON
79+
gpio_function(BOARD_GPIO_BUTTON, pad_func_0);
80+
// Pull up if active low. Down if active high.
81+
gpio_pull(BOARD_GPIO_BUTTON, (BOARD_GPIO_BUTTON_STATE_ACTIVE == 0)?pad_pull_pullup:pad_pull_pulldown);
82+
gpio_dir(BOARD_GPIO_BUTTON, pad_dir_input);
7383
#endif
7484

7585
sys_enable(sys_device_timer_wdt);
@@ -82,26 +92,26 @@ void board_init(void)
8292

8393
// Setup VBUS detect GPIO. If the device is connected then this
8494
// will set the MASK_SYS_PMCFG_DEV_DETECT_EN bit in PMCFG.
85-
gpio_interrupt_disable(USBD_VBUS_DTC_PIN);
86-
gpio_function(USBD_VBUS_DTC_PIN, pad_vbus_dtc);
87-
gpio_pull(USBD_VBUS_DTC_PIN, pad_pull_pulldown);
88-
gpio_dir(USBD_VBUS_DTC_PIN, pad_dir_input);
95+
gpio_interrupt_disable(BOARD_USBD_VBUS_DTC_PIN);
96+
gpio_function(BOARD_USBD_VBUS_DTC_PIN, pad_vbus_dtc);
97+
gpio_pull(BOARD_USBD_VBUS_DTC_PIN, pad_pull_pulldown);
98+
gpio_dir(BOARD_USBD_VBUS_DTC_PIN, pad_dir_input);
8999

90100
interrupt_attach(interrupt_0, (int8_t)interrupt_0, board_pm_ISR);
91101

92-
#ifdef GPIO_REMOTE_WAKEUP
93-
//Configuring GPIO pin to wakeup.
102+
#ifdef BOARD_GPIO_REMOTE_WAKEUP
103+
// Configuring GPIO pin to wakeup.
94104
// Set up the wakeup pin.
95-
gpio_dir(GPIO_REMOTE_WAKEUP_PIN, pad_dir_input);
96-
gpio_pull(GPIO_REMOTE_WAKEUP_PIN, pad_pull_pullup);
105+
gpio_dir(BOARD_GPIO_REMOTE_WAKEUP, pad_dir_input);
106+
gpio_pull(BOARD_GPIO_REMOTE_WAKEUP, pad_pull_pullup);
97107

98108
// Attach an interrupt handler.
99109
interrupt_attach(interrupt_gpio, (uint8_t)interrupt_gpio, gpio_ISR);
100-
gpio_interrupt_enable(GPIO_REMOTE_WAKEUP_PIN, gpio_int_edge_falling);
110+
gpio_interrupt_enable(BOARD_GPIO_REMOTE_WAKEUP, gpio_int_edge_falling);
101111
#endif
102112

103-
uart_disable_interrupt(UART0, uart_interrupt_tx);
104-
uart_disable_interrupt(UART0, uart_interrupt_rx);
113+
uart_disable_interrupt(BOARD_UART, uart_interrupt_tx);
114+
uart_disable_interrupt(BOARD_UART, uart_interrupt_rx);
105115

106116
// Enable all peripheral interrupts.
107117
interrupt_enable_globally();
@@ -117,10 +127,10 @@ void timer_ISR(void)
117127
}
118128
}
119129

120-
#ifdef GPIO_REMOTE_WAKEUP
130+
#ifdef BOARD_GPIO_REMOTE_WAKEUP
121131
void gpio_ISR(void)
122132
{
123-
if (gpio_is_interrupted(GPIO_REMOTE_WAKEUP_PIN))
133+
if (gpio_is_interrupted(BOARD_GPIO_REMOTE_WAKEUP))
124134
{
125135
}
126136
}
@@ -153,16 +163,16 @@ void board_pm_ISR(void)
153163
)
154164
{
155165
#if CFG_TUD_ENABLED
156-
ft90x_usbd_pm_ISR(pmcfg);
166+
ft9xx_usbd_pm_ISR(pmcfg);
157167
#endif
158168
}
159169
#endif
160170
}
161171

162172
#if CFG_TUD_ENABLED
163-
int8_t board_ft90x_vbus(void)
173+
int8_t board_ft9xx_vbus(void)
164174
{
165-
return gpio_read(USBD_VBUS_DTC_PIN);
175+
return gpio_read(BOARD_USBD_VBUS_DTC_PIN);
166176
}
167177
#endif
168178

@@ -173,31 +183,48 @@ int8_t board_ft90x_vbus(void)
173183
// Turn LED on or off
174184
void board_led_write(bool state)
175185
{
176-
gpio_write(GPIO_ETH_LED0, state);
186+
#ifdef BOARD_GPIO_LED
187+
gpio_write(BOARD_GPIO_LED, (state == 0)?(BOARD_GPIO_LED_STATE_ON?0:1):BOARD_GPIO_LED_STATE_ON);
188+
#endif
177189
}
178190

179191
// Get the current state of button
180192
// a '1' means active (pressed), a '0' means inactive.
181193
uint32_t board_button_read(void)
182194
{
183-
return 0;
195+
uint32_t state = 0;
196+
#ifdef BOARD_GPIO_BUTTON
197+
state = (gpio_read(BOARD_GPIO_BUTTON) == BOARD_GPIO_BUTTON_STATE_ACTIVE)?1:0;
198+
#endif
199+
return state;
184200
}
185201

186202
// Get characters from UART
187203
int board_uart_read(uint8_t *buf, int len)
188204
{
189-
int r = uart_readn(UART0, (uint8_t *)buf, len);
205+
int r = 0;
206+
207+
#ifdef BOARD_UART
208+
if (uart_rx_has_data(BOARD_UART))
209+
{
210+
r = uart_readn(BOARD_UART, (uint8_t *)buf, len);
211+
}
212+
#endif
190213

191214
return r;
192215
}
193216

194217
// Send characters to UART
195218
int board_uart_write(void const *buf, int len)
196219
{
220+
int r = 0;
221+
222+
#ifdef BOARD_UART
197223
#pragma GCC diagnostic push
198224
#pragma GCC diagnostic ignored "-Wcast-qual" // uart_writen does not have const for buffer parameter.
199-
int r = uart_writen(UART0, (uint8_t *)((const void *)buf), len);
225+
r = uart_writen(BOARD_UART, (uint8_t *)((const void *)buf), len);
200226
#pragma GCC diagnostic pop
227+
#endif
201228

202229
return r;
203230
}
@@ -213,3 +240,18 @@ uint32_t board_millis(void)
213240

214241
return safe_ms;
215242
}
243+
244+
// Restart the program
245+
// Called in the event of a watchdog timeout
246+
void chip_reboot(void)
247+
{
248+
// SOFT reset
249+
__asm__("call 0");
250+
#if 0
251+
// HARD reset
252+
// Initiates data transfer from Flash Memory to Data Memory (DBG_CMDF2D3)
253+
// followed by a system reboot
254+
dbg_memory_copy(0xfe, 0, 0, 255);
255+
#endif
256+
}
257+

0 commit comments

Comments
 (0)