summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-11-21 00:12:11 +0700
committerhathach <[email protected]>2018-11-21 00:12:11 +0700
commita46b42a54e2926a33231c657777882f87e0c0daa (patch)
tree1cc1fcb4a6bbd93d2945f0e872aa963e3049d77a
parent867d3cb02d78f85d388cb3ad9fc92f06d2bc5e10 (diff)
move metro m4 clock init to board
-rw-r--r--examples/device/device_composite/ses/device_composite.emProject4
-rw-r--r--hw/bsp/metro_m4_express/board_metro_m4_express.c26
2 files changed, 25 insertions, 5 deletions
diff --git a/examples/device/device_composite/ses/device_composite.emProject b/examples/device/device_composite/ses/device_composite.emProject
index 4ea41db2a..2d658f9bd 100644
--- a/examples/device/device_composite/ses/device_composite.emProject
+++ b/examples/device/device_composite/ses/device_composite.emProject
@@ -118,7 +118,7 @@
arm_target_device_name="ATSAMD51J19"
arm_target_interface_type="SWD"
build_treat_warnings_as_errors="Yes"
- c_preprocessor_definitions="__SAMD51_FAMILY;__SAMD51J19A__;ARM_MATH_CM4;FLASH_PLACEMENT=1;USE_SIMPLE_ASSERT;CIRCUITPY_GCLK_INIT_1ST=0xffff;BOARD_METRO_M4_EXPRESS;CFG_TUSB_MCU=OPT_MCU_SAMD51"
+ c_preprocessor_definitions="__SAMD51_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)/config;$(asf4Dir)/hri;$(asf4Dir)/hal/include;$(asf4Dir)/hal/utils/include;$(asf4Dir)/hpl/port;$(asf4Dir)/hpl/gclk"
debug_register_definition_file="ses_samd51/ATSAMD51J19A_Registers.xml"
debug_target_connection="J-Link"
@@ -214,7 +214,7 @@
arm_target_device_name="ATSAMD21G18A"
arm_target_interface_type="SWD"
build_treat_warnings_as_errors="Yes"
- c_preprocessor_definitions="__SAMD21G18A__;__SAMD21_FAMILY;__SAM_D21_SUBFAMILY;ARM_MATH_CM0PLUS;FLASH_PLACEMENT=1;USE_SIMPLE_ASSERT;CIRCUITPY_GCLK_INIT_1ST=0xffff;BOARD_METRO_M0_EXPRESS;CFG_TUSB_MCU=OPT_MCU_SAMD21"
+ c_preprocessor_definitions="__SAMD21G18A__;__SAMD21_FAMILY;__SAM_D21_SUBFAMILY;ARM_MATH_CM0PLUS;FLASH_PLACEMENT=1;USE_SIMPLE_ASSERT;BOARD_METRO_M0_EXPRESS;CFG_TUSB_MCU=OPT_MCU_SAMD21"
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;$(asf4Dir)/hpl/pm"
debug_register_definition_file="ses_samd21/ATSAMD21G18A_Registers.xml"
debug_target_connection="J-Link"
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 23b9e987d..0c251e808 100644
--- a/hw/bsp/metro_m4_express/board_metro_m4_express.c
+++ b/hw/bsp/metro_m4_express/board_metro_m4_express.c
@@ -41,6 +41,8 @@
#include "sam.h"
#include "hal/include/hal_gpio.h"
#include "hal/include/hal_init.h"
+#include "hpl/gclk/hpl_gclk_base.h"
+#include "hpl_mclk_config.h"
#include "peripheral_clk_config.h"
@@ -49,16 +51,34 @@
//--------------------------------------------------------------------+
#define LED_STATE_ON 1
+/* Referenced GCLKs, should be initialized firstly */
+#define _GCLK_INIT_1ST 0xFFFFFFFF
+
+/* Not referenced GCLKs, initialized last */
+#define _GCLK_INIT_LAST (~_GCLK_INIT_1ST)
+
void board_init(void)
{
- init_mcu();
+ // Clock init ( follow hpl_init.c )
+ //hri_nvmctrl_set_CTRLA_RWS_bf(NVMCTRL, CONF_NVM_WAIT_STATE);
+
+ _osc32kctrl_init_sources();
+ _oscctrl_init_sources();
+ _mclk_init();
+#if _GCLK_INIT_1ST
+ _gclk_init_generators_by_fref(_GCLK_INIT_1ST);
+#endif
+ _oscctrl_init_referenced_generators();
+ _gclk_init_generators_by_fref(_GCLK_INIT_LAST);
+ // Led init
gpio_set_pin_direction(BOARD_LED0, GPIO_DIRECTION_OUT);
- gpio_set_pin_level(BOARD_LED0, 1-LED_STATE_ON);
+ gpio_set_pin_level(BOARD_LED0, 1 - LED_STATE_ON);
+ // Systick init
#if CFG_TUSB_OS == OPT_OS_NONE
// Tick init
- SysTick_Config(SystemCoreClock/1000);
+ SysTick_Config(SystemCoreClock / 1000);
#endif
/* USB Clock init