From 027d9ef4bda78ff2baff1181682b61e4fa328f94 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 17 Nov 2018 12:40:23 +0700 Subject: pass mcu option from compiler --- examples/device/device_composite/ses/device_composite.emProject | 4 ++-- examples/device/device_composite/src/tusb_config.h | 7 ++++++- examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/device/device_composite/ses/device_composite.emProject b/examples/device/device_composite/ses/device_composite.emProject index 35463b25d..f2f052ed2 100644 --- a/examples/device/device_composite/ses/device_composite.emProject +++ b/examples/device/device_composite/ses/device_composite.emProject @@ -19,7 +19,7 @@ arm_target_device_name="nRF52840_xxAA" arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" - c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_PCA10056" + c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_PCA10056;CFG_TUSB_MCU=OPT_MCU_NRF5X" c_user_include_directories="../src;$(rootDir)/hw/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(nrfxDir)/..;$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include" debug_register_definition_file="ses_nrf5x/nrf52840_Registers.xml" debug_target_connection="J-Link" @@ -118,7 +118,7 @@ arm_target_device_name="ATSAMD51J19" arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" - c_preprocessor_definitions="__SAME51_FAMILY;__SAMD51J19A__;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_METRO_M4_EXPRESS;USE_SIMPLE_ASSERT" + c_preprocessor_definitions="__SAME51_FAMILY;__SAMD51J19A__;ARM_MATH_CM4;FLASH_PLACEMENT=1;USE_SIMPLE_ASSERT;BOARD_METRO_M4_EXPRESS;CFG_TUSB_MCU=OPT_MCU_SAMD51" c_user_include_directories="../src;$(rootDir)/hw/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(asf4Dir);$(asf4Dir)/include;$(asf4Dir)/hri;$(asf4Dir)/hal/include;$(asf4Dir)/hal/utils/include;$(asf4Dir)/hpl/port" debug_register_definition_file="ses_samd51/ATSAME51J19A_Registers.xml" debug_target_connection="J-Link" diff --git a/examples/device/device_composite/src/tusb_config.h b/examples/device/device_composite/src/tusb_config.h index 680036859..b802a4131 100644 --- a/examples/device/device_composite/src/tusb_config.h +++ b/examples/device/device_composite/src/tusb_config.h @@ -48,7 +48,12 @@ //-------------------------------------------------------------------- // COMMON CONFIGURATION //-------------------------------------------------------------------- -#define CFG_TUSB_MCU OPT_MCU_NRF5X + +// defined by compiler flags for flexibility +#ifndef CFG_TUSB_MCU + #error CFG_TUSB_MCU should be defined using compiler flags +#endif + #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE #define CFG_TUSB_DEBUG 2 diff --git a/examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject b/examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject index 661dc12a6..f36a76fed 100644 --- a/examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject +++ b/examples/device/nrf52840_freertos/segger/nrf5x_freertos.emProject @@ -19,7 +19,7 @@ arm_target_device_name="nRF52840_xxAA" arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" - c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_PCA10056" + c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_PCA10056;CFG_TUSB_MCU=OPT_MCU_NRF5X" c_user_include_directories="../src;$(tusbDir)/hw/cmsis/Include;$(tusbDir)/hw;$(tusbDir)/src;$(nrfxDir)/..;$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(freertosDir)/Source/include;$(freertosDir)/Source/portable/GCC/ARM_CM4F" debug_register_definition_file="$(ProjectDir)/nrf52840_Registers.xml" debug_target_connection="J-Link" -- cgit v1.3.1 From 99f758ecd9bffd0c8da35e5ffd906eb09e5fb7f7 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 17 Nov 2018 12:58:27 +0700 Subject: samd51 project update --- .../device_composite/ses/device_composite.emProject | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/device/device_composite/ses/device_composite.emProject b/examples/device/device_composite/ses/device_composite.emProject index f2f052ed2..df41c7f1e 100644 --- a/examples/device/device_composite/ses/device_composite.emProject +++ b/examples/device/device_composite/ses/device_composite.emProject @@ -163,15 +163,6 @@ - - - - - - - - - @@ -181,5 +172,11 @@ + -- cgit v1.3.1 From 4e2c357579629c10bad92f2f76161b2073fab107 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 17 Nov 2018 13:26:14 +0700 Subject: clean up --- examples/device/device_composite/src/main.c | 63 +++++++++++++---------------- 1 file changed, 29 insertions(+), 34 deletions(-) (limited to 'examples') diff --git a/examples/device/device_composite/src/main.c b/examples/device/device_composite/src/main.c index 11b73ebf9..4c8730242 100644 --- a/examples/device/device_composite/src/main.c +++ b/examples/device/device_composite/src/main.c @@ -36,9 +36,6 @@ */ /**************************************************************************/ -//--------------------------------------------------------------------+ -// INCLUDE -//--------------------------------------------------------------------+ #include #include #include @@ -47,15 +44,39 @@ #include "tusb.h" //--------------------------------------------------------------------+ -// MACRO CONSTANT TYPEDEF -//--------------------------------------------------------------------+ - -//--------------------------------------------------------------------+ -// INTERNAL OBJECT & FUNCTION DECLARATION +// MACRO CONSTANT TYPEDEF PROTYPES //--------------------------------------------------------------------+ void print_greeting(void); void led_blinking_task(void); +/*------------- MAIN -------------*/ +int main(void) +{ + board_init(); + print_greeting(); + + tusb_init(); + + while (1) + { + tusb_task(); + + led_blinking_task(); + +#if CFG_TUD_CDC + extern void virtual_com_task(void); + virtual_com_task(); +#endif + +#if CFG_TUD_HID + extern void usb_hid_task(void); + usb_hid_task(); +#endif + } + + return 0; +} + //--------------------------------------------------------------------+ // USB CDC //--------------------------------------------------------------------+ @@ -90,8 +111,6 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) tud_cdc_write_str("tinyusb usb cdc\n"); } } -#else -#define virtual_com_task() #endif //--------------------------------------------------------------------+ @@ -151,32 +170,8 @@ void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_t { // TODO not Implemented } - -#else -#define usb_hid_task() #endif - -/*------------- MAIN -------------*/ -int main(void) -{ - board_init(); - print_greeting(); - - tusb_init(); - - while (1) - { - tusb_task(); - - led_blinking_task(); - virtual_com_task(); - usb_hid_task(); - } - - return 0; -} - //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -- cgit v1.3.1 From 5e65886fdd2bc5bac4ee9335fff1726f9382c109 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 20 Nov 2018 01:21:54 +0700 Subject: samd51 metro m4 add init_mcu() and usb init - device regconized on bus but doesnt response with setup packet. - temp disable msc --- .../ses/device_composite.emProject | 21 +++++++++++++++-- examples/device/device_composite/src/tusb_config.h | 2 +- hw/bsp/metro_m4_express/board_metro_m4_express.c | 27 +++++++++++++++++++++- 3 files changed, 46 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/device/device_composite/ses/device_composite.emProject b/examples/device/device_composite/ses/device_composite.emProject index df41c7f1e..371ef8bb7 100644 --- a/examples/device/device_composite/ses/device_composite.emProject +++ b/examples/device/device_composite/ses/device_composite.emProject @@ -118,8 +118,8 @@ arm_target_device_name="ATSAMD51J19" arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" - c_preprocessor_definitions="__SAME51_FAMILY;__SAMD51J19A__;ARM_MATH_CM4;FLASH_PLACEMENT=1;USE_SIMPLE_ASSERT;BOARD_METRO_M4_EXPRESS;CFG_TUSB_MCU=OPT_MCU_SAMD51" - c_user_include_directories="../src;$(rootDir)/hw/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(asf4Dir);$(asf4Dir)/include;$(asf4Dir)/hri;$(asf4Dir)/hal/include;$(asf4Dir)/hal/utils/include;$(asf4Dir)/hpl/port" + c_preprocessor_definitions="__SAME51_FAMILY;__SAMD51J19A__;ARM_MATH_CM4;FLASH_PLACEMENT=1;USE_SIMPLE_ASSERT;BOARD_METRO_M4_EXPRESS;CIRCUITPY_GCLK_INIT_1ST=0xffff;CFG_TUSB_MCU=OPT_MCU_SAMD51" + c_user_include_directories="../src;$(rootDir)/hw/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(asf4Dir);$(asf4Dir)/include;$(asf4Dir)/config;$(asf4Dir)/hri;$(asf4Dir)/hal/include;$(asf4Dir)/hal/utils/include;$(asf4Dir)/hpl/port;$(asf4Dir)/hpl/gclk" debug_register_definition_file="ses_samd51/ATSAME51J19A_Registers.xml" debug_target_connection="J-Link" gcc_entry_point="Reset_Handler" @@ -156,6 +156,23 @@ + + + + + + + + + + + + + + + + + diff --git a/examples/device/device_composite/src/tusb_config.h b/examples/device/device_composite/src/tusb_config.h index b802a4131..b5b4fe088 100644 --- a/examples/device/device_composite/src/tusb_config.h +++ b/examples/device/device_composite/src/tusb_config.h @@ -87,7 +87,7 @@ //------------- CLASS -------------// #define CFG_TUD_CDC 1 -#define CFG_TUD_MSC 1 +#define CFG_TUD_MSC 0 #define CFG_TUD_HID 0 #define CFG_TUD_HID_KEYBOARD 0 diff --git a/hw/bsp/metro_m4_express/board_metro_m4_express.c b/hw/bsp/metro_m4_express/board_metro_m4_express.c index a4af9cec3..23b9e987d 100644 --- a/hw/bsp/metro_m4_express/board_metro_m4_express.c +++ b/hw/bsp/metro_m4_express/board_metro_m4_express.c @@ -37,7 +37,12 @@ /**************************************************************************/ #include "bsp/board.h" + +#include "sam.h" #include "hal/include/hal_gpio.h" +#include "hal/include/hal_init.h" +#include "peripheral_clk_config.h" + //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION @@ -46,6 +51,8 @@ void board_init(void) { + init_mcu(); + gpio_set_pin_direction(BOARD_LED0, GPIO_DIRECTION_OUT); gpio_set_pin_level(BOARD_LED0, 1-LED_STATE_ON); @@ -53,6 +60,24 @@ void board_init(void) // Tick init SysTick_Config(SystemCoreClock/1000); #endif + + /* USB Clock init + * The USB module requires a GCLK_USB of 48 MHz ~ 0.25% clock + * for low speed and full speed operation. */ + hri_gclk_write_PCHCTRL_reg(GCLK, USB_GCLK_ID, CONF_GCLK_USB_SRC | GCLK_PCHCTRL_CHEN); + hri_mclk_set_AHBMASK_USB_bit(MCLK); + hri_mclk_set_APBBMASK_USB_bit(MCLK); + + // USB Pin Init + gpio_set_pin_direction(PIN_PA24, GPIO_DIRECTION_OUT); + gpio_set_pin_level(PIN_PA24, false); + gpio_set_pin_pull_mode(PIN_PA24, GPIO_PULL_OFF); + gpio_set_pin_direction(PIN_PA25, GPIO_DIRECTION_OUT); + gpio_set_pin_level(PIN_PA25, false); + gpio_set_pin_pull_mode(PIN_PA25, GPIO_PULL_OFF); + + gpio_set_pin_function(PIN_PA24, PINMUX_PA24H_USB_DM); + gpio_set_pin_function(PIN_PA25, PINMUX_PA25H_USB_DP); } void board_led_control(uint32_t led_id, bool state) @@ -76,4 +101,4 @@ uint32_t tusb_hal_millis(void) { return board_tick2ms(system_ticks); } -#endif \ No newline at end of file +#endif -- cgit v1.3.1