├── .gitignore ├── LICENSE ├── Makefile ├── README.cn.md ├── README.md ├── app ├── Makefile ├── inc │ └── wm_it.h └── src │ ├── Makefile │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── demo ├── Makefile ├── adc │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── fatfs │ ├── fatfs_mmc.c │ ├── fatfs_mmc.h │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── flash │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── freertos │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── gpio │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── i2c │ ├── at24cxx │ │ ├── main.c │ │ ├── wm_hal_msp.c │ │ └── wm_it.c │ └── ssd1306_oled │ │ ├── main.c │ │ ├── ssd1306.c │ │ ├── ssd1306.h │ │ ├── wm_hal_msp.c │ │ └── wm_it.c ├── i2s │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── pmu │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── pwm │ ├── 2_led_fade_complementary │ │ ├── main.c │ │ ├── wm_hal_msp.c │ │ └── wm_it.c │ ├── 2_led_fade_synchronized │ │ ├── main.c │ │ ├── wm_hal_msp.c │ │ └── wm_it.c │ ├── 5_led_fade_synchronized │ │ ├── main.c │ │ ├── wm_hal_msp.c │ │ └── wm_it.c │ └── led_fade_independent │ │ ├── main.c │ │ ├── wm_hal_msp.c │ │ └── wm_it.c ├── rtc │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── spi │ ├── nrf24l01 │ │ ├── main.c │ │ ├── nrf24l01.c │ │ ├── nrf24l01.h │ │ ├── wm_hal_msp.c │ │ └── wm_it.c │ ├── spi_basic │ │ ├── main.c │ │ ├── wm_hal_msp.c │ │ └── wm_it.c │ ├── st7567_lcd │ │ ├── main.c │ │ ├── st7567.c │ │ ├── st7567.h │ │ ├── wm_hal_msp.c │ │ └── wm_it.c │ └── st77xx_lcd │ │ ├── README.cn.md │ │ ├── README.md │ │ ├── main.c │ │ ├── st7735.c │ │ ├── st7735.h │ │ ├── st7789.c │ │ ├── st7789.h │ │ ├── st77xx.c │ │ ├── st77xx.h │ │ ├── testimg.h │ │ ├── wm_hal_msp.c │ │ └── wm_it.c ├── tft_lcd │ ├── lcd.c │ ├── lcd.h │ ├── lufei.h │ ├── main.c │ ├── pikaqiu.h │ ├── st7789_parallel.c │ ├── st7789_parallel.h │ ├── st7789_serial.c │ ├── st7789_serial.h │ ├── wm_hal_msp.c │ └── wm_it.c ├── tim │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── touch │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── uart │ ├── fifo.c │ ├── fifo.h │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c └── wwdg │ ├── main.c │ ├── wm_hal_msp.c │ └── wm_it.c ├── include ├── arch │ └── xt804 │ │ ├── csi_config.h │ │ ├── csi_core │ │ ├── core_804.h │ │ ├── csi_core.h │ │ └── csi_gcc.h │ │ └── csi_dsp │ │ ├── csky_common_tables.h │ │ ├── csky_const_structs.h │ │ ├── csky_math.h │ │ ├── csky_vdsp2_const_structs.h │ │ └── csky_vdsp2_math.h ├── driver │ ├── wm_adc.h │ ├── wm_cpu.h │ ├── wm_dma.h │ ├── wm_gpio.h │ ├── wm_gpio_ex.h │ ├── wm_hal.h │ ├── wm_i2c.h │ ├── wm_i2s.h │ ├── wm_internal_flash.h │ ├── wm_pmu.h │ ├── wm_pwm.h │ ├── wm_rcc.h │ ├── wm_spi.h │ ├── wm_spi_flash.h │ ├── wm_tim.h │ ├── wm_touch.h │ ├── wm_uart.h │ └── wm_wdg.h ├── wm_regs.h └── wm_type_def.h ├── ld └── W806 │ └── gcc_csky.ld ├── lib └── W806 │ └── libdsp.a ├── platform ├── arch │ ├── Makefile │ └── xt804 │ │ ├── Makefile │ │ ├── bsp │ │ ├── Makefile │ │ ├── board_init.c │ │ ├── startup.S │ │ ├── system.c │ │ ├── trap_c.c │ │ └── vectors.S │ │ └── libc │ │ ├── Makefile │ │ └── libc_port.c ├── component │ ├── FatFs │ │ ├── LICENSE.txt │ │ ├── Makefile │ │ ├── diskio.c │ │ ├── diskio.h │ │ ├── ff.c │ │ ├── ff.h │ │ ├── ffconf.h │ │ ├── ffsystem.c │ │ └── ffunicode.c │ ├── FreeRTOS │ │ ├── Makefile │ │ ├── croutine.c │ │ ├── event_groups.c │ │ ├── include │ │ │ ├── FreeRTOS.h │ │ │ ├── FreeRTOSConfig.h │ │ │ ├── StackMacros.h │ │ │ ├── atomic.h │ │ │ ├── croutine.h │ │ │ ├── deprecated_definitions.h │ │ │ ├── event_groups.h │ │ │ ├── list.h │ │ │ ├── message_buffer.h │ │ │ ├── mpu_prototypes.h │ │ │ ├── mpu_wrappers.h │ │ │ ├── portable.h │ │ │ ├── projdefs.h │ │ │ ├── queue.h │ │ │ ├── semphr.h │ │ │ ├── stack_macros.h │ │ │ ├── stdint.readme │ │ │ ├── stream_buffer.h │ │ │ ├── task.h │ │ │ └── timers.h │ │ ├── list.c │ │ ├── portable │ │ │ ├── Makefile │ │ │ ├── MemMang │ │ │ │ ├── Makefile │ │ │ │ ├── ReadMe.url │ │ │ │ └── heap_5.c │ │ │ └── xt804 │ │ │ │ ├── Makefile │ │ │ │ ├── cpu_task_sw.S │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ ├── queue.c │ │ ├── stream_buffer.c │ │ ├── tasks.c │ │ └── timers.c │ ├── Makefile │ ├── ascii_fonts │ │ ├── Makefile │ │ ├── ascii_fonts.c │ │ └── ascii_fonts.h │ └── auto_dl │ │ ├── Makefile │ │ └── auto_dl.c └── drivers │ ├── Makefile │ ├── wm_adc.c │ ├── wm_cpu.c │ ├── wm_dma.c │ ├── wm_gpio.c │ ├── wm_hal.c │ ├── wm_i2c.c │ ├── wm_i2s.c │ ├── wm_internal_flash.c │ ├── wm_pmu.c │ ├── wm_pwm.c │ ├── wm_spi.c │ ├── wm_spi_flash.c │ ├── wm_tim.c │ ├── wm_touch.c │ ├── wm_uart.c │ └── wm_wdg.c └── tools └── W806 ├── W806_secboot.bin ├── W806_secboot.img ├── ca ├── cakey.pem └── capub.pem ├── conf.mk ├── config ├── Makefile ├── confdata.c ├── expr.c ├── expr.h ├── images.c ├── list.h ├── lkc.h ├── lkc_proto.h ├── lxdialog │ ├── checklist.c │ ├── dialog.h │ ├── inputbox.c │ ├── menubox.c │ ├── textbox.c │ ├── util.c │ └── yesno.c ├── mconf.c ├── menu.c ├── symbol.c ├── util.c ├── zconf.gperf ├── zconf.hash.c ├── zconf.lex.c └── zconf.tab.c ├── inc.mk ├── mconfig.sh ├── projects └── SDK_Project │ └── project │ └── CDK_WS │ ├── CDK_WS.cdkws │ └── W806_SDK │ ├── Makefile │ ├── W806_SDK.cdkproj │ └── W806_SDK.cdkws ├── rules.mk ├── utilities ├── aft_build_project.sh ├── cdk_aft_build.sh ├── download.mk ├── flashinit └── gdb.init ├── wconfig ├── wm_getver.c ├── wm_tool.c └── wm_tool.exe /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.la 22 | *.lo 23 | 24 | # Shared objects (inc. Windows DLLs) 25 | *.dll 26 | *.so 27 | *.so.* 28 | *.dylib 29 | 30 | # Executables 31 | *.out 32 | *.app 33 | *.i*86 34 | *.x86_64 35 | *.hex 36 | 37 | # Debug files 38 | *.dSYM/ 39 | *.su 40 | *.idb 41 | *.pdb 42 | 43 | # Kernel Module Compile Results 44 | *.mod* 45 | *.cmd 46 | .vscode/ 47 | .tmp_versions/ 48 | tools/W806/wm_tool 49 | tools/W806/wm_getver 50 | tools/W806/wm_getver.exe 51 | tools/W806/.config 52 | tools/W806/.config.old 53 | bin/* 54 | lib/W806/libappuser.a 55 | lib/W806/libdrivers.a 56 | lib/W806/libwmarch.a 57 | lib/W806/libwmcomponent.a 58 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR := . 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR # { 5 | GEN_IMAGES= $(TARGET).elf 6 | GEN_BINS = $(TARGET).bin 7 | SUBDIRS = \ 8 | $(TOP_DIR)/app \ 9 | $(TOP_DIR)/demo 10 | endif # } PDIR 11 | 12 | ifndef PDIR # { 13 | ifeq ($(USE_LIB), 0) 14 | SUBDIRS += \ 15 | $(TOP_DIR)/platform/arch \ 16 | $(TOP_DIR)/platform/component \ 17 | $(TOP_DIR)/platform/drivers 18 | endif 19 | endif 20 | 21 | COMPONENTS_$(TARGET) = \ 22 | $(TOP_DIR)/app/libappuser$(LIB_EXT) \ 23 | $(TOP_DIR)/demo/libdemo$(LIB_EXT) 24 | 25 | ifeq ($(USE_LIB), 0) 26 | COMPONENTS_$(TARGET) += \ 27 | $(TOP_DIR)/platform/boot/libwmarch$(LIB_EXT) \ 28 | $(TOP_DIR)/platform/component/libwmcomponent$(LIB_EXT) \ 29 | $(TOP_DIR)/platform/drivers/libdrivers$(LIB_EXT) 30 | endif 31 | 32 | LINKLIB = \ 33 | $(TOP_DIR)/lib/$(CONFIG_ARCH_TYPE)/libdsp$(LIB_EXT) 34 | ifeq ($(USE_LIB), 1) 35 | LINKLIB += \ 36 | $(TOP_DIR)/lib/$(CONFIG_ARCH_TYPE)/libwmarch$(LIB_EXT) \ 37 | $(TOP_DIR)/lib/$(CONFIG_ARCH_TYPE)/libwmcomponent$(LIB_EXT) \ 38 | $(TOP_DIR)/lib/$(CONFIG_ARCH_TYPE)/libdrivers$(LIB_EXT) 39 | endif 40 | 41 | LINKFLAGS_$(TARGET) = \ 42 | $(LINKLIB) 43 | 44 | CONFIGURATION_DEFINES = 45 | 46 | DEFINES += \ 47 | $(CONFIGURATION_DEFINES) 48 | 49 | DDEFINES += \ 50 | $(CONFIGURATION_DEFINES) 51 | 52 | INCLUDES := $(INCLUDES) -I$(PDIR)include 53 | INCLUDES += -I ./ 54 | 55 | sinclude $(TOP_DIR)/tools/$(CONFIG_ARCH_TYPE)/rules.mk 56 | 57 | .PHONY: FORCE 58 | FORCE: 59 | -------------------------------------------------------------------------------- /app/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = .. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libappuser$(LIB_EXT) 6 | COMPONENTS_libappuser = src/libappsrc$(LIB_EXT) 7 | endif 8 | 9 | #DEFINES += 10 | 11 | sinclude $(TOP_DIR)/tools/W806/rules.mk 12 | INCLUDES := $(INCLUDES) -I $(PDIR)include 13 | 14 | PDIR := ../$(PDIR) 15 | sinclude $(PDIR)Makefile 16 | 17 | -------------------------------------------------------------------------------- /app/inc/wm_it.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM_IT_H__ 2 | #define __WM_IT_H__ 3 | 4 | void CORET_IRQHandler(void); 5 | void GPIOA_IRQHandler(void); 6 | void GPIOB_IRQHandler(void); 7 | void UART0_IRQHandler(void); 8 | void UART1_IRQHandler(void); 9 | void UART2_4_IRQHandler(void); 10 | void WDG_IRQHandler(void); 11 | void TIM0_5_IRQHandler(void); 12 | void ADC_IRQHandler(void); 13 | void PMU_IRQHandler(void); 14 | void TOUCH_IRQHandler(void); 15 | 16 | #endif -------------------------------------------------------------------------------- /app/src/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libappsrc$(LIB_EXT) 6 | endif 7 | 8 | #DEFINES += 9 | 10 | sinclude $(TOP_DIR)/tools/W806/rules.mk 11 | 12 | INCLUDES := $(INCLUDES) -I $(PDIR)include 13 | 14 | PDIR := ../$(PDIR) 15 | sinclude $(PDIR)Makefile -------------------------------------------------------------------------------- /app/src/main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file main.c 4 | * \author IOsetting | iosetting@outlook.com 5 | * \date 6 | * \brief Demo code of PWM in independent mode 7 | * \note This will drive 3 on-board LEDs to show fade effect 8 | * \version v0.1 9 | * \ingroup demo 10 | * \remarks test-board: HLK-W806-KIT-V1.0 11 | * PWM Frequency = 40MHz / Prescaler / (Period + 1); 12 | Duty Cycle(Edge Aligned) = (Pulse + 1) / (Period + 1) 13 | Duty Cycle(Center Aligned) = (2 * Pulse + 1) / (2 * (Period + 1)) 14 | * 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include "wm_hal.h" 19 | 20 | #define DUTY_MAX 100 21 | #define DUTY_MIN 50 22 | PWM_HandleTypeDef pwm[3]; 23 | int i, j, m[3] = {0}, d[3] = {DUTY_MIN, (DUTY_MIN + DUTY_MAX) / 2, DUTY_MAX - 1}; 24 | 25 | static void PWM_Init(PWM_HandleTypeDef *hpwm, uint32_t channel); 26 | void Error_Handler(void); 27 | 28 | int main(void) 29 | { 30 | SystemClock_Config(CPU_CLK_160M); 31 | printf("enter main\r\n"); 32 | 33 | for (i = 2; i >= 0; i--) 34 | { 35 | PWM_Init(&pwm[i], PWM_CHANNEL_0 + i); 36 | HAL_PWM_Start(&pwm[i]); 37 | } 38 | 39 | while (1) 40 | { 41 | for (i = 0; i < 3; i++) 42 | { 43 | if (m[i] == 0) // Increasing 44 | { 45 | HAL_PWM_Duty_Set(&pwm[i], d[i]++); 46 | if (d[i] == DUTY_MAX) 47 | { 48 | m[i] = 1; 49 | } 50 | } 51 | else // Decreasing 52 | { 53 | HAL_PWM_Duty_Set(&pwm[i], d[i]--); 54 | if (d[i] == DUTY_MIN) 55 | { 56 | m[i] = 0; 57 | } 58 | } 59 | } 60 | HAL_Delay(20); 61 | } 62 | } 63 | 64 | static void PWM_Init(PWM_HandleTypeDef *hpwm, uint32_t channel) 65 | { 66 | hpwm->Instance = PWM; 67 | hpwm->Init.AutoReloadPreload = PWM_AUTORELOAD_PRELOAD_ENABLE; 68 | hpwm->Init.CounterMode = PWM_COUNTERMODE_EDGEALIGNED_DOWN; 69 | hpwm->Init.Prescaler = 4; 70 | hpwm->Init.Period = 99; // Frequency = 40,000,000 / 4 / (99 + 1) = 100,000 = 100KHz 71 | hpwm->Init.Pulse = 19; // Duty Cycle = (19 + 1) / (99 + 1) = 20% 72 | hpwm->Init.OutMode = PWM_OUT_MODE_INDEPENDENT; // Independent mode 73 | hpwm->Channel = channel; 74 | HAL_PWM_Init(hpwm); 75 | } 76 | 77 | void Error_Handler(void) 78 | { 79 | while (1) 80 | { 81 | } 82 | } 83 | 84 | void assert_failed(uint8_t *file, uint32_t line) 85 | { 86 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 87 | } -------------------------------------------------------------------------------- /app/src/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_PWM_MspInit(PWM_HandleTypeDef *hpwm) 9 | { 10 | __HAL_RCC_PWM_CLK_ENABLE(); 11 | __HAL_AFIO_REMAP_PWM0(GPIOB, GPIO_PIN_0); 12 | __HAL_AFIO_REMAP_PWM1(GPIOB, GPIO_PIN_1); 13 | __HAL_AFIO_REMAP_PWM2(GPIOB, GPIO_PIN_2); 14 | } 15 | 16 | void HAL_PWM_MspDeInit(PWM_HandleTypeDef *hpwm) 17 | { 18 | __HAL_RCC_PWM_CLK_DISABLE(); 19 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2); 20 | } 21 | -------------------------------------------------------------------------------- /app/src/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = .. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | 5 | ifndef PDIR 6 | GEN_LIBS = libdemo$(LIB_EXT) 7 | endif 8 | 9 | #DEFINES += 10 | 11 | sinclude $(TOP_DIR)/tools/W806/rules.mk 12 | INCLUDES := $(INCLUDES) -I $(PDIR)include 13 | PDIR := ../$(PDIR) 14 | sinclude $(PDIR)Makefile -------------------------------------------------------------------------------- /demo/adc/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | void Error_Handler(void); 6 | static void ADC_Init(void); 7 | ADC_HandleTypeDef hadc; 8 | 9 | int main(void) 10 | { 11 | int value; 12 | double voltage = 0.0; 13 | 14 | SystemClock_Config(CPU_CLK_160M); 15 | printf("enter main\r\n"); 16 | 17 | ADC_Init(); 18 | while (1) 19 | { 20 | value = HAL_ADC_GET_INPUT_VOLTAGE(&hadc); 21 | printf("value = %dmv\r\n", value); 22 | HAL_Delay(1000); 23 | } 24 | } 25 | 26 | static void ADC_Init(void) 27 | { 28 | hadc.Instance = ADC; 29 | hadc.Init.channel = ADC_CHANNEL_0; 30 | hadc.Init.freq = 1000; 31 | 32 | if (HAL_ADC_Init(&hadc) != HAL_OK) 33 | { 34 | Error_Handler(); 35 | } 36 | } 37 | 38 | void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) 39 | { 40 | 41 | } 42 | 43 | void Error_Handler(void) 44 | { 45 | while (1) 46 | { 47 | } 48 | } 49 | 50 | void assert_failed(uint8_t *file, uint32_t line) 51 | { 52 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 53 | } -------------------------------------------------------------------------------- /demo/adc/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) 9 | { 10 | if (hadc->Instance == ADC) 11 | { 12 | __HAL_RCC_ADC_CLK_ENABLE(); 13 | __HAL_RCC_GPIO_CLK_ENABLE(); 14 | 15 | //ADC_CHANNEL_0 : PA1 16 | //ADC_CHANNEL_1 : PA4 17 | //ADC_CHANNEL_2 : PA3 18 | //ADC_CHANNEL_3 : PA2 19 | //ADC_CHANNEL_0_1 : PA1 and PA4 20 | //ADC_CHANNEL_2_3 : PA3 and PA2 21 | if (hadc->Init.channel == ADC_CHANNEL_0) 22 | { 23 | __HAL_AFIO_REMAP_ADC(GPIOA, GPIO_PIN_1); 24 | } 25 | else if (hadc->Init.channel == ADC_CHANNEL_1) 26 | { 27 | __HAL_AFIO_REMAP_ADC(GPIOA, GPIO_PIN_4); 28 | } 29 | else if (hadc->Init.channel == ADC_CHANNEL_2) 30 | { 31 | __HAL_AFIO_REMAP_ADC(GPIOA, GPIO_PIN_3); 32 | } 33 | else if (hadc->Init.channel == ADC_CHANNEL_3) 34 | { 35 | __HAL_AFIO_REMAP_ADC(GPIOA, GPIO_PIN_2); 36 | } 37 | else if (hadc->Init.channel == ADC_CHANNEL_0_1) 38 | { 39 | __HAL_AFIO_REMAP_ADC(GPIOA, GPIO_PIN_1); 40 | __HAL_AFIO_REMAP_ADC(GPIOA, GPIO_PIN_4); 41 | } 42 | else if (hadc->Init.channel == ADC_CHANNEL_2_3) 43 | { 44 | __HAL_AFIO_REMAP_ADC(GPIOA, GPIO_PIN_3); 45 | __HAL_AFIO_REMAP_ADC(GPIOA, GPIO_PIN_2); 46 | } 47 | 48 | // 如果用到中断方式需要使能中断 49 | HAL_NVIC_SetPriority(ADC_IRQn, 0); 50 | HAL_NVIC_EnableIRQ(ADC_IRQn); 51 | } 52 | } 53 | 54 | void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) 55 | { 56 | __HAL_RCC_ADC_CLK_DISABLE(); 57 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1); 58 | HAL_NVIC_DisableIRQ(ADC_IRQn); 59 | } 60 | 61 | -------------------------------------------------------------------------------- /demo/adc/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | extern ADC_HandleTypeDef hadc; 5 | 6 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 7 | __attribute__((isr)) void CORET_IRQHandler(void) 8 | { 9 | readl(0xE000E010); 10 | HAL_IncTick(); 11 | } 12 | 13 | __attribute__((isr)) void ADC_IRQHandler(void) 14 | { 15 | HAL_ADC_IRQHandler(&hadc); 16 | } -------------------------------------------------------------------------------- /demo/fatfs/fatfs_mmc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOsetting 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __FATFS_MMC_H 16 | #define __FATFS_MMC_H 17 | 18 | #include "wm_hal.h" 19 | #include "ff.h" 20 | #include "diskio.h" 21 | 22 | extern SPI_HandleTypeDef hspi; 23 | extern RTC_TimeTypeDef rtc_time; 24 | 25 | // CS: B4, B14 26 | #define MMC_CS_PORT GPIOB 27 | #define MMC_CS_PIN GPIO_PIN_14 28 | // SCK: B1, B2, B15, B24 29 | #define MMC_SCK_PORT GPIOB 30 | #define MMC_SCK_PIN GPIO_PIN_15 31 | // MOSI: B5, B17, B26, PA7 32 | #define MMC_MOSI_PORT GPIOB 33 | #define MMC_MOSI_PIN GPIO_PIN_17 34 | // MISO: B0, B3, B16, B25 35 | #define MMC_MISO_PORT GPIOB 36 | #define MMC_MISO_PIN GPIO_PIN_16 37 | 38 | #define MMC_CS_LOW __HAL_SPI_SET_CS_LOW(&hspi) 39 | #define MMC_CS_HIGH __HAL_SPI_SET_CS_HIGH(&hspi) 40 | 41 | /* Definitions for MMC/SDC command */ 42 | #define CMD0 (0x40+0) /* GO_IDLE_STATE */ 43 | #define CMD1 (0x40+1) /* SEND_OP_COND */ 44 | #define CMD8 (0x40+8) /* SEND_IF_COND */ 45 | #define CMD9 (0x40+9) /* SEND_CSD */ 46 | #define CMD10 (0x40+10) /* SEND_CID */ 47 | #define CMD12 (0x40+12) /* STOP_TRANSMISSION */ 48 | #define CMD16 (0x40+16) /* SET_BLOCKLEN */ 49 | #define CMD17 (0x40+17) /* READ_SINGLE_BLOCK */ 50 | #define CMD18 (0x40+18) /* READ_MULTIPLE_BLOCK */ 51 | #define CMD23 (0x40+23) /* SET_BLOCK_COUNT */ 52 | #define CMD24 (0x40+24) /* WRITE_BLOCK */ 53 | #define CMD25 (0x40+25) /* WRITE_MULTIPLE_BLOCK */ 54 | #define CMD41 (0x40+41) /* SEND_OP_COND (ACMD) */ 55 | #define CMD55 (0x40+55) /* APP_CMD */ 56 | #define CMD58 (0x40+58) /* READ_OCR */ 57 | 58 | /* MMC card type flags (MMC_GET_TYPE) */ 59 | #define CT_MMC 0x01 /* MMC ver 3 */ 60 | #define CT_SD1 0x02 /* SD ver 1 */ 61 | #define CT_SD2 0x04 /* SD ver 2 */ 62 | #define CT_SDC 0x06 /* SD */ 63 | #define CT_BLOCK 0x08 /* Block addressing */ 64 | 65 | #define ACMD41_HCS 0x40000000 66 | #define ACMD41_SDXC_POWER 0x10000000 67 | #define ACMD41_S18R 0x04000000 68 | #define ACMD41_VOLTAGE 0x00ff8000 69 | #define ACMD41_ARG_HC (ACMD41_HCS|ACMD41_SDXC_POWER|ACMD41_VOLTAGE) 70 | #define ACMD41_ARG_SC (ACMD41_VOLTAGE) 71 | 72 | #define SPI_TIMEOUT 100 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /demo/fatfs/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | #include "fatfs_mmc.h" 3 | 4 | void HAL_MspInit(void) 5 | { 6 | 7 | } 8 | 9 | void HAL_PMU_MspInit(PMU_HandleTypeDef *hpmu) 10 | { 11 | HAL_NVIC_EnableIRQ(PMU_IRQn); 12 | } 13 | 14 | void HAL_PMU_MspDeInit(PMU_HandleTypeDef *hpmu) 15 | { 16 | HAL_NVIC_DisableIRQ(PMU_IRQn); 17 | } 18 | 19 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 20 | { 21 | __HAL_RCC_SPI_CLK_ENABLE(); 22 | __HAL_AFIO_REMAP_SPI_CS(MMC_CS_PORT, MMC_CS_PIN); 23 | __HAL_AFIO_REMAP_SPI_CLK(MMC_SCK_PORT, MMC_SCK_PIN); 24 | __HAL_AFIO_REMAP_SPI_MOSI(MMC_MOSI_PORT, MMC_MOSI_PIN); 25 | __HAL_AFIO_REMAP_SPI_MISO(MMC_MISO_PORT, MMC_MISO_PIN); 26 | } 27 | 28 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 29 | { 30 | __HAL_RCC_SPI_CLK_DISABLE(); 31 | HAL_GPIO_DeInit(MMC_CS_PORT, MMC_CS_PIN); 32 | HAL_GPIO_DeInit(MMC_SCK_PORT, MMC_SCK_PIN); 33 | HAL_GPIO_DeInit(MMC_MOSI_PORT, MMC_MOSI_PIN); 34 | HAL_GPIO_DeInit(MMC_MISO_PORT, MMC_MISO_PIN); 35 | } -------------------------------------------------------------------------------- /demo/fatfs/wm_it.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | extern PMU_HandleTypeDef hpmu; 4 | 5 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 6 | __attribute__((isr)) void CORET_IRQHandler(void) 7 | { 8 | readl(0xE000E010); 9 | HAL_IncTick(); 10 | } 11 | __attribute__((isr)) void PMU_IRQHandler(void) 12 | { 13 | HAL_PMU_IRQHandler(&hpmu); 14 | } -------------------------------------------------------------------------------- /demo/flash/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | void Error_Handler(void); 6 | 7 | /******************************0x80FFFFF 8 | * USER PARAM 9 | * ****************************0x80XXXXX 10 | * RUN IMAGE 11 | * ****************************0x8010400 12 | * RUN IMAGE HEADER 13 | * ****************************0x8010000 14 | * SECBOOT IMAGE 15 | * ****************************0x8002400 16 | * SECBOOT IMAGE HEAER 17 | * ****************************0x8002000 18 | * CHIP DATA 19 | * ****************************0x8000000*/ 20 | 21 | #define LEN 5000 22 | #define TEST_ADDR 0x80000 23 | uint8_t test_buf[LEN]={0}; 24 | 25 | int main(void) 26 | { 27 | int i = 0; 28 | 29 | SystemClock_Config(CPU_CLK_160M); 30 | printf("enter main\r\n"); 31 | for (i = 0; i < LEN; i++) 32 | { 33 | test_buf[i] = i % 256; 34 | } 35 | 36 | HAL_FLASH_Write(TEST_ADDR, test_buf, 100); 37 | HAL_FLASH_Write(TEST_ADDR + 100, test_buf + 100, 4096); 38 | HAL_FLASH_Write(TEST_ADDR + 100 + 4096, test_buf + 100 + 4096, LEN - 100 - 4096); 39 | 40 | memset(test_buf, 0, LEN); 41 | HAL_FLASH_Read(TEST_ADDR, test_buf, LEN); 42 | for (i = 0; i < 100; i++) 43 | { 44 | if (test_buf[i] != (i % 256)) 45 | { 46 | printf("test failed\r\n"); 47 | break; 48 | } 49 | } 50 | if (i == 100) 51 | { 52 | printf("test success\r\n"); 53 | } 54 | 55 | while (1) 56 | { 57 | printf("."); 58 | HAL_Delay(1000); 59 | } 60 | } 61 | 62 | void Error_Handler(void) 63 | { 64 | while (1) 65 | { 66 | } 67 | } 68 | 69 | void assert_failed(uint8_t *file, uint32_t line) 70 | { 71 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 72 | } -------------------------------------------------------------------------------- /demo/flash/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | -------------------------------------------------------------------------------- /demo/flash/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/freertos/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | #include "FreeRTOS.h" 5 | #include "task.h" 6 | 7 | void Error_Handler(void); 8 | void task1_handle(void *p); 9 | void task2_handle(void *p); 10 | 11 | const HeapRegion_t xHeapRegions[] = 12 | { 13 | { ( uint8_t * ) 0x20020000UL, 0x5000 }, 14 | { NULL, 0 }/*终止数组 */ 15 | }; 16 | 17 | TaskHandle_t htask1 = NULL; 18 | TaskHandle_t htask2 = NULL; 19 | 20 | /* 使用RreeRTOS时,需要将/include/arch/xt804/csi_config.h里 21 | * 的#define CONFIG_KERNEL_NONE 1宏定义注释掉,否则os的systic 22 | * 会出错导致os系统异常 23 | */ 24 | int main(void) 25 | { 26 | SystemClock_Config(CPU_CLK_160M); 27 | printf("enter main\r\n"); 28 | 29 | vPortDefineHeapRegions( xHeapRegions ); 30 | xTaskCreate(task1_handle, "task1", 512, NULL, 35, &htask1); 31 | xTaskCreate(task2_handle, "task2", 512, NULL, 32, &htask2); 32 | vTaskStartScheduler(); 33 | 34 | return 0; 35 | } 36 | 37 | void task1_handle(void *p) 38 | { 39 | for (;;) 40 | { 41 | printf("task1_handle\r\n"); 42 | vTaskDelay(1000); 43 | } 44 | } 45 | 46 | void task2_handle(void *p) 47 | { 48 | for (;;) 49 | { 50 | printf("task2_handle\r\n"); 51 | vTaskDelay(1000); 52 | } 53 | } 54 | 55 | void Error_Handler(void) 56 | { 57 | while (1) 58 | { 59 | } 60 | } 61 | 62 | void assert_failed(uint8_t *file, uint32_t line) 63 | { 64 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 65 | } -------------------------------------------------------------------------------- /demo/freertos/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | -------------------------------------------------------------------------------- /demo/freertos/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | #include "FreeRTOS.h" 4 | #include "task.h" 5 | #include "FreeRTOSConfig.h" 6 | 7 | 8 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 9 | __attribute__((isr)) void CORET_IRQHandler(void) 10 | { 11 | readl(0xE000E010); 12 | HAL_IncTick(); 13 | 14 | #if (INCLUDE_xTaskGetSchedulerState == 1) 15 | if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) 16 | { 17 | #endif 18 | xPortSysTickHandler(); 19 | #if (INCLUDE_xTaskGetSchedulerState == 1) 20 | } 21 | #endif 22 | } 23 | -------------------------------------------------------------------------------- /demo/gpio/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | void Error_Handler(void); 6 | static void GPIO_Init(void); 7 | 8 | static volatile uint8_t key_flag = 0; 9 | 10 | int main(void) 11 | { 12 | SystemClock_Config(CPU_CLK_160M); 13 | printf("enter main\r\n"); 14 | HAL_Init(); 15 | GPIO_Init(); 16 | 17 | while (1) 18 | { 19 | if (key_flag == 1) 20 | { 21 | HAL_Delay(20); 22 | if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5) == GPIO_PIN_RESET) 23 | { 24 | HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2); 25 | } 26 | key_flag = 0; 27 | } 28 | } 29 | 30 | return 0; 31 | } 32 | 33 | static void GPIO_Init(void) 34 | { 35 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 36 | 37 | __HAL_RCC_GPIO_CLK_ENABLE(); 38 | 39 | GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2; 40 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT; 41 | GPIO_InitStruct.Pull = GPIO_NOPULL; 42 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 43 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2, GPIO_PIN_SET); 44 | 45 | GPIO_InitStruct.Pin = GPIO_PIN_5; 46 | GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; 47 | GPIO_InitStruct.Pull = GPIO_PULLUP; 48 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 49 | 50 | HAL_NVIC_SetPriority(GPIOB_IRQn, 0); 51 | HAL_NVIC_EnableIRQ(GPIOB_IRQn); 52 | 53 | } 54 | 55 | void HAL_GPIO_EXTI_Callback(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) 56 | { 57 | if ((GPIOx == GPIOB) && (GPIO_Pin == GPIO_PIN_5)) 58 | { 59 | key_flag = 1; 60 | } 61 | } 62 | 63 | void Error_Handler(void) 64 | { 65 | while (1) 66 | { 67 | } 68 | } 69 | 70 | void assert_failed(uint8_t *file, uint32_t line) 71 | { 72 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 73 | } -------------------------------------------------------------------------------- /demo/gpio/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | -------------------------------------------------------------------------------- /demo/gpio/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | 11 | __attribute__((isr)) void GPIOA_IRQHandler(void) 12 | { 13 | HAL_GPIO_EXTI_IRQHandler(GPIOA, GPIO_PIN_0); 14 | } 15 | 16 | __attribute__((isr)) void GPIOB_IRQHandler(void) 17 | { 18 | HAL_GPIO_EXTI_IRQHandler(GPIOB, GPIO_PIN_5); 19 | } 20 | -------------------------------------------------------------------------------- /demo/i2c/at24cxx/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | I2C_HandleTypeDef hi2c; 6 | void Error_Handler(void); 7 | static void I2C_Init(void); 8 | static void GPIO_Init(void); 9 | 10 | #define DEVICE_ADDR 0xA0 11 | 12 | int main(void) 13 | { 14 | char *w_buf = "AT24CXX I2C WRITE THEN READ TEST FOR LONG TIME"; 15 | uint8_t len = strlen(w_buf); 16 | uint8_t r_buf[50] = {0}; 17 | int i = 0; 18 | 19 | SystemClock_Config(CPU_CLK_160M); 20 | printf("enter main\r\n"); 21 | printf("len = %d\n", len); 22 | GPIO_Init(); 23 | I2C_Init(); 24 | for (i = 0; i < len; i++) 25 | { 26 | HAL_I2C_Write(&hi2c, DEVICE_ADDR, 0x00 + i, (uint8_t *)(w_buf + i), 1); 27 | HAL_Delay(10); 28 | } 29 | 30 | while (1) 31 | { 32 | memset(r_buf, 0, len); 33 | if (HAL_I2C_Read(&hi2c, DEVICE_ADDR, 0x00, r_buf, len) != HAL_OK) 34 | { 35 | printf("read failed\r\n"); 36 | } 37 | if (memcmp(w_buf, r_buf, len)) 38 | { 39 | printf("err: %s\r\n", r_buf); 40 | } 41 | i++; 42 | if ((i % 10000) == 0) 43 | { 44 | printf("i = %d\r\n", i); 45 | } 46 | } 47 | 48 | while (1) 49 | { 50 | HAL_Delay(1000); 51 | } 52 | } 53 | 54 | static void I2C_Init(void) 55 | { 56 | hi2c.Instance = I2C; 57 | hi2c.Frequency = 400000; 58 | HAL_I2C_Init(&hi2c); 59 | } 60 | 61 | static void GPIO_Init(void) 62 | { 63 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 64 | __HAL_RCC_GPIO_CLK_ENABLE(); 65 | GPIO_InitStruct.Pin = GPIO_PIN_1; 66 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT; 67 | GPIO_InitStruct.Pull = GPIO_PULLUP; 68 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 69 | GPIO_InitStruct.Pin = GPIO_PIN_4; 70 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT; 71 | GPIO_InitStruct.Pull = GPIO_PULLUP; 72 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 73 | } 74 | 75 | void Error_Handler(void) 76 | { 77 | while (1) 78 | { 79 | } 80 | } 81 | 82 | void assert_failed(uint8_t *file, uint32_t line) 83 | { 84 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 85 | } -------------------------------------------------------------------------------- /demo/i2c/at24cxx/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) 9 | { 10 | __HAL_RCC_I2C_CLK_ENABLE(); 11 | __HAL_AFIO_REMAP_I2C_SCL(GPIOA, GPIO_PIN_1); 12 | __HAL_AFIO_REMAP_I2C_SDA(GPIOA, GPIO_PIN_4); 13 | } 14 | 15 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c) 16 | { 17 | __HAL_RCC_I2C_CLK_DISABLE(); 18 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1); 19 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4); 20 | } 21 | -------------------------------------------------------------------------------- /demo/i2c/at24cxx/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/i2c/ssd1306_oled/ssd1306.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOsetting 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __SSD1306_H__ 16 | #define __SSD1306_H__ 17 | 18 | /* C++ detection */ 19 | #ifdef __cplusplus 20 | extern C { 21 | #endif 22 | 23 | /** 24 | * This SSD1306 LCD uses I2C for communication 25 | * 26 | * Library features functions for drawing lines, rectangles and circles. 27 | * 28 | * It also allows you to draw texts and characters using appropriate functions provided in library. 29 | * 30 | * Default pinout 31 | * 32 | SSD1306 |W806 |DESCRIPTION 33 | 34 | VCC |3.3V | 35 | GND |GND | 36 | SCL |PA1 |Serial clock line 37 | SDA |PA4 |Serial data line 38 | */ 39 | 40 | #include "wm_hal.h" 41 | #include "ascii_fonts.h" 42 | 43 | #include "stdlib.h" 44 | #include "string.h" 45 | 46 | /** 47 | * Mode switch: 0 - SPI, 1 - I2C 48 | */ 49 | #define SSD1306_MODE_I2C 1 50 | 51 | #if SSD1306_MODE_I2C 52 | #define SSD1306_SCL_PORT GPIOA 53 | #define SSD1306_SCL_PIN GPIO_PIN_1 54 | #define SSD1306_SDA_PORT GPIOA 55 | #define SSD1306_SDA_PIN GPIO_PIN_4 56 | 57 | /* I2C address 58 | * address: 7 bit slave address, left aligned, bits 7:1 are used, LSB bit is not used 59 | */ 60 | #ifndef SSD1306_I2C_ADDR 61 | #define SSD1306_I2C_ADDR 0x78 62 | //#define SSD1306_I2C_ADDR 0x7A 63 | #endif 64 | 65 | #else 66 | 67 | // CS: B4, B14 68 | #define SSD1306_CS_PORT GPIOB 69 | #define SSD1306_CS_PIN GPIO_PIN_14 70 | // SCK: B1, B2, B15, B24 71 | #define SSD1306_SCK_PORT GPIOB 72 | #define SSD1306_SCK_PIN GPIO_PIN_15 73 | // MOSI: B5, B17, B26, PA7 74 | #define SSD1306_MOSI_PORT GPIOB 75 | #define SSD1306_MOSI_PIN GPIO_PIN_17 76 | // MISO: B0, B3, B16, B25 77 | 78 | #define SSD1306_RES_PORT GPIOB 79 | #define SSD1306_RES_PIN GPIO_PIN_10 80 | #define SSD1306_DC_PORT GPIOB 81 | #define SSD1306_DC_PIN GPIO_PIN_11 82 | 83 | #define SSD1306_CS_LOW __HAL_SPI_SET_CS_LOW(&hspi) 84 | #define SSD1306_CS_HIGH __HAL_SPI_SET_CS_HIGH(&hspi) 85 | #define SSD1306_DC_LOW HAL_GPIO_WritePin(SSD1306_DC_PORT, SSD1306_DC_PIN, GPIO_PIN_RESET) 86 | #define SSD1306_DC_HIGH HAL_GPIO_WritePin(SSD1306_DC_PORT, SSD1306_DC_PIN, GPIO_PIN_SET) 87 | #define SSD1306_RESET_LOW HAL_GPIO_WritePin(SSD1306_RES_PORT, SSD1306_RES_PIN, GPIO_PIN_RESET) 88 | #define SSD1306_RESET_HIGH HAL_GPIO_WritePin(SSD1306_RES_PORT, SSD1306_RES_PIN, GPIO_PIN_SET) 89 | 90 | #endif 91 | 92 | /* SSD1306 settings */ 93 | /* SSD1306 width in pixels */ 94 | #ifndef SSD1306_WIDTH 95 | #define SSD1306_WIDTH 128 96 | #endif 97 | /* SSD1306 LCD height in pixels */ 98 | #ifndef SSD1306_HEIGHT 99 | #define SSD1306_HEIGHT 64 100 | #endif 101 | 102 | #ifndef SSD1306_TIMEOUT 103 | #define SSD1306_TIMEOUT 20000 104 | #endif 105 | 106 | #define SSD1306_COLOR_BLACK 0x00 107 | #define SSD1306_COLOR_WHITE 0x01 108 | 109 | uint8_t SSD1306_Init(void); 110 | void SSD1306_UpdateScreen(void); 111 | void SSD1306_ToggleInvert(void); 112 | void SSD1306_Fill(uint8_t Color); 113 | void SSD1306_DrawPixel(uint16_t x, uint16_t y, uint8_t color); 114 | void SSD1306_GotoXY(uint16_t x, uint16_t y); 115 | char SSD1306_Putc(char ch, FontDef_t* Font, uint8_t color); 116 | char SSD1306_Puts(char* str, FontDef_t* Font, uint8_t color); 117 | void SSD1306_DrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint8_t c); 118 | void SSD1306_DrawCircle(int16_t x0, int16_t y0, int16_t r, uint8_t c); 119 | void SSD1306_Image(uint8_t *img, uint8_t frame, uint8_t x, uint8_t y); 120 | 121 | /** 122 | * @brief Writes single byte command to slave 123 | * @param command: command to be written 124 | * @retval None 125 | */ 126 | void SSD1306_WriteCommand(uint8_t command); 127 | 128 | /** 129 | * @brief Writes single byte data to slave 130 | * @param data: data to be written 131 | * @retval None 132 | */ 133 | void SSD1306_WriteData(uint8_t data); 134 | 135 | /* C++ detection */ 136 | #ifdef __cplusplus 137 | } 138 | #endif 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /demo/i2c/ssd1306_oled/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | #include "ssd1306.h" 3 | 4 | void HAL_MspInit(void) 5 | { 6 | 7 | } 8 | 9 | #if SSD1306_MODE_I2C 10 | 11 | void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) 12 | { 13 | __HAL_RCC_I2C_CLK_ENABLE(); 14 | __HAL_AFIO_REMAP_I2C_SCL(SSD1306_SCL_PORT, SSD1306_SCL_PIN); 15 | __HAL_AFIO_REMAP_I2C_SDA(SSD1306_SDA_PORT, SSD1306_SDA_PIN); 16 | } 17 | 18 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c) 19 | { 20 | __HAL_RCC_I2C_CLK_DISABLE(); 21 | HAL_GPIO_DeInit(SSD1306_SCL_PORT, SSD1306_SCL_PIN); 22 | HAL_GPIO_DeInit(SSD1306_SDA_PORT, SSD1306_SDA_PIN); 23 | } 24 | 25 | #else 26 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 27 | { 28 | __HAL_RCC_SPI_CLK_ENABLE(); 29 | __HAL_AFIO_REMAP_SPI_CS(SSD1306_CS_PORT, SSD1306_CS_PIN); 30 | __HAL_AFIO_REMAP_SPI_CLK(SSD1306_SCK_PORT, SSD1306_SCK_PIN); 31 | __HAL_AFIO_REMAP_SPI_MOSI(SSD1306_MOSI_PORT, SSD1306_MOSI_PIN); 32 | } 33 | 34 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 35 | { 36 | __HAL_RCC_SPI_CLK_DISABLE(); 37 | HAL_GPIO_DeInit(SSD1306_CS_PORT, SSD1306_CS_PIN); 38 | HAL_GPIO_DeInit(SSD1306_SCK_PORT, SSD1306_SCK_PIN); 39 | HAL_GPIO_DeInit(SSD1306_MOSI_PORT, SSD1306_MOSI_PIN); 40 | } 41 | #endif -------------------------------------------------------------------------------- /demo/i2c/ssd1306_oled/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/i2s/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | I2S_HandleTypeDef hi2s; 6 | DMA_HandleTypeDef hdma_i2s_tx; 7 | DMA_HandleTypeDef hdma_i2s_rx; 8 | 9 | static void I2S_Init(void); 10 | static void DMA_Init(void); 11 | void Error_Handler(void); 12 | 13 | uint32_t tx_buf[1000] = {0}; 14 | uint32_t rx_buf[1000] = {0}; 15 | 16 | int main(void) 17 | { 18 | int i = 0; 19 | SystemClock_Config(CPU_CLK_160M); 20 | printf("enter main\r\n"); 21 | HAL_Init(); 22 | DMA_Init(); 23 | I2S_Init(); 24 | 25 | for (i = 0; i < 1000; i++) 26 | { 27 | tx_buf[i] = i; 28 | rx_buf[i] = i; 29 | } 30 | 31 | HAL_I2S_Transmit_DMA(&hi2s, (uint32_t *)tx_buf, 1000); 32 | 33 | // HAL_I2S_Receive_DMA(&hi2s, (uint32_t *)rx_buf, 1000); 34 | while (1) 35 | { 36 | printf("."); 37 | HAL_Delay(1000); 38 | } 39 | } 40 | 41 | static void I2S_Init(void) 42 | { 43 | hi2s.Instance = I2S; 44 | hi2s.Init.Mode = I2S_MODE_MASTER; 45 | hi2s.Init.Standard = I2S_STANDARD_PHILIPS; 46 | hi2s.Init.DataFormat = I2S_DATAFORMAT_32B; 47 | hi2s.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE; 48 | hi2s.Init.AudioFreq = I2S_AUDIOFREQ_44K; 49 | hi2s.Init.Channel = I2S_CHANNEL_MONO; 50 | hi2s.Init.ChannelSel = I2S_CHANNELSEL_LEFT; 51 | if (HAL_I2S_Init(&hi2s) != HAL_OK) 52 | { 53 | Error_Handler(); 54 | } 55 | } 56 | 57 | static void DMA_Init(void) 58 | { 59 | __HAL_RCC_DMA_CLK_ENABLE(); 60 | 61 | HAL_NVIC_SetPriority(DMA_Channel0_IRQn, 0); 62 | HAL_NVIC_EnableIRQ(DMA_Channel0_IRQn); 63 | 64 | HAL_NVIC_SetPriority(DMA_Channel1_IRQn, 0); 65 | HAL_NVIC_EnableIRQ(DMA_Channel1_IRQn); 66 | } 67 | 68 | void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) 69 | { 70 | printf("tx halfcplt\r\n"); 71 | } 72 | 73 | void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) 74 | { 75 | printf("tx cplt\r\n"); 76 | } 77 | 78 | void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) 79 | { 80 | printf("rx halfcplt\r\n"); 81 | } 82 | 83 | void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) 84 | { 85 | printf("rx cmplt\r\n"); 86 | } 87 | 88 | void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s) 89 | { 90 | printf("err cb\r\n"); 91 | } 92 | 93 | void Error_Handler(void) 94 | { 95 | while (1) 96 | { 97 | printf("error handler\r\n"); 98 | } 99 | } 100 | 101 | void assert_failed(uint8_t *file, uint32_t line) 102 | { 103 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 104 | } -------------------------------------------------------------------------------- /demo/i2s/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | extern DMA_HandleTypeDef hdma_i2s_tx; 4 | extern DMA_HandleTypeDef hdma_i2s_rx; 5 | 6 | static DMA_LinkDescriptor tx_desc[2]; 7 | static DMA_LinkDescriptor rx_desc[2]; 8 | 9 | extern void Error_Handler(void); 10 | 11 | void HAL_MspInit(void) 12 | { 13 | 14 | } 15 | 16 | void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s) 17 | { 18 | if (hi2s->Instance == I2S) 19 | { 20 | __HAL_RCC_I2S_CLK_ENABLE(); 21 | __HAL_RCC_GPIO_CLK_ENABLE(); 22 | 23 | __HAL_AFIO_REMAP_I2S_MCK(GPIOA, GPIO_PIN_7); 24 | __HAL_AFIO_REMAP_I2S_WS(GPIOB, GPIO_PIN_9); 25 | __HAL_AFIO_REMAP_I2S_CK(GPIOB, GPIO_PIN_8); 26 | __HAL_AFIO_REMAP_I2S_MOSI(GPIOB, GPIO_PIN_11); 27 | __HAL_AFIO_REMAP_I2S_MISO(GPIOB, GPIO_PIN_10); 28 | 29 | hdma_i2s_tx.Instance = DMA_Channel0; 30 | hdma_i2s_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; 31 | hdma_i2s_tx.Init.DestInc = DMA_DINC_DISABLE; 32 | hdma_i2s_tx.Init.SrcInc = DMA_SINC_ENABLE; 33 | hdma_i2s_tx.Init.DataAlignment = DMA_DATAALIGN_WORD; 34 | hdma_i2s_tx.Init.Mode = DMA_MODE_LINK_SINGLE; 35 | hdma_i2s_tx.Init.RequestSourceSel = DMA_REQUEST_SOURCE_I2S_TX; 36 | 37 | hdma_i2s_tx.LinkDesc = tx_desc; 38 | 39 | if (HAL_DMA_Init(&hdma_i2s_tx) != HAL_OK) 40 | { 41 | Error_Handler(); 42 | } 43 | __HAL_LINKDMA(hi2s, hdmatx, hdma_i2s_tx); 44 | 45 | hdma_i2s_rx.Instance = DMA_Channel1; 46 | hdma_i2s_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; 47 | hdma_i2s_rx.Init.DestInc = DMA_DINC_ENABLE; 48 | hdma_i2s_rx.Init.SrcInc = DMA_SINC_DISABLE; 49 | hdma_i2s_rx.Init.DataAlignment = DMA_DATAALIGN_WORD; 50 | hdma_i2s_rx.Init.Mode = DMA_MODE_LINK_SINGLE; 51 | hdma_i2s_rx.Init.RequestSourceSel = DMA_REQUEST_SOURCE_I2S_RX; 52 | 53 | hdma_i2s_rx.LinkDesc = rx_desc; 54 | 55 | if (HAL_DMA_Init(&hdma_i2s_rx) != HAL_OK) 56 | { 57 | Error_Handler(); 58 | } 59 | __HAL_LINKDMA(hi2s, hdmarx, hdma_i2s_rx); 60 | 61 | HAL_NVIC_SetPriority(I2S_IRQn, 1); 62 | HAL_NVIC_EnableIRQ(I2S_IRQn); 63 | } 64 | } 65 | 66 | void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s) 67 | { 68 | if (hi2s->Instance == I2S) 69 | { 70 | __HAL_RCC_I2S_CLK_DISABLE(); 71 | 72 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7); 73 | HAL_GPIO_DeInit(GPIOB, (GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11)); 74 | } 75 | } -------------------------------------------------------------------------------- /demo/i2s/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | extern I2S_HandleTypeDef hi2s; 5 | extern DMA_HandleTypeDef hdma_i2s_tx; 6 | extern DMA_HandleTypeDef hdma_i2s_rx; 7 | 8 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 9 | __attribute__((isr)) void CORET_IRQHandler(void) 10 | { 11 | readl(0xE000E010); 12 | HAL_IncTick(); 13 | } 14 | 15 | __attribute__((isr)) void I2S_IRQHandler(void) 16 | { 17 | HAL_I2S_IRQHandler(&hi2s); 18 | } 19 | 20 | __attribute__((isr)) void DMA_Channel0_IRQHandler(void) 21 | { 22 | HAL_DMA_IRQHandler(&hdma_i2s_tx); 23 | } 24 | 25 | __attribute__((isr)) void DMA_Channel1_IRQHandler(void) 26 | { 27 | HAL_DMA_IRQHandler(&hdma_i2s_rx); 28 | } -------------------------------------------------------------------------------- /demo/pmu/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | PMU_HandleTypeDef hpmu; 6 | void Error_Handler(void); 7 | static void PMU_Init(void); 8 | static void PMU_Sleep_Tim0(void); 9 | static void PMU_Sleep_IO(void); 10 | static void PMU_Standby_Tim0(void); 11 | static void PMU_Standby_IO(void); 12 | 13 | int main(void) 14 | { 15 | SystemClock_Config(CPU_CLK_160M); 16 | printf("enter main\r\n"); 17 | 18 | PMU_Init(); 19 | PMU_Standby_IO(); 20 | while (1) 21 | { 22 | printf("."); 23 | HAL_Delay(1000); 24 | } 25 | } 26 | 27 | static void PMU_Init(void) 28 | { 29 | hpmu.Instance = PMU; 30 | hpmu.ClkSource = PMU_CLKSOURCE_32RC; 31 | 32 | HAL_PMU_Init(&hpmu); 33 | } 34 | 35 | static void PMU_Sleep_Tim0(void) 36 | { 37 | HAL_PMU_TIMER0_Start(&hpmu, 5); 38 | while (1) 39 | { 40 | HAL_PMU_Enter_Sleep(&hpmu); 41 | printf("."); 42 | } 43 | } 44 | 45 | static void PMU_Sleep_IO(void) 46 | { 47 | HAL_PMU_Enter_Sleep(&hpmu); 48 | } 49 | 50 | static void PMU_Standby_Tim0(void) 51 | { 52 | HAL_PMU_TIMER0_Start(&hpmu, 5); 53 | HAL_PMU_Enter_Standby(&hpmu); 54 | } 55 | 56 | static void PMU_Standby_IO(void) 57 | { 58 | HAL_PMU_Enter_Standby(&hpmu); 59 | } 60 | 61 | void HAL_PMU_Tim0_Callback(PMU_HandleTypeDef *hpmu) 62 | { 63 | printf("pmu tim0 callback\r\n"); 64 | } 65 | 66 | void HAL_PMU_IO_Callback(PMU_HandleTypeDef *hpmu) 67 | { 68 | printf("pmu io callback\r\n"); 69 | } 70 | 71 | void Error_Handler(void) 72 | { 73 | while (1) 74 | { 75 | } 76 | } 77 | 78 | void assert_failed(uint8_t *file, uint32_t line) 79 | { 80 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 81 | } -------------------------------------------------------------------------------- /demo/pmu/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_PMU_MspInit(PMU_HandleTypeDef *hpmu) 9 | { 10 | HAL_NVIC_EnableIRQ(PMU_IRQn); 11 | } 12 | 13 | void HAL_PMU_MspDeInit(PMU_HandleTypeDef *hpmu) 14 | { 15 | HAL_NVIC_DisableIRQ(PMU_IRQn); 16 | } -------------------------------------------------------------------------------- /demo/pmu/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | extern PMU_HandleTypeDef hpmu; 5 | 6 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 7 | __attribute__((isr)) void CORET_IRQHandler(void) 8 | { 9 | readl(0xE000E010); 10 | HAL_IncTick(); 11 | } 12 | 13 | __attribute__((isr)) void PMU_IRQHandler(void) 14 | { 15 | HAL_PMU_IRQHandler(&hpmu); 16 | } -------------------------------------------------------------------------------- /demo/pwm/2_led_fade_complementary/main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file main.c 4 | * \author IOsetting | iosetting@outlook.com 5 | * \date 6 | * \brief Demo code of PWM in 2-complementary mode 7 | * \note This will drive 4 LEDs (3 onboard and 1 external) to show 2-complementary mode 8 | * \version v0.1 9 | * \ingroup demo 10 | * \remarks test-board: HLK-W806-KIT-V1.0 11 | * PWM Frequency = 40MHz / Prescaler / (Period + 1); 12 | * Duty Cycle(Edge Aligned) = (Pulse + 1) / (Period + 1) 13 | * Duty Cycle(Center Aligned) = (2 * Pulse + 1) / (2 * (Period + 1)) 14 | * 15 | * Connect PB3 to an external LED for PWM3 output 16 | * PB3 -> ext LED1(-) 17 | * 3V3 -> ext LED1(+)(with 1KR resistor) 18 | * 19 | ******************************************************************************/ 20 | 21 | #include 22 | #include "wm_hal.h" 23 | 24 | #define DUTY_MAX 100 25 | #define DUTY_MIN 0 26 | PWM_HandleTypeDef pwm[2]; 27 | int i, j, m[2] = {0}, d[2] = {DUTY_MIN, (DUTY_MIN + DUTY_MAX) / 2}; 28 | 29 | static void PWM_Init(PWM_HandleTypeDef *hpwm, uint32_t channel); 30 | void Error_Handler(void); 31 | 32 | int main(void) 33 | { 34 | SystemClock_Config(CPU_CLK_160M); 35 | printf("enter main\r\n"); 36 | 37 | PWM_Init(pwm + 1, PWM_CHANNEL_2); 38 | HAL_PWM_Start(pwm + 1); 39 | PWM_Init(pwm, PWM_CHANNEL_0); 40 | HAL_PWM_Start(pwm); 41 | 42 | while (1) 43 | { 44 | for (i = 0; i < 2; i++) 45 | { 46 | if (m[i] == 0) // Increasing 47 | { 48 | HAL_PWM_Duty_Set(pwm + i, d[i]++); 49 | if (d[i] == DUTY_MAX) 50 | { 51 | m[i] = 1; 52 | } 53 | } 54 | else // Decreasing 55 | { 56 | HAL_PWM_Duty_Set(pwm + i, d[i]--); 57 | if (d[i] == DUTY_MIN) 58 | { 59 | m[i] = 0; 60 | } 61 | } 62 | } 63 | HAL_Delay(20); 64 | } 65 | } 66 | 67 | static void PWM_Init(PWM_HandleTypeDef *hpwm, uint32_t channel) 68 | { 69 | hpwm->Instance = PWM; 70 | hpwm->Init.AutoReloadPreload = PWM_AUTORELOAD_PRELOAD_ENABLE; 71 | hpwm->Init.CounterMode = PWM_COUNTERMODE_EDGEALIGNED_DOWN; 72 | hpwm->Init.Prescaler = 4; 73 | hpwm->Init.Period = 99; // Frequency = 40,000,000 / 4 / (99 + 1) = 100,000 = 100KHz 74 | hpwm->Init.Pulse = 19; // Duty Cycle = (19 + 1) / (99 + 1) = 20% 75 | hpwm->Init.OutMode = PWM_OUT_MODE_2COMPLEMENTARY; // 2-channel complementary mode 76 | hpwm->Channel = channel; // Only Channel 0 and Channel 2 are allowed 77 | HAL_PWM_Init(hpwm); 78 | } 79 | 80 | void Error_Handler(void) 81 | { 82 | while (1) 83 | { 84 | } 85 | } 86 | 87 | void assert_failed(uint8_t *file, uint32_t line) 88 | { 89 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 90 | } -------------------------------------------------------------------------------- /demo/pwm/2_led_fade_complementary/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_PWM_MspInit(PWM_HandleTypeDef *hpwm) 9 | { 10 | __HAL_RCC_PWM_CLK_ENABLE(); 11 | __HAL_AFIO_REMAP_PWM0(GPIOB, GPIO_PIN_0); 12 | __HAL_AFIO_REMAP_PWM1(GPIOB, GPIO_PIN_1); 13 | __HAL_AFIO_REMAP_PWM2(GPIOB, GPIO_PIN_2); 14 | __HAL_AFIO_REMAP_PWM3(GPIOB, GPIO_PIN_3); 15 | } 16 | 17 | void HAL_PWM_MspDeInit(PWM_HandleTypeDef *hpwm) 18 | { 19 | __HAL_RCC_PWM_CLK_DISABLE(); 20 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0); 21 | } 22 | -------------------------------------------------------------------------------- /demo/pwm/2_led_fade_complementary/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/pwm/2_led_fade_synchronized/main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file main.c 4 | * \author IOsetting | iosetting@outlook.com 5 | * \date 6 | * \brief Demo code of PWM in 2-sync mode 7 | * \note This will drive 4 LEDs (3 onboard and 1 external) to show 2-sync mode 8 | * \version v0.1 9 | * \ingroup demo 10 | * \remarks test-board: HLK-W806-KIT-V1.0 11 | * PWM Frequency = 40MHz / Prescaler / (Period + 1); 12 | * Duty Cycle(Edge Aligned) = (Pulse + 1) / (Period + 1) 13 | * Duty Cycle(Center Aligned) = (2 * Pulse + 1) / (2 * (Period + 1)) 14 | * 15 | * Connect PB3 to an external LED for PWM3 output 16 | * PB3 -> ext LED1(-) 17 | * 3V3 -> ext LED1(+)(with 1KR resistor) 18 | * 19 | ******************************************************************************/ 20 | 21 | #include 22 | #include "wm_hal.h" 23 | 24 | #define DUTY_MAX 100 25 | #define DUTY_MIN 50 26 | PWM_HandleTypeDef pwm[2]; 27 | int i, j, m[2] = {0}, d[2] = {DUTY_MIN, (DUTY_MIN + DUTY_MAX) / 2}; 28 | 29 | static void PWM_Init(PWM_HandleTypeDef *hpwm, uint32_t channel); 30 | void Error_Handler(void); 31 | 32 | int main(void) 33 | { 34 | SystemClock_Config(CPU_CLK_160M); 35 | printf("enter main\r\n"); 36 | 37 | PWM_Init(pwm + 1, PWM_CHANNEL_2); 38 | HAL_PWM_Start(pwm + 1); 39 | PWM_Init(pwm, PWM_CHANNEL_0); 40 | HAL_PWM_Start(pwm); 41 | 42 | while (1) 43 | { 44 | for (i = 0; i < 2; i++) 45 | { 46 | if (m[i] == 0) // Increasing 47 | { 48 | HAL_PWM_Duty_Set(pwm + i, d[i]++); 49 | if (d[i] == DUTY_MAX) 50 | { 51 | m[i] = 1; 52 | } 53 | } 54 | else // Decreasing 55 | { 56 | HAL_PWM_Duty_Set(pwm + i, d[i]--); 57 | if (d[i] == DUTY_MIN) 58 | { 59 | m[i] = 0; 60 | } 61 | } 62 | } 63 | HAL_Delay(20); 64 | } 65 | } 66 | 67 | static void PWM_Init(PWM_HandleTypeDef *hpwm, uint32_t channel) 68 | { 69 | hpwm->Instance = PWM; 70 | hpwm->Init.AutoReloadPreload = PWM_AUTORELOAD_PRELOAD_ENABLE; 71 | hpwm->Init.CounterMode = PWM_COUNTERMODE_EDGEALIGNED_DOWN; 72 | hpwm->Init.Prescaler = 4; 73 | hpwm->Init.Period = 99; // Frequency = 40,000,000 / 4 / (99 + 1) = 100,000 = 100KHz 74 | hpwm->Init.Pulse = 19; // Duty Cycle = (19 + 1) / (99 + 1) = 20% 75 | hpwm->Init.OutMode = PWM_OUT_MODE_2SYNC; // 2-channel sync mode 76 | hpwm->Channel = channel; // Only Channel 0 and Channel 2 are allowed 77 | HAL_PWM_Init(hpwm); 78 | } 79 | 80 | void Error_Handler(void) 81 | { 82 | while (1) 83 | { 84 | } 85 | } 86 | 87 | void assert_failed(uint8_t *file, uint32_t line) 88 | { 89 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 90 | } -------------------------------------------------------------------------------- /demo/pwm/2_led_fade_synchronized/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_PWM_MspInit(PWM_HandleTypeDef *hpwm) 9 | { 10 | __HAL_RCC_PWM_CLK_ENABLE(); 11 | __HAL_AFIO_REMAP_PWM0(GPIOB, GPIO_PIN_0); 12 | __HAL_AFIO_REMAP_PWM1(GPIOB, GPIO_PIN_1); 13 | __HAL_AFIO_REMAP_PWM2(GPIOB, GPIO_PIN_2); 14 | __HAL_AFIO_REMAP_PWM3(GPIOB, GPIO_PIN_3); 15 | } 16 | 17 | void HAL_PWM_MspDeInit(PWM_HandleTypeDef *hpwm) 18 | { 19 | __HAL_RCC_PWM_CLK_DISABLE(); 20 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3); 21 | } 22 | -------------------------------------------------------------------------------- /demo/pwm/2_led_fade_synchronized/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/pwm/5_led_fade_synchronized/main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file main.c 4 | * \author IOsetting | iosetting@outlook.com 5 | * \date 6 | * \brief Demo code of PWM in 5-sync mode 7 | * \note This will drive 5 LEDs (3 onboard and 2 external) to show 5-sync mode 8 | * \version v0.1 9 | * \ingroup demo 10 | * \remarks test-board: HLK-W806-KIT-V1.0 11 | * PWM Frequency = 40MHz / Prescaler / (Period + 1); 12 | * Duty Cycle(Edge Aligned) = (Pulse + 1) / (Period + 1) 13 | * Duty Cycle(Center Aligned) = (2 * Pulse + 1) / (2 * (Period + 1)) 14 | * 15 | * Connect PB3 and PB16 to an external LEDs for PWM3 and PWM4 output 16 | * PB3 -> ext LED1(-) 17 | * 3V3 -> ext LED1(+)(with 1KR resistor) 18 | * PB16 -> ext LED2(-) 19 | * 3V3 -> ext LED2(+)(with 1KR resistor) 20 | * 21 | ******************************************************************************/ 22 | 23 | #include 24 | #include "wm_hal.h" 25 | 26 | #define DUTY_MAX 100 27 | #define DUTY_MIN 50 28 | 29 | PWM_HandleTypeDef hpwm; 30 | int i, j, m, d; 31 | 32 | static void PWM_Init(uint32_t channel); 33 | void Error_Handler(void); 34 | 35 | uint32_t ch = PWM_CHANNEL_0; 36 | 37 | int main(void) 38 | { 39 | int i = 0; 40 | 41 | SystemClock_Config(CPU_CLK_160M); 42 | printf("enter main\r\n"); 43 | 44 | PWM_Init(ch); 45 | HAL_PWM_Start(&hpwm); 46 | 47 | while (1) 48 | { 49 | if (m == 0) // Increasing 50 | { 51 | HAL_PWM_Duty_Set(&hpwm, d++); 52 | if (d == DUTY_MAX) 53 | { 54 | m = 1; 55 | } 56 | } 57 | else // Decreasing 58 | { 59 | HAL_PWM_Duty_Set(&hpwm, d--); 60 | if (d == DUTY_MIN) 61 | { 62 | m = 0; 63 | } 64 | } 65 | HAL_Delay(20); 66 | } 67 | } 68 | 69 | static void PWM_Init(uint32_t channel) 70 | { 71 | hpwm.Instance = PWM; 72 | hpwm.Init.AutoReloadPreload = PWM_AUTORELOAD_PRELOAD_ENABLE; 73 | hpwm.Init.CounterMode = PWM_COUNTERMODE_EDGEALIGNED_DOWN; 74 | hpwm.Init.Prescaler = 4; 75 | hpwm.Init.Period = 99; // Frequency = 40,000,000 / 4 / (99 + 1) = 100,000 = 100KHz 76 | hpwm.Init.Pulse = 19; // Duty Cycle = (19 + 1) / (99 + 1) = 20% 77 | hpwm.Init.OutMode = PWM_OUT_MODE_5SYNC; // Make 5 channels output the same 78 | hpwm.Channel = channel; 79 | 80 | HAL_PWM_Init(&hpwm); 81 | } 82 | 83 | void Error_Handler(void) 84 | { 85 | while (1) 86 | { 87 | } 88 | } 89 | 90 | void assert_failed(uint8_t *file, uint32_t line) 91 | { 92 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 93 | } -------------------------------------------------------------------------------- /demo/pwm/5_led_fade_synchronized/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_PWM_MspInit(PWM_HandleTypeDef *hpwm) 9 | { 10 | __HAL_RCC_PWM_CLK_ENABLE(); 11 | __HAL_AFIO_REMAP_PWM0(GPIOB, GPIO_PIN_0); 12 | __HAL_AFIO_REMAP_PWM1(GPIOB, GPIO_PIN_1); 13 | __HAL_AFIO_REMAP_PWM2(GPIOB, GPIO_PIN_2); 14 | __HAL_AFIO_REMAP_PWM3(GPIOB, GPIO_PIN_3); 15 | __HAL_AFIO_REMAP_PWM4(GPIOB, GPIO_PIN_16); 16 | } 17 | 18 | void HAL_PWM_MspDeInit(PWM_HandleTypeDef *hpwm) 19 | { 20 | __HAL_RCC_PWM_CLK_DISABLE(); 21 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0); 22 | } 23 | -------------------------------------------------------------------------------- /demo/pwm/5_led_fade_synchronized/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/pwm/led_fade_independent/main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file main.c 4 | * \author IOsetting | iosetting@outlook.com 5 | * \date 6 | * \brief Demo code of PWM in independent mode 7 | * \note This will drive 3 onboard LEDs to show independent mode 8 | * \version v0.1 9 | * \ingroup demo 10 | * \remarks test-board: HLK-W806-KIT-V1.0 11 | * PWM Frequency = 40MHz / Prescaler / (Period + 1); 12 | Duty Cycle(Edge Aligned) = (Pulse + 1) / (Period + 1) 13 | Duty Cycle(Center Aligned) = (2 * Pulse + 1) / (2 * (Period + 1)) 14 | * 15 | ******************************************************************************/ 16 | 17 | #include 18 | #include "wm_hal.h" 19 | 20 | #define DUTY_MAX 100 21 | #define DUTY_MIN 50 22 | PWM_HandleTypeDef pwm[3]; 23 | int i, j, m[3] = {0}, d[3] = {DUTY_MIN, (DUTY_MIN + DUTY_MAX) / 2, DUTY_MAX - 1}; 24 | 25 | static void PWM_Init(PWM_HandleTypeDef *hpwm, uint32_t channel); 26 | void Error_Handler(void); 27 | 28 | int main(void) 29 | { 30 | SystemClock_Config(CPU_CLK_160M); 31 | printf("enter main\r\n"); 32 | 33 | for (i = 2; i >= 0; i--) 34 | { 35 | PWM_Init(&pwm[i], PWM_CHANNEL_0 + i); 36 | HAL_PWM_Start(&pwm[i]); 37 | } 38 | 39 | while (1) 40 | { 41 | for (i = 0; i < 3; i++) 42 | { 43 | if (m[i] == 0) // Increasing 44 | { 45 | HAL_PWM_Duty_Set(&pwm[i], d[i]++); 46 | if (d[i] == DUTY_MAX) 47 | { 48 | m[i] = 1; 49 | } 50 | } 51 | else // Decreasing 52 | { 53 | HAL_PWM_Duty_Set(&pwm[i], d[i]--); 54 | if (d[i] == DUTY_MIN) 55 | { 56 | m[i] = 0; 57 | } 58 | } 59 | } 60 | HAL_Delay(20); 61 | } 62 | } 63 | 64 | static void PWM_Init(PWM_HandleTypeDef *hpwm, uint32_t channel) 65 | { 66 | hpwm->Instance = PWM; 67 | hpwm->Init.AutoReloadPreload = PWM_AUTORELOAD_PRELOAD_ENABLE; 68 | hpwm->Init.CounterMode = PWM_COUNTERMODE_EDGEALIGNED_DOWN; 69 | hpwm->Init.Prescaler = 4; 70 | hpwm->Init.Period = 99; // Frequency = 40,000,000 / 4 / (99 + 1) = 100,000 = 100KHz 71 | hpwm->Init.Pulse = 19; // Duty Cycle = (19 + 1) / (99 + 1) = 20% 72 | hpwm->Init.OutMode = PWM_OUT_MODE_INDEPENDENT; // Independent mode 73 | hpwm->Channel = channel; 74 | HAL_PWM_Init(hpwm); 75 | } 76 | 77 | void Error_Handler(void) 78 | { 79 | while (1) 80 | { 81 | } 82 | } 83 | 84 | void assert_failed(uint8_t *file, uint32_t line) 85 | { 86 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 87 | } -------------------------------------------------------------------------------- /demo/pwm/led_fade_independent/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_PWM_MspInit(PWM_HandleTypeDef *hpwm) 9 | { 10 | __HAL_RCC_PWM_CLK_ENABLE(); 11 | __HAL_AFIO_REMAP_PWM0(GPIOB, GPIO_PIN_0); 12 | __HAL_AFIO_REMAP_PWM1(GPIOB, GPIO_PIN_1); 13 | __HAL_AFIO_REMAP_PWM2(GPIOB, GPIO_PIN_2); 14 | } 15 | 16 | void HAL_PWM_MspDeInit(PWM_HandleTypeDef *hpwm) 17 | { 18 | __HAL_RCC_PWM_CLK_DISABLE(); 19 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2); 20 | } 21 | -------------------------------------------------------------------------------- /demo/pwm/led_fade_independent/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/rtc/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | PMU_HandleTypeDef hpmu; 6 | 7 | static void RTC_Init(void); 8 | static void RTC_Demo(void); 9 | static void RTC_Alarm_Demo(void); 10 | void Error_Handler(void); 11 | 12 | int main(void) 13 | { 14 | SystemClock_Config(CPU_CLK_160M); 15 | printf("enter main\r\n"); 16 | 17 | RTC_Demo(); 18 | // RTC_Alarm_Demo(); 19 | while (1) 20 | { 21 | printf("."); 22 | HAL_Delay(1000); 23 | } 24 | } 25 | 26 | static void RTC_Demo(void) 27 | { 28 | RTC_TimeTypeDef time; 29 | 30 | RTC_Init(); 31 | time.Year = 121; 32 | time.Month = 6; 33 | time.Date = 10; 34 | time.Hours = 14; 35 | time.Minutes = 28; 36 | time.Seconds = 10; 37 | HAL_PMU_RTC_Start(&hpmu, &time); 38 | 39 | while (1) 40 | { 41 | HAL_PMU_RTC_GetTime(&hpmu, &time); 42 | printf("%d-%d-%d %d:%d:%d\r\n", (time.Year + 1900), time.Month, time.Date, time.Hours, time.Minutes, time.Seconds); 43 | HAL_Delay(1000); 44 | } 45 | } 46 | 47 | static void RTC_Alarm_Demo(void) 48 | { 49 | RTC_TimeTypeDef time; 50 | 51 | RTC_Init(); 52 | time.Year = 121; 53 | time.Month = 6; 54 | time.Date = 10; 55 | time.Hours = 14; 56 | time.Minutes = 28; 57 | time.Seconds = 10; 58 | HAL_PMU_RTC_Start(&hpmu, &time); 59 | 60 | time.Seconds = 15; 61 | HAL_PMU_RTC_Alarm_Enable(&hpmu, &time); 62 | 63 | while (1) 64 | { 65 | HAL_PMU_RTC_GetTime(&hpmu, &time); 66 | printf("%d-%d-%d %d:%d:%d\r\n", (time.Year + 1900), time.Month, time.Date, time.Hours, time.Minutes, time.Seconds); 67 | HAL_Delay(1000); 68 | } 69 | } 70 | 71 | static void RTC_Init(void) 72 | { 73 | hpmu.Instance = PMU; 74 | hpmu.ClkSource = PMU_CLKSOURCE_32RC; 75 | HAL_PMU_Init(&hpmu); 76 | } 77 | 78 | void HAL_PMU_RTC_Callback(PMU_HandleTypeDef *hpmu) 79 | { 80 | printf("rtc irq callback\r\n"); 81 | } 82 | 83 | void Error_Handler(void) 84 | { 85 | while (1) 86 | { 87 | } 88 | } 89 | 90 | void assert_failed(uint8_t *file, uint32_t line) 91 | { 92 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 93 | } 94 | -------------------------------------------------------------------------------- /demo/rtc/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_PMU_MspInit(PMU_HandleTypeDef *hpmu) 9 | { 10 | HAL_NVIC_EnableIRQ(PMU_IRQn); 11 | } 12 | 13 | void HAL_PMU_MspDeInit(PMU_HandleTypeDef *hpmu) 14 | { 15 | HAL_NVIC_DisableIRQ(PMU_IRQn); 16 | } -------------------------------------------------------------------------------- /demo/rtc/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | extern PMU_HandleTypeDef hpmu; 5 | 6 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 7 | __attribute__((isr)) void CORET_IRQHandler(void) 8 | { 9 | readl(0xE000E010); 10 | HAL_IncTick(); 11 | } 12 | __attribute__((isr)) void PMU_IRQHandler(void) 13 | { 14 | HAL_PMU_IRQHandler(&hpmu); 15 | } -------------------------------------------------------------------------------- /demo/spi/nrf24l01/main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file main.c 4 | * \author IOsetting | iosetting@outlook.com 5 | * \date 6 | * \brief Demo code of NRF24L01 7 | * \note 8 | * \version v0.1 9 | * \ingroup demo 10 | * \remarks test-board: HLK-W806-KIT-V1.0 11 | * 12 | ******************************************************************************/ 13 | 14 | #include "wm_hal.h" 15 | #include "nrf24l01.h" 16 | 17 | extern NRF24L01_bufStruct NRF24L01_rxbuff; 18 | 19 | void Error_Handler(void); 20 | 21 | SPI_HandleTypeDef hspi; 22 | 23 | static void SPI_Init(void) 24 | { 25 | hspi.Instance = SPI; 26 | hspi.Init.Mode = SPI_MODE_MASTER; 27 | hspi.Init.CLKPolarity = SPI_POLARITY_LOW; 28 | hspi.Init.CLKPhase = SPI_PHASE_1EDGE; 29 | hspi.Init.NSS = SPI_NSS_SOFT; 30 | hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; 31 | hspi.Init.FirstByte = SPI_LITTLEENDIAN; 32 | 33 | if (HAL_SPI_Init(&hspi) != HAL_OK) 34 | { 35 | Error_Handler(); 36 | } 37 | } 38 | 39 | int main(void) 40 | { 41 | SystemClock_Config(CPU_CLK_240M); 42 | NRF24L01_GPIO_Init(); 43 | SPI_Init(); 44 | 45 | if (NRF24L01_initCheck(&hspi) != HAL_OK) { 46 | printf("Check failed\r\n"); 47 | Error_Handler(); 48 | } else { 49 | printf("Check succeeded\r\n"); 50 | } 51 | 52 | uint8_t tmp[] = { 53 | 0x1F, 0x80, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 54 | 0x21, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x28, 55 | 0x31, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x38, 56 | 0x41, 0x12, 0x13, 0x14, 0x15, 0x16, 0x37, 0x48}; 57 | uint8_t txaddr[5] = {0x32, 0x4E, 0x6F, 0x64, 0x65}; 58 | uint8_t rxaddr[5] = {0x32, 0x4E, 0x6F, 0x64, 0x22}; 59 | if (NRF24L01_config(&hspi, txaddr, rxaddr) != HAL_OK) { 60 | printf("Config failed\r\n"); 61 | Error_Handler(); 62 | } else { 63 | printf("Config succeeded\r\n"); 64 | } 65 | 66 | NRF24L01_dumpConfig(&hspi); 67 | 68 | if (NRF24L01_MODE == NRF24L01_modeRX) 69 | { 70 | while (1); 71 | } 72 | else 73 | { 74 | uint8_t succ = 0, err = 0; 75 | while (1) 76 | { 77 | if (NRF24L01_writeFast(&hspi, tmp) != HAL_OK) 78 | { 79 | NRF24L01_resetTX(&hspi); 80 | err++; 81 | } 82 | else 83 | { 84 | succ++; 85 | } 86 | if (err == 255 || succ == 255) 87 | { 88 | printf("Fail/Succ: %d/%d\r\n", err, succ); 89 | err = 0; 90 | succ = 0; 91 | } 92 | } 93 | } 94 | } 95 | 96 | void HAL_GPIO_EXTI_Callback(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) 97 | { 98 | if ((GPIOx == NRF24L01_IRQ_PORT) && (GPIO_Pin == NRF24L01_IRQ_PIN)) 99 | { 100 | NRF24L01_handelIrqFlag(&hspi); 101 | for (uint8_t i = 0; i < NRF24L01_PLOAD_WIDTH; i++) 102 | { 103 | printf("%02X ", NRF24L01_rxbuff.buf[i]); 104 | } 105 | printf("\r\n"); 106 | } 107 | } 108 | 109 | void Error_Handler(void) 110 | { 111 | while (1); 112 | } 113 | 114 | void assert_failed(uint8_t *file, uint32_t line) 115 | { 116 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 117 | } 118 | -------------------------------------------------------------------------------- /demo/spi/nrf24l01/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | #include "nrf24l01.h" 3 | 4 | void HAL_MspInit(void) 5 | { 6 | 7 | } 8 | 9 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 10 | { 11 | __HAL_RCC_SPI_CLK_ENABLE(); 12 | __HAL_AFIO_REMAP_SPI_CS(NRF24L01_CS_PORT, NRF24L01_CS_PIN); 13 | __HAL_AFIO_REMAP_SPI_CLK(NRF24L01_SCK_PORT, NRF24L01_SCK_PIN); 14 | __HAL_AFIO_REMAP_SPI_MOSI(NRF24L01_MOSI_PORT, NRF24L01_MOSI_PIN); 15 | __HAL_AFIO_REMAP_SPI_MISO(NRF24L01_MISO_PORT, NRF24L01_MISO_PIN); 16 | } 17 | 18 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 19 | { 20 | __HAL_RCC_SPI_CLK_DISABLE(); 21 | HAL_GPIO_DeInit(NRF24L01_CS_PORT, NRF24L01_CS_PIN); 22 | HAL_GPIO_DeInit(NRF24L01_SCK_PORT, NRF24L01_SCK_PIN); 23 | HAL_GPIO_DeInit(NRF24L01_MOSI_PORT, NRF24L01_MOSI_PIN); 24 | HAL_GPIO_DeInit(NRF24L01_MISO_PORT, NRF24L01_MISO_PIN); 25 | } -------------------------------------------------------------------------------- /demo/spi/nrf24l01/wm_it.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | #include "nrf24l01.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | 11 | __attribute__((isr)) void GPIOB_IRQHandler(void) 12 | { 13 | HAL_GPIO_EXTI_IRQHandler(NRF24L01_IRQ_PORT, NRF24L01_IRQ_PIN); 14 | } -------------------------------------------------------------------------------- /demo/spi/spi_basic/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | void Error_Handler(void); 6 | 7 | SPI_HandleTypeDef hspi; 8 | DMA_HandleTypeDef hdma_spi_tx; 9 | DMA_HandleTypeDef hdma_spi_rx; 10 | 11 | static void SPI_Init(void); 12 | static void DMA_Init(void); 13 | #define data_len (10000) 14 | uint8_t tx_data[data_len] = {0}; 15 | uint8_t rx_data[data_len] = {0}; 16 | 17 | int main(void) 18 | { 19 | int i = 0; 20 | uint16_t *p = (uint16_t *)tx_data; 21 | 22 | SystemClock_Config(CPU_CLK_160M); 23 | printf("enter main\r\n"); 24 | DMA_Init(); 25 | SPI_Init(); 26 | 27 | for(i = 0; i < (data_len / 2); i++) 28 | { 29 | p[i] = i; 30 | } 31 | __HAL_SPI_SET_CS_LOW(&hspi); 32 | HAL_SPI_Transmit_DMA(&hspi, (uint8_t *)tx_data, data_len); 33 | 34 | // __HAL_SPI_SET_CS_LOW(&hspi); 35 | // HAL_SPI_Receive_DMA(&hspi, (uint8_t *)rx_data, data_len); 36 | 37 | while (1) 38 | { 39 | HAL_Delay(1000); 40 | } 41 | } 42 | 43 | static void SPI_Init(void) 44 | { 45 | hspi.Instance = SPI; 46 | hspi.Init.Mode = SPI_MODE_MASTER; 47 | hspi.Init.CLKPolarity = SPI_POLARITY_LOW; 48 | hspi.Init.CLKPhase = SPI_PHASE_1EDGE; 49 | hspi.Init.NSS = SPI_NSS_SOFT; 50 | hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_20; 51 | hspi.Init.FirstByte = SPI_LITTLEENDIAN; 52 | 53 | if (HAL_SPI_Init(&hspi) != HAL_OK) 54 | { 55 | Error_Handler(); 56 | } 57 | } 58 | 59 | static void DMA_Init(void) 60 | { 61 | __HAL_RCC_DMA_CLK_ENABLE(); 62 | 63 | HAL_NVIC_SetPriority(DMA_Channel0_IRQn, 0); 64 | HAL_NVIC_EnableIRQ(DMA_Channel0_IRQn); 65 | 66 | HAL_NVIC_SetPriority(DMA_Channel1_IRQn, 0); 67 | HAL_NVIC_EnableIRQ(DMA_Channel1_IRQn); 68 | } 69 | 70 | void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) 71 | { 72 | __HAL_SPI_SET_CS_HIGH(hspi); 73 | printf("tx cplt\r\n"); 74 | } 75 | 76 | void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) 77 | { 78 | __HAL_SPI_SET_CS_HIGH(hspi); 79 | printf("rx cplt\r\n"); 80 | } 81 | 82 | void Error_Handler(void) 83 | { 84 | while (1) 85 | { 86 | } 87 | } 88 | 89 | void assert_failed(uint8_t *file, uint32_t line) 90 | { 91 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 92 | } -------------------------------------------------------------------------------- /demo/spi/spi_basic/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | extern DMA_HandleTypeDef hdma_spi_tx; 4 | extern DMA_HandleTypeDef hdma_spi_rx; 5 | 6 | extern void Error_Handler(void); 7 | 8 | void HAL_MspInit(void) 9 | { 10 | 11 | } 12 | 13 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 14 | { 15 | __HAL_RCC_SPI_CLK_ENABLE(); 16 | __HAL_AFIO_REMAP_SPI_CS(GPIOB, GPIO_PIN_4); 17 | __HAL_AFIO_REMAP_SPI_CLK(GPIOB, GPIO_PIN_2); 18 | __HAL_AFIO_REMAP_SPI_MISO(GPIOB, GPIO_PIN_3); 19 | __HAL_AFIO_REMAP_SPI_MOSI(GPIOB, GPIO_PIN_5); 20 | 21 | hdma_spi_tx.Instance = DMA_Channel0; 22 | hdma_spi_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; 23 | hdma_spi_tx.Init.DestInc = DMA_DINC_DISABLE; 24 | hdma_spi_tx.Init.SrcInc = DMA_SINC_ENABLE; 25 | hdma_spi_tx.Init.DataAlignment = DMA_DATAALIGN_WORD; 26 | hdma_spi_tx.Init.Mode = DMA_MODE_NORMAL_SINGLE; 27 | hdma_spi_tx.Init.RequestSourceSel = DMA_REQUEST_SOURCE_SPI_TX; 28 | 29 | __HAL_LINKDMA(hspi, hdmatx, hdma_spi_tx); 30 | if (HAL_DMA_Init(&hdma_spi_tx) != HAL_OK) 31 | { 32 | Error_Handler(); 33 | } 34 | 35 | hdma_spi_rx.Instance = DMA_Channel1; 36 | hdma_spi_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; 37 | hdma_spi_rx.Init.DestInc = DMA_DINC_ENABLE; 38 | hdma_spi_rx.Init.SrcInc = DMA_SINC_DISABLE; 39 | hdma_spi_rx.Init.DataAlignment = DMA_DATAALIGN_WORD; 40 | hdma_spi_rx.Init.Mode = DMA_MODE_NORMAL_SINGLE; 41 | hdma_spi_rx.Init.RequestSourceSel = DMA_REQUEST_SOURCE_SPI_RX; 42 | 43 | __HAL_LINKDMA(hspi, hdmarx, hdma_spi_rx); 44 | if (HAL_DMA_Init(&hdma_spi_rx) != HAL_OK) 45 | { 46 | Error_Handler(); 47 | } 48 | 49 | HAL_NVIC_SetPriority(SPI_LS_IRQn, 1); 50 | HAL_NVIC_EnableIRQ(SPI_LS_IRQn); 51 | } 52 | 53 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 54 | { 55 | __HAL_RCC_SPI_CLK_DISABLE(); 56 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5); 57 | } 58 | 59 | -------------------------------------------------------------------------------- /demo/spi/spi_basic/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | extern SPI_HandleTypeDef hspi; 5 | extern DMA_HandleTypeDef hdma_spi_tx; 6 | extern DMA_HandleTypeDef hdma_spi_rx; 7 | 8 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 9 | __attribute__((isr)) void CORET_IRQHandler(void) 10 | { 11 | readl(0xE000E010); 12 | HAL_IncTick(); 13 | } 14 | 15 | __attribute__((isr)) void SPI_LS_IRQHandler(void) 16 | { 17 | HAL_SPI_IRQHandler(&hspi); 18 | } 19 | 20 | __attribute__((isr)) void DMA_Channel0_IRQHandler(void) 21 | { 22 | HAL_DMA_IRQHandler(&hdma_spi_tx); 23 | } 24 | 25 | __attribute__((isr)) void DMA_Channel1_IRQHandler(void) 26 | { 27 | HAL_DMA_IRQHandler(&hdma_spi_rx); 28 | } -------------------------------------------------------------------------------- /demo/spi/st7567_lcd/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | #include "st7567.h" 3 | 4 | void HAL_MspInit(void) 5 | { 6 | 7 | } 8 | 9 | #if ST7567_HARDWARE_SPI 10 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 11 | { 12 | __HAL_RCC_SPI_CLK_ENABLE(); 13 | __HAL_AFIO_REMAP_SPI_CS(ST7567_CS_PORT, ST7567_CS_PIN); 14 | __HAL_AFIO_REMAP_SPI_CLK(ST7567_SCK_PORT, ST7567_SCK_PIN); 15 | __HAL_AFIO_REMAP_SPI_MOSI(ST7567_MOSI_PORT, ST7567_MOSI_PIN); 16 | } 17 | 18 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 19 | { 20 | __HAL_RCC_SPI_CLK_DISABLE(); 21 | HAL_GPIO_DeInit(ST7567_CS_PORT, ST7567_CS_PIN); 22 | HAL_GPIO_DeInit(ST7567_SCK_PORT, ST7567_SCK_PIN); 23 | HAL_GPIO_DeInit(ST7567_MOSI_PORT, ST7567_MOSI_PIN); 24 | } 25 | #endif -------------------------------------------------------------------------------- /demo/spi/st7567_lcd/wm_it.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 4 | __attribute__((isr)) void CORET_IRQHandler(void) 5 | { 6 | readl(0xE000E010); 7 | HAL_IncTick(); 8 | } 9 | -------------------------------------------------------------------------------- /demo/spi/st77xx_lcd/README.cn.md: -------------------------------------------------------------------------------- 1 | # 示例: ST77xx 2 | 3 | W806开发板 ST7735/ST7789 TFT LCD 显示屏示例的使用说明. 4 | 5 | # 接线 6 | 7 | ## ST7735, ST7735S, ST7735R 8 | 9 | 大多数 ST7735 LCD 显示屏使用8线的排针, 预设为4线SPI模式, pin脚为: 10 | * GND, 接地 11 | * VCC, 接3.3V 12 | * SCL, SPI时钟, 连接到 SPI SCK/CLK 13 | * SDA, SPI数据, 连接到 SPI MOSI 14 | * RES, reset脚, 连接到GPIO 15 | * DC, (或者 CD), 命令/数据切换脚, 连接到GPIO 16 | * CS, 片选脚, 连接到SPI CS 17 | * BL, 背光, 连接到GPIO 18 | 19 | 本示例使用的接线 20 | * GND -> GND 21 | * VCC -> 3.3V (切记, 不能接5V) 22 | * SCL -> PB15 23 | * SDA -> PB17 24 | * RES -> PB10 25 | * DC -> PB11 26 | * CS -> PB14 27 | * BL -> PB16 28 | 29 | ## ST7789, ST7789V 30 | 31 | ST7789 LCD 显示屏的种类比较多, 带的排针数量也更多, 多出来的接线, 主要是用于背光LED和模式选择, 这些多出来的接线, 接到对应的GPIO上就可以. 主体的接线(GND, VCC, SCL/SCK/CLK, SDA, RES/RESET, DC, CS, BL/LEDA)和ST7735是一样的. 32 | 33 | 需要确认ST7789 LCD 工作在4线SPI模式. 34 | 35 | # 代码 36 | 37 | 演示代码的文件结构为 38 | ``` 39 | ├── ascii_fonts.c # 英文字体文件 40 | ├── ascii_fonts.h # 英文字体头文件 41 | ├── main.c # 程序入口 42 | ├── st7735.c # ST7735的初始化方法 43 | ├── st7735.h # ST7735的头文件 44 | ├── st7789.c # ST7789的初始化方法 45 | ├── st7789.h # ST7789的头文件 46 | ├── st77xx.c # ST7735和ST7789的公共方法 47 | ├── st77xx.h # ST7735和ST7789的公共方法头文件 48 | ├── testimg.h # 测试图片, 尺寸为128x128 49 | ├── wm_hal_msp.c # 外设初始化方法 50 | └── wm_it.c # 中断处理方法 51 | ``` 52 | 53 | 为运行演示代码, 54 | * 将 app/src 目录下除了 Makefile 以外的其他文件删除 55 | * 将本目录下的所有文件复制到 app/src 56 | 57 | ## 配置 58 | 59 | ### st77xx.h 60 | 61 | 基础配置 62 | * ST77XX\_BUF\_SIZE 缓冲的大小, 单位为字节 63 | * ST77XX\_HARDWARE\_SPI 是否使用硬件SPI, 0:否, 1:是 64 | * ST77XX\_**\_PORT 和 ST77XX\_**\_PIN 各pin脚的选择 65 | ```c 66 | #define ST77XX_BUF_SIZE 1024 67 | #define ST77XX_HARDWARE_SPI 1 68 | 69 | // 如果修改了pin脚, 需要对应调整接线 70 | 71 | // CS: B4, B14 72 | #define ST77XX_CS_PORT GPIOB 73 | #define ST77XX_CS_PIN GPIO_PIN_14 74 | // SCK: B1, B2, B15, B24 75 | #define ST77XX_SCK_PORT GPIOB 76 | #define ST77XX_SCK_PIN GPIO_PIN_15 77 | // MOSI: B5, B17, B26, PA7 78 | #define ST77XX_MOSI_PORT GPIOB 79 | #define ST77XX_MOSI_PIN GPIO_PIN_17 80 | // MISO: B0, B3, B16, B25 81 | 82 | #define ST77XX_RES_PORT GPIOB 83 | #define ST77XX_RES_PIN GPIO_PIN_10 84 | #define ST77XX_DC_PORT GPIOB 85 | #define ST77XX_DC_PIN GPIO_PIN_11 86 | #define ST77XX_BL_PORT GPIOB 87 | #define ST77XX_BL_PIN GPIO_PIN_16 88 | ``` 89 | LCD 设置 90 | 91 | 在下面的液晶屏尺寸和显示方向色彩格式中选择适合自己屏幕的配置, 并取消注释(注意不要重复定义), 如果没有合适的就需要自己定义 92 | ```c 93 | #define ST77XX_WIDTH 128 94 | #define ST77XX_HEIGHT 160 95 | #define ST77XX_XSTART 2 96 | #define ST77XX_YSTART 1 97 | #define ST77XX_ROTATION (ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB) 98 | ``` 99 | 对于大多数 ST7789 LCD 显示屏, 使用宽度 240, 高度 320, xstart 和 ystart 都是 0. 100 | 101 | # 使用 102 | 103 | ### wm_hal_msp.c 104 | 105 | 添加外设初始化/反初始化代码, 如果使用软件SPI可以跳过这步. 106 | ```c 107 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 108 | { 109 | __HAL_RCC_SPI_CLK_ENABLE(); 110 | __HAL_AFIO_REMAP_SPI_CS(ST77XX_CS_PORT, ST77XX_CS_PIN); 111 | __HAL_AFIO_REMAP_SPI_CLK(ST77XX_SCK_PORT, ST77XX_SCK_PIN); 112 | __HAL_AFIO_REMAP_SPI_MOSI(ST77XX_MOSI_PORT, ST77XX_MOSI_PIN); 113 | } 114 | 115 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 116 | { 117 | __HAL_RCC_SPI_CLK_DISABLE(); 118 | HAL_GPIO_DeInit(ST77XX_CS_PORT, ST77XX_CS_PIN); 119 | HAL_GPIO_DeInit(ST77XX_SCK_PORT, ST77XX_SCK_PIN); 120 | HAL_GPIO_DeInit(ST77XX_MOSI_PORT, ST77XX_MOSI_PIN); 121 | } 122 | ``` 123 | 124 | ### main.c 125 | 126 | 引入头文件, 如果使用的是ST7789 LCD, 将 `st7735.h` 替换为 `st7789.h`. 127 | ```c 128 | #include "st7735.h" 129 | #include "testimg.h" 130 | ``` 131 | Initialize SPI 132 | ```c 133 | SPI_HandleTypeDef hspi; 134 | 135 | static void SPI_Init(void) 136 | { 137 | hspi.Instance = SPI; 138 | hspi.Init.Mode = SPI_MODE_MASTER; 139 | hspi.Init.CLKPolarity = SPI_POLARITY_LOW; 140 | hspi.Init.CLKPhase = SPI_PHASE_1EDGE; 141 | hspi.Init.NSS = SPI_NSS_SOFT; 142 | hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; 143 | hspi.Init.FirstByte = SPI_LITTLEENDIAN; 144 | 145 | if (HAL_SPI_Init(&hspi) != HAL_OK) 146 | { 147 | Error_Handler(); 148 | } 149 | } 150 | ``` 151 | 在 main() 方法中初始化, 如果使用的是ST7789 LCD, 将 `ST7735_Init()` 替换为 `ST7789_Init()` 152 | ```c 153 | int main(void) 154 | { 155 | //... 156 | ST77XX_GPIO_Init(); 157 | SPI_Init(); 158 | ST7735_Init(); 159 | //... 160 | } 161 | ``` 162 | 然后就可以调用ST77XX_开头的方法输出显示了. 163 | 164 | -------------------------------------------------------------------------------- /demo/spi/st77xx_lcd/main.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file main.c 4 | * \author IOsetting | iosetting@outlook.com 5 | * \date 6 | * \brief Demo code of ST7735 and ST7789 TFT LCD 7 | * \note 8 | * \version v0.1 9 | * \ingroup demo 10 | * \remarks test-board: HLK-W806-KIT-V1.0 11 | * 12 | ******************************************************************************/ 13 | 14 | #include "wm_hal.h" 15 | #include "st7735.h" 16 | #include "testimg.h" 17 | 18 | void Error_Handler(void); 19 | 20 | #if ST77XX_HARDWARE_SPI 21 | SPI_HandleTypeDef hspi; 22 | 23 | static void SPI_Init(void) 24 | { 25 | hspi.Instance = SPI; 26 | hspi.Init.Mode = SPI_MODE_MASTER; 27 | hspi.Init.CLKPolarity = SPI_POLARITY_LOW; 28 | hspi.Init.CLKPhase = SPI_PHASE_1EDGE; 29 | hspi.Init.NSS = SPI_NSS_SOFT; 30 | hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; 31 | hspi.Init.FirstByte = SPI_LITTLEENDIAN; 32 | 33 | if (HAL_SPI_Init(&hspi) != HAL_OK) 34 | { 35 | Error_Handler(); 36 | } 37 | } 38 | #endif 39 | 40 | int main(void) 41 | { 42 | uint8_t y = 10; 43 | SystemClock_Config(CPU_CLK_240M); 44 | ST77XX_GPIO_Init(); 45 | 46 | #if ST77XX_HARDWARE_SPI 47 | SPI_Init(); 48 | #endif 49 | 50 | ST7735_Init(); 51 | while(1) 52 | { 53 | ST77XX_BackLight_On(); 54 | HAL_Delay(500); 55 | ST77XX_Fill(0, 0, ST77XX_WIDTH, ST77XX_HEIGHT, ST77XX_RED); 56 | HAL_Delay(500); 57 | ST77XX_Fill(0, 0, ST77XX_WIDTH, ST77XX_HEIGHT, ST77XX_YELLOW); 58 | HAL_Delay(500); 59 | ST77XX_Fill(0, 0, ST77XX_WIDTH, ST77XX_HEIGHT, ST77XX_BLUE); 60 | HAL_Delay(500); 61 | ST77XX_Fill(0, 0, ST77XX_WIDTH, ST77XX_HEIGHT, ST77XX_GREEN); 62 | HAL_Delay(500); 63 | 64 | y = 10; 65 | 66 | ST77XX_DrawString(5, y, (const char *)"0123456789ABCDE", &Font_6x12, ST77XX_YELLOW, ST77XX_RED); 67 | HAL_Delay(500); 68 | y += Font_6x12.height + 2; 69 | 70 | ST77XX_DrawString(5, y, (const char *)"0123456789ABCDE", &Font_7x10, ST77XX_YELLOW, ST77XX_BLUE); 71 | HAL_Delay(500); 72 | y += Font_7x10.height + 2; 73 | 74 | ST77XX_DrawString(5, y, (const char *)"0123456789ABCDE", &Font_8x16, ST77XX_YELLOW, ST77XX_BLUE); 75 | HAL_Delay(500); 76 | y += Font_8x16.height + 2; 77 | 78 | ST77XX_DrawString(5, y, (const char *)"0123456ABC", &Font_11x18, ST77XX_YELLOW, ST77XX_BLUE); 79 | HAL_Delay(500); 80 | y += Font_11x18.height + 2; 81 | 82 | ST77XX_DrawString(5, y, (const char *)"0123456AB", &Font_12x24, ST77XX_YELLOW, ST77XX_BLUE); 83 | HAL_Delay(500); 84 | y += Font_12x24.height + 2; 85 | 86 | ST77XX_DrawString(5, y, (const char *)"ST7735", &Font_16x26, ST77XX_WHITE, ST77XX_BLUE); 87 | HAL_Delay(500); 88 | y += Font_16x26.height + 2; 89 | 90 | ST77XX_DrawString(0, y, (const char *)"W806 SDK", &Font_16x32, ST77XX_WHITE, ST77XX_BLUE); 91 | HAL_Delay(3000); 92 | 93 | ST77XX_DrawImage(0, 0, 128, 128, (uint16_t *)test_img_128x128); 94 | HAL_Delay(2000); 95 | 96 | } 97 | } 98 | 99 | void Error_Handler(void) 100 | { 101 | while (1) 102 | { 103 | } 104 | } 105 | 106 | void assert_failed(uint8_t *file, uint32_t line) 107 | { 108 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 109 | } -------------------------------------------------------------------------------- /demo/spi/st77xx_lcd/st7735.h: -------------------------------------------------------------------------------- 1 | #ifndef __ST7735_H 2 | #define __ST7735_H 3 | 4 | #include "wm_hal.h" 5 | #include "st77xx.h" 6 | 7 | // Some register settings 8 | #define ST7735_FRMCTR1 0xB1 9 | #define ST7735_FRMCTR2 0xB2 10 | #define ST7735_FRMCTR3 0xB3 11 | #define ST7735_INVCTR 0xB4 12 | #define ST7735_DISSET5 0xB6 13 | 14 | #define ST7735_PWCTR1 0xC0 15 | #define ST7735_PWCTR2 0xC1 16 | #define ST7735_PWCTR3 0xC2 17 | #define ST7735_PWCTR4 0xC3 18 | #define ST7735_PWCTR5 0xC4 19 | #define ST7735_VMCTR1 0xC5 20 | 21 | #define ST7735_PWCTR6 0xFC 22 | 23 | #define ST7735_GMCTRP1 0xE0 24 | #define ST7735_GMCTRN1 0xE1 25 | 26 | 27 | void ST7735_Init(void); 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /demo/spi/st77xx_lcd/st7789.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file st7789.c 4 | * \author IOsetting | iosetting@outlook.com 5 | * \date 6 | * \brief Library of ST7789/ST7789V TFT LCD on W806 7 | * \note 8 | * \version v0.1 9 | * \ingroup demo 10 | * \remarks test-board: HLK-W806-KIT-V1.0 11 | * 12 | ******************************************************************************/ 13 | 14 | #include "st7789.h" 15 | 16 | static const uint8_t init_cmds[] = { 17 | 9, // 9 commands in list: 18 | ST77XX_SWRESET, ST77XX_CMD_DELAY, // 1: Software reset, no args, w/delay 19 | 150, // 150 ms delay 20 | ST77XX_SLPOUT, ST77XX_CMD_DELAY, // 2: Out of sleep mode, no args, w/delay 21 | 10, // 10 ms delay 22 | ST77XX_COLMOD, 1 | ST77XX_CMD_DELAY, // 3: Set color mode, 1 arg + delay: 23 | (ST7789_COLMOD_65K | ST7789_COLMOD_16BIT), // 16-bit color 0x55 24 | 10, // 10 ms delay 25 | ST77XX_MADCTL, 1, // 4: Memory access ctrl (directions), 1 arg: 26 | ST77XX_ROTATION, // Row addr/col addr, bottom to top refresh 27 | ST77XX_CASET, 4, // 5: Column addr set, 4 args, no delay: 28 | 0, 0, // XSTART 29 | 0, ST77XX_WIDTH, // XEND 30 | ST77XX_RASET, 4, // 6: Row addr set, 4 args, no delay: 31 | 0, 0, // YSTART = 0 32 | ST77XX_HEIGHT >> 8, ST77XX_HEIGHT & 0xff, // YEND = 320 33 | ST77XX_INVOFF, ST77XX_CMD_DELAY, // 7: Inversion OFF 34 | 10, 35 | ST77XX_NORON, ST77XX_CMD_DELAY, // 8: Normal display on, no args, w/delay 36 | 10, // 10 ms delay 37 | ST77XX_DISPON, ST77XX_CMD_DELAY, // 9: Main screen turn on, no args, w/delay 38 | 10 39 | }; 40 | 41 | void ST7789_Init(void) 42 | { 43 | ST77XX_Reset(); 44 | ST77XX_ExecuteCommandList(init_cmds); 45 | } 46 | -------------------------------------------------------------------------------- /demo/spi/st77xx_lcd/st7789.h: -------------------------------------------------------------------------------- 1 | #ifndef __ST7789_H 2 | #define __ST7789_H 3 | 4 | #include "wm_hal.h" 5 | #include "st77xx.h" 6 | 7 | // Some register settings 8 | #define ST7789_INVCTR 0xB4 9 | #define ST7789_DISSET5 0xB6 10 | 11 | #define ST7789_PWCTR1 0xC0 12 | #define ST7789_PWCTR2 0xC1 13 | #define ST7789_PWCTR3 0xC2 14 | #define ST7789_PWCTR4 0xC3 15 | #define ST7789_PWCTR5 0xC4 16 | #define ST7789_VMCTR1 0xC5 17 | 18 | #define ST7789_PWCTR6 0xFC 19 | 20 | #define ST7789_GMCTRP1 0xE0 21 | #define ST7789_GMCTRN1 0xE1 22 | 23 | // Color Mode for COLMOD 24 | #define ST7789_COLMOD_65K 0x50 25 | #define ST7789_COLMOD_262K 0x60 26 | #define ST7789_COLMOD_12BIT 0x03 27 | #define ST7789_COLMOD_16BIT 0x05 28 | #define ST7789_COLMOD_18BIT 0x06 29 | #define ST7789_COLMOD_16M 0x07 30 | 31 | 32 | void ST7789_Init(void); 33 | 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /demo/spi/st77xx_lcd/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | #include "st7735.h" 3 | 4 | void HAL_MspInit(void) 5 | { 6 | 7 | } 8 | 9 | #if ST77XX_HARDWARE_SPI 10 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 11 | { 12 | __HAL_RCC_SPI_CLK_ENABLE(); 13 | __HAL_AFIO_REMAP_SPI_CS(ST77XX_CS_PORT, ST77XX_CS_PIN); 14 | __HAL_AFIO_REMAP_SPI_CLK(ST77XX_SCK_PORT, ST77XX_SCK_PIN); 15 | __HAL_AFIO_REMAP_SPI_MOSI(ST77XX_MOSI_PORT, ST77XX_MOSI_PIN); 16 | } 17 | 18 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 19 | { 20 | __HAL_RCC_SPI_CLK_DISABLE(); 21 | HAL_GPIO_DeInit(ST77XX_CS_PORT, ST77XX_CS_PIN); 22 | HAL_GPIO_DeInit(ST77XX_SCK_PORT, ST77XX_SCK_PIN); 23 | HAL_GPIO_DeInit(ST77XX_MOSI_PORT, ST77XX_MOSI_PIN); 24 | } 25 | #endif -------------------------------------------------------------------------------- /demo/spi/st77xx_lcd/wm_it.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 4 | __attribute__((isr)) void CORET_IRQHandler(void) 5 | { 6 | readl(0xE000E010); 7 | HAL_IncTick(); 8 | } 9 | -------------------------------------------------------------------------------- /demo/tft_lcd/lcd.h: -------------------------------------------------------------------------------- 1 | #ifndef __LCD_H__ 2 | #define __LCD_H__ 3 | 4 | #include "wm_hal.h" 5 | 6 | #define ST7789_SPI 1 7 | #define ST7789_8080 1 8 | 9 | #if ST7789_SPI 10 | #include "st7789_serial.h" 11 | #endif 12 | #if ST7789_8080 13 | #include "st7789_parallel.h" 14 | #endif 15 | 16 | void LCD_Back_On(void); 17 | void LCD_Back_Off(void); 18 | void LCD_Init(void); 19 | void LCD_Address_Set(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye); 20 | void LCD_Fill(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint16_t color); 21 | void LCD_DrawPoint(uint16_t x, uint16_t y, uint16_t color); 22 | void LCD_DrawLine(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint16_t color); 23 | void LCD_DrawRectangle(uint16_t xs, uint16_t ys, uint16_t xe, uint16_t ye, uint16_t color); 24 | void LCD_DrawCircle(uint16_t x, uint16_t y, uint8_t r, uint16_t color); 25 | void LCD_ShowPicture(uint16_t x, uint16_t y, uint16_t length, uint16_t width, uint8_t *data); 26 | 27 | #endif -------------------------------------------------------------------------------- /demo/tft_lcd/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | #include "lcd.h" 5 | #include "lufei.h" 6 | #include "pikaqiu.h" 7 | 8 | static void GPIO_Init(void); 9 | 10 | #if ST7789_SPI 11 | SPI_HandleTypeDef hspi; 12 | static void SPI_Init(void); 13 | #endif 14 | void Error_Handler(void); 15 | 16 | int main(void) 17 | { 18 | SystemClock_Config(CPU_CLK_240M); 19 | printf("enter main\r\n"); 20 | 21 | GPIO_Init(); 22 | #if ST7789_SPI 23 | SPI_Init(); 24 | #endif 25 | LCD_Init(); 26 | 27 | while (1) 28 | { 29 | LCD_ShowPicture(0, 40, 240, 240, gImage_pikaqiu); 30 | HAL_Delay(1000); 31 | LCD_ShowPicture(0, 40, 240, 240, gImage_lufei); 32 | HAL_Delay(1000); 33 | } 34 | } 35 | 36 | static void GPIO_Init(void) 37 | { 38 | GPIO_InitTypeDef GPIO_InitStruct; 39 | 40 | __HAL_RCC_GPIO_CLK_ENABLE(); 41 | #if ST7789_SPI 42 | GPIO_InitStruct.Pin = S_LEDA1_PIN; 43 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT; 44 | GPIO_InitStruct.Pull = GPIO_NOPULL; 45 | HAL_GPIO_Init(S_LEDA1_PORT, &GPIO_InitStruct); 46 | HAL_GPIO_WritePin(S_LEDA1_PORT, S_LEDA1_PIN, GPIO_PIN_RESET); 47 | 48 | GPIO_InitStruct.Pin = S_LEDA2_PIN; 49 | HAL_GPIO_Init(S_LEDA2_PORT, &GPIO_InitStruct); 50 | HAL_GPIO_WritePin(S_LEDA2_PORT, S_LEDA2_PIN, GPIO_PIN_RESET); 51 | 52 | GPIO_InitStruct.Pin = S_CD_PIN; 53 | HAL_GPIO_Init(S_CD_PORT, &GPIO_InitStruct); 54 | HAL_GPIO_WritePin(S_CD_PORT, S_CD_PIN, GPIO_PIN_SET); 55 | 56 | GPIO_InitStruct.Pin = S_RESET_PIN; 57 | HAL_GPIO_Init(S_RESET_PORT, &GPIO_InitStruct); 58 | HAL_GPIO_WritePin(S_RESET_PORT, S_RESET_PIN, GPIO_PIN_RESET); 59 | 60 | GPIO_InitStruct.Pin = S_FMARK_PIN; 61 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 62 | HAL_GPIO_Init(S_FMARK_PORT, &GPIO_InitStruct); 63 | #endif 64 | 65 | #if ST7789_8080 66 | GPIO_InitStruct.Pin = P_LEDA_PIN; 67 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT; 68 | GPIO_InitStruct.Pull = GPIO_NOPULL; 69 | HAL_GPIO_Init(P_LEDA_PORT, &GPIO_InitStruct); 70 | HAL_GPIO_WritePin(P_LEDA_PORT, P_LEDA_PIN, GPIO_PIN_SET); 71 | 72 | GPIO_InitStruct.Pin = P_RD_PIN; 73 | HAL_GPIO_Init(P_RD_PORT, &GPIO_InitStruct); 74 | HAL_GPIO_WritePin(P_RD_PORT, P_RD_PIN, GPIO_PIN_SET); 75 | 76 | GPIO_InitStruct.Pin = P_WR_PIN; 77 | HAL_GPIO_Init(P_WR_PORT, &GPIO_InitStruct); 78 | HAL_GPIO_WritePin(P_WR_PORT, P_WR_PIN, GPIO_PIN_RESET); 79 | 80 | GPIO_InitStruct.Pin = P_CD_PIN; 81 | HAL_GPIO_Init(P_CD_PORT, &GPIO_InitStruct); 82 | HAL_GPIO_WritePin(P_CD_PORT, P_CD_PIN, GPIO_PIN_SET); 83 | 84 | GPIO_InitStruct.Pin = P_CS_PIN; 85 | HAL_GPIO_Init(P_CS_PORT, &GPIO_InitStruct); 86 | HAL_GPIO_WritePin(P_CS_PORT, P_CS_PIN, GPIO_PIN_SET); 87 | 88 | GPIO_InitStruct.Pin = P_RESET_PIN; 89 | HAL_GPIO_Init(P_RESET_PORT, &GPIO_InitStruct); 90 | HAL_GPIO_WritePin(P_RESET_PORT, P_RESET_PIN, GPIO_PIN_SET); 91 | 92 | GPIO_InitStruct.Pin = P_DATA_PIN; 93 | HAL_GPIO_Init(P_DATA_PORT, &GPIO_InitStruct); 94 | HAL_GPIO_WritePin(P_DATA_PORT, P_DATA_PIN, GPIO_PIN_RESET); 95 | 96 | GPIO_InitStruct.Pin = P_FMARK_PIN; 97 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 98 | HAL_GPIO_Init(P_FMARK_PORT, &GPIO_InitStruct); 99 | 100 | #endif 101 | 102 | } 103 | 104 | #if ST7789_SPI 105 | static void SPI_Init(void) 106 | { 107 | hspi.Instance = SPI; 108 | hspi.Init.Mode = SPI_MODE_MASTER; 109 | hspi.Init.CLKPolarity = SPI_POLARITY_LOW; 110 | hspi.Init.CLKPhase = SPI_PHASE_1EDGE; 111 | hspi.Init.NSS = SPI_NSS_SOFT; 112 | hspi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; 113 | hspi.Init.FirstByte = SPI_LITTLEENDIAN; 114 | 115 | if (HAL_SPI_Init(&hspi) != HAL_OK) 116 | { 117 | Error_Handler(); 118 | } 119 | } 120 | #endif 121 | 122 | void Error_Handler(void) 123 | { 124 | while (1) 125 | { 126 | } 127 | } 128 | 129 | void assert_failed(uint8_t *file, uint32_t line) 130 | { 131 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 132 | } -------------------------------------------------------------------------------- /demo/tft_lcd/st7789_parallel.c: -------------------------------------------------------------------------------- 1 | #include "st7789_parallel.h" 2 | 3 | void P_Back_On(void) 4 | { 5 | HAL_GPIO_WritePin(P_LEDA_PORT, P_LEDA_PIN, GPIO_PIN_SET); 6 | } 7 | 8 | void P_Back_Off(void) 9 | { 10 | HAL_GPIO_WritePin(P_LEDA_PORT, P_LEDA_PIN, GPIO_PIN_RESET); 11 | } 12 | 13 | static void P_WaitTe(void) 14 | { 15 | while ((P_FMARK_PORT->DATA & P_FMARK_PIN) == 0); 16 | } 17 | 18 | void P_WriteReg(uint8_t reg) 19 | { 20 | P_CS_LOW; 21 | P_CD_LOW; 22 | P_WR_LOW; 23 | MODIFY_REG(P_DATA_PORT->DATA, P_DATA_PIN, reg); 24 | P_WR_HIGH; 25 | P_CD_HIGH; 26 | P_CS_HIGH; 27 | } 28 | 29 | void P_WriteData8(uint8_t data) 30 | { 31 | P_CS_LOW; 32 | P_WR_LOW; 33 | MODIFY_REG(P_DATA_PORT->DATA, P_DATA_PIN, data); 34 | P_WR_HIGH; 35 | P_CS_HIGH; 36 | } 37 | 38 | void P_WriteData16(uint16_t data) 39 | { 40 | P_CS_LOW; 41 | P_WR_LOW; 42 | MODIFY_REG(P_DATA_PORT->DATA, P_DATA_PIN, (data >> 8)); 43 | P_WR_HIGH; 44 | P_WR_LOW; 45 | MODIFY_REG(P_DATA_PORT->DATA, P_DATA_PIN, (data & 0x00FF)); 46 | P_WR_HIGH; 47 | P_CS_HIGH; 48 | } 49 | 50 | void P_WriteData(uint8_t *data, uint32_t len) 51 | { 52 | int i = 0; 53 | 54 | P_CS_LOW; 55 | P_DATA_PORT->DATA_B_EN &= P_DATA_PIN; 56 | P_WR_PORT->DATA_B_EN &= P_WR_PIN; 57 | for (i = 0; i < len; i ++) 58 | { 59 | P_WR_PORT->DATA = 0; 60 | P_DATA_PORT->DATA = data[i]; 61 | P_WR_PORT->DATA = P_WR_PIN; 62 | } 63 | P_WR_PORT->DATA_B_EN |= ~P_WR_PIN; 64 | P_DATA_PORT->DATA_B_EN |= ~P_DATA_PIN; 65 | P_CS_HIGH; 66 | } 67 | -------------------------------------------------------------------------------- /demo/tft_lcd/st7789_parallel.h: -------------------------------------------------------------------------------- 1 | #ifndef __ST7789_PARALLEL_H__ 2 | #define __ST7789_PARALLEL_H__ 3 | 4 | #include "wm_hal.h" 5 | 6 | #define P_LEDA_PORT GPIOA 7 | #define P_LEDA_PIN GPIO_PIN_5 8 | #define P_RD_PORT GPIOA 9 | #define P_RD_PIN GPIO_PIN_6 10 | #define P_WR_PORT GPIOA 11 | #define P_WR_PIN GPIO_PIN_7 12 | #define P_CD_PORT GPIOA 13 | #define P_CD_PIN GPIO_PIN_8 14 | #define P_CS_PORT GPIOA 15 | #define P_CS_PIN GPIO_PIN_9 16 | #define P_FMARK_PORT GPIOA 17 | #define P_FMARK_PIN GPIO_PIN_12 18 | #define P_RESET_PORT GPIOA 19 | #define P_RESET_PIN GPIO_PIN_13 20 | #define P_DATA_PORT GPIOB 21 | #define P_DATA_PIN 0xFF 22 | 23 | #define P_CD_LOW P_CD_PORT->DATA &= ~P_CD_PIN 24 | #define P_CD_HIGH P_CD_PORT->DATA |= P_CD_PIN 25 | #define P_CS_LOW P_CS_PORT->DATA &= ~P_CS_PIN 26 | #define P_CS_HIGH P_CS_PORT->DATA |= P_CS_PIN 27 | #define P_RESET_LOW P_RESET_PORT->DATA &= ~P_RESET_PIN 28 | #define P_RESET_HIGH P_RESET_PORT->DATA |= P_RESET_PIN 29 | #define P_WR_LOW P_WR_PORT->DATA &= ~P_WR_PIN 30 | #define P_WR_HIGH P_WR_PORT->DATA |= P_WR_PIN 31 | #define P_RD_HIGH P_RD_PORT->DATA |= P_RD_PIN 32 | 33 | void P_Back_On(void); 34 | void P_Back_Off(void); 35 | void P_WriteReg(uint8_t reg); 36 | void P_WriteData8(uint8_t data); 37 | void P_WriteData16(uint16_t data); 38 | void P_WriteData(uint8_t *data, uint32_t len); 39 | 40 | #endif -------------------------------------------------------------------------------- /demo/tft_lcd/st7789_serial.c: -------------------------------------------------------------------------------- 1 | #include "st7789_serial.h" 2 | 3 | void S_Back_On(void) 4 | { 5 | HAL_GPIO_WritePin(S_LEDA1_PORT, S_LEDA1_PIN, GPIO_PIN_SET); 6 | HAL_GPIO_WritePin(S_LEDA2_PORT, S_LEDA2_PIN, GPIO_PIN_SET); 7 | } 8 | 9 | void S_Back_Off(void) 10 | { 11 | HAL_GPIO_WritePin(S_LEDA1_PORT, S_LEDA1_PIN, GPIO_PIN_RESET); 12 | HAL_GPIO_WritePin(S_LEDA2_PORT, S_LEDA2_PIN, GPIO_PIN_RESET); 13 | } 14 | 15 | static void S_WaitTe(void) 16 | { 17 | while ((S_FMARK_PORT->DATA & S_FMARK_PIN) == 0); 18 | } 19 | 20 | void S_WriteReg(uint8_t reg) 21 | { 22 | S_CD_LOW; 23 | S_CS_LOW; 24 | HAL_SPI_Transmit(&hspi, ®, 1, 100); 25 | S_CS_HIGH; 26 | S_CD_HIGH; 27 | } 28 | 29 | void S_WriteData8(uint8_t data) 30 | { 31 | S_CS_LOW; 32 | HAL_SPI_Transmit(&hspi, &data, 1, 100); 33 | S_CS_HIGH; 34 | } 35 | 36 | void S_WriteData16(uint16_t data) 37 | { 38 | uint8_t temp[2]; 39 | 40 | temp[0] = data >> 8; 41 | temp[1] = data; 42 | S_CS_LOW; 43 | HAL_SPI_Transmit(&hspi, temp, 2, 100); 44 | S_CS_HIGH; 45 | } 46 | 47 | #define DMA_Channel0 ((DMA_Channel_TypeDef *)DMA_Channel0_BASE) 48 | void HAL_SPI_Transmit_dma(SPI_HandleTypeDef *hspi, uint8_t *pData, uint32_t Size) 49 | { 50 | uint32_t block_cnt = 0, tx_block_cnt = 0, tx_size = 0; 51 | 52 | __HAL_RCC_DMA_CLK_ENABLE(); 53 | block_cnt = Size / BLOCK_SIZE; 54 | while (tx_block_cnt <= block_cnt) 55 | { 56 | if (tx_block_cnt < block_cnt) 57 | { 58 | tx_size = BLOCK_SIZE; 59 | } 60 | else 61 | { 62 | tx_size = Size % BLOCK_SIZE; 63 | } 64 | __HAL_SPI_CLEAR_FIFO(hspi); 65 | 66 | DMA_Channel0->MODE = 0x15; 67 | DMA_Channel0->SA = (uint32_t)(pData + (BLOCK_SIZE * tx_block_cnt)); 68 | DMA_Channel0->DA = (uint32_t)(&(hspi->Instance->TXDATA)); 69 | DMA_Channel0->CR2 = ((tx_size << 8) | 0x42); 70 | hspi->Instance->MODE_CFG = 0x01; 71 | 72 | __HAL_SPI_SET_CLK_NUM(hspi, tx_size * 8); 73 | DMA_Channel0->CR1 |= 0x1; 74 | __HAL_SPI_SET_START(hspi); 75 | while (DMA_Channel0->CR1 & 0x01); 76 | while (hspi->Instance->STATUS & (1 << 12)); 77 | __HAL_SPI_CELAR_FLAG(hspi, 0xFF); 78 | *((uint32_t *)(0x40000804)) |= 0x03; 79 | tx_block_cnt++; 80 | } 81 | } 82 | 83 | void S_WriteData(uint8_t *data, uint32_t len) 84 | { 85 | S_CS_LOW; 86 | HAL_SPI_Transmit(&hspi, data, len, 1000); 87 | // HAL_SPI_Transmit_dma(&hspi, data, len); 88 | S_CS_HIGH; 89 | } -------------------------------------------------------------------------------- /demo/tft_lcd/st7789_serial.h: -------------------------------------------------------------------------------- 1 | #ifndef __ST7789_SERIAL_H__ 2 | #define __ST7789_SERIAL_H__ 3 | 4 | #include "wm_hal.h" 5 | 6 | #define S_LEDA1_PORT GPIOB 7 | #define S_LEDA1_PIN GPIO_PIN_25 8 | #define S_LEDA2_PORT GPIOB 9 | #define S_LEDA2_PIN GPIO_PIN_26 10 | #define S_FMARK_PORT GPIOB 11 | #define S_FMARK_PIN GPIO_PIN_18 12 | #define S_SDA_PORT GPIOB 13 | #define S_SDA_PIN GPIO_PIN_17 14 | #define S_CD_PORT GPIOB 15 | #define S_CD_PIN GPIO_PIN_16 16 | #define S_SCL_PORT GPIOB 17 | #define S_SCL_PIN GPIO_PIN_15 18 | #define S_CS_PORT GPIOB 19 | #define S_CS_PIN GPIO_PIN_14 20 | #define S_RESET_PORT GPIOB 21 | #define S_RESET_PIN GPIO_PIN_13 22 | 23 | extern SPI_HandleTypeDef hspi; 24 | 25 | #define S_CD_LOW HAL_GPIO_WritePin(S_CD_PORT, S_CD_PIN, GPIO_PIN_RESET) 26 | #define S_CD_HIGH HAL_GPIO_WritePin(S_CD_PORT, S_CD_PIN, GPIO_PIN_SET) 27 | #define S_CS_LOW __HAL_SPI_SET_CS_LOW(&hspi) 28 | #define S_CS_HIGH __HAL_SPI_SET_CS_HIGH(&hspi) 29 | #define S_RESET_LOW HAL_GPIO_WritePin(S_RESET_PORT, S_RESET_PIN, GPIO_PIN_RESET) 30 | #define S_RESET_HIGH HAL_GPIO_WritePin(S_RESET_PORT, S_RESET_PIN, GPIO_PIN_SET) 31 | 32 | void S_Back_On(void); 33 | void S_Back_Off(void); 34 | void S_WriteReg(uint8_t reg); 35 | void S_WriteData8(uint8_t data); 36 | void S_WriteData16(uint16_t data); 37 | void S_WriteData(uint8_t *data, uint32_t len); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /demo/tft_lcd/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | #include "lcd.h" 3 | 4 | void HAL_MspInit(void) 5 | { 6 | 7 | } 8 | 9 | #if ST7789_SPI 10 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 11 | { 12 | __HAL_RCC_SPI_CLK_ENABLE(); 13 | __HAL_AFIO_REMAP_SPI_CS(S_CS_PORT, S_CS_PIN); 14 | __HAL_AFIO_REMAP_SPI_CLK(S_SCL_PORT, S_SCL_PIN); 15 | __HAL_AFIO_REMAP_SPI_MOSI(S_SDA_PORT, S_SDA_PIN); 16 | } 17 | 18 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 19 | { 20 | __HAL_RCC_SPI_CLK_DISABLE(); 21 | HAL_GPIO_DeInit(S_CS_PORT, S_CS_PIN); 22 | HAL_GPIO_DeInit(S_SCL_PORT, S_SCL_PIN); 23 | HAL_GPIO_DeInit(S_SDA_PORT, S_SDA_PIN); 24 | } 25 | #endif -------------------------------------------------------------------------------- /demo/tft_lcd/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | -------------------------------------------------------------------------------- /demo/tim/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | TIM_HandleTypeDef htim0; 6 | TIM_HandleTypeDef htim1; 7 | TIM_HandleTypeDef htim2; 8 | TIM_HandleTypeDef htim3; 9 | TIM_HandleTypeDef htim4; 10 | TIM_HandleTypeDef htim5; 11 | 12 | void Error_Handler(void); 13 | static void TIM0_Init(void); 14 | static void TIM1_Init(void); 15 | static void TIM2_Init(void); 16 | static void TIM3_Init(void); 17 | static void TIM4_Init(void); 18 | static void TIM5_Init(void); 19 | 20 | int main(void) 21 | { 22 | SystemClock_Config(CPU_CLK_160M); 23 | printf("enter main\r\n"); 24 | 25 | TIM0_Init(); 26 | HAL_TIM_Base_Start_IT(&htim0); 27 | TIM1_Init(); 28 | HAL_TIM_Base_Start_IT(&htim1); 29 | TIM2_Init(); 30 | HAL_TIM_Base_Start_IT(&htim2); 31 | TIM3_Init(); 32 | HAL_TIM_Base_Start_IT(&htim3); 33 | TIM4_Init(); 34 | HAL_TIM_Base_Start_IT(&htim4); 35 | TIM5_Init(); 36 | HAL_TIM_Base_Start_IT(&htim5); 37 | 38 | while(1) 39 | { 40 | HAL_Delay(1000); 41 | } 42 | } 43 | 44 | static void TIM0_Init(void) 45 | { 46 | htim0.Instance = TIM0; 47 | htim0.Init.Unit = TIM_UNIT_US; 48 | htim0.Init.Period = 1000000; 49 | htim0.Init.AutoReload = TIM_AUTORELOAD_PRELOAD_ENABLE; 50 | if (HAL_TIM_Base_Init(&htim0) != HAL_OK) 51 | { 52 | Error_Handler(); 53 | } 54 | } 55 | 56 | static void TIM1_Init(void) 57 | { 58 | htim1.Instance = TIM1; 59 | htim1.Init.Unit = TIM_UNIT_US; 60 | htim1.Init.Period = 1001000; 61 | htim1.Init.AutoReload = TIM_AUTORELOAD_PRELOAD_ENABLE; 62 | if (HAL_TIM_Base_Init(&htim1) != HAL_OK) 63 | { 64 | Error_Handler(); 65 | } 66 | } 67 | 68 | static void TIM2_Init(void) 69 | { 70 | htim2.Instance = TIM2; 71 | htim2.Init.Unit = TIM_UNIT_US; 72 | htim2.Init.Period = 1002000; 73 | htim2.Init.AutoReload = TIM_AUTORELOAD_PRELOAD_ENABLE; 74 | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) 75 | { 76 | Error_Handler(); 77 | } 78 | } 79 | 80 | static void TIM3_Init(void) 81 | { 82 | htim3.Instance = TIM3; 83 | htim3.Init.Unit = TIM_UNIT_US; 84 | htim3.Init.Period = 1003000; 85 | htim3.Init.AutoReload = TIM_AUTORELOAD_PRELOAD_ENABLE; 86 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK) 87 | { 88 | Error_Handler(); 89 | } 90 | } 91 | 92 | static void TIM4_Init(void) 93 | { 94 | htim4.Instance = TIM4; 95 | htim4.Init.Unit = TIM_UNIT_US; 96 | htim4.Init.Period = 1004000; 97 | htim4.Init.AutoReload = TIM_AUTORELOAD_PRELOAD_ENABLE; 98 | if (HAL_TIM_Base_Init(&htim4) != HAL_OK) 99 | { 100 | Error_Handler(); 101 | } 102 | } 103 | 104 | static void TIM5_Init(void) 105 | { 106 | htim5.Instance = TIM5; 107 | htim5.Init.Unit = TIM_UNIT_US; 108 | htim5.Init.Period = 1005000; 109 | htim5.Init.AutoReload = TIM_AUTORELOAD_PRELOAD_ENABLE; 110 | if (HAL_TIM_Base_Init(&htim5) != HAL_OK) 111 | { 112 | Error_Handler(); 113 | } 114 | } 115 | 116 | void HAL_TIM_Callback(TIM_HandleTypeDef *htim) 117 | { 118 | printf("%d ", htim->Instance); 119 | if (htim->Instance == TIM0) 120 | { 121 | 122 | } 123 | if (htim->Instance == TIM1) 124 | { 125 | 126 | } 127 | if (htim->Instance == TIM2) 128 | { 129 | 130 | } 131 | if (htim->Instance == TIM3) 132 | { 133 | 134 | } 135 | if (htim->Instance == TIM4) 136 | { 137 | 138 | } 139 | if (htim->Instance == TIM5) 140 | { 141 | 142 | } 143 | } 144 | 145 | void Error_Handler(void) 146 | { 147 | while (1) 148 | { 149 | } 150 | } 151 | 152 | void assert_failed(uint8_t *file, uint32_t line) 153 | { 154 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 155 | } -------------------------------------------------------------------------------- /demo/tim/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) 9 | { 10 | __HAL_RCC_TIM_CLK_ENABLE(); 11 | HAL_NVIC_SetPriority(TIM_IRQn, 0); 12 | HAL_NVIC_EnableIRQ(TIM_IRQn); 13 | } 14 | 15 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) 16 | { 17 | // 由于所有的TIM共用一个时钟和中断,所以如果只用了一路TIM,在DeInit时可以关闭时钟和中断,但如果使用了多路TIM,在某一路DeInit时,如果 18 | // 关闭时钟和中断,会影响其他在运行的TIM 19 | // __HAL_RCC_TIM_CLK_DISABLE(); 20 | // HAL_NVIC_DisableIRQ(TIM_IRQn); 21 | } -------------------------------------------------------------------------------- /demo/tim/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | extern TIM_HandleTypeDef htim0; 5 | extern TIM_HandleTypeDef htim1; 6 | extern TIM_HandleTypeDef htim2; 7 | extern TIM_HandleTypeDef htim3; 8 | extern TIM_HandleTypeDef htim4; 9 | extern TIM_HandleTypeDef htim5; 10 | 11 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 12 | __attribute__((isr)) void CORET_IRQHandler(void) 13 | { 14 | readl(0xE000E010); 15 | HAL_IncTick(); 16 | } 17 | 18 | __attribute__((isr)) void TIM0_5_IRQHandler(void) 19 | { 20 | HAL_TIM_IRQHandler(&htim0); 21 | HAL_TIM_IRQHandler(&htim1); 22 | HAL_TIM_IRQHandler(&htim2); 23 | HAL_TIM_IRQHandler(&htim3); 24 | HAL_TIM_IRQHandler(&htim4); 25 | HAL_TIM_IRQHandler(&htim5); 26 | } -------------------------------------------------------------------------------- /demo/touch/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "wm_hal.h" 5 | 6 | TOUCH_HandleTypeDef htouch; 7 | 8 | static void Touch_init(void); 9 | void Error_Handler(void); 10 | 11 | int main(void) 12 | { 13 | SystemClock_Config(CPU_CLK_160M); 14 | printf("enter main\r\n"); 15 | 16 | Touch_init(); 17 | 18 | while(1) 19 | { 20 | HAL_Delay(1000); 21 | } 22 | 23 | return 0; 24 | } 25 | 26 | // 在使用TOUCH功能时,TOUCH0(PA7)必须复用为TOUCH功能,不可以作为其他功能!!! 27 | 28 | static void Touch_init(void) 29 | { 30 | htouch.Instance = TOUCH; 31 | htouch.Init.Channel = TOUCH_CH_0 | TOUCH_CH_8 | TOUCH_CH_9 | TOUCH_CH_11 | TOUCH_CH_12 | TOUCH_CH_13 | TOUCH_CH_14; 32 | htouch.Init.ScanPeriod = 16; 33 | htouch.Init.Window = 32; 34 | htouch.Init.Threshold[0] = 120; 35 | htouch.Init.Threshold[8] = 120; 36 | htouch.Init.Threshold[9] = 120; 37 | htouch.Init.Threshold[11] = 120; 38 | htouch.Init.Threshold[12] = 120; 39 | htouch.Init.Threshold[13] = 120; 40 | htouch.Init.Threshold[14] = 120; 41 | 42 | htouch.Init.Irq_en = 1 << 0 | 1 << 8 | 1 << 9 | 1 << 11 | 1 << 12 | 1 << 13 | 1 << 14; 43 | 44 | HAL_TOUCH_Init(&htouch); 45 | } 46 | 47 | void HAL_TOUCH_Callback(TOUCH_HandleTypeDef *htouch, uint16_t Flag) 48 | { 49 | printf("%x\r\n", Flag); 50 | } 51 | 52 | void Error_Handler(void) 53 | { 54 | while (1) 55 | { 56 | } 57 | } 58 | 59 | void assert_failed(uint8_t *file, uint32_t line) 60 | { 61 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 62 | } -------------------------------------------------------------------------------- /demo/touch/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | void HAL_TOUCH_MspInit(TOUCH_HandleTypeDef* htouch) 5 | { 6 | __HAL_RCC_TOUCH_CLK_ENABLE(); 7 | // 如果用到TOUCH功能,PA7必须复用为TOUCH功能,不可他用 8 | __HAL_AFIO_REMAP_TOUCH(GPIOA, GPIO_PIN_7); 9 | __HAL_AFIO_REMAP_TOUCH(GPIOB, GPIO_PIN_5); 10 | __HAL_AFIO_REMAP_TOUCH(GPIOB, GPIO_PIN_6); 11 | __HAL_AFIO_REMAP_TOUCH(GPIOB, GPIO_PIN_8); 12 | __HAL_AFIO_REMAP_TOUCH(GPIOB, GPIO_PIN_9); 13 | __HAL_AFIO_REMAP_TOUCH(GPIOA, GPIO_PIN_12); 14 | __HAL_AFIO_REMAP_TOUCH(GPIOA, GPIO_PIN_14); 15 | HAL_NVIC_SetPriority(TOUCH_IRQn, 0); 16 | HAL_NVIC_EnableIRQ(TOUCH_IRQn); 17 | } 18 | 19 | void HAL_TOUCH_MspDeInit(TOUCH_HandleTypeDef* htouch) 20 | { 21 | __HAL_RCC_TOUCH_CLK_DISABLE(); 22 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_7); 23 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_5); 24 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6); 25 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8); 26 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_9); 27 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_12); 28 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_14); 29 | HAL_NVIC_DisableIRQ(TOUCH_IRQn); 30 | } -------------------------------------------------------------------------------- /demo/touch/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | 11 | extern TOUCH_HandleTypeDef htouch; 12 | 13 | __attribute__((isr)) void TOUCH_IRQHandler(void) 14 | { 15 | HAL_TOUCH_IRQHandler(&htouch); 16 | } 17 | -------------------------------------------------------------------------------- /demo/uart/fifo.c: -------------------------------------------------------------------------------- 1 | 2 | #include "fifo.h" 3 | #include "string.h" 4 | 5 | _fifo_str fifo_str; 6 | 7 | int FifoInit(uint8_t *fifo_addr, uint32_t fifo_size) 8 | { 9 | _fifo_str *p = &fifo_str; 10 | 11 | if(fifo_addr == NULL || fifo_size == 0) 12 | return -1; 13 | 14 | memset((char *)p, 0, sizeof(_fifo_str)); 15 | p->buf = fifo_addr; 16 | p->in = 0; 17 | p->out = 0; 18 | p->size = fifo_size; 19 | return 0; 20 | } 21 | 22 | int FifoDataLen(void) 23 | { 24 | _fifo_str *p = &fifo_str; 25 | 26 | return (p->in - p->out); 27 | } 28 | 29 | int FifoSpaceLen(void) 30 | { 31 | _fifo_str *p = &fifo_str; 32 | 33 | return (p->size - (p->in - p->out)); 34 | } 35 | 36 | int FifoRead(uint8_t *buf, uint32_t len) 37 | { 38 | uint32_t i = 0, j = 0; 39 | _fifo_str *p = &fifo_str; 40 | 41 | j = (p->out % p->size); 42 | len = min(len, p->in - p->out); 43 | i = min(len, p->size - j); 44 | memcpy(buf, p->buf + j, i); 45 | memcpy(buf + i, p->buf, len - i); 46 | p->out += len; 47 | return len; 48 | } 49 | 50 | int FifoWrite(uint8_t *buf, uint32_t len) 51 | { 52 | uint32_t i = 0, j = 0; 53 | _fifo_str *p = &fifo_str; 54 | 55 | j = p->in % p->size; 56 | len = min(len, p->size - p->in + p->out); 57 | i = min(len, p->size - j); 58 | memcpy(p->buf + j, buf, i); 59 | memcpy(p->buf, buf + i, len - i); 60 | p->in += len; 61 | 62 | return len; 63 | } 64 | 65 | void FifoClear(void) 66 | { 67 | _fifo_str *p = &fifo_str; 68 | 69 | p->in = 0; 70 | p->out = 0; 71 | } 72 | 73 | 74 | -------------------------------------------------------------------------------- /demo/uart/fifo.h: -------------------------------------------------------------------------------- 1 | #ifndef _FIF0_H_ 2 | #define _FIFO_H_ 3 | 4 | #include "wm_hal.h" 5 | 6 | typedef struct fifo_t { 7 | uint8_t *buf; 8 | uint32_t size; 9 | uint32_t in; 10 | uint32_t out; 11 | } _fifo_str; 12 | 13 | #define min(x,y) ((x) < (y)?(x):(y)) 14 | 15 | int FifoInit(uint8_t *fifo_addr, uint32_t fifo_size); 16 | 17 | int FifoDataLen(void); 18 | 19 | int FifoSpaceLen(void); 20 | 21 | int FifoRead(uint8_t *buf, uint32_t len); 22 | 23 | int FifoWrite(uint8_t *buf, uint32_t len); 24 | 25 | void FifoClear(void); 26 | 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /demo/uart/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "wm_hal.h" 5 | #include "fifo.h" 6 | 7 | UART_HandleTypeDef huart1; 8 | 9 | static void UART1_Init(void); 10 | void Error_Handler(void); 11 | 12 | #define IT_LEN 0 // 大于等于0,0:接收不定长数据即可触发中断回调;大于0:接收N个长度数据才触发中断回调 13 | static uint8_t buf[32] = {0}; // 必须大于等于32字节 14 | #define LEN 2048 15 | static uint8_t pdata[LEN] = {0}; 16 | int main(void) 17 | { 18 | volatile int tx_len = 0; 19 | uint8_t tx_buf[100] = {0}; 20 | 21 | SystemClock_Config(CPU_CLK_160M); 22 | printf("enter main\r\n"); 23 | 24 | UART1_Init(); 25 | FifoInit(pdata, LEN); 26 | HAL_UART_Receive_IT(&huart1, buf, IT_LEN); // 只需调用一次,接收够设定的长度,进入中断回调,用户需要在中断回调中取走数据,此处设置了 27 | // 0个字节,即不定长 28 | while(1) 29 | { 30 | tx_len = FifoDataLen(); 31 | if (tx_len > 0) 32 | { 33 | tx_len = (tx_len > 100) ? 100 : tx_len; 34 | FifoRead(tx_buf, tx_len); 35 | HAL_UART_Transmit(&huart1, tx_buf, tx_len, 1000); 36 | } 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | static void UART1_Init(void) 43 | { 44 | huart1.Instance = UART1; 45 | huart1.Init.BaudRate = 115200; 46 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 47 | huart1.Init.StopBits = UART_STOPBITS_1; 48 | huart1.Init.Parity = UART_PARITY_NONE; 49 | huart1.Init.Mode = UART_MODE_TX | UART_MODE_RX; 50 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 51 | if (HAL_UART_Init(&huart1) != HAL_OK) 52 | { 53 | Error_Handler(); 54 | } 55 | } 56 | 57 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 58 | { 59 | if (FifoSpaceLen() >= huart->RxXferCount) 60 | { 61 | FifoWrite(huart->pRxBuffPtr, huart->RxXferCount); 62 | } 63 | } 64 | 65 | void Error_Handler(void) 66 | { 67 | while (1) 68 | { 69 | } 70 | } 71 | 72 | void assert_failed(uint8_t *file, uint32_t line) 73 | { 74 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 75 | } -------------------------------------------------------------------------------- /demo/uart/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) 5 | { 6 | if (huart->Instance == UART1) 7 | { 8 | __HAL_RCC_UART1_CLK_ENABLE(); 9 | __HAL_RCC_GPIO_CLK_ENABLE(); 10 | 11 | // PB6: UART1_TX 12 | // PB7: UART1_RX 13 | __HAL_AFIO_REMAP_UART1_TX(GPIOB, GPIO_PIN_6); 14 | __HAL_AFIO_REMAP_UART1_RX(GPIOB, GPIO_PIN_7); 15 | HAL_NVIC_SetPriority(UART1_IRQn, 0); 16 | HAL_NVIC_EnableIRQ(UART1_IRQn); 17 | } 18 | } 19 | 20 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 21 | { 22 | if (huart->Instance == UART1) 23 | { 24 | __HAL_RCC_UART1_CLK_DISABLE(); 25 | HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /demo/uart/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 5 | __attribute__((isr)) void CORET_IRQHandler(void) 6 | { 7 | readl(0xE000E010); 8 | HAL_IncTick(); 9 | } 10 | 11 | extern UART_HandleTypeDef huart1; 12 | 13 | __attribute__((isr)) void UART1_IRQHandler(void) 14 | { 15 | HAL_UART_IRQHandler(&huart1); 16 | } 17 | -------------------------------------------------------------------------------- /demo/wwdg/main.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "wm_hal.h" 4 | 5 | void Error_Handler(void); 6 | static void WDG_Init(void); 7 | 8 | WDG_HandleTypeDef hwdg; 9 | 10 | int main(void) 11 | { 12 | SystemClock_Config(CPU_CLK_160M); 13 | printf("enter main\r\n"); 14 | 15 | WDG_Init(); 16 | while (1) 17 | { 18 | printf("."); 19 | HAL_Delay(1000); 20 | } 21 | } 22 | 23 | static void WDG_Init(void) 24 | { 25 | hwdg.Instance = WDG; 26 | hwdg.Init.Reload = 5 * 1000 * 1000; // 5s 27 | if (HAL_WDG_Init(&hwdg) != HAL_OK) 28 | { 29 | Error_Handler(); 30 | } 31 | } 32 | 33 | void Error_Handler(void) 34 | { 35 | while (1) 36 | { 37 | } 38 | } 39 | 40 | void assert_failed(uint8_t *file, uint32_t line) 41 | { 42 | printf("Wrong parameters value: file %s on line %d\r\n", file, line); 43 | } -------------------------------------------------------------------------------- /demo/wwdg/wm_hal_msp.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | void HAL_MspInit(void) 4 | { 5 | 6 | } 7 | 8 | void HAL_WDG_MspInit(WDG_HandleTypeDef* hwdg) 9 | { 10 | if(hwdg->Instance == WDG) 11 | { 12 | HAL_NVIC_SetPriority(WDG_IRQn, 0); 13 | HAL_NVIC_EnableIRQ(WDG_IRQn); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /demo/wwdg/wm_it.c: -------------------------------------------------------------------------------- 1 | 2 | #include "wm_hal.h" 3 | 4 | extern WDG_HandleTypeDef hwdg; 5 | 6 | #define readl(addr) ({unsigned int __v = (*(volatile unsigned int *) (addr)); __v;}) 7 | __attribute__((isr)) void CORET_IRQHandler(void) 8 | { 9 | readl(0xE000E010); 10 | HAL_IncTick(); 11 | } 12 | 13 | __attribute__((isr)) void WDG_IRQHandler(void) 14 | { 15 | HAL_WDG_IRQHandler(&hwdg); 16 | } -------------------------------------------------------------------------------- /include/arch/xt804/csi_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __CSI_CONFIG_H__ 2 | #define __CSI_CONFIG_H__ 3 | #define CONFIG_CHIP_SL04 1 4 | #define CONFIG_KERNEL_NONE 1 5 | #define CONFIG_HAVE_VIC 1 6 | #define CONFIG_SEPARATE_IRQ_SP 1 7 | #define CONFIG_ARCH_INTERRUPTSTACK 4096 8 | #define CONFIG_IRQ_VECTOR_SIZE 256 9 | #define USE_UART0_PRINT 1 // UART0 printf, 0:OFF, 1:ON 10 | 11 | #if USE_UART0_PRINT 12 | #define USE_UART0_AUTO_DL 0 // Auto download, 0:OFF, 1:ON 13 | #endif 14 | 15 | #ifdef CONFIG_KERNEL_NONE 16 | #define CONFIG_SYSTEM_SECURE 1 17 | #endif 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/arch/xt804/csi_core/csi_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /****************************************************************************** 18 | * @file csi_core.h 19 | * @brief CSI Core Layer Header File 20 | * @version V1.0 21 | * @date 02. June 2017 22 | ******************************************************************************/ 23 | 24 | #ifndef _CORE_H_ 25 | #define _CORE_H_ 26 | 27 | #include 28 | 29 | #if defined(__CK801__) || defined(__E801__) 30 | #include 31 | #elif defined(__CK802__) || defined(__E802__) || defined(__S802__) 32 | #include 33 | #elif defined(__E803__) || defined(__S803__) 34 | #include 35 | #elif defined(__CK803__) || defined(__CK804__) || defined(__E804__) || defined(__E804D__) || defined(__E804F__) || defined (__E804DF__) 36 | #include 37 | #elif defined(__CK805__) || defined(__I805__) || defined(__I805F__) 38 | #include 39 | #elif defined(__CK610__) 40 | #include 41 | #elif defined(__CK810__) || defined(__C810__) || defined(__C810V__) 42 | #include 43 | #elif defined(__CK807__) || defined(__C807__) || defined(__C807F__) || defined(__C807FV__) 44 | #include 45 | #elif defined(__riscv) 46 | #include 47 | #endif 48 | 49 | #ifdef __riscv 50 | #include 51 | #else 52 | #include 53 | #endif 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* _CORE_H_ */ 64 | -------------------------------------------------------------------------------- /include/driver/wm_cpu.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wm_cpu.h 3 | * 4 | * @brief cpu driver module 5 | * 6 | * @author dave 7 | * 8 | * @copyright (c) 2014 Winner Microelectronics Co., Ltd. 9 | */ 10 | #ifndef __WM_CPU_H__ 11 | #define __WM_CPU_H__ 12 | 13 | #include "wm_hal.h" 14 | 15 | /**BASE PLL CLOCK*/ 16 | #define W806_PLL_CLK_MHZ (480) 17 | 18 | #define IS_NVIC_DEVICE_IRQ(IRQ) ((IRQ) >= (IRQn_Type)0x00U) 19 | 20 | enum CPU_CLK{ 21 | CPU_CLK_240M = 2, 22 | CPU_CLK_160M = 3, 23 | CPU_CLK_80M = 6, 24 | CPU_CLK_40M = 12, 25 | CPU_CLK_2M = 240, 26 | }; 27 | 28 | typedef union { 29 | struct { 30 | uint32_t CPU: 8; /*!< bit: 0.. 7 cpu clock divider */ 31 | uint32_t WLAN: 8; /*!< bit: 8.. 15 Wlan clock divider */ 32 | uint32_t BUS2: 8; /*!< bit: 16.. 23 clock dividing ratio of bus2 & bus1 */ 33 | uint32_t PD: 4; /*!< bit: 24.. 27 peripheral divider */ 34 | uint32_t RSV: 3; /*!< bit: 28.. 30 Reserved */ 35 | uint32_t DIV_EN: 1; /*!< bit: 31 divide frequency enable */ 36 | } b; 37 | uint32_t w; 38 | } clk_div_reg; 39 | 40 | #define UNIT_MHZ (1000000) 41 | 42 | 43 | typedef struct{ 44 | uint32_t apbclk; 45 | uint32_t cpuclk; 46 | uint32_t wlanclk; 47 | }wm_sys_clk; 48 | 49 | typedef enum 50 | { 51 | HAL_TICK_FREQ_10HZ = 10, 52 | HAL_TICK_FREQ_100HZ = 100, 53 | HAL_TICK_FREQ_1KHZ = 1000, 54 | HAL_TICK_FREQ_DEFAULT = HAL_TICK_FREQ_1KHZ 55 | } HAL_TickFreqTypeDef; 56 | 57 | 58 | #ifdef __cplusplus 59 | extern "C"{ 60 | #endif 61 | void SystemClock_Config(uint32_t clk); 62 | void SystemClock_Get(wm_sys_clk *sysclk); 63 | 64 | HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); 65 | void HAL_IncTick(void); 66 | uint32_t HAL_GetTick(void); 67 | void HAL_Delay(uint32_t Delay); 68 | 69 | void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t Priority); 70 | void HAL_NVIC_EnableIRQ(IRQn_Type IRQn); 71 | void HAL_NVIC_DisableIRQ(IRQn_Type IRQn); 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif /* WM_CPU_H */ 77 | -------------------------------------------------------------------------------- /include/driver/wm_gpio.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM_GPIO_H__ 2 | #define __WM_GPIO_H__ 3 | 4 | #include "wm_hal.h" 5 | 6 | typedef struct 7 | { 8 | uint32_t Pin; 9 | uint32_t Mode; 10 | uint32_t Pull; 11 | } GPIO_InitTypeDef; 12 | 13 | typedef enum 14 | { 15 | GPIO_PIN_RESET = 0, 16 | GPIO_PIN_SET 17 | } GPIO_PinState; 18 | 19 | #define GPIOA ((GPIO_TypeDef *)GPIOA_BASE) 20 | #define GPIOB ((GPIO_TypeDef *)GPIOB_BASE) 21 | 22 | #define GPIO_PIN_0 ((uint32_t)0x00000001) 23 | #define GPIO_PIN_1 ((uint32_t)0x00000002) 24 | #define GPIO_PIN_2 ((uint32_t)0x00000004) 25 | #define GPIO_PIN_3 ((uint32_t)0x00000008) 26 | #define GPIO_PIN_4 ((uint32_t)0x00000010) 27 | #define GPIO_PIN_5 ((uint32_t)0x00000020) 28 | #define GPIO_PIN_6 ((uint32_t)0x00000040) 29 | #define GPIO_PIN_7 ((uint32_t)0x00000080) 30 | #define GPIO_PIN_8 ((uint32_t)0x00000100) 31 | #define GPIO_PIN_9 ((uint32_t)0x00000200) 32 | #define GPIO_PIN_10 ((uint32_t)0x00000400) 33 | #define GPIO_PIN_11 ((uint32_t)0x00000800) 34 | #define GPIO_PIN_12 ((uint32_t)0x00001000) 35 | #define GPIO_PIN_13 ((uint32_t)0x00002000) 36 | #define GPIO_PIN_14 ((uint32_t)0x00004000) 37 | #define GPIO_PIN_15 ((uint32_t)0x00008000) 38 | #define GPIO_PIN_16 ((uint32_t)0x00010000) 39 | #define GPIO_PIN_17 ((uint32_t)0x00020000) 40 | #define GPIO_PIN_18 ((uint32_t)0x00040000) 41 | #define GPIO_PIN_19 ((uint32_t)0x00080000) 42 | #define GPIO_PIN_20 ((uint32_t)0x00100000) 43 | #define GPIO_PIN_21 ((uint32_t)0x00200000) 44 | #define GPIO_PIN_22 ((uint32_t)0x00400000) 45 | #define GPIO_PIN_23 ((uint32_t)0x00800000) 46 | #define GPIO_PIN_24 ((uint32_t)0x01000000) 47 | #define GPIO_PIN_25 ((uint32_t)0x02000000) 48 | #define GPIO_PIN_26 ((uint32_t)0x04000000) 49 | #define GPIO_PIN_27 ((uint32_t)0x08000000) 50 | #define GPIO_PIN_28 ((uint32_t)0x10000000) 51 | #define GPIO_PIN_29 ((uint32_t)0x20000000) 52 | #define GPIO_PIN_30 ((uint32_t)0x40000000) 53 | #define GPIO_PIN_31 ((uint32_t)0x80000000) 54 | #define GPIO_PIN_ALL ((uint32_t)0xFFFFFFFF) 55 | 56 | #define GPIO_PIN_MASK 0xFFFFFFFF 57 | 58 | #define GPIO_MODE_INPUT 0x01 59 | #define GPIO_MODE_OUTPUT 0x02 60 | 61 | #define GPIO_MODE_IT_RISING 0x87 62 | #define GPIO_MODE_IT_FALLING 0x88 63 | #define GPIO_MODE_IT_RISING_FALLING 0x89 64 | #define GPIO_MODE_IT_HIGH_LEVEL 0x8a 65 | #define GPIO_MODE_IT_LOW_LEVEL 0x8b 66 | 67 | #define GPIO_NOPULL 0x12 68 | #define GPIO_PULLUP 0x13 69 | #define GPIO_PULLDOWN 0x14 70 | 71 | #define IS_GPIO_ALL_INSTANCE(INSTANCE) (((INSTANCE) == GPIOA) || \ 72 | ((INSTANCE) == GPIOB)) 73 | 74 | #define IS_GPIO_AF_INSTANCE(INSTANCE) IS_GPIO_ALL_INSTANCE(INSTANCE) 75 | 76 | #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET)) 77 | 78 | #define IS_GPIO_PIN(PIN) (((((uint32_t)PIN) & GPIO_PIN_MASK ) != 0x00u) && ((((uint32_t)PIN) & ~GPIO_PIN_MASK) == 0x00u)) 79 | 80 | #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT) ||\ 81 | ((MODE) == GPIO_MODE_OUTPUT) ||\ 82 | ((MODE) == GPIO_MODE_IT_RISING) ||\ 83 | ((MODE) == GPIO_MODE_IT_FALLING) ||\ 84 | ((MODE) == GPIO_MODE_IT_RISING_FALLING)) 85 | 86 | #define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \ 87 | ((PULL) == GPIO_PULLDOWN)) 88 | 89 | 90 | #ifdef __cplusplus 91 | extern "C"{ 92 | #endif 93 | void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init); 94 | void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); 95 | 96 | GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); 97 | void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin, GPIO_PinState PinState); 98 | void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); 99 | void HAL_GPIO_EXTI_IRQHandler(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); 100 | void HAL_GPIO_EXTI_Callback(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif -------------------------------------------------------------------------------- /include/driver/wm_hal.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM_HAL_H__ 2 | #define __WM_HAL_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "wm_type_def.h" 8 | #include "wm_regs.h" 9 | #include "wm_cpu.h" 10 | #include "wm_gpio.h" 11 | #include "wm_gpio_ex.h" 12 | #include "wm_uart.h" 13 | #include "wm_rcc.h" 14 | #include "wm_spi.h" 15 | #include "wm_wdg.h" 16 | #include "wm_tim.h" 17 | #include "wm_internal_flash.h" 18 | #include "wm_adc.h" 19 | #include "wm_pwm.h" 20 | #include "wm_pmu.h" 21 | #include "wm_spi_flash.h" 22 | #include "wm_i2c.h" 23 | #include "wm_touch.h" 24 | #include "wm_i2s.h" 25 | #include "wm_dma.h" 26 | 27 | #define VER "0.6.0" 28 | 29 | #define __HAL_LOCK(__HANDLE__) \ 30 | do{ \ 31 | if((__HANDLE__)->Lock == HAL_LOCKED) \ 32 | { \ 33 | return HAL_BUSY; \ 34 | } \ 35 | else \ 36 | { \ 37 | (__HANDLE__)->Lock = HAL_LOCKED; \ 38 | } \ 39 | }while (0) 40 | 41 | #define __HAL_UNLOCK(__HANDLE__) \ 42 | do{ \ 43 | (__HANDLE__)->Lock = HAL_UNLOCKED; \ 44 | }while (0) 45 | 46 | 47 | #ifdef __cplusplus 48 | extern "C"{ 49 | #endif 50 | HAL_StatusTypeDef HAL_Init(void); 51 | HAL_StatusTypeDef HAL_DeInit(void); 52 | void HAL_MspInit(void); 53 | void HAL_MspDeInit(void); 54 | 55 | #ifdef USE_FULL_ASSERT 56 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 57 | void assert_failed(uint8_t* file, uint32_t line); 58 | #else 59 | #define assert_param(expr) ((void)0U) 60 | #endif 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif -------------------------------------------------------------------------------- /include/driver/wm_i2c.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 IOsetting 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef __WM_I2C_H__ 16 | #define __WM_I2C_H__ 17 | 18 | #include "wm_hal.h" 19 | 20 | typedef struct __I2C_HandleTypeDef 21 | { 22 | I2C_TypeDef *Instance; /*!< I2C registers base address */ 23 | uint32_t Frequency; 24 | HAL_LockTypeDef Lock; /*!< Object lock */ 25 | __IO uint32_t ErrorCode; /*!< I2C Error code */ 26 | } I2C_HandleTypeDef; 27 | 28 | #define I2C ((I2C_TypeDef *)I2C_BASE) 29 | 30 | #ifdef __cplusplus 31 | extern "C"{ 32 | #endif 33 | 34 | HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c); 35 | HAL_StatusTypeDef HAL_I2C_DeInit(I2C_HandleTypeDef *hi2c); 36 | void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c); 37 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c); 38 | 39 | HAL_StatusTypeDef HAL_I2C_Write(I2C_HandleTypeDef *hi2c, uint8_t DevAddress, uint8_t MemAddress, uint8_t *pData, uint16_t Size); 40 | HAL_StatusTypeDef HAL_I2C_Read(I2C_HandleTypeDef *hi2c, uint8_t DevAddress, uint8_t MemAddress, uint8_t *pData, uint16_t Size); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif -------------------------------------------------------------------------------- /include/driver/wm_pmu.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM_PMU_H__ 2 | #define __WM_PMU_H__ 3 | 4 | #include "wm_hal.h" 5 | 6 | typedef struct 7 | { 8 | uint8_t Year; // range [0, 99] 9 | uint8_t Month; // range [1, 12] 10 | uint8_t Date; // range [1, 31] 11 | uint8_t Hours; // range [0, 23] 12 | uint8_t Minutes; // range [0, 59] 13 | uint8_t Seconds; // range [0, 59] 14 | } RTC_TimeTypeDef; 15 | 16 | typedef struct 17 | { 18 | PMU_TypeDef *Instance; 19 | uint32_t ClkSource; /* This parameter can be a value of @ref PMU_ClkSource_Definitions */ 20 | } PMU_HandleTypeDef; 21 | 22 | #define PMU ((PMU_TypeDef *)PMU_BASE) 23 | 24 | // PMU_ClkSource_Definitions 25 | #define PMU_CLKSOURCE_32RC PMU_CR_32KRC_CAL_EN 26 | #define PMU_CLKSOURCE_32RCBYPASS PMU_CR_32KRCBYPASS 27 | 28 | #define IS_PMU_ALL_INSTANCE(INSTANCE) ((INSTANCE) == PMU) 29 | 30 | #define IS_PMU_TIMPERIOD(__PERIOD__) (((__PERIOD__) >= 0x0000) && ((__PERIOD__) <= 0x0FFFF)) 31 | 32 | #define IS_PMU_CLKSOURCE(SOURCE) (((SOURCE) == PMU_CR_32KRC_CAL_EN) || ((SOURCE) == PMU_CR_32KRCBYPASS)) 33 | #define IS_RTC_HOUR24(HOUR) ((HOUR) <= 23U) 34 | #define IS_RTC_MINUTES(MINUTES) ((MINUTES) <= 59U) 35 | #define IS_RTC_SECONDS(SECONDS) ((SECONDS) <= 59U) 36 | #define IS_RTC_YEAR(YEAR) ((YEAR) <= 99U) 37 | #define IS_RTC_MONTH(MONTH) (((MONTH) >= 1U) && ((MONTH) <= 12U)) 38 | #define IS_RTC_DATE(DATE) (((DATE) >= 1U) && ((DATE) <= 31U)) 39 | 40 | 41 | #ifdef __cplusplus 42 | extern "C"{ 43 | #endif 44 | 45 | HAL_StatusTypeDef HAL_PMU_Init(PMU_HandleTypeDef *hpmu); 46 | HAL_StatusTypeDef HAL_PMU_DeInit(PMU_HandleTypeDef *hpmu); 47 | 48 | void HAL_PMU_MspInit(PMU_HandleTypeDef *hpmu); 49 | void HAL_PMU_MspDeInit(PMU_HandleTypeDef *hpmu); 50 | void HAL_PMU_Enter_Sleep(PMU_HandleTypeDef *hpmu); 51 | void HAL_PMU_Enter_Standby(PMU_HandleTypeDef *hpmu); 52 | 53 | /** 54 | * Set and start timer 0 55 | */ 56 | HAL_StatusTypeDef HAL_PMU_TIMER0_Start(PMU_HandleTypeDef *hpmu, uint32_t Period); 57 | HAL_StatusTypeDef HAL_PMU_TIMER0_Stop(PMU_HandleTypeDef *hpmu); 58 | 59 | /** 60 | * Set and start clock 61 | */ 62 | HAL_StatusTypeDef HAL_PMU_RTC_Start(PMU_HandleTypeDef *hpmu, RTC_TimeTypeDef *Time); 63 | HAL_StatusTypeDef HAL_PMU_RTC_Stop(PMU_HandleTypeDef *hpmu); 64 | HAL_StatusTypeDef HAL_PMU_RTC_GetTime(PMU_HandleTypeDef *hpmu, RTC_TimeTypeDef *Time); 65 | HAL_StatusTypeDef HAL_PMU_RTC_Alarm_Enable(PMU_HandleTypeDef *hpmu, RTC_TimeTypeDef *Time); 66 | HAL_StatusTypeDef HAL_PMU_RTC_Alarm_Disable(PMU_HandleTypeDef *hpmu); 67 | 68 | void HAL_PMU_Tim0_Callback(PMU_HandleTypeDef *hpmu); 69 | 70 | void HAL_PMU_IO_Callback(PMU_HandleTypeDef *hpmu); 71 | 72 | void HAL_PMU_RTC_Callback(PMU_HandleTypeDef *hpmu); 73 | 74 | void HAL_PMU_IRQHandler(PMU_HandleTypeDef *hpmu); 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /include/driver/wm_rcc.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM_RCC_H__ 2 | #define __WM_RCC_H__ 3 | 4 | #define RCC ((RCC_TypeDef *)RCC_BASE) 5 | 6 | #define __HAL_RCC_ALL_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_ALL) 7 | 8 | #define __HAL_RCC_SPI_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_LSPI) 9 | 10 | #define __HAL_RCC_SPI_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_LSPI) 11 | 12 | #define __HAL_RCC_PWM_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_PWM) 13 | 14 | #define __HAL_RCC_PWM_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_PWM) 15 | 16 | #define __HAL_RCC_ADC_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_ADC) 17 | 18 | #define __HAL_RCC_ADC_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_ADC) 19 | 20 | #define __HAL_RCC_GPIO_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_GPIO) 21 | 22 | #define __HAL_RCC_GPIO_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_GPIO) 23 | 24 | #define __HAL_RCC_UART0_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_UART0) 25 | 26 | #define __HAL_RCC_UART0_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_UART0) 27 | 28 | #define __HAL_RCC_UART1_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_UART1) 29 | 30 | #define __HAL_RCC_UART1_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_UART1) 31 | 32 | #define __HAL_RCC_UART2_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_UART2) 33 | 34 | #define __HAL_RCC_UART2_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_UART2) 35 | 36 | #define __HAL_RCC_UART3_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_UART3) 37 | 38 | #define __HAL_RCC_UART3_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_UART3) 39 | 40 | #define __HAL_RCC_UART4_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_UART4) 41 | 42 | #define __HAL_RCC_UART4_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_UART4) 43 | 44 | #define __HAL_RCC_UART5_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_UART5) 45 | 46 | #define __HAL_RCC_UART5_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_UART5) 47 | 48 | #define __HAL_RCC_TIM_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_TIMER) 49 | 50 | #define __HAL_RCC_TIM_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_TIMER) 51 | 52 | #define __HAL_RCC_I2C_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_I2C) 53 | 54 | #define __HAL_RCC_I2C_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_I2C) 55 | 56 | #define __HAL_RCC_TOUCH_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_TOUCH) 57 | 58 | #define __HAL_RCC_TOUCH_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_TOUCH) 59 | 60 | #define __HAL_RCC_DMA_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_DMA) 61 | 62 | #define __HAL_RCC_DMA_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_DMA) 63 | 64 | #define __HAL_RCC_I2S_CLK_ENABLE() SET_BIT(RCC->CLK_EN, RCC_CLK_EN_I2S) 65 | 66 | #define __HAL_RCC_I2S_CLK_DISABLE() CLEAR_BIT(RCC->CLK_EN, RCC_CLK_EN_I2S) 67 | 68 | 69 | 70 | #endif -------------------------------------------------------------------------------- /include/driver/wm_spi_flash.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM_SPI_FLASH_H__ 2 | #define __WM_SPI_FLASH_H__ 3 | 4 | #include "wm_hal.h" 5 | 6 | #define PAGE_SIZE 256 7 | #define SECTOR_SIZE 4096 8 | 9 | #define EXFLASH_ID (0x9F) 10 | #define EXFLASH_READ_DATA (0x03) 11 | #define EXFLASH_PAGE_PROGRAM (0x02) 12 | #define EXFLASH_SECTOR_ERASE (0x20) 13 | #define EXFLASH_CIHP_ERASE (0xC7) 14 | #define EXFLASH_WRITE_ENABLE (0x06) 15 | #define EXFLASH_READ_SR1 (0x05) 16 | #define EXFLASH_READ_SR2 (0x35) 17 | 18 | #define EXFLASH_STATUS_BUSY (1 << 0) 19 | #define EXFLASH_STATUS_WEL (1 << 1) 20 | 21 | #define swap32(a) (((a & 0xFF) << 24) | ((a & 0xFF00) << 8) | ((a & 0xFF0000) >> 8) | (a >> 24)) 22 | 23 | #ifdef __cplusplus 24 | extern "C"{ 25 | #endif 26 | int SPIFLS_Init(void); 27 | 28 | int SPIFLS_Read_ID(uint8_t *id); 29 | 30 | int SPIFLS_Read(uint32_t addr, uint8_t *buf, uint32_t len); 31 | 32 | int SPIFLS_Write(uint32_t addr, uint8_t *buf, uint32_t len); 33 | 34 | int SPIFLS_Erase(uint32_t sector); 35 | 36 | int SPIFLS_Chip_Erase(void); 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif -------------------------------------------------------------------------------- /include/driver/wm_tim.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM_TIM_H__ 2 | #define __WM_TIM_H__ 3 | 4 | #include "wm_hal.h" 5 | 6 | #define TIM ((TIM_TypeDef *)TIM_BASE) 7 | #define TIM0 0 8 | #define TIM1 1 9 | #define TIM2 2 10 | #define TIM3 3 11 | #define TIM4 4 12 | #define TIM5 5 13 | 14 | typedef enum 15 | { 16 | HAL_TIM_STATE_RESET = 0x00U, 17 | HAL_TIM_STATE_READY = 0x01U, 18 | HAL_TIM_STATE_BUSY = 0x02U, 19 | HAL_TIM_STATE_TIMEOUT = 0x03U, 20 | HAL_TIM_STATE_ERROR = 0x04U 21 | } HAL_TIM_StateTypeDef; 22 | 23 | typedef struct 24 | { 25 | uint32_t Unit; 26 | uint32_t AutoReload; 27 | uint32_t Period; 28 | 29 | } TIM_Base_InitTypeDef; 30 | 31 | typedef struct 32 | { 33 | uint32_t Instance; 34 | TIM_Base_InitTypeDef Init; 35 | 36 | HAL_LockTypeDef Lock; 37 | __IO HAL_TIM_StateTypeDef State; 38 | 39 | } TIM_HandleTypeDef; 40 | 41 | #define TIM_UNIT_US 0x00000000U 42 | #define TIM_UNIT_MS 0x00000001U 43 | 44 | #define TIM_AUTORELOAD_PRELOAD_DISABLE 0x00000001U 45 | #define TIM_AUTORELOAD_PRELOAD_ENABLE 0x00000000U 46 | 47 | #define IS_TIM_INSTANCE(INSTANCE)\ 48 | (((INSTANCE) == TIM0) || \ 49 | ((INSTANCE) == TIM1) || \ 50 | ((INSTANCE) == TIM2) || \ 51 | ((INSTANCE) == TIM3) || \ 52 | ((INSTANCE) == TIM4) || \ 53 | ((INSTANCE) == TIM5)) 54 | 55 | #define IS_TIM_UNIT(UNIT) (((UNIT) == TIM_UNIT_US) || \ 56 | ((UNIT) == TIM_UNIT_MS)) 57 | 58 | #define IS_TIM_AUTORELOAD(PRELOAD) (((PRELOAD) == TIM_AUTORELOAD_PRELOAD_DISABLE) || \ 59 | ((PRELOAD) == TIM_AUTORELOAD_PRELOAD_ENABLE)) 60 | 61 | #define __HAL_TIM_ENABLE(__HANDLE__) (TIM->CR |= TIM_CR_TIM_EN((__HANDLE__)->Instance - TIM0)) 62 | 63 | #define __HAL_TIM_DISABLE(__HANDLE__) (TIM->CR &= ~(TIM_CR_TIM_EN((__HANDLE__)->Instance - TIM0))) 64 | 65 | #define __HAL_TIM_ENABLE_IT(__HANDLE__) (TIM->CR |= TIM_CR_TIM_TIE((__HANDLE__)->Instance - TIM0)) 66 | 67 | #define __HAL_TIM_DISABLE_IT(__HANDLE__) (TIM->CR &= ~(TIM_CR_TIM_TIE((__HANDLE__)->Instance - TIM0))) 68 | 69 | #define __HAL_TIM_GET_FLAG(__HANDLE__) ((TIM->CR & TIM_CR_TIM_TIF((__HANDLE__)->Instance - TIM0)) == \ 70 | TIM_CR_TIM_TIF((__HANDLE__)->Instance - TIM0)) 71 | 72 | #define __HAL_TIM_CLEAR_IT(__HANDLE__) (TIM->CR |= TIM_CR_TIM_TIF((__HANDLE__)->Instance - TIM0)) 73 | 74 | #ifdef __cplusplus 75 | extern "C"{ 76 | #endif 77 | HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim); 78 | HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim); 79 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim); 80 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim); 81 | 82 | HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim); 83 | HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim); 84 | 85 | HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim); 86 | HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim); 87 | 88 | HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim); 89 | 90 | void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim); 91 | 92 | void HAL_TIM_Callback(TIM_HandleTypeDef *htim); 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /include/driver/wm_wdg.h: -------------------------------------------------------------------------------- 1 | #ifndef __WM_WDG_H__ 2 | #define __WM_WDG_H__ 3 | 4 | #include "wm_hal.h" 5 | 6 | #define WDG ((WDG_TypeDef *)WDG_BASE) 7 | 8 | typedef struct 9 | { 10 | uint32_t Reload; // unit: us 11 | 12 | } WDG_InitTypeDef; 13 | 14 | typedef struct 15 | { 16 | WDG_TypeDef *Instance; 17 | 18 | WDG_InitTypeDef Init; 19 | 20 | } WDG_HandleTypeDef; 21 | 22 | 23 | #define IS_WDG_ALL_INSTANCE(INSTANCE) ((INSTANCE) == WDG) 24 | 25 | #define IS_WDG_RELOAD(__RELOAD__) ((__RELOAD__) <= WDG_LD) 26 | 27 | #define __HAL_WDG_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLR = __FLAG__) 28 | 29 | #ifdef __cplusplus 30 | extern "C"{ 31 | #endif 32 | HAL_StatusTypeDef HAL_WDG_Init(WDG_HandleTypeDef *hwdg); 33 | 34 | void HAL_WDG_MspInit(WDG_HandleTypeDef* hwdg); 35 | 36 | HAL_StatusTypeDef HAL_WDG_DeInit(WDG_HandleTypeDef *hwdg); 37 | 38 | void HAL_WDG_IRQHandler(WDG_HandleTypeDef *hwdg); 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/wm_type_def.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wm_type_def.h 3 | * 4 | * @brief WM type redefine 5 | * 6 | * @author winnermicro 7 | * 8 | * Copyright (c) 2015 Winner Microelectronics Co., Ltd. 9 | */ 10 | #ifndef __WM_TYPE_DEF_H__ 11 | #define __WM_TYPE_DEF_H__ 12 | 13 | 14 | #include 15 | #include 16 | 17 | typedef enum 18 | { 19 | HAL_OK = 0x00U, 20 | HAL_ERROR = 0x01U, 21 | HAL_BUSY = 0x02U, 22 | HAL_TIMEOUT = 0x03U 23 | } HAL_StatusTypeDef; 24 | 25 | typedef enum 26 | { 27 | HAL_UNLOCKED = 0x00U, 28 | HAL_LOCKED = 0x01U 29 | } HAL_LockTypeDef; 30 | 31 | typedef enum 32 | { 33 | RESET = 0, 34 | SET = !RESET 35 | } FlagStatus, ITStatus; 36 | 37 | #define UNUSED(X) (void)X 38 | 39 | #ifndef NULL 40 | #define NULL ((void *)0) 41 | #endif 42 | 43 | #define HAL_MAX_DELAY 0xFFFFFFFF 44 | 45 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != 0U) 46 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U) 47 | 48 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \ 49 | do{ \ 50 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \ 51 | (__DMA_HANDLE__).Parent = (__HANDLE__); \ 52 | } while(0U) 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /lib/W806/libdsp.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOsetting/wm-sdk-w806/385b9f0c306df6837183bb86b5c550a5ced20b63/lib/W806/libdsp.a -------------------------------------------------------------------------------- /platform/arch/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libwmarch$(LIB_EXT) 6 | COMPONENTS_libwmarch = xt804/libwmxt804$(LIB_EXT) 7 | endif 8 | 9 | #DEFINES += 10 | 11 | sinclude $(TOP_DIR)/tools/W806/rules.mk 12 | INCLUDES := $(INCLUDES) -I $(PDIR)include 13 | PDIR := ../$(PDIR) 14 | sinclude $(PDIR)Makefile -------------------------------------------------------------------------------- /platform/arch/xt804/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libwmxt804$(LIB_EXT) 6 | COMPONENTS_libwmxt804 = bsp/libwmbsp$(LIB_EXT) \ 7 | libc/libwmlibc$(LIB_EXT) 8 | endif 9 | 10 | #DEFINES += 11 | 12 | sinclude $(TOP_DIR)/tools/W806/rules.mk 13 | INCLUDES := $(INCLUDES) -I $(PDIR)include 14 | PDIR := ../$(PDIR) 15 | sinclude $(PDIR)Makefile -------------------------------------------------------------------------------- /platform/arch/xt804/bsp/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libwmbsp$(LIB_EXT) 6 | endif 7 | 8 | #DEFINES += 9 | 10 | sinclude $(TOP_DIR)/tools/W806/rules.mk 11 | INCLUDES := $(INCLUDES) -I $(PDIR)include 12 | PDIR := ../$(PDIR) 13 | sinclude $(PDIR)Makefile -------------------------------------------------------------------------------- /platform/arch/xt804/bsp/board_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /****************************************************************************** 18 | * @file board_init.c 19 | * @brief CSI Source File for board init 20 | * @version V1.0 21 | * @date 02. June 2017 22 | ******************************************************************************/ 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include "wm_regs.h" 28 | #include "wm_hal.h" 29 | 30 | #define UART_TXEN_BIT (0x40) 31 | #define UART_RXEN_BIT (0x80) 32 | #define UART_PARITYEN_BIT (0x08) 33 | #define UART_PARITYODD_BIT (0x10) 34 | #define UART_BITSTOP_VAL (0x03) /// 1 stop-bit; no crc; 8 data-bits 35 | 36 | static void uart0Init (int bandrate) 37 | { 38 | unsigned int bd; 39 | 40 | #if USE_UART0_AUTO_DL 41 | WRITE_REG(UART0->INTM, ~UART_RX_INT_FLAG); 42 | NVIC_ClearPendingIRQ(UART0_IRQn); 43 | NVIC_EnableIRQ(UART0_IRQn); 44 | #else 45 | NVIC_DisableIRQ(UART0_IRQn); 46 | NVIC_ClearPendingIRQ(UART0_IRQn); 47 | #endif 48 | 49 | bd = (APB_CLK/(16*bandrate) - 1)|(((APB_CLK%(bandrate*16))*16/(bandrate*16))<<16); 50 | WRITE_REG(UART0->BAUDR, bd); 51 | 52 | WRITE_REG(UART0->LC, UART_BITSTOP_VAL | UART_TXEN_BIT | UART_RXEN_BIT); 53 | WRITE_REG(UART0->FC, 0x00); /* Disable afc */ 54 | WRITE_REG(UART0->DMAC, 0x00); /* Disable DMA */ 55 | WRITE_REG(UART0->FIFOC, 0x00); /* one byte TX/RX */ 56 | // WRITE_REG(UART0->INTM, 0x00); /* Disable INT */ 57 | 58 | } 59 | #if 0 60 | static void uart1_io_init(void) 61 | { 62 | uint32_t temp; 63 | 64 | /* PB6.7 AF Close */ 65 | temp = READ_REG(GPIOB->AF_SEL); 66 | temp &= ~0xC0; 67 | WRITE_REG(GPIOB->AF_SEL, temp); 68 | 69 | /* PB6.7 AF Open opt1 */ 70 | temp = READ_REG(GPIOB->AF_SEL); 71 | temp |= 0xC0; 72 | WRITE_REG(GPIOB->AF_SEL, temp); 73 | 74 | temp = READ_REG(GPIOB->AF_S0); 75 | temp &= ~0xC0; 76 | WRITE_REG(GPIOB->AF_S0, temp); 77 | 78 | temp = READ_REG(GPIOB->AF_S1); 79 | temp &= ~0xC0; 80 | WRITE_REG(GPIOB->AF_S1, temp); 81 | 82 | } 83 | static void uart1Init (int bandrate) 84 | { 85 | unsigned int bd; 86 | 87 | NVIC_DisableIRQ(UART1_IRQn); 88 | NVIC_ClearPendingIRQ(UART1_IRQn); 89 | 90 | bd = (APB_CLK/(16*bandrate) - 1)|(((APB_CLK%(bandrate*16))*16/(bandrate*16))<<16); 91 | WRITE_REG(UART1->BAUDR, bd); 92 | 93 | WRITE_REG(UART1->LC, UART_BITSTOP_VAL | UART_TXEN_BIT | UART_RXEN_BIT); 94 | WRITE_REG(UART1->FC, 0x00); /* Disable afc */ 95 | WRITE_REG(UART1->DMAC, 0x00); /* Disable DMA */ 96 | WRITE_REG(UART1->FIFOC, 0x00); /* one byte TX/RX */ 97 | WRITE_REG(UART1->INTM, 0x00); /* Disable INT */ 98 | 99 | } 100 | #endif 101 | void board_init(void) 102 | { 103 | 104 | #if USE_UART0_PRINT 105 | /* use uart0 as log output io */ 106 | uart0Init(115200); 107 | #else 108 | //uart1_io_init(); 109 | /* use uart1 as log output io */ 110 | //uart1Init(115200); 111 | #endif 112 | } 113 | -------------------------------------------------------------------------------- /platform/arch/xt804/bsp/system.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /****************************************************************************** 18 | * @file system.c 19 | * @brief CSI Device System Source File 20 | * @version V1.0 21 | * @date 02. June 2017 22 | ******************************************************************************/ 23 | 24 | #include 25 | #include "csi_core.h" 26 | 27 | /** 28 | * @brief initialize the system 29 | * Initialize the psr and vbr. 30 | * @param None 31 | * @return None 32 | */ 33 | void SystemInit(void) 34 | { 35 | __set_VBR((uint32_t) & (irq_vectors)); 36 | 37 | #if defined(CONFIG_SEPARATE_IRQ_SP) && !defined(CONFIG_KERNEL_NONE) 38 | /* 801 not supported */ 39 | extern int32_t g_top_irqstack; 40 | __set_Int_SP((uint32_t)&g_top_irqstack); 41 | __set_CHR(__get_CHR() | CHR_ISE_Msk); 42 | VIC->TSPR = 0xFF; 43 | #endif 44 | 45 | __set_CHR(__get_CHR() | CHR_IAE_Msk); 46 | 47 | /* Clear active and pending IRQ */ 48 | VIC->IABR[0] = 0x0; 49 | VIC->ICPR[0] = 0xFFFFFFFF; 50 | 51 | #ifdef CONFIG_KERNEL_NONE 52 | __enable_excp_irq(); 53 | #endif 54 | } 55 | -------------------------------------------------------------------------------- /platform/arch/xt804/bsp/trap_c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /****************************************************************************** 18 | * @file trap_c.c 19 | * @brief source file for the trap process 20 | * @version V1.0 21 | * @date 12. December 2017 22 | ******************************************************************************/ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void trap_c(uint32_t *regs) 30 | { 31 | int i; 32 | uint32_t vec = 0; 33 | asm volatile( 34 | "mfcr %0, psr \n" 35 | "lsri %0, 16 \n" 36 | "sextb %0 \n" 37 | :"=r"(vec):); 38 | //while (1); 39 | printf("CPU Exception : %u", vec); 40 | printf("\n"); 41 | 42 | for (i = 0; i < 16; i++) { 43 | printf("r%d: %08x\t", i, regs[i]); 44 | 45 | if ((i % 5) == 4) { 46 | printf("\n"); 47 | } 48 | } 49 | 50 | printf("\n"); 51 | printf("epsr: %8x\n", regs[16]); 52 | printf("epc : %8x\n", regs[17]); 53 | 54 | while (1); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /platform/arch/xt804/libc/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libwmlibc$(LIB_EXT) 6 | endif 7 | 8 | #DEFINES += 9 | 10 | sinclude $(TOP_DIR)/tools/W806/rules.mk 11 | INCLUDES := $(INCLUDES) -I $(PDIR)include 12 | PDIR := ../$(PDIR) 13 | sinclude $(PDIR)Makefile -------------------------------------------------------------------------------- /platform/component/FatFs/LICENSE.txt: -------------------------------------------------------------------------------- 1 | FatFs License 2 | 3 | FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that heading the source files. 4 | 5 | /*----------------------------------------------------------------------------/ 6 | / FatFs - Generic FAT Filesystem Module Rx.xx / 7 | /-----------------------------------------------------------------------------/ 8 | / 9 | / Copyright (C) 20xx, ChaN, all right reserved. 10 | / 11 | / FatFs module is an open source software. Redistribution and use of FatFs in 12 | / source and binary forms, with or without modification, are permitted provided 13 | / that the following condition is met: 14 | / 15 | / 1. Redistributions of source code must retain the above copyright notice, 16 | / this condition and the following disclaimer. 17 | / 18 | / This software is provided by the copyright holder and contributors "AS IS" 19 | / and any warranties related to this software are DISCLAIMED. 20 | / The copyright owner or contributors be NOT LIABLE for any damages caused 21 | / by use of this software. 22 | /----------------------------------------------------------------------------*/ 23 | 24 | Therefore FatFs license is one of the BSD-style licenses, but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, do not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses include GNU GPL. When you redistribute the FatFs source code with changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license. 25 | -------------------------------------------------------------------------------- /platform/component/FatFs/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libfatfs$(LIB_EXT) 6 | endif 7 | 8 | #DEFINES += 9 | 10 | sinclude $(TOP_DIR)/tools/W806/rules.mk 11 | INCLUDES := $(INCLUDES) -I $(PDIR)include 12 | PDIR := ../$(PDIR) 13 | sinclude $(PDIR)Makefile 14 | -------------------------------------------------------------------------------- /platform/component/FatFs/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */ 3 | /*-----------------------------------------------------------------------*/ 4 | /* If a working storage control module is available, it should be */ 5 | /* attached to the FatFs via a glue function rather than modifying it. */ 6 | /* This is an example of glue functions to attach various exsisting */ 7 | /* storage control modules to the FatFs module with a defined API. */ 8 | /*-----------------------------------------------------------------------*/ 9 | 10 | #include "ff.h" /* Obtains integer types */ 11 | #include "diskio.h" /* Declarations of disk functions */ 12 | #include "stdio.h" 13 | 14 | /* Definitions of physical drive number for each drive */ 15 | #define DEV_RAM 0 /* Example: Map Ramdisk to physical drive 0 */ 16 | #define DEV_MMC 1 /* Example: Map MMC/SD card to physical drive 1 */ 17 | #define DEV_USB 2 /* Example: Map USB MSD to physical drive 2 */ 18 | 19 | 20 | /*-----------------------------------------------------------------------*/ 21 | /* Get Drive Status */ 22 | /*-----------------------------------------------------------------------*/ 23 | 24 | DSTATUS disk_status ( 25 | BYTE pdrv /* Physical drive nmuber to identify the drive */ 26 | ) 27 | { 28 | //printf("disk_status %02x\r\n", pdrv); 29 | return MMC_disk_status(); 30 | } 31 | 32 | /*-----------------------------------------------------------------------*/ 33 | /* Inidialize a Drive */ 34 | /*-----------------------------------------------------------------------*/ 35 | 36 | DSTATUS disk_initialize ( 37 | BYTE pdrv /* Physical drive nmuber to identify the drive */ 38 | ) 39 | { 40 | //printf("disk_initialize %02x\r\n", pdrv); 41 | return MMC_disk_initialize(); 42 | } 43 | 44 | 45 | 46 | /*-----------------------------------------------------------------------*/ 47 | /* Read Sector(s) */ 48 | /*-----------------------------------------------------------------------*/ 49 | 50 | DRESULT disk_read ( 51 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 52 | BYTE *buff, /* Data buffer to store read data */ 53 | LBA_t sector, /* Start sector in LBA */ 54 | UINT count /* Number of sectors to read */ 55 | ) 56 | { 57 | //printf("disk_read %02x\r\n", pdrv); 58 | return MMC_disk_read(buff, sector, count); 59 | } 60 | 61 | 62 | 63 | /*-----------------------------------------------------------------------*/ 64 | /* Write Sector(s) */ 65 | /*-----------------------------------------------------------------------*/ 66 | 67 | #if FF_FS_READONLY == 0 68 | 69 | DRESULT disk_write ( 70 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 71 | const BYTE *buff, /* Data to be written */ 72 | LBA_t sector, /* Start sector in LBA */ 73 | UINT count /* Number of sectors to write */ 74 | ) 75 | { 76 | //printf("disk_write %02x\r\n", pdrv); 77 | return MMC_disk_write(buff, sector, count); 78 | } 79 | 80 | #endif 81 | 82 | 83 | /*-----------------------------------------------------------------------*/ 84 | /* Miscellaneous Functions */ 85 | /*-----------------------------------------------------------------------*/ 86 | 87 | DRESULT disk_ioctl ( 88 | BYTE pdrv, /* Physical drive nmuber (0..) */ 89 | BYTE cmd, /* Control code */ 90 | void *buff /* Buffer to send/receive control data */ 91 | ) 92 | { 93 | //printf("disk_ioctl %02x\r\n", pdrv); 94 | return MMC_disk_ioctl(cmd, buff); 95 | } 96 | 97 | DWORD get_fattime (void) 98 | { 99 | return MMC_get_fattime(); 100 | } 101 | 102 | 103 | __attribute__((weak)) DSTATUS MMC_disk_status(void); 104 | __attribute__((weak)) DSTATUS MMC_disk_initialize(void); 105 | __attribute__((weak)) DRESULT MMC_disk_read(BYTE *buff, LBA_t sector, UINT count); 106 | __attribute__((weak)) DRESULT MMC_disk_write(const BYTE *buff, LBA_t sector, UINT count); 107 | __attribute__((weak)) DRESULT MMC_disk_ioctl(BYTE cmd, void* buff); 108 | __attribute__((weak)) DWORD MMC_get_fattime(); 109 | -------------------------------------------------------------------------------- /platform/component/FatFs/diskio.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------/ 2 | / Low level disk interface modlue include file (C)ChaN, 2019 / 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Status of Disk Functions */ 13 | typedef BYTE DSTATUS; 14 | 15 | /* Results of Disk Functions */ 16 | typedef enum { 17 | RES_OK = 0, /* 0: Successful */ 18 | RES_ERROR, /* 1: R/W Error */ 19 | RES_WRPRT, /* 2: Write Protected */ 20 | RES_NOTRDY, /* 3: Not Ready */ 21 | RES_PARERR /* 4: Invalid Parameter */ 22 | } DRESULT; 23 | 24 | 25 | /*---------------------------------------*/ 26 | /* Prototypes for disk control functions */ 27 | 28 | 29 | DSTATUS disk_initialize (BYTE pdrv); 30 | DSTATUS disk_status (BYTE pdrv); 31 | DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count); 32 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count); 33 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); 34 | 35 | 36 | /* Disk Status Bits (DSTATUS) */ 37 | 38 | #define STA_NOINIT 0x01 /* Drive not initialized */ 39 | #define STA_NODISK 0x02 /* No medium in the drive */ 40 | #define STA_PROTECT 0x04 /* Write protected */ 41 | 42 | 43 | /* Command code for disk_ioctrl fucntion */ 44 | 45 | /* Generic command (Used by FatFs) */ 46 | #define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */ 47 | #define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */ 48 | #define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */ 49 | #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */ 50 | #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */ 51 | 52 | /* Generic command (Not used by FatFs) */ 53 | #define CTRL_POWER 5 /* Get/Set power status */ 54 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 55 | #define CTRL_EJECT 7 /* Eject media */ 56 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 57 | 58 | /* MMC/SDC specific ioctl command */ 59 | #define MMC_GET_TYPE 10 /* Get card type */ 60 | #define MMC_GET_CSD 11 /* Get CSD */ 61 | #define MMC_GET_CID 12 /* Get CID */ 62 | #define MMC_GET_OCR 13 /* Get OCR */ 63 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 64 | #define ISDIO_READ 55 /* Read data form SD iSDIO register */ 65 | #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ 66 | #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ 67 | 68 | /* ATA/CF specific ioctl command */ 69 | #define ATA_GET_REV 20 /* Get F/W revision */ 70 | #define ATA_GET_MODEL 21 /* Get model name */ 71 | #define ATA_GET_SN 22 /* Get serial number */ 72 | 73 | 74 | DSTATUS MMC_disk_status(void); 75 | DSTATUS MMC_disk_initialize(void); 76 | DRESULT MMC_disk_read(BYTE *buff, LBA_t sector, UINT count); 77 | DRESULT MMC_disk_write(const BYTE *buff, LBA_t sector, UINT count); 78 | DRESULT MMC_disk_ioctl(BYTE cmd, void* buff); 79 | DWORD MMC_get_fattime(); 80 | 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /platform/component/FreeRTOS/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libwmrtos$(LIB_EXT) 6 | COMPONENTS_libwmrtos = portable/libwmportable$(LIB_EXT) 7 | endif 8 | 9 | #DEFINES += 10 | 11 | sinclude $(TOP_DIR)/tools/W806/rules.mk 12 | INCLUDES := $(INCLUDES) -I $(PDIR)include 13 | PDIR := ../$(PDIR) 14 | sinclude $(PDIR)Makefile 15 | -------------------------------------------------------------------------------- /platform/component/FreeRTOS/include/StackMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.4.1 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | 28 | #ifndef _MSC_VER /* Visual Studio doesn't support #warning. */ 29 | #warning The name of this file has changed to stack_macros.h. Please update your code accordingly. This source file (which has the original name) will be removed in future released. 30 | #endif 31 | 32 | #include "stack_macros.h" 33 | -------------------------------------------------------------------------------- /platform/component/FreeRTOS/include/stdint.readme: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FREERTOS_STDINT 3 | #define FREERTOS_STDINT 4 | 5 | /******************************************************************************* 6 | * THIS IS NOT A FULL stdint.h IMPLEMENTATION - It only contains the definitions 7 | * necessary to build the FreeRTOS code. It is provided to allow FreeRTOS to be 8 | * built using compilers that do not provide their own stdint.h definition. 9 | * 10 | * To use this file: 11 | * 12 | * 1) Copy this file into the directory that contains your FreeRTOSConfig.h 13 | * header file, as that directory will already be in the compilers include 14 | * path. 15 | * 16 | * 2) Rename the copied file stdint.h. 17 | * 18 | */ 19 | 20 | typedef signed char int8_t; 21 | typedef unsigned char uint8_t; 22 | typedef short int16_t; 23 | typedef unsigned short uint16_t; 24 | typedef long int32_t; 25 | typedef unsigned long uint32_t; 26 | 27 | #endif /* FREERTOS_STDINT */ 28 | -------------------------------------------------------------------------------- /platform/component/FreeRTOS/portable/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libwmportable$(LIB_EXT) 6 | COMPONENTS_libwmportable = MemMang/libptmemmang$(LIB_EXT) \ 7 | xt804/libptxt804$(LIB_EXT) 8 | endif 9 | 10 | #DEFINES += 11 | 12 | sinclude $(TOP_DIR)/tools/W806/rules.mk 13 | 14 | PDIR := ../$(PDIR) 15 | sinclude $(PDIR)Makefile 16 | -------------------------------------------------------------------------------- /platform/component/FreeRTOS/portable/MemMang/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libptmemmang$(LIB_EXT) 6 | 7 | endif 8 | 9 | #DEFINES += 10 | 11 | sinclude $(TOP_DIR)/tools/W806/rules.mk 12 | INCLUDES := $(INCLUDES) -I $(PDIR)include 13 | PDIR := ../$(PDIR) 14 | sinclude $(PDIR)Makefile 15 | -------------------------------------------------------------------------------- /platform/component/FreeRTOS/portable/MemMang/ReadMe.url: -------------------------------------------------------------------------------- 1 | [{000214A0-0000-0000-C000-000000000046}] 2 | Prop3=19,2 3 | [InternetShortcut] 4 | URL=https://www.FreeRTOS.org/a00111.html 5 | IDList= 6 | -------------------------------------------------------------------------------- /platform/component/FreeRTOS/portable/xt804/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libptxt804$(LIB_EXT) 6 | 7 | endif 8 | 9 | #DEFINES += 10 | 11 | sinclude $(TOP_DIR)/tools/W806/rules.mk 12 | INCLUDES := $(INCLUDES) -I $(PDIR)include 13 | PDIR := ../$(PDIR) 14 | sinclude $(PDIR)Makefile 15 | -------------------------------------------------------------------------------- /platform/component/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libwmcomponent$(LIB_EXT) 6 | COMPONENTS_libwmcomponent = FreeRTOS/libwmrtos$(LIB_EXT) \ 7 | FatFs/libfatfs$(LIB_EXT) \ 8 | auto_dl/libautodl$(LIB_EXT) \ 9 | ascii_fonts/libasciifonts$(LIB_EXT) 10 | endif 11 | 12 | #DEFINES += 13 | 14 | sinclude $(TOP_DIR)/tools/W806/rules.mk 15 | 16 | PDIR := ../$(PDIR) 17 | sinclude $(PDIR)Makefile 18 | -------------------------------------------------------------------------------- /platform/component/ascii_fonts/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libasciifonts$(LIB_EXT) 6 | endif 7 | 8 | #DEFINES += 9 | 10 | sinclude $(TOP_DIR)/tools/W806/rules.mk 11 | INCLUDES := $(INCLUDES) -I $(PDIR)include 12 | PDIR := ../$(PDIR) 13 | sinclude $(PDIR)Makefile 14 | -------------------------------------------------------------------------------- /platform/component/ascii_fonts/ascii_fonts.h: -------------------------------------------------------------------------------- 1 | #ifndef __ASCII_FONTS_H__ 2 | #define __ASCII_FONTS_H__ 3 | 4 | #include 5 | 6 | typedef struct { 7 | uint8_t width; 8 | uint8_t height; 9 | uint8_t order; 10 | uint8_t bytes; 11 | const uint8_t *data; 12 | } FontDef_t; 13 | 14 | extern FontDef_t Font_3x5; 15 | extern FontDef_t Font_5x7; 16 | extern FontDef_t Font_6x8; 17 | extern FontDef_t Font_6x12; 18 | extern FontDef_t Font_7x10; 19 | extern FontDef_t Font_8x16; 20 | extern FontDef_t Font_11x18; 21 | extern FontDef_t Font_12x24; 22 | extern FontDef_t Font_16x26; 23 | extern FontDef_t Font_16x32; 24 | 25 | #endif // __ASCII_FONTS_H__ 26 | -------------------------------------------------------------------------------- /platform/component/auto_dl/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libautodl$(LIB_EXT) 6 | endif 7 | 8 | #DEFINES += 9 | 10 | sinclude $(TOP_DIR)/tools/W806/rules.mk 11 | INCLUDES := $(INCLUDES) -I $(PDIR)include 12 | PDIR := ../$(PDIR) 13 | sinclude $(PDIR)Makefile 14 | -------------------------------------------------------------------------------- /platform/component/auto_dl/auto_dl.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ** 3 | * \file auto_dl.c 4 | * \author Xu Ruijun | 1687701765@qq.com 5 | * \date 6 | * \brief Reset device with UART0 AT+Z command 7 | * \note Set USE_UART0_AUTO_DL = 1 to enable this feature 8 | * \version 9 | * \ingroup 10 | * \remarks 11 | * 12 | ******************************************************************************/ 13 | 14 | #include "wm_hal.h" 15 | 16 | #if USE_UART0_AUTO_DL 17 | 18 | #define __AUTO_DL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->INTS |= __FLAG__) 19 | #define __AUTO_DL_TIMEOUT 5 20 | #define __AUTO_DL_BUF_SIZE 32 21 | 22 | const static uint8_t auto_dl_cmd[] = {'A', 'T', '+', 'Z', '\r', '\n'}; 23 | uint8_t auto_dl_buf[__AUTO_DL_BUF_SIZE] = {0}, auto_dl_buf_pt = 0, auto_dl_cmd_pt = 0; 24 | uint32_t auto_dl_act_ts = 0; 25 | 26 | void AUTO_DL_Reset(void) 27 | { 28 | CLEAR_REG(RCC->RST); // reset all peripherals 29 | uint32_t rv = *(uint32_t*)(0x00000000U); // get reset vector 30 | ((void (*)())(rv))(); // go to ROM 31 | } 32 | 33 | __attribute__((weak)) void USER_UART0_RX(uint8_t ch) 34 | { 35 | UNUSED(ch); 36 | } 37 | 38 | void AUTO_DL_UART_IRQHandler(USART_TypeDef* huart) 39 | { 40 | uint8_t ch, count; 41 | uint32_t ts, isrflags = READ_REG(huart->INTS), isrmasks = READ_REG(huart->INTM); 42 | // Clear interrupts 43 | __AUTO_DL_UART_CLEAR_FLAG(huart, isrflags); 44 | 45 | if (((isrflags & UART_RX_INT_FLAG) != RESET) && ((isrmasks & UART_RX_INT_FLAG) == RESET)) 46 | { 47 | /** 48 | * 1) Data always comes in as single bytes, so the count is always 1(or 0); 49 | * 2) Each byte will comes in twice, the second time with count=0 will be ignored; 50 | */ 51 | count = ((READ_REG(huart->FIFOS) & UART_FIFOS_RFC) >> UART_FIFOS_RFC_Pos); 52 | while (count-- > 0) 53 | { 54 | // Write ch to ring buffer 55 | ch = (uint8_t)(huart->RDW); 56 | auto_dl_buf[auto_dl_buf_pt++] = ch; 57 | if (auto_dl_buf_pt == __AUTO_DL_BUF_SIZE) auto_dl_buf_pt = 0; 58 | 59 | // Command detection 60 | ts = HAL_GetTick(); 61 | if ((ts - auto_dl_act_ts) > __AUTO_DL_TIMEOUT) 62 | { 63 | // Restart the comparison if timeout 64 | auto_dl_cmd_pt = 0; 65 | if (auto_dl_cmd[auto_dl_cmd_pt] == ch) 66 | { 67 | auto_dl_cmd_pt++; 68 | } 69 | } 70 | else 71 | { 72 | // Avoid starting new comparison in the middle of RX 73 | if ((auto_dl_cmd[auto_dl_cmd_pt] == ch) && (auto_dl_cmd_pt > 0)) 74 | { 75 | auto_dl_cmd_pt++; 76 | if (auto_dl_cmd_pt == sizeof(auto_dl_cmd)) 77 | { 78 | AUTO_DL_Reset(); 79 | } 80 | } 81 | else 82 | { 83 | // Restart the comparison 84 | auto_dl_cmd_pt = 0; 85 | } 86 | } 87 | // Record last active timestamp 88 | auto_dl_act_ts = ts; 89 | USER_UART0_RX(ch); 90 | } 91 | } 92 | 93 | if (((isrflags & UART_INTS_TL) != RESET) && ((isrmasks & UART_INTM_RL) == RESET)) 94 | { 95 | //UART_Transmit_IT(huart); 96 | } 97 | 98 | if (((isrflags & UART_INTS_TEMPT) != RESET) && ((isrmasks & UART_INTM_TEMPT) == RESET)) 99 | { 100 | //UART_EndTransmit_IT(huart); 101 | } 102 | } 103 | 104 | __attribute__((isr)) void UART0_IRQHandler(void) 105 | { 106 | AUTO_DL_UART_IRQHandler(UART0); 107 | } 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /platform/drivers/Makefile: -------------------------------------------------------------------------------- 1 | TOP_DIR = ../.. 2 | sinclude $(TOP_DIR)/tools/W806/conf.mk 3 | 4 | ifndef PDIR 5 | GEN_LIBS = libdrivers$(LIB_EXT) 6 | endif 7 | 8 | #DEFINES += 9 | 10 | sinclude $(TOP_DIR)/tools/W806/rules.mk 11 | INCLUDES := $(INCLUDES) -I $(PDIR)include 12 | PDIR := ../$(PDIR) 13 | sinclude $(PDIR)Makefile -------------------------------------------------------------------------------- /platform/drivers/wm_cpu.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file wm_cpu.c 3 | * 4 | * @brief cpu driver module 5 | * 6 | * @author kevin 7 | * 8 | * Copyright (c) 2014 Winner Microelectronics Co., Ltd. 9 | */ 10 | #include "wm_regs.h" 11 | #include "wm_cpu.h" 12 | #include "core_804.h" 13 | #include "wm_hal.h" 14 | 15 | #define TICK_INT_PRIORITY 7 16 | 17 | __IO uint32_t uwTick; 18 | uint32_t uwTickPrio; 19 | static HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */ 20 | /** 21 | * @brief This function is used to set cpu clock 22 | * 23 | * @param[in] clk select cpu clock, this parameter can be a value of @ref enum CPU_CLK 24 | * 25 | * @return None 26 | * 27 | * @note None 28 | */ 29 | void SystemClock_Config(uint32_t clk) 30 | { 31 | uint32_t RegValue, bus2Fac, wlanDiv, cpuDiv = clk; 32 | 33 | if ((clk < 2) || (clk > 240)) 34 | { 35 | return; 36 | } 37 | 38 | /*Close those not initialized clk. Except uart and gpio. */ 39 | RegValue = READ_REG(RCC->CLK_EN); 40 | RegValue &= ~0x3FFFFF; 41 | RegValue |= 0x802; 42 | WRITE_REG(RCC->CLK_EN, RegValue); 43 | 44 | /* Close bbp clk */ 45 | WRITE_REG(RCC->BBP_CLK, 0x0F); 46 | 47 | /* Config clk div */ 48 | RegValue = READ_REG(RCC->CLK_DIV); 49 | wlanDiv = (RegValue>>8)&0xFF; 50 | RegValue &= 0xFF000000; 51 | RegValue |= 0x80000000; 52 | if(cpuDiv > 12) 53 | { 54 | bus2Fac = 1; 55 | wlanDiv = cpuDiv/4; 56 | } 57 | else /*wlan can run*/ 58 | { 59 | wlanDiv=3; 60 | bus2Fac = (wlanDiv*4/cpuDiv)&0xFF; 61 | } 62 | RegValue |= (bus2Fac<<16) | (wlanDiv<<8) | cpuDiv; 63 | WRITE_REG(RCC->CLK_DIV, RegValue); 64 | 65 | HAL_InitTick(TICK_INT_PRIORITY); 66 | return; 67 | } 68 | 69 | /** 70 | * @brief This function is used to get cpu clock 71 | * 72 | * @param[out] *sysclk point to the addr for system clk output 73 | * 74 | * @return None 75 | * 76 | * @note None 77 | */ 78 | void SystemClock_Get(wm_sys_clk *sysclk) 79 | { 80 | clk_div_reg clk_div; 81 | 82 | clk_div.w = READ_REG(RCC->CLK_DIV); 83 | sysclk->cpuclk = W806_PLL_CLK_MHZ/(clk_div.b.CPU); 84 | sysclk->wlanclk = W806_PLL_CLK_MHZ/(clk_div.b.WLAN); 85 | sysclk->apbclk = sysclk->cpuclk / clk_div.b.BUS2; 86 | } 87 | 88 | 89 | __attribute__((weak)) HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 90 | { 91 | wm_sys_clk sysclk; 92 | 93 | SystemClock_Get(&sysclk); 94 | SysTick_Config(sysclk.cpuclk * UNIT_MHZ / uwTickFreq); 95 | HAL_NVIC_SetPriority(SYS_TICK_IRQn, TickPriority); 96 | HAL_NVIC_EnableIRQ(SYS_TICK_IRQn); 97 | uwTickPrio = TickPriority; 98 | return HAL_OK; 99 | } 100 | 101 | __attribute__((weak)) void HAL_IncTick(void) 102 | { 103 | uwTick += 1; 104 | } 105 | 106 | __attribute__((weak)) uint32_t HAL_GetTick(void) 107 | { 108 | return uwTick; 109 | } 110 | 111 | __attribute__((weak)) void HAL_Delay(uint32_t Delay) 112 | { 113 | uint32_t tickstart = HAL_GetTick(); 114 | uint32_t wait = Delay; 115 | 116 | while ((HAL_GetTick() - tickstart) < wait) 117 | { 118 | } 119 | } 120 | 121 | /* Priority: a value between 0 and 15 122 | * A lower priority value indicates a higher priority */ 123 | void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t Priority) 124 | { 125 | NVIC_SetPriority(IRQn, Priority); 126 | } 127 | 128 | void HAL_NVIC_EnableIRQ(IRQn_Type IRQn) 129 | { 130 | /* Check the parameters */ 131 | assert_param(IS_NVIC_DEVICE_IRQ(IRQn)); 132 | 133 | /* Enable interrupt */ 134 | NVIC_EnableIRQ(IRQn); 135 | } 136 | 137 | void HAL_NVIC_DisableIRQ(IRQn_Type IRQn) 138 | { 139 | /* Check the parameters */ 140 | assert_param(IS_NVIC_DEVICE_IRQ(IRQn)); 141 | 142 | /* Disable interrupt */ 143 | NVIC_DisableIRQ(IRQn); 144 | } -------------------------------------------------------------------------------- /platform/drivers/wm_hal.c: -------------------------------------------------------------------------------- 1 | #include "wm_hal.h" 2 | 3 | HAL_StatusTypeDef HAL_Init(void) 4 | { 5 | HAL_MspInit(); 6 | return HAL_OK; 7 | } 8 | 9 | HAL_StatusTypeDef HAL_DeInit(void) 10 | { 11 | return HAL_OK; 12 | } 13 | 14 | __attribute__((weak)) void HAL_MspInit(void) 15 | { 16 | 17 | } 18 | 19 | __attribute__((weak)) void HAL_MspDeInit(void) 20 | { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /platform/drivers/wm_tim.c: -------------------------------------------------------------------------------- 1 | #include "wm_tim.h" 2 | 3 | HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) 4 | { 5 | uint32_t offset = 0; 6 | wm_sys_clk sysclk; 7 | 8 | if (htim == NULL) 9 | { 10 | return HAL_ERROR; 11 | } 12 | 13 | assert_param(IS_TIM_INSTANCE(htim->Instance)); 14 | assert_param(IS_TIM_UNIT(htim->Init.Unit)); 15 | assert_param(IS_TIM_AUTORELOAD(htim->Init.AutoReload)); 16 | 17 | if (htim->State == HAL_TIM_STATE_RESET) 18 | { 19 | htim->Lock = HAL_UNLOCKED; 20 | HAL_TIM_Base_MspInit(htim); 21 | } 22 | htim->State = HAL_TIM_STATE_BUSY; 23 | 24 | SystemClock_Get(&sysclk); 25 | WRITE_REG(TIM->TMR_CONFIG, sysclk.apbclk-1); 26 | offset = htim->Instance - TIM0; 27 | MODIFY_REG(TIM->CR, (TIM_CR_TIM_MODE(offset) | TIM_CR_TIM_UNIT(offset)), 28 | ((htim->Init.AutoReload << TIM_CR_TIM_MODE_Pos(offset)) | (htim->Init.Unit << TIM_CR_TIM_UNIT_Pos(offset)))); 29 | 30 | WRITE_REG(*(uint32_t *)(&(TIM->TIM0_PRD) + offset), htim->Init.Period); 31 | htim->State = HAL_TIM_STATE_READY; 32 | 33 | return HAL_OK; 34 | } 35 | 36 | HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim) 37 | { 38 | assert_param(IS_TIM_INSTANCE(htim->Instance)); 39 | 40 | htim->State = HAL_TIM_STATE_BUSY; 41 | __HAL_TIM_DISABLE(htim); 42 | HAL_TIM_Base_MspDeInit(htim); 43 | htim->State = HAL_TIM_STATE_RESET; 44 | __HAL_UNLOCK(htim); 45 | 46 | return HAL_OK; 47 | } 48 | 49 | __attribute__((weak)) void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) 50 | { 51 | UNUSED(htim); 52 | } 53 | 54 | __attribute__((weak)) void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) 55 | { 56 | UNUSED(htim); 57 | } 58 | 59 | HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim) 60 | { 61 | assert_param(IS_TIM_INSTANCE(htim->Instance)); 62 | 63 | if (htim->State != HAL_TIM_STATE_READY) 64 | { 65 | return HAL_ERROR; 66 | } 67 | 68 | htim->State = HAL_TIM_STATE_BUSY; 69 | __HAL_TIM_ENABLE(htim); 70 | 71 | return HAL_OK; 72 | } 73 | 74 | HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim) 75 | { 76 | assert_param(IS_TIM_INSTANCE(htim->Instance)); 77 | 78 | __HAL_TIM_DISABLE(htim); 79 | 80 | htim->State = HAL_TIM_STATE_READY; 81 | 82 | return HAL_OK; 83 | } 84 | 85 | HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) 86 | { 87 | assert_param(IS_TIM_INSTANCE(htim->Instance)); 88 | 89 | if (htim->State != HAL_TIM_STATE_READY) 90 | { 91 | return HAL_ERROR; 92 | } 93 | htim->State = HAL_TIM_STATE_BUSY; 94 | __HAL_TIM_ENABLE_IT(htim); 95 | __HAL_TIM_ENABLE(htim); 96 | 97 | return HAL_OK; 98 | } 99 | 100 | HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) 101 | { 102 | assert_param(IS_TIM_INSTANCE(htim->Instance)); 103 | 104 | __HAL_TIM_DISABLE_IT(htim); 105 | __HAL_TIM_DISABLE(htim); 106 | htim->State = HAL_TIM_STATE_READY; 107 | 108 | return HAL_OK; 109 | } 110 | 111 | HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim) 112 | { 113 | return htim->State; 114 | } 115 | 116 | __attribute__((weak)) void HAL_TIM_Callback(TIM_HandleTypeDef *htim) 117 | { 118 | UNUSED(htim); 119 | } 120 | 121 | void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) 122 | { 123 | if (__HAL_TIM_GET_FLAG(htim) != RESET) 124 | { 125 | __HAL_TIM_CLEAR_IT(htim); 126 | HAL_TIM_Callback(htim); 127 | } 128 | } 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /platform/drivers/wm_touch.c: -------------------------------------------------------------------------------- 1 | #include "wm_touch.h" 2 | 3 | // 在使用TOUCH功能时,TOUCH0(PA7)必须复用为TOUCH功能,不可以作为其他功能!!! 4 | 5 | 6 | HAL_StatusTypeDef HAL_TOUCH_Init(TOUCH_HandleTypeDef *htouch) 7 | { 8 | int i; 9 | 10 | if (htouch == NULL) 11 | { 12 | return HAL_ERROR; 13 | } 14 | assert_param(IS_TOUCH_INSTANCE(htouch->Instance)); 15 | assert_param(IS_TOUCH_CHANNELS(htouch->Init.Channel)); 16 | assert_param(IS_TOUCH_WINDOW(htouch->Init.Window)); 17 | assert_param(IS_TOUCH_SCANPERIOD(htouch->Init.ScanPeriod)); 18 | 19 | HAL_TOUCH_MspInit(htouch); 20 | WRITE_REG(htouch->Instance->CR, 0); 21 | WRITE_REG(htouch->Instance->IE_IF, 0x0000FFFF); 22 | for (i = 0; i < 16; i++) 23 | { 24 | if (htouch->Init.Channel & (1 << i)) 25 | { 26 | assert_param(IS_TOUCH_THRESHOLD(htouch->Init.Threshold[i])); 27 | MODIFY_REG(*((&(htouch->Instance->CH0CR)) + i), TOUCH_CH0CR_THRESHOLD, htouch->Init.Threshold[i]); 28 | if (htouch->Init.Irq_en & (1 << i)) 29 | { 30 | SET_BIT(htouch->Instance->IE_IF, (1 << (16 + i))); 31 | } 32 | } 33 | } 34 | WRITE_REG(htouch->Instance->CR, ((htouch->Init.Channel << TOUCH_CR_CH_SEL_Pos) | 35 | (htouch->Init.ScanPeriod << TOUCH_CR_SCAN_PERIOD_Pos) | 36 | (htouch->Init.Window << TOUCH_CR_CAPDET_CNT_Pos) | 37 | TOUCH_CR_EN)); 38 | 39 | return HAL_OK; 40 | } 41 | 42 | HAL_StatusTypeDef HAL_TOUCH_DeInit(TOUCH_HandleTypeDef *htouch) 43 | { 44 | if (htouch == NULL) 45 | { 46 | return HAL_ERROR; 47 | } 48 | CLEAR_BIT(htouch->Instance->CR, TOUCH_CR_EN); 49 | HAL_TOUCH_MspDeInit(htouch); 50 | 51 | return HAL_OK; 52 | } 53 | 54 | __attribute__((weak)) void HAL_TOUCH_MspInit(TOUCH_HandleTypeDef *htouch) 55 | { 56 | UNUSED(htouch); 57 | } 58 | 59 | __attribute__((weak)) void HAL_TOUCH_MspDeInit(TOUCH_HandleTypeDef *htouch) 60 | { 61 | UNUSED(htouch); 62 | } 63 | 64 | __attribute__((weak)) void HAL_TOUCH_Callback(TOUCH_HandleTypeDef *htouch, uint16_t Flag) 65 | { 66 | UNUSED(htouch); 67 | } 68 | 69 | void HAL_TOUCH_IRQHandler(TOUCH_HandleTypeDef *htouch) 70 | { 71 | uint32_t flag = __HAL_TOUCH_GET_FLAG(htouch); 72 | if (flag != RESET) 73 | { 74 | __HAL_TOUCH_CLEAR_IT(htouch, flag); 75 | HAL_TOUCH_Callback(htouch, flag & TOUCH_IE_IF_FLAG); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /platform/drivers/wm_wdg.c: -------------------------------------------------------------------------------- 1 | #include "wm_wdg.h" 2 | 3 | HAL_StatusTypeDef HAL_WDG_Init(WDG_HandleTypeDef *hwdg) 4 | { 5 | wm_sys_clk sysclk; 6 | 7 | if (hwdg == NULL) 8 | { 9 | return HAL_ERROR; 10 | } 11 | 12 | assert_param(IS_WDG_ALL_INSTANCE(hwdg->Instance)); 13 | assert_param(IS_WDG_COUNTER(hwdg->Init.Reload)); 14 | 15 | HAL_WDG_MspInit(hwdg); 16 | 17 | SystemClock_Get(&sysclk); 18 | WRITE_REG(hwdg->Instance->LD, (sysclk.apbclk * hwdg->Init.Reload)); 19 | WRITE_REG(hwdg->Instance->CR, 0x03); 20 | 21 | return HAL_OK; 22 | } 23 | 24 | HAL_StatusTypeDef HAL_WDG_DeInit(WDG_HandleTypeDef *hwdg) 25 | { 26 | HAL_NVIC_DisableIRQ(WDG_IRQn); 27 | WRITE_REG(hwdg->Instance->CR, 0); 28 | __HAL_WDG_CLEAR_FLAG(hwdg, WDG_CLR); 29 | 30 | return HAL_OK; 31 | } 32 | 33 | __attribute__((weak)) void HAL_WDG_MspInit(WDG_HandleTypeDef *hwdg) 34 | { 35 | UNUSED(hwdg); 36 | } 37 | 38 | void HAL_WDG_IRQHandler(WDG_HandleTypeDef *hwdg) 39 | { 40 | __HAL_WDG_CLEAR_FLAG(hwdg, WDG_CLR); // 如果不清除中断,不会立即复位,在下一个周期中断到来时才复位。 41 | // 例如定时5s,第一次来中断时没清除,则5s后下一个中断到来才复位 42 | } -------------------------------------------------------------------------------- /tools/W806/W806_secboot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOsetting/wm-sdk-w806/385b9f0c306df6837183bb86b5c550a5ced20b63/tools/W806/W806_secboot.bin -------------------------------------------------------------------------------- /tools/W806/W806_secboot.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOsetting/wm-sdk-w806/385b9f0c306df6837183bb86b5c550a5ced20b63/tools/W806/W806_secboot.img -------------------------------------------------------------------------------- /tools/W806/ca/cakey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQDPFl2+EagsO7AaH2N9b1d7pnOQ1dtQoahmOJRCc+6ZBLS4fpDj 3 | Ahl8kpt43f/JTWBdTyIPti6rVKYuWHVozJ0dccgJl2FuklPICoLSxVv5ExknIm2Q 4 | TIgS8WpxuoqhrCtNeJXWrcpAa09d6BtZXE1kN6eh000zq1yLyE5tXLA+vwIDAQAB 5 | AoGARF94F/cwdVpHrHhMmu+WDMdKRLm3LYoSVZ28pawtTOxW1stC/xCEZbLqDiAO 6 | AeLAPE6SSmm2Qu8x5v9h1HYqMSQ3LMhF9Da3zGy+cPiAoAUM26R1+6oF7Rbjf89f 7 | n4a4b/57YhefcE1ZuU94fpZFHi3mE4Nq/vR/eg+q5JPe6RECQQD1GlBETd+mcHgX 8 | a7//AkVwykSNxCaf/2wb5Db3YlIUF8INOO80T53i3Yyok1MH4xWRmCc6/bSYtB7d 9 | daM9N7YrAkEA2EtfXipKshrhiTEtDV11MZJWZBaEY2w+eYTre+rrvGv2Gc6eCglF 10 | UZh5L/zX/YgXq23Ba+oZl5wpcXkGtmTDvQJAAazsX4sovDqIl6Bk75lUYDEBxvZQ 11 | TUextX8Z4RcK+Jgw+2YoPHNO4P4iuARJzQQAYb5ohj61vVV94IWtV/3JgQJBALwh 12 | 8zXIu2fnkbzvFSzG2aTgkFxGaajBAiZYwyrpz1n43frciQJZxf2PDfn7hzNzKINn 13 | 2BGxcck5f6K/jmMfilECQGAA5FekuiIWs7VY1St/blRqcISuqcqBnA2464dqJ9RL 14 | FM2V12eP4kGSsXWIrM+BgWBLnQyQfK4uNoBnsoWaGus= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /tools/W806/ca/capub.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDPFl2+EagsO7AaH2N9b1d7pnOQ 3 | 1dtQoahmOJRCc+6ZBLS4fpDjAhl8kpt43f/JTWBdTyIPti6rVKYuWHVozJ0dccgJ 4 | l2FuklPICoLSxVv5ExknIm2QTIgS8WpxuoqhrCtNeJXWrcpAa09d6BtZXE1kN6eh 5 | 000zq1yLyE5tXLA+vwIDAQAB 6 | -----END PUBLIC KEY----- 7 | -------------------------------------------------------------------------------- /tools/W806/config/Makefile: -------------------------------------------------------------------------------- 1 | MENUBUILD := ../../../bin/build/config 2 | 3 | MENUCFLAGS := -I/usr/include/ncurses -DCURSES_LOC="" -DLOCALE -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer 4 | MENULDFLAGS := -lncurses 5 | 6 | UNAME:=$(shell uname) 7 | ifeq ($(UNAME),Linux) 8 | # do nothing 9 | else ifeq ($(UNAME),OpenBSD) 10 | MENUCFLAGS += -I/usr/local/include 11 | MENULDFLAGS += -L/usr/local/lib -lintl 12 | else 13 | MENULDFLAGS += -lintl 14 | endif 15 | 16 | HOSTCC := cc 17 | 18 | CONFBASE := $(MENUBUILD)/lxdialog/menubox.o \ 19 | $(MENUBUILD)/lxdialog/yesno.o \ 20 | $(MENUBUILD)/lxdialog/textbox.o \ 21 | $(MENUBUILD)/lxdialog/inputbox.o \ 22 | $(MENUBUILD)/lxdialog/util.o \ 23 | $(MENUBUILD)/lxdialog/checklist.o \ 24 | $(MENUBUILD)/zconf.tab.o 25 | 26 | all: mconf 27 | 28 | $(MENUBUILD)/%.o: %.c 29 | @mkdir -p $(MENUBUILD) 30 | @mkdir -p $(MENUBUILD)/lxdialog 31 | @echo "HOSTCC $<"; $(HOSTCC) -c $(MENUCFLAGS) $< -o $@ 32 | 33 | mconf: $(CONFBASE) \ 34 | $(MENUBUILD)/mconf.o 35 | @echo "HOSTLD $@"; $(HOSTCC) -o $(MENUBUILD)/$@ $^ $(MENULDFLAGS) 36 | 37 | clean : 38 | @find $(MENUBUILD) -name "*.o" -exec rm "{}" \; 39 | # @rm -rf $(MENUBUILD) 40 | -------------------------------------------------------------------------------- /tools/W806/config/list.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | 4 | /* 5 | * Copied from include/linux/... 6 | */ 7 | 8 | #undef offsetof 9 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 10 | 11 | /** 12 | * container_of - cast a member of a structure out to the containing structure 13 | * @ptr: the pointer to the member. 14 | * @type: the type of the container struct this is embedded in. 15 | * @member: the name of the member within the struct. 16 | * 17 | */ 18 | #define container_of(ptr, type, member) ({ \ 19 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 20 | (type *)( (char *)__mptr - offsetof(type,member) );}) 21 | 22 | 23 | struct list_head { 24 | struct list_head *next, *prev; 25 | }; 26 | 27 | 28 | #define LIST_HEAD_INIT(name) { &(name), &(name) } 29 | 30 | #define LIST_HEAD(name) \ 31 | struct list_head name = LIST_HEAD_INIT(name) 32 | 33 | /** 34 | * list_entry - get the struct for this entry 35 | * @ptr: the &struct list_head pointer. 36 | * @type: the type of the struct this is embedded in. 37 | * @member: the name of the list_head within the struct. 38 | */ 39 | #define list_entry(ptr, type, member) \ 40 | container_of(ptr, type, member) 41 | 42 | /** 43 | * list_for_each_entry - iterate over list of given type 44 | * @pos: the type * to use as a loop cursor. 45 | * @head: the head for your list. 46 | * @member: the name of the list_head within the struct. 47 | */ 48 | #define list_for_each_entry(pos, head, member) \ 49 | for (pos = list_entry((head)->next, typeof(*pos), member); \ 50 | &pos->member != (head); \ 51 | pos = list_entry(pos->member.next, typeof(*pos), member)) 52 | 53 | /** 54 | * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry 55 | * @pos: the type * to use as a loop cursor. 56 | * @n: another type * to use as temporary storage 57 | * @head: the head for your list. 58 | * @member: the name of the list_head within the struct. 59 | */ 60 | #define list_for_each_entry_safe(pos, n, head, member) \ 61 | for (pos = list_entry((head)->next, typeof(*pos), member), \ 62 | n = list_entry(pos->member.next, typeof(*pos), member); \ 63 | &pos->member != (head); \ 64 | pos = n, n = list_entry(n->member.next, typeof(*n), member)) 65 | 66 | /** 67 | * list_empty - tests whether a list is empty 68 | * @head: the list to test. 69 | */ 70 | static inline int list_empty(const struct list_head *head) 71 | { 72 | return head->next == head; 73 | } 74 | 75 | /* 76 | * Insert a new entry between two known consecutive entries. 77 | * 78 | * This is only for internal list manipulation where we know 79 | * the prev/next entries already! 80 | */ 81 | static inline void __list_add(struct list_head *_new, 82 | struct list_head *prev, 83 | struct list_head *next) 84 | { 85 | next->prev = _new; 86 | _new->next = next; 87 | _new->prev = prev; 88 | prev->next = _new; 89 | } 90 | 91 | /** 92 | * list_add_tail - add a new entry 93 | * @new: new entry to be added 94 | * @head: list head to add it before 95 | * 96 | * Insert a new entry before the specified head. 97 | * This is useful for implementing queues. 98 | */ 99 | static inline void list_add_tail(struct list_head *_new, struct list_head *head) 100 | { 101 | __list_add(_new, head->prev, head); 102 | } 103 | 104 | /* 105 | * Delete a list entry by making the prev/next entries 106 | * point to each other. 107 | * 108 | * This is only for internal list manipulation where we know 109 | * the prev/next entries already! 110 | */ 111 | static inline void __list_del(struct list_head *prev, struct list_head *next) 112 | { 113 | next->prev = prev; 114 | prev->next = next; 115 | } 116 | 117 | #define LIST_POISON1 ((void *) 0x00100100) 118 | #define LIST_POISON2 ((void *) 0x00200200) 119 | /** 120 | * list_del - deletes entry from list. 121 | * @entry: the element to delete from the list. 122 | * Note: list_empty() on entry does not return true after this, the entry is 123 | * in an undefined state. 124 | */ 125 | static inline void list_del(struct list_head *entry) 126 | { 127 | __list_del(entry->prev, entry->next); 128 | entry->next = (struct list_head*)LIST_POISON1; 129 | entry->prev = (struct list_head*)LIST_POISON2; 130 | } 131 | #endif 132 | -------------------------------------------------------------------------------- /tools/W806/config/lkc_proto.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* confdata.c */ 4 | void conf_parse(const char *name); 5 | int conf_read(const char *name); 6 | int conf_read_simple(const char *name, int); 7 | int conf_write_defconfig(const char *name); 8 | int conf_write(const char *name); 9 | int conf_write_autoconf(void); 10 | bool conf_get_changed(void); 11 | void conf_set_changed_callback(void (*fn)(void)); 12 | void conf_set_message_callback(void (*fn)(const char *fmt, va_list ap)); 13 | 14 | /* menu.c */ 15 | extern struct menu rootmenu; 16 | 17 | bool menu_is_empty(struct menu *menu); 18 | bool menu_is_visible(struct menu *menu); 19 | bool menu_has_prompt(struct menu *menu); 20 | const char * menu_get_prompt(struct menu *menu); 21 | struct menu * menu_get_root_menu(struct menu *menu); 22 | struct menu * menu_get_parent_menu(struct menu *menu); 23 | bool menu_has_help(struct menu *menu); 24 | const char * menu_get_help(struct menu *menu); 25 | struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head); 26 | void menu_get_ext_help(struct menu *menu, struct gstr *help); 27 | 28 | /* symbol.c */ 29 | extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; 30 | 31 | struct symbol * sym_lookup(const char *name, int flags); 32 | struct symbol * sym_find(const char *name); 33 | const char * sym_expand_string_value(const char *in); 34 | const char * sym_escape_string_value(const char *in); 35 | struct symbol ** sym_re_search(const char *pattern); 36 | const char * sym_type_name(enum symbol_type type); 37 | void sym_calc_value(struct symbol *sym); 38 | enum symbol_type sym_get_type(struct symbol *sym); 39 | bool sym_tristate_within_range(struct symbol *sym,tristate tri); 40 | bool sym_set_tristate_value(struct symbol *sym,tristate tri); 41 | tristate sym_toggle_tristate_value(struct symbol *sym); 42 | bool sym_string_valid(struct symbol *sym, const char *newval); 43 | bool sym_string_within_range(struct symbol *sym, const char *str); 44 | bool sym_set_string_value(struct symbol *sym, const char *newval); 45 | bool sym_is_changable(struct symbol *sym); 46 | struct property * sym_get_choice_prop(struct symbol *sym); 47 | const char * sym_get_string_value(struct symbol *sym); 48 | 49 | const char * prop_get_type_name(enum prop_type type); 50 | 51 | /* expr.c */ 52 | void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken); 53 | -------------------------------------------------------------------------------- /tools/W806/config/lxdialog/yesno.c: -------------------------------------------------------------------------------- 1 | /* 2 | * yesno.c -- implements the yes/no box 3 | * 4 | * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) 5 | * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | #include "dialog.h" 23 | 24 | extern int g_lang_index; 25 | static const char *yes_str[2] = {" Yes ", "Y确定"}; 26 | static const char *no_str[2] = {" No ", "N取消"}; 27 | 28 | /* 29 | * Display termination buttons 30 | */ 31 | static void print_buttons(WINDOW * dialog, int height, int width, int selected) 32 | { 33 | int x = width / 2 - 10; 34 | int y = height - 2; 35 | 36 | print_button(dialog, gettext(yes_str[g_lang_index]), y, x, selected == 0); 37 | print_button(dialog, gettext(no_str[g_lang_index]), y, x + 13, selected == 1); 38 | 39 | wmove(dialog, y, x + 1 + 13 * selected); 40 | wrefresh(dialog); 41 | } 42 | 43 | /* 44 | * Display a dialog box with two buttons - Yes and No 45 | */ 46 | int dialog_yesno(const char *title, const char *prompt, int height, int width) 47 | { 48 | int i, x, y, key = 0, button = 0; 49 | WINDOW *dialog; 50 | 51 | do_resize: 52 | if (getmaxy(stdscr) < (height + YESNO_HEIGTH_MIN)) 53 | return -ERRDISPLAYTOOSMALL; 54 | if (getmaxx(stdscr) < (width + YESNO_WIDTH_MIN)) 55 | return -ERRDISPLAYTOOSMALL; 56 | 57 | /* center dialog box on screen */ 58 | x = (getmaxx(stdscr) - width) / 2; 59 | y = (getmaxy(stdscr) - height) / 2; 60 | 61 | draw_shadow(stdscr, y, x, height, width); 62 | 63 | dialog = newwin(height, width, y, x); 64 | keypad(dialog, TRUE); 65 | 66 | draw_box(dialog, 0, 0, height, width, 67 | dlg.dialog.atr, dlg.border.atr); 68 | wattrset(dialog, dlg.border.atr); 69 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); 70 | for (i = 0; i < width - 2; i++) 71 | waddch(dialog, ACS_HLINE); 72 | wattrset(dialog, dlg.dialog.atr); 73 | waddch(dialog, ACS_RTEE); 74 | 75 | print_title(dialog, title, width); 76 | 77 | wattrset(dialog, dlg.dialog.atr); 78 | print_autowrap(dialog, prompt, width - 2, 1, 3); 79 | 80 | print_buttons(dialog, height, width, 0); 81 | 82 | while (key != KEY_ESC) { 83 | key = wgetch(dialog); 84 | switch (key) { 85 | case 'Y': 86 | case 'y': 87 | delwin(dialog); 88 | return 0; 89 | case 'N': 90 | case 'n': 91 | delwin(dialog); 92 | return 1; 93 | 94 | case TAB: 95 | case KEY_LEFT: 96 | case KEY_RIGHT: 97 | button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); 98 | 99 | print_buttons(dialog, height, width, button); 100 | wrefresh(dialog); 101 | break; 102 | case ' ': 103 | case '\n': 104 | delwin(dialog); 105 | return button; 106 | case KEY_ESC: 107 | key = on_key_esc(dialog); 108 | break; 109 | case KEY_RESIZE: 110 | delwin(dialog); 111 | on_key_resize(); 112 | goto do_resize; 113 | } 114 | } 115 | 116 | delwin(dialog); 117 | return key; /* ESC pressed */ 118 | } 119 | -------------------------------------------------------------------------------- /tools/W806/config/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002-2005 Roman Zippel 3 | * Copyright (C) 2002-2005 Sam Ravnborg 4 | * 5 | * Released under the terms of the GNU GPL v2.0. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "lkc.h" 12 | 13 | /* file already present in list? If not add it */ 14 | struct file *file_lookup(const char *name) 15 | { 16 | struct file *file; 17 | const char *file_name = sym_expand_string_value(name); 18 | 19 | for (file = file_list; file; file = file->next) { 20 | if (!strcmp(name, file->name)) { 21 | free((void *)file_name); 22 | return file; 23 | } 24 | } 25 | 26 | file = xmalloc(sizeof(*file)); 27 | memset(file, 0, sizeof(*file)); 28 | file->name = file_name; 29 | file->next = file_list; 30 | file_list = file; 31 | return file; 32 | } 33 | 34 | /* write a dependency file as used by kbuild to track dependencies */ 35 | int file_write_dep(const char *name) 36 | { 37 | struct symbol *sym, *env_sym; 38 | struct expr *e; 39 | struct file *file; 40 | FILE *out; 41 | 42 | if (!name) 43 | name = ".kconfig.d"; 44 | out = fopen("..config.tmp", "w"); 45 | if (!out) 46 | return 1; 47 | fprintf(out, "deps_config := \\\n"); 48 | for (file = file_list; file; file = file->next) { 49 | if (file->next) 50 | fprintf(out, "\t%s \\\n", file->name); 51 | else 52 | fprintf(out, "\t%s\n", file->name); 53 | } 54 | fprintf(out, "\n%s: \\\n" 55 | "\t$(deps_config)\n\n", conf_get_autoconfig_name()); 56 | 57 | expr_list_for_each_sym(sym_env_list, e, sym) { 58 | struct property *prop; 59 | const char *value; 60 | 61 | prop = sym_get_env_prop(sym); 62 | env_sym = prop_get_symbol(prop); 63 | if (!env_sym) 64 | continue; 65 | value = getenv(env_sym->name); 66 | if (!value) 67 | value = ""; 68 | fprintf(out, "ifneq \"$(%s)\" \"%s\"\n", env_sym->name, value); 69 | fprintf(out, "%s: FORCE\n", conf_get_autoconfig_name()); 70 | fprintf(out, "endif\n"); 71 | } 72 | 73 | fprintf(out, "\n$(deps_config): ;\n"); 74 | fclose(out); 75 | rename("..config.tmp", name); 76 | return 0; 77 | } 78 | 79 | 80 | /* Allocate initial growable string */ 81 | struct gstr str_new(void) 82 | { 83 | struct gstr gs; 84 | gs.s = xmalloc(sizeof(char) * 64); 85 | gs.len = 64; 86 | gs.max_width = 0; 87 | strcpy(gs.s, "\0"); 88 | return gs; 89 | } 90 | 91 | /* Free storage for growable string */ 92 | void str_free(struct gstr *gs) 93 | { 94 | if (gs->s) 95 | free(gs->s); 96 | gs->s = NULL; 97 | gs->len = 0; 98 | } 99 | 100 | /* Append to growable string */ 101 | void str_append(struct gstr *gs, const char *s) 102 | { 103 | size_t l; 104 | if (s) { 105 | l = strlen(gs->s) + strlen(s) + 1; 106 | if (l > gs->len) { 107 | gs->s = realloc(gs->s, l); 108 | gs->len = l; 109 | } 110 | strcat(gs->s, s); 111 | } 112 | } 113 | 114 | /* Append printf formatted string to growable string */ 115 | void str_printf(struct gstr *gs, const char *fmt, ...) 116 | { 117 | va_list ap; 118 | char s[10000]; /* big enough... */ 119 | va_start(ap, fmt); 120 | vsnprintf(s, sizeof(s), fmt, ap); 121 | str_append(gs, s); 122 | va_end(ap); 123 | } 124 | 125 | /* Retrieve value of growable string */ 126 | const char *str_get(struct gstr *gs) 127 | { 128 | return gs->s; 129 | } 130 | 131 | void *xmalloc(size_t size) 132 | { 133 | void *p = malloc(size); 134 | if (p) 135 | return p; 136 | fprintf(stderr, "Out of memory.\n"); 137 | exit(1); 138 | } 139 | 140 | void *xcalloc(size_t nmemb, size_t size) 141 | { 142 | void *p = calloc(nmemb, size); 143 | if (p) 144 | return p; 145 | fprintf(stderr, "Out of memory.\n"); 146 | exit(1); 147 | } 148 | -------------------------------------------------------------------------------- /tools/W806/config/zconf.gperf: -------------------------------------------------------------------------------- 1 | %language=ANSI-C 2 | %define hash-function-name kconf_id_hash 3 | %define lookup-function-name kconf_id_lookup 4 | %define string-pool-name kconf_id_strings 5 | %compare-strncmp 6 | %enum 7 | %pic 8 | %struct-type 9 | 10 | struct kconf_id; 11 | 12 | static const struct kconf_id *kconf_id_lookup(register const char *str, register unsigned int len); 13 | 14 | %% 15 | mainmenu, T_MAINMENU, TF_COMMAND 16 | menu, T_MENU, TF_COMMAND 17 | endmenu, T_ENDMENU, TF_COMMAND 18 | source, T_SOURCE, TF_COMMAND 19 | choice, T_CHOICE, TF_COMMAND 20 | endchoice, T_ENDCHOICE, TF_COMMAND 21 | comment, T_COMMENT, TF_COMMAND 22 | config, T_CONFIG, TF_COMMAND 23 | menuconfig, T_MENUCONFIG, TF_COMMAND 24 | help, T_HELP, TF_COMMAND 25 | if, T_IF, TF_COMMAND|TF_PARAM 26 | endif, T_ENDIF, TF_COMMAND 27 | depends, T_DEPENDS, TF_COMMAND 28 | optional, T_OPTIONAL, TF_COMMAND 29 | default, T_DEFAULT, TF_COMMAND, S_UNKNOWN 30 | prompt, T_PROMPT, TF_COMMAND 31 | tristate, T_TYPE, TF_COMMAND, S_TRISTATE 32 | def_tristate, T_DEFAULT, TF_COMMAND, S_TRISTATE 33 | bool, T_TYPE, TF_COMMAND, S_BOOLEAN 34 | boolean, T_TYPE, TF_COMMAND, S_BOOLEAN 35 | def_bool, T_DEFAULT, TF_COMMAND, S_BOOLEAN 36 | int, T_TYPE, TF_COMMAND, S_INT 37 | hex, T_TYPE, TF_COMMAND, S_HEX 38 | string, T_TYPE, TF_COMMAND, S_STRING 39 | select, T_SELECT, TF_COMMAND 40 | range, T_RANGE, TF_COMMAND 41 | visible, T_VISIBLE, TF_COMMAND 42 | option, T_OPTION, TF_COMMAND 43 | on, T_ON, TF_PARAM 44 | modules, T_OPT_MODULES, TF_OPTION 45 | defconfig_list, T_OPT_DEFCONFIG_LIST,TF_OPTION 46 | env, T_OPT_ENV, TF_OPTION 47 | allnoconfig_y, T_OPT_ALLNOCONFIG_Y,TF_OPTION 48 | %% 49 | -------------------------------------------------------------------------------- /tools/W806/inc.mk: -------------------------------------------------------------------------------- 1 | INCLUDES := $(INC) $(INCLUDES) -I $(PDIR)include 2 | 3 | INCLUDES += -I $(TOP_DIR)/include 4 | INCLUDES += -I $(TOP_DIR)/include/app 5 | INCLUDES += -I $(TOP_DIR)/include/arch/xt804 6 | INCLUDES += -I $(TOP_DIR)/include/arch/xt804/csi_core 7 | INCLUDES += -I $(TOP_DIR)/include/arch/xt804/csi_dsp 8 | INCLUDES += -I $(TOP_DIR)/include/driver 9 | INCLUDES += -I $(TOP_DIR)/include/net 10 | INCLUDES += -I $(TOP_DIR)/include/os 11 | INCLUDES += -I $(TOP_DIR)/include/platform 12 | INCLUDES += -I $(TOP_DIR)/include/wifi 13 | INCLUDES += -I $(TOP_DIR)/include/bt 14 | 15 | INCLUDES += -I $(TOP_DIR)/platform/component/ascii_fonts 16 | INCLUDES += -I $(TOP_DIR)/platform/component/FreeRTOS/include 17 | INCLUDES += -I $(TOP_DIR)/platform/component/FreeRTOS/portable/xt804 18 | INCLUDES += -I $(TOP_DIR)/platform/component/FatFs 19 | 20 | INCLUDES += -I $(TOP_DIR)/src/app/wm_atcmd 21 | INCLUDES += -I $(TOP_DIR)/src/app/dhcpserver 22 | INCLUDES += -I $(TOP_DIR)/src/app/dnsserver 23 | INCLUDES += -I $(TOP_DIR)/src/app/web 24 | INCLUDES += -I $(TOP_DIR)/src/app/cloud 25 | INCLUDES += -I $(TOP_DIR)/src/app/cJSON 26 | INCLUDES += -I $(TOP_DIR)/src/app/rmms 27 | INCLUDES += -I $(TOP_DIR)/src/app/ntp 28 | INCLUDES += -I $(TOP_DIR)/src/app/httpclient 29 | INCLUDES += -I $(TOP_DIR)/src/app/oneshotconfig 30 | INCLUDES += -I $(TOP_DIR)/src/app/iperf 31 | INCLUDES += -I $(TOP_DIR)/src/app/mqtt 32 | INCLUDES += -I $(TOP_DIR)/src/app/ping 33 | INCLUDES += -I $(TOP_DIR)/src/app/polarssl/include 34 | INCLUDES += -I $(TOP_DIR)/src/app/mDNS/mDNSPosix 35 | INCLUDES += -I $(TOP_DIR)/src/app/mDNS/mDNSCore 36 | INCLUDES += -I $(TOP_DIR)/src/app/ota 37 | INCLUDES += -I $(TOP_DIR)/src/app/libwebsockets-2.1-stable 38 | INCLUDES += -I $(TOP_DIR)/src/app/fatfs 39 | INCLUDES += -I $(TOP_DIR)/src/app/mbedtls/include 40 | INCLUDES += -I $(TOP_DIR)/src/app/mbedtls/ports 41 | INCLUDES += -I $(TOP_DIR)/src/network/api2.0.3 42 | INCLUDES += -I $(TOP_DIR)/src/network/lwip2.0.3/include 43 | INCLUDES += -I $(TOP_DIR)/src/os/rtos/include 44 | 45 | INCLUDES += -I $(TOP_DIR)/demo 46 | 47 | INCLUDES += -I $(TOP_DIR)/app/inc 48 | -------------------------------------------------------------------------------- /tools/W806/mconfig.sh: -------------------------------------------------------------------------------- 1 | MAKE=$1 2 | if [ -z ${MAKE} ]; then 3 | MAKE=make 4 | fi 5 | 6 | cd tools/W806/config 7 | ${MAKE} mconf 8 | cd .. 9 | ../../bin/build/config/mconf wconfig 10 | -------------------------------------------------------------------------------- /tools/W806/projects/SDK_Project/project/CDK_WS/CDK_WS.cdkws: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tools/W806/projects/SDK_Project/project/CDK_WS/W806_SDK/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean All 2 | 3 | All: 4 | @echo "----------Building project:[ W806_SDK - BuildSet ]----------" 5 | @ 6 | @make -f "W806_SDK.mk" MakeIntermediateDirs && make -f "W806_SDK.mk" -j 4 7 | @echo Executing Post Build commands ... 8 | @export CDKPath="D:/software/CDK" ProjectPath="D:/work_svn/WM_FAE/trunk/FAE_001/project/W806_mcu/code/wm_sdk_w806/tools/W806/projects/SDK_Project/project/CDK_WS/W806_SDK" && ../../../../../../../tools/W806/utilities/cdk_aft_build.sh;../../../../../../../tools/W806/utilities/aft_build_project.sh 9 | @echo Done 10 | 11 | clean: 12 | @echo "----------Cleaning project:[ W806_SDK - BuildSet ]----------" 13 | @make -f "W806_SDK.mk" clean 14 | -------------------------------------------------------------------------------- /tools/W806/projects/SDK_Project/project/CDK_WS/W806_SDK/W806_SDK.cdkws: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tools/W806/utilities/aft_build_project.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ProjName="W806" 3 | signature=0 4 | prikey_sel=0 5 | code_encrypt=0 6 | sign_pubkey_src=0 7 | img_type=1 8 | zip_type=1 9 | 10 | sec_img_header=8002000 11 | sec_img_pos=8002400 12 | run_img_header=8010000 13 | run_img_pos=8010400 14 | upd_img_pos=8010000 15 | 16 | 17 | echo $ProjName 18 | if [ $prikey_sel -gt 0 ] 19 | then 20 | let img_type=$img_type+32*$prikey_sel 21 | fi 22 | 23 | if [ $code_encrypt -eq 1 ] 24 | then 25 | let img_type=$img_type+16 26 | fi 27 | 28 | if [ $signature -eq 1 ] 29 | then 30 | let img_type=$img_type+256 31 | fi 32 | 33 | if [ $sign_pubkey_src -eq 1 ] 34 | then 35 | let img_type=$img_type+512 36 | fi 37 | 38 | echo $img_type 39 | 40 | csky-elfabiv2-objcopy -O binary ./"$ProjName".elf ./"$ProjName".bin 41 | 42 | if [ $code_encrypt -eq 1 ] 43 | then 44 | let prikey_sel=$prikey_sel+1 45 | openssl enc -aes-128-ecb -in ./"$ProjName".bin -out ./"$ProjName"_enc.bin -K 30313233343536373839616263646566 -iv 01010101010101010101010101010101 46 | openssl rsautl -encrypt -in ../../../../../tools/W806/ca/key.txt -inkey ../../../../../tools/W806/ca/capub_"$prikey_sel".pem -pubin -out key_en.dat 47 | cat "$ProjName"_enc.bin key_en.dat > "$ProjName"_enc_key.bin 48 | cat "$ProjName"_enc_key.bin ../../../../../tools/W806/ca/capub_"$prikey_sel"_N.dat > "$ProjName"_enc_key_N.bin 49 | ../../../../../../../tools/W806/wm_tool.exe -b ./"$ProjName"_enc_key_N.bin -o ./"$ProjName" -it $img_type -fc 0 -ra $run_img_pos -ih $run_img_header -ua $upd_img_pos -nh 0 -un 0 50 | else 51 | ../../../../../../../tools/W806/wm_tool.exe -b ./"$ProjName".bin -o ./"$ProjName" -it $img_type -fc 0 -ra $run_img_pos -ih $run_img_header -ua $upd_img_pos -nh 0 -un 0 52 | fi 53 | 54 | mkdir -p ../../../../../../../bin/W806 55 | mv ./"$ProjName".map ../../../../../../../bin/W806/"$ProjName".map 56 | 57 | if [ $signature -eq 1 ] 58 | then 59 | openssl dgst -sign ../../../../../../../tools/W806/ca/cakey.pem -sha1 -out "$ProjName"_sign.dat ./"$ProjName".img 60 | cat "$ProjName".img "$ProjName"_sign.dat > "$ProjName"_sign.img 61 | mv ./"$ProjName"_sign.img ../../../../../../../bin/W806/"$ProjName"_sign.img 62 | 63 | #when you change run-area image's ih, you must remake secboot img with secboot img's -nh address same as run-area image's ih 64 | ../../../../../../../tools/W806/wm_tool.exe -b ../../../../../../../tools/W806/W806_secboot.bin -o ../../../../../../../tools/W806/W806_secboot -it 0 -fc 0 -ra $sec_img_pos -ih $sec_img_header -ua $upd_img_pos -nh $run_img_header -un 0 65 | cat ../../../../../../../tools/W806/"$ProjName"_secboot.img ../../../../../../../bin/W806/"$ProjName"_sign.img > ../../../../../../../bin/W806/"$ProjName".fls 66 | else 67 | mv ./"$ProjName".img ../../../../../../../bin/W806/"$ProjName".img 68 | 69 | #when you change run-area image's ih, you must remake secboot img with secboot img's -nh address same as run-area image's ih 70 | ../../../../../../../tools/W806/wm_tool.exe -b ../../../../../../../tools/W806/W806_secboot.bin -o ../../../../../../../tools/W806/W806_secboot -it 0 -fc 0 -ra $sec_img_pos -ih $sec_img_header -ua $upd_img_pos -nh $run_img_header -un 0 71 | cat ../../../../../../../tools/W806/"$ProjName"_secboot.img ../../../../../../../bin/W806/"$ProjName".img > ../../../../../../../bin/W806/"$ProjName".fls 72 | fi 73 | 74 | #produce compressed ota firmware*/ 75 | if [ $zip_type -eq 1 ] 76 | then 77 | if [ $signature -eq 1 ] 78 | then 79 | ../../../../../../../tools/W806/wm_tool.exe -b ./"$ProjName"_sign.img -o ../../../../../../../bin/W806/"$ProjName"_sign -it $img_type -fc 1 -ra $run_img_pos -ih $run_img_header -ua $upd_img_pos -nh 0 -un 0 80 | mv ../../../../../../../bin/W806/"$ProjName"_sign_gz.img ../../../../../../../bin/W806/"$ProjName"_sign_ota.img 81 | else 82 | ../../../../../../../tools/W806/wm_tool.exe -b ../../../../../../../bin/W806/"$ProjName".img -o ../../../../../../../bin/W806/"$ProjName" -it $img_type -fc 1 -ra $run_img_pos -ih $run_img_header -ua $upd_img_pos -nh 0 -un 0 83 | mv ../../../../../../../bin/W806/"$ProjName"_gz.img ../../../../../../../bin/W806/"$ProjName"_ota.img 84 | fi 85 | fi 86 | #openssl --help -------------------------------------------------------------------------------- /tools/W806/utilities/cdk_aft_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ProjName="W806" 3 | 4 | cp ./Obj/"$ProjName".elf ./"$ProjName".elf 5 | mv ./Lst/"$ProjName".map ./"$ProjName".map -------------------------------------------------------------------------------- /tools/W806/utilities/download.mk: -------------------------------------------------------------------------------- 1 | download: 2 | @echo "" 3 | @echo "follow the prompts until the firmware download is complete:" 4 | @echo "" 5 | @../../../../../wm_tool -c $(DL_PORT) -rs at -ds 2M -dl ../../../../../../../bin/W806/W806.fls -------------------------------------------------------------------------------- /tools/W806/utilities/flashinit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOsetting/wm-sdk-w806/385b9f0c306df6837183bb86b5c550a5ced20b63/tools/W806/utilities/flashinit -------------------------------------------------------------------------------- /tools/W806/utilities/gdb.init: -------------------------------------------------------------------------------- 1 | reset 2 | set $psr=0xe0000000 3 | -------------------------------------------------------------------------------- /tools/W806/wconfig: -------------------------------------------------------------------------------- 1 | mainmenu "WinnerMicro W800 Configuration" 2 | 3 | menu "Firmware Configuration" 4 | 5 | config W800_TARGET_NAME 6 | string "target name" 7 | default W806 8 | help 9 | w800 firmware name. 10 | 11 | config W800_IMAGE_TYPE 12 | int "image type" 13 | default 1 14 | help 15 | w800 image type. 16 | 17 | config W800_IMAGE_HEADER 18 | hex "image header address" 19 | default 8010000 20 | help 21 | w800 image header address. 22 | 23 | config W800_RUN_ADDRESS 24 | hex "image run address" 25 | default 8010400 26 | help 27 | w800 image run address. 28 | 29 | config W800_UPDATE_ADDRESS 30 | hex "image update address" 31 | default 8010000 32 | help 33 | w800 image update address. 34 | 35 | config W800_PRIKEY_SEL 36 | int "image key select" 37 | default 0 38 | help 39 | w800 image key select. 40 | 41 | config W800_IMAGE_SIGNATURE 42 | int "image signature" 43 | default 0 44 | help 45 | w800 image signature. 46 | 47 | config W800_CODE_ENCRYPT 48 | int "image encrypt" 49 | default 0 50 | help 51 | w800 image encrypt. 52 | 53 | config W800_SIGN_PUBKEY_SRC 54 | int "image decrypt" 55 | default 0 56 | help 57 | w800 image decrypt. 58 | endmenu 59 | 60 | menu "Download Configuration" 61 | 62 | config W800_DOWNLOAD_PORT 63 | string "download port" 64 | default ttyUSB0 65 | help 66 | w800 download port. 67 | 68 | config W800_DOWNLOAD_RATE 69 | int "download rate" 70 | default 2000000 71 | help 72 | w800 download rate. 73 | endmenu 74 | 75 | menu "Compile Configuration" 76 | 77 | config W800_USE_LIB 78 | bool "enable use lib" 79 | default n 80 | help 81 | w800 sdk use lib. 82 | 83 | config W800_FIRMWARE_DEBUG 84 | bool "enable JTAG debug" 85 | default y 86 | help 87 | w800 enable JTAG debug. 88 | endmenu 89 | 90 | menu "Toolchain Configuration" 91 | 92 | config W800_TOOLCHAIN_PREFIX 93 | string "toolchain prefix" 94 | default "csky-abiv2-elf" 95 | help 96 | w800 toolchain prefix, the common name is csky-abiv2-elf, 97 | you can also use csky-elfabiv2 for minilibc, and csky-elf-noneabiv2 for newlib. 98 | 99 | config W800_TOOLCHAIN_PATH 100 | string "toolchain path" 101 | default "" 102 | help 103 | w800 toolchain path, please add / at the end of the path. 104 | endmenu 105 | -------------------------------------------------------------------------------- /tools/W806/wm_getver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define LINE_LEN_MAX 1024 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | FILE *fp; 10 | char buf[LINE_LEN_MAX]; 11 | char *pos; 12 | unsigned char major = 0; 13 | unsigned char minor = 0; 14 | unsigned char patch = 0; 15 | int done = 0; 16 | 17 | if (2 != argc) 18 | { 19 | printf("error: parameters please pass wm_main.c path\r\n"); 20 | return -1; 21 | } 22 | 23 | fp = fopen(argv[1], "rb"); 24 | if (!fp) 25 | { 26 | printf("error: failed to open %s\r\n", argv[1]); 27 | return -2; 28 | } 29 | 30 | while (fgets(buf, LINE_LEN_MAX, fp)) 31 | { 32 | if (0 == done) 33 | { 34 | pos = strstr(buf, "FW_MAJOR_VER"); 35 | if (pos) 36 | { 37 | pos = strchr(pos, '0'); 38 | if (pos) 39 | { 40 | major = strtol(pos, NULL, 16); 41 | done = 1; 42 | } 43 | } 44 | } 45 | 46 | if (1 == done) 47 | { 48 | pos = strstr(buf, "FW_MINOR_VER"); 49 | if (pos) 50 | { 51 | pos = strchr(pos, '0'); 52 | if (pos) 53 | { 54 | minor = strtol(pos, NULL, 16); 55 | done = 2; 56 | } 57 | } 58 | } 59 | 60 | if (2 == done) 61 | { 62 | pos = strstr(buf, "FW_PATCH_VER"); 63 | if (pos) 64 | { 65 | pos = strchr(pos, '0'); 66 | if (pos) 67 | { 68 | patch = strtol(pos, NULL, 16); 69 | done = 3; 70 | break; 71 | } 72 | } 73 | } 74 | } 75 | 76 | fclose(fp); 77 | 78 | if (3 == done) 79 | { 80 | sprintf(buf, "G%02X.%02X.%02X", major, minor, patch); 81 | printf("%s", buf); 82 | return 0; 83 | } 84 | 85 | return -4; 86 | } 87 | 88 | -------------------------------------------------------------------------------- /tools/W806/wm_tool.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOsetting/wm-sdk-w806/385b9f0c306df6837183bb86b5c550a5ced20b63/tools/W806/wm_tool.exe --------------------------------------------------------------------------------