summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-09-26 19:09:36 +0700
committerhathach <[email protected]>2023-09-26 19:09:36 +0700
commitf6ca86c3ddeaec18f52b15f1065a5c9eea210c00 (patch)
tree73e59ce660d5a59931c0fcd3ef48f517a96468e2 /hw
parenta7c136c03f0c4a057f8b49c10ed9cddcecf52879 (diff)
tested cdc_msc_hid_freertos with samd51
add -Wno-error=format for espressif wrap up cdc_msc_hid_freertos
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/espressif/boards/CMakeLists.txt2
-rw-r--r--hw/bsp/espressif/boards/family.c39
-rw-r--r--hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt1
-rw-r--r--hw/bsp/nrf/family.c106
-rw-r--r--hw/bsp/samd21/family.c9
-rw-r--r--hw/bsp/samd51/FreeRTOSConfig/FreeRTOSConfig.h2
-rw-r--r--hw/bsp/samd51/family.c8
7 files changed, 95 insertions, 72 deletions
diff --git a/hw/bsp/espressif/boards/CMakeLists.txt b/hw/bsp/espressif/boards/CMakeLists.txt
index 325263c1d..8209e8747 100644
--- a/hw/bsp/espressif/boards/CMakeLists.txt
+++ b/hw/bsp/espressif/boards/CMakeLists.txt
@@ -4,3 +4,5 @@ idf_component_register(SRCS family.c
INCLUDE_DIRS "." ${BOARD} ${hw_dir}
PRIV_REQUIRES "driver"
REQUIRES led_strip src tinyusb_src)
+
+target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=format)
diff --git a/hw/bsp/espressif/boards/family.c b/hw/bsp/espressif/boards/family.c
index 250b7001e..d96d86670 100644
--- a/hw/bsp/espressif/boards/family.c
+++ b/hw/bsp/espressif/boards/family.c
@@ -33,6 +33,7 @@
#include "soc/usb_periph.h"
#include "driver/rmt.h"
+#include "driver/uart.h"
#if ESP_IDF_VERSION_MAJOR > 4
#include "esp_private/periph_ctrl.h"
@@ -145,9 +146,7 @@ uint32_t board_button_read(void) {
// Get characters from UART
int board_uart_read(uint8_t *buf, int len) {
- (void) buf;
- (void) len;
- return 0;
+ return uart_read_bytes(UART_NUM_0, buf, len, 0);
}
// Send characters to UART
@@ -157,6 +156,11 @@ int board_uart_write(void const *buf, int len) {
return 0;
}
+int board_getchar(void) {
+ char c;
+ return (uart_read_bytes(UART_NUM_0, &c, 1, 0) > 0) ? (int) c : (-1);
+}
+
//--------------------------------------------------------------------+
// API: SPI transfer with MAX3421E, must be implemented by application
//--------------------------------------------------------------------+
@@ -164,12 +168,12 @@ int board_uart_write(void const *buf, int len) {
static spi_device_handle_t max3421_spi;
-static void IRAM_ATTR max3421_isr_handler(void* arg)
-{
- (void) arg;
- //uint32_t gpio_num = (uint32_t) arg;
+static void IRAM_ATTR max3421_isr_handler(void* arg) {
+ (void) arg; // arg is gpio num
//xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
+ gpio_set_level(13, 1);
tuh_int_handler(1);
+ gpio_set_level(13, 0);
}
static void max3421_init(void) {
@@ -188,12 +192,11 @@ static void max3421_init(void) {
.data5_io_num = -1,
.data6_io_num = -1,
.data7_io_num = -1,
- .max_transfer_sz = 128
+ .max_transfer_sz = 1024
};
ESP_ERROR_CHECK( spi_bus_initialize(MAX3421_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO) );
spi_device_interface_config_t max3421_cfg = {
- .command_bits = 8,
.mode = 0,
.clock_speed_hz = 4000000, // 26000000
.spics_io_num = -1, // manual control CS
@@ -201,12 +204,16 @@ static void max3421_init(void) {
};
ESP_ERROR_CHECK( spi_bus_add_device(MAX3421_SPI_HOST, &max3421_cfg, &max3421_spi) );
+ // debug
+ gpio_set_direction(13, GPIO_MODE_OUTPUT);
+ gpio_set_level(13, 0);
+
// Interrupt pin
-// gpio_set_direction(MAX3421_INTR_PIN, GPIO_MODE_INPUT);
-// gpio_set_intr_type(MAX3421_INTR_PIN, GPIO_INTR_NEGEDGE);
-//
-// gpio_install_isr_service(ESP_INTR_FLAG_EDGE);
-// gpio_isr_handler_add(MAX3421_INTR_PIN, max3421_isr_handler, NULL);
+ gpio_set_direction(MAX3421_INTR_PIN, GPIO_MODE_INPUT);
+ gpio_set_intr_type(MAX3421_INTR_PIN, GPIO_INTR_NEGEDGE);
+
+ gpio_install_isr_service(0);
+ gpio_isr_handler_add(MAX3421_INTR_PIN, max3421_isr_handler, NULL);
}
void tuh_max3421_int_api(uint8_t rhport, bool enabled) {
@@ -227,8 +234,8 @@ bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf, size_t tx_l
(void) rhport;
spi_transaction_t xact = {
- .length = tx_len,
- .rxlength = rx_len,
+ .length = tx_len << 3, // length in bits
+ .rxlength = rx_len << 3, // length in bits
.tx_buffer = tx_buf,
.rx_buffer = rx_buf
};
diff --git a/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt b/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt
index 2a154a8ff..abe276910 100644
--- a/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt
+++ b/hw/bsp/espressif/components/tinyusb_src/CMakeLists.txt
@@ -70,3 +70,4 @@ idf_component_register(SRCS ${srcs}
)
target_compile_definitions(${COMPONENT_LIB} PUBLIC ${compile_definitions})
+target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=format)
diff --git a/hw/bsp/nrf/family.c b/hw/bsp/nrf/family.c
index 6fcfd9476..3620bc8cc 100644
--- a/hw/bsp/nrf/family.c
+++ b/hw/bsp/nrf/family.c
@@ -95,13 +95,8 @@ TU_ATTR_UNUSED static void power_event_handler(nrfx_power_usb_evt_t event) {
//------------- Host using MAX2341E -------------//
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
+static void max3421_init(void);
static nrfx_spim_t _spi = NRFX_SPIM_INSTANCE(1);
-
-void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
- if (!(pin == MAX3421_INTR_PIN && action == NRF_GPIOTE_POLARITY_HITOLO)) return;
-
- tuh_int_handler(1);
-}
#endif
@@ -191,50 +186,7 @@ void board_init(void) {
#endif
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
- // MAX3421 need 3.3v signal (may not be needed)
- #if defined(UICR_REGOUT0_VOUT_Msk) && 0
- if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) != UICR_REGOUT0_VOUT_3V3) {
- NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
-
- NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~UICR_REGOUT0_VOUT_Msk) | UICR_REGOUT0_VOUT_3V3;
-
- NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
- while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
-
- NVIC_SystemReset();
- }
- #endif
-
- // manually manage CS
- nrf_gpio_cfg_output(MAX3421_CS_PIN);
- nrf_gpio_pin_write(MAX3421_CS_PIN, 1);
-
- // USB host using max3421e usb controller via SPI
- nrfx_spim_config_t cfg = {
- .sck_pin = MAX3421_SCK_PIN,
- .mosi_pin = MAX3421_MOSI_PIN,
- .miso_pin = MAX3421_MISO_PIN,
- .ss_pin = NRFX_SPIM_PIN_NOT_USED,
- .ss_active_high = false,
- .irq_priority = 3,
- .orc = 0xFF,
- // default setting 4 Mhz, Mode 0, MSB first
- .frequency = NRF_SPIM_FREQ_4M,
- .mode = NRF_SPIM_MODE_0,
- .bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST,
- };
-
- // no handler --> blocking
- nrfx_spim_init(&_spi, &cfg, NULL, NULL);
-
- // max3421e interrupt pin
- nrfx_gpiote_init(1);
- nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
- in_config.pull = NRF_GPIO_PIN_PULLUP;
-
- nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);
- nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);
+ max3421_init();
#endif
}
@@ -317,6 +269,60 @@ void nrf_error_cb(uint32_t id, uint32_t pc, uint32_t info) {
//--------------------------------------------------------------------+
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
+void max3421_int_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
+ if (!(pin == MAX3421_INTR_PIN && action == NRF_GPIOTE_POLARITY_HITOLO)) return;
+ tuh_int_handler(1);
+}
+
+static void max3421_init(void) {
+ // MAX3421 need 3.3v signal (may not be needed)
+// #if defined(UICR_REGOUT0_VOUT_Msk)
+// if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) != UICR_REGOUT0_VOUT_3V3) {
+// NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
+// while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
+//
+// NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~UICR_REGOUT0_VOUT_Msk) | UICR_REGOUT0_VOUT_3V3;
+//
+// NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
+// while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
+//
+// NVIC_SystemReset();
+// }
+// #endif
+
+ // manually manage CS
+ nrf_gpio_cfg_output(MAX3421_CS_PIN);
+ nrf_gpio_pin_write(MAX3421_CS_PIN, 1);
+
+ // USB host using max3421e usb controller via SPI
+ nrfx_spim_config_t cfg = {
+ .sck_pin = MAX3421_SCK_PIN,
+ .mosi_pin = MAX3421_MOSI_PIN,
+ .miso_pin = MAX3421_MISO_PIN,
+ .ss_pin = NRFX_SPIM_PIN_NOT_USED,
+ .ss_active_high = false,
+ .irq_priority = 3,
+ .orc = 0xFF,
+ // default setting 4 Mhz, Mode 0, MSB first
+ .frequency = NRF_SPIM_FREQ_4M,
+ .mode = NRF_SPIM_MODE_0,
+ .bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST,
+ };
+
+ // no handler --> blocking
+ nrfx_spim_init(&_spi, &cfg, NULL, NULL);
+
+ // max3421e interrupt pin
+ nrfx_gpiote_init(1);
+ nrfx_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
+ in_config.pull = NRF_GPIO_PIN_PULLUP;
+
+ NVIC_SetPriority(GPIOTE_IRQn, 2);
+
+ nrfx_gpiote_in_init(MAX3421_INTR_PIN, &in_config, max3421_int_handler);
+ nrfx_gpiote_trigger_enable(MAX3421_INTR_PIN, true);
+}
+
void tuh_max3421_int_api(uint8_t rhport, bool enabled) {
(void) rhport;
diff --git a/hw/bsp/samd21/family.c b/hw/bsp/samd21/family.c
index 395155548..335039e2f 100644
--- a/hw/bsp/samd21/family.c
+++ b/hw/bsp/samd21/family.c
@@ -261,6 +261,7 @@ void SysTick_Handler(void) {
uint32_t board_millis(void) {
return system_ticks;
}
+#endif
//--------------------------------------------------------------------+
//
@@ -344,6 +345,11 @@ static void max3421_init(void) {
EIC->CONFIG[0].reg &= ~(7 << sense_shift);
EIC->CONFIG[0].reg |= 2 << sense_shift;
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
+ // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
+ NVIC_SetPriority(EIC_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+#endif
+
// Enable External Interrupt
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << MAX3421_INTR_EIC_ID);
@@ -413,6 +419,3 @@ bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf, size_t tx_l
}
#endif
-
-
-#endif
diff --git a/hw/bsp/samd51/FreeRTOSConfig/FreeRTOSConfig.h b/hw/bsp/samd51/FreeRTOSConfig/FreeRTOSConfig.h
index e3ee529cf..32db4ad95 100644
--- a/hw/bsp/samd51/FreeRTOSConfig/FreeRTOSConfig.h
+++ b/hw/bsp/samd51/FreeRTOSConfig/FreeRTOSConfig.h
@@ -59,7 +59,7 @@
#define configTICK_RATE_HZ ( 1000 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( 128 )
-#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*4*1024 )
+#define configTOTAL_HEAP_SIZE ( configSUPPORT_DYNAMIC_ALLOCATION*6*1024 )
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
diff --git a/hw/bsp/samd51/family.c b/hw/bsp/samd51/family.c
index c1b914a02..7b9de35c9 100644
--- a/hw/bsp/samd51/family.c
+++ b/hw/bsp/samd51/family.c
@@ -175,6 +175,7 @@ void SysTick_Handler(void) {
uint32_t board_millis(void) {
return system_ticks;
}
+#endif
//--------------------------------------------------------------------+
// API: SPI transfer with MAX3421E, must be implemented by application
@@ -290,6 +291,11 @@ static void max3421_init(void) {
*eic_config &= ~(7 << sense_shift);
*eic_config |= 2 << sense_shift;
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
+ // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
+ NVIC_SetPriority(EIC_0_IRQn + MAX3421_INTR_EIC_ID, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
+#endif
+
// Enable External Interrupt
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << MAX3421_INTR_EIC_ID);
@@ -360,5 +366,3 @@ bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf, size_t tx_l
}
#endif
-
-#endif