#include "board.h" #define USING_BOOT_KEY 1 //#define RUN_LED_PORT GPIOB //#define RUN_LED_PIN PIN10 #define RUN_LED_PORT GPIOD #define RUN_LED_PIN PIN10 #define BOOT_KEY_PORT GPIOC #define BOOT_KEY_PIN PIN0 //运行状态灯的定时器 static sw_timer_t run_status_timer; unsigned long run_led_speed = 500000; /** * 强制灭灯 * * @author LXZ (121219) * * @param void */ void hw_run_status_off(void) { RUN_LED_PORT->BSRR = RUN_LED_PIN; } /** * 强制亮灯 * * @author LXZ (121219) * * @param void */ void hw_run_status_on(void) { RUN_LED_PORT->BRR = RUN_LED_PIN; } /** * 初始化运行灯的IO口 * * @author lxz */ static void hw_run_status_init(void) { uint32_t port = (uint32_t)RUN_LED_PORT; unsigned short pin = RUN_LED_PIN; if (port >= GPIOA_BASE && port <= GPIOG_BASE) { RCC->APB2ENR |= 0x04 << ((port - GPIOA_BASE) / 0x400); GPIO_Set((GPIO_TypeDef *)port, pin, GPIO_MODE_OUT_PP, GPIO_SPEED_50M, GPIO_PUPD_PU); ((GPIO_TypeDef *)port)->BRR = pin; } sw_timer_start(&run_status_timer, 1, 0); } /** * 控制板初始化 * * @author lxz * * @param void */ void hw_board_init(void) { Stm32_Clock_Init(10); //120Mhz //配置向量表 Sys_NVIC_SetVectorTable(ST_FLASH_SECTOR_5,0x00000200); //Sys_NVIC_SetVectorTable(ST_FLASH_SECTOR_0,0x00000000); st_dma_init(); hw_delay_init(120); sw_timer_init(120); //开启IO复用功能 RCC->APB2ENR |= 1<< 0; hw_io_pin_init(); hw_run_status_init(); hw_dma_uart_init(120); hw_power_off_init(); // hw_iic_init(); INTX_ENABLE(); } void hw_boot_key_init(void) { #if USING_BOOT_KEY uint32_t port = (uint32_t)BOOT_KEY_PORT; unsigned short pin = BOOT_KEY_PIN; if (port >= GPIOA_BASE && port <= GPIOG_BASE) { RCC->APB2ENR |= 0x04 << ((port - GPIOA_BASE) / 0x400); GPIO_Set((GPIO_TypeDef *)port, pin, GPIO_MODE_IPU, GPIO_SPEED_50M, GPIO_PUPD_PU); ((GPIO_TypeDef *)port)->BRR = pin; } #else return ; #endif } int hw_boot_key_read(void) { #if USING_BOOT_KEY uint32_t port = (uint32_t)BOOT_KEY_PORT; unsigned short pin = BOOT_KEY_PIN; volatile uint32_t i = 200000; if (port >= GPIOA_BASE && port <= GPIOG_BASE) { RCC->APB2ENR |= 0x04 << ((port - GPIOA_BASE) / 0x400); GPIO_Set((GPIO_TypeDef *)port, pin, GPIO_MODE_IPU, GPIO_SPEED_50M, GPIO_PUPD_PU); ((GPIO_TypeDef *)port)->BRR = pin; } while (i-- > 0); return (BOOT_KEY_PORT->IDR & BOOT_KEY_PIN) == 0; #else return 0; #endif } /** * 显示用于运行等指示的状态 * * @author lxz * * @param void */ void hw_run_status_show(void) { if (sw_timer_expire(&run_status_timer)) { if (RUN_LED_PORT->ODR & RUN_LED_PIN) { RUN_LED_PORT->BRR = RUN_LED_PIN; } else { RUN_LED_PORT->BSRR = RUN_LED_PIN; } sw_timer_start(&run_status_timer, 0, run_led_speed); } } //临时保存数据参数,由于是放在了非初始化,允许保存app参数给Bootloader调用 static int hw_noinit_data[16] __attribute__((section(".noinit"))); /** * 写入保存参数 * * @author lxz * * @param no * @param value */ void hw_noinit_write(int no, int value) { hw_noinit_data[no] = value; } /** * 读取临时保存参数 * * @author lxz * * @param no * * @return int */ int hw_noinit_read(int no) { return hw_noinit_data[no]; } void hw_board_enter_powerless(void) { int index = 0; //立刻所有IO高阻态 while (index < 5) { GPIO_TypeDef *gpio = (GPIO_TypeDef *)(GPIOA_BASE + index * 0x400); gpio->CRL = 0x44444444; gpio->CRH = 0x44444444; index++; } hw_run_status_init(); } /** * 硬件复位 * * @author LXZ (051820) * * @param void */ void hw_board_reboot(void) { Sys_Soft_Reset(); }