/************************************************************************ Project: Welling Motor Control Paltform Filename: hwsetup.c Partner Filename: hwsetup.h Description: Hardware setup Complier: IAR Embedded Workbench for ARM 8.40.2 CPU TYPE : GD32F30x ************************************************************************* Copyright (c) 2022 Welling Motor Technology(Shanghai) Co. Ltd. All rights reserved. ************************************************************************* ************************************************************************* Revising History (ECL of this file): ************************************************************************/ /************************************************************************ Beginning of File, do not put anything above here except notes Compiler Directives: *************************************************************************/ #ifndef _HWSETUP_C_ #define _HWSETUP_C_ #endif /************************************************************************ Included File *************************************************************************/ /*#include "user.h" #include "FuncLayerAPI.h" #include "can.h"*/ #include "hwsetup.h" #include "uart_driver.h" #include "RefreshMenu.h" /************************************************************************ Constant Table (N/A) *************************************************************************/ /************************************************************************* Exported Functions: *************************************************************************/ /************************************************************************* Function: hw_voHardwareSetup; Description: Hardware Setup function. Call by: main(); Input Variables: All HW registers Output/Return Variables: All HW registers Subroutine Call: ...; Reference: N/A *************************************************************************/ void hw_voHardwareSetup(void) { // Initialize System Control registers, WatchDog to a know state hw_voInitSysCtrl(); // nvic_priority_group_config(NVIC_PRIORITY_GROUP_4); // Select GPIO for the device or for the specific application: hw_voInitGPIO(); hw_voInitSysTick(); hw_voInitUART(); } /************************************************************************* Function: Description: Call by: Input Variables: Output/Return Variables: Subroutine Call: Reference: *************************************************************************/ void hw_voInitSysCtrl(void) { // /* reset crm */ // crm_reset(); // // /* config flash psr register */ // flash_psr_set(FLASH_WAIT_CYCLE_2); // // /* enable lick */ // crm_clock_source_enable(CRM_CLOCK_SOURCE_LICK, TRUE); // // /* wait till lick is ready */ // while(crm_flag_get(CRM_LICK_STABLE_FLAG) != SET) // { // } // // /* enable hick */ // crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE); // // /* wait till hick is ready */ // while(crm_flag_get(CRM_HICK_STABLE_FLAG) != SET) // { // } // // /* config pll clock resource */ // crm_pll_config(CRM_PLL_SOURCE_HICK, CRM_PLL_MULT_18); // // /* enable pll */ // crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE); // // /* wait till pll is ready */ // while(crm_flag_get(CRM_PLL_STABLE_FLAG) != SET) // { // } // // /* config ahbclk */ // crm_ahb_div_set(CRM_AHB_DIV_1); // // /* config apb2clk */ // crm_apb2_div_set(CRM_APB2_DIV_1); // // /* config apb1clk */ // crm_apb1_div_set(CRM_APB1_DIV_1); // // /* select pll as system clock source */ // crm_sysclk_switch(CRM_SCLK_PLL); // // /* wait till pll is used as system clock source */ // while(crm_sysclk_switch_status_get() != CRM_SCLK_PLL) // { // } // // /* update system_core_clock global variable */ // system_core_clock_update(); } /************************************************************************* Function: Description: Call by: Input Variables: Output/Return Variables: Subroutine Call: Reference: *************************************************************************/ void hw_voInitGPIO(void) { // gpio_init_type gpio_init_struct; // // /* enable the gpioa clock */ // crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE); // // /* set default parameter */ //// gpio_default_para_init(&gpio_init_struct); // // /* configure the gpio */ // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; // gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; // gpio_init_struct.gpio_pins = GPIO_PINS_15|GPIO_PINS_13; // gpio_init_struct.gpio_pull = GPIO_PULL_NONE; // gpio_init(GPIOC, &gpio_init_struct); // // gpio_bits_reset(GPIOC,GPIO_PINS_15); // gpio_bits_reset(GPIOC,GPIO_PINS_13); } /************************************************************************* Function: Description: Call by: Input Variables: Output/Return Variables: Subroutine Call: Reference: *************************************************************************/ void hw_voInitUART() { // gpio_init_type gpio_init_struct; // // /* enable the usart2 and gpio clock */ // // /* enable the usart1 and gpio clock */ // crm_periph_clock_enable(CRM_USART1_PERIPH_CLOCK, TRUE); // crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE); // //// gpio_default_para_init(&gpio_init_struct); // // /* configure the usart2 tx/rx pin */ // gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; // gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; // gpio_init_struct.gpio_mode = GPIO_MODE_MUX; // gpio_init_struct.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7; // gpio_init_struct.gpio_pull = GPIO_PULL_NONE; // gpio_init(GPIOB, &gpio_init_struct); // // /* config usart1 iomux */ // gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE6, GPIO_MUX_0); // gpio_pin_mux_config(GPIOB, GPIO_PINS_SOURCE7, GPIO_MUX_0); // // /* config usart2 and usart1 nvic interrupt */ // nvic_irq_enable(USART1_IRQn, 0, 0); // // /* configure usart1 param */ // usart_init(USART1, 19200, USART_DATA_8BITS, USART_STOP_1_BIT); // usart_transmitter_enable(USART1, TRUE); // usart_receiver_enable(USART1, TRUE); // // usart_interrupt_enable(USART1, USART_RDBF_INT, TRUE); // usart_enable(USART1, TRUE); // // usart_interrupt_enable(USART1, USART_TDBE_INT, TRUE); // // //#if UART2_ENABLE // crm_periph_clock_enable(CRM_USART2_PERIPH_CLOCK, TRUE); // crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE); // // gpio_init_struct.gpio_pins = GPIO_PINS_14 | GPIO_PINS_15; // gpio_init(GPIOA, &gpio_init_struct); // // gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE14, GPIO_MUX_1); // gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE15, GPIO_MUX_1); // // nvic_irq_enable(USART2_IRQn, 0, 0); // // usart_init(USART2, 57600, USART_DATA_8BITS, USART_STOP_1_BIT); // usart_transmitter_enable(USART2, TRUE); // usart_receiver_enable(USART2, TRUE); // // usart_interrupt_enable(USART2, USART_RDBF_INT, TRUE); // usart_enable(USART2, TRUE); // // usart_interrupt_enable(USART2, USART_TDBE_INT, TRUE); //#endif } /************************************************************************* Function: Description: Call by: Input Variables: Output/Return Variables: Subroutine Call: Reference: *************************************************************************/ #define FSYSTICK_HZ 1000 void hw_voInitSysTick(void) { // /* Setup systick timer interrupts */ // /* Do not exceed 2^24-1=16777215 */ // systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV); // // SysTick_Config(SystemCoreClock / FSYSTICK_HZ); } volatile static uint32_t delay; uint32_t delaytest; /*! \brief delay a time in milliseconds \param[in] count: count in milliseconds \param[out] none \retval none */ void delay_1ms(uint32_t count) { delay = count; while(0U != delay){ } } /*! \brief delay decrement \param[in] none \param[out] none \retval none */ //void delay_decrement(void) //{ // if (0U != delay){ // delay--; // } //} /*! \brief this function handles SysTick exception \param[in] none \param[out] none \retval none */ void SysTick_Handler(void) { if (0U != delay){ delay--; } delaytest=delay; // delay_decrement(); Period_Stick(); } /************************************************************************* Copyright (c) 2022 Welling Motor Technology(Shanghai) Co. Ltd. All rights reserved. *************************************************************************/ #ifdef _HWSETUP_C_ #undef _HWSETUP_C_ #endif /************************************************************************ End of this File (EOF)! Do not put anything after this part! *************************************************************************/