├── .gitattributes ├── .github └── workflows │ └── main.yml ├── LICENSE ├── README.md ├── README_zh.md ├── demos ├── README.md ├── esp32_spi_flash │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── components │ │ └── FlashDB │ │ │ ├── CMakeLists.txt │ │ │ ├── component.mk │ │ │ ├── inc │ │ │ ├── fal_cfg.h │ │ │ └── fdb_cfg.h │ │ │ └── porting │ │ │ └── fal_flash_esp32_port.c │ ├── main │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ └── main.c │ ├── partitions.csv │ └── sdkconfig.defaults ├── esp8266_spi_flash │ ├── .gitignore │ ├── CMakeLists.txt │ ├── ESP8266_flashDB_log.rtf │ ├── Makefile │ ├── README.md │ ├── components │ │ └── FlashDB │ │ │ ├── component.mk │ │ │ ├── inc │ │ │ ├── fal_cfg.h │ │ │ └── fdb_cfg.h │ │ │ └── porting │ │ │ └── fal_flash_esp8266_port.c │ ├── main │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ └── hello_world_main.c │ └── sdkconfig ├── linux │ ├── Makefile │ ├── README.md │ ├── applications │ │ ├── fdb_cfg.h │ │ └── main.c │ └── out │ │ └── .gitignore ├── stm32f103ve │ ├── .cproject │ ├── .gitattributes │ ├── .gitignore │ ├── .project │ ├── .settings │ │ ├── FlashDB_STM32F103.JLink.Debug.rttlaunch │ │ ├── FlashDB_STM32F103.STLink.Debug.rttlaunch │ │ ├── language.settings.xml │ │ ├── org.eclipse.core.resources.prefs │ │ ├── org.eclipse.core.runtime.prefs │ │ └── projcfg.ini │ ├── README.md │ ├── RVMDK │ │ ├── .gitignore │ │ ├── FlashDB.uvoptx │ │ └── FlashDB.uvprojx │ ├── applications │ │ ├── fal_cfg.h │ │ ├── fdb_cfg.h │ │ ├── main.c │ │ ├── syscall_armlibc.c │ │ └── syscall_newlib.c │ ├── drivers │ │ ├── board.c │ │ ├── board.h │ │ ├── drv_clk.c │ │ ├── drv_common.c │ │ ├── drv_usart.c │ │ ├── stm32f1xx_hal_conf.h │ │ └── uart_config.h │ ├── libraries │ │ ├── CMSIS │ │ │ ├── Device │ │ │ │ └── ST │ │ │ │ │ └── STM32F1xx │ │ │ │ │ ├── Include │ │ │ │ │ ├── stm32f103xe.h │ │ │ │ │ ├── stm32f1xx.h │ │ │ │ │ └── system_stm32f1xx.h │ │ │ │ │ └── Source │ │ │ │ │ └── Templates │ │ │ │ │ ├── arm │ │ │ │ │ └── startup_stm32f103xe.s │ │ │ │ │ ├── gcc │ │ │ │ │ └── startup_stm32f103xe.S │ │ │ │ │ └── system_stm32f1xx.c │ │ │ ├── Include │ │ │ │ ├── cmsis_armcc.h │ │ │ │ ├── cmsis_armclang.h │ │ │ │ ├── cmsis_compiler.h │ │ │ │ ├── cmsis_gcc.h │ │ │ │ ├── cmsis_iccarm.h │ │ │ │ ├── cmsis_version.h │ │ │ │ ├── core_armv8mbl.h │ │ │ │ ├── core_armv8mml.h │ │ │ │ ├── core_cm0.h │ │ │ │ ├── core_cm0plus.h │ │ │ │ ├── core_cm1.h │ │ │ │ ├── core_cm23.h │ │ │ │ ├── core_cm3.h │ │ │ │ ├── core_cm33.h │ │ │ │ ├── core_cm4.h │ │ │ │ ├── core_cm7.h │ │ │ │ ├── core_sc000.h │ │ │ │ ├── core_sc300.h │ │ │ │ ├── mpu_armv7.h │ │ │ │ ├── mpu_armv8.h │ │ │ │ └── tz_context.h │ │ │ ├── Lib │ │ │ │ └── GCC │ │ │ │ │ ├── libarm_cortexM4l_math.a │ │ │ │ │ └── libarm_cortexM4lf_math.a │ │ │ └── RTOS │ │ │ │ └── Template │ │ │ │ └── cmsis_os.h │ │ └── STM32F1xx_HAL_Driver │ │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ ├── stm32_hal_legacy.h │ │ │ │ ├── stm32f1xx_hal_can_ex_legacy.h │ │ │ │ └── stm32f1xx_hal_can_legacy.h │ │ │ ├── stm32_assert_template.h │ │ │ ├── stm32f1xx_hal.h │ │ │ ├── stm32f1xx_hal_adc.h │ │ │ ├── stm32f1xx_hal_adc_ex.h │ │ │ ├── stm32f1xx_hal_can.h │ │ │ ├── stm32f1xx_hal_cec.h │ │ │ ├── stm32f1xx_hal_conf_template.h │ │ │ ├── stm32f1xx_hal_cortex.h │ │ │ ├── stm32f1xx_hal_crc.h │ │ │ ├── stm32f1xx_hal_dac.h │ │ │ ├── stm32f1xx_hal_dac_ex.h │ │ │ ├── stm32f1xx_hal_def.h │ │ │ ├── stm32f1xx_hal_dma.h │ │ │ ├── stm32f1xx_hal_dma_ex.h │ │ │ ├── stm32f1xx_hal_eth.h │ │ │ ├── stm32f1xx_hal_exti.h │ │ │ ├── stm32f1xx_hal_flash.h │ │ │ ├── stm32f1xx_hal_flash_ex.h │ │ │ ├── stm32f1xx_hal_gpio.h │ │ │ ├── stm32f1xx_hal_gpio_ex.h │ │ │ ├── stm32f1xx_hal_hcd.h │ │ │ ├── stm32f1xx_hal_i2c.h │ │ │ ├── stm32f1xx_hal_i2s.h │ │ │ ├── stm32f1xx_hal_irda.h │ │ │ ├── stm32f1xx_hal_iwdg.h │ │ │ ├── stm32f1xx_hal_mmc.h │ │ │ ├── stm32f1xx_hal_nand.h │ │ │ ├── stm32f1xx_hal_nor.h │ │ │ ├── stm32f1xx_hal_pccard.h │ │ │ ├── stm32f1xx_hal_pcd.h │ │ │ ├── stm32f1xx_hal_pcd_ex.h │ │ │ ├── stm32f1xx_hal_pwr.h │ │ │ ├── stm32f1xx_hal_rcc.h │ │ │ ├── stm32f1xx_hal_rcc_ex.h │ │ │ ├── stm32f1xx_hal_rtc.h │ │ │ ├── stm32f1xx_hal_rtc_ex.h │ │ │ ├── stm32f1xx_hal_sd.h │ │ │ ├── stm32f1xx_hal_smartcard.h │ │ │ ├── stm32f1xx_hal_spi.h │ │ │ ├── stm32f1xx_hal_sram.h │ │ │ ├── stm32f1xx_hal_tim.h │ │ │ ├── stm32f1xx_hal_tim_ex.h │ │ │ ├── stm32f1xx_hal_uart.h │ │ │ ├── stm32f1xx_hal_usart.h │ │ │ ├── stm32f1xx_hal_wwdg.h │ │ │ ├── stm32f1xx_ll_adc.h │ │ │ ├── stm32f1xx_ll_bus.h │ │ │ ├── stm32f1xx_ll_cortex.h │ │ │ ├── stm32f1xx_ll_crc.h │ │ │ ├── stm32f1xx_ll_dac.h │ │ │ ├── stm32f1xx_ll_dma.h │ │ │ ├── stm32f1xx_ll_exti.h │ │ │ ├── stm32f1xx_ll_fsmc.h │ │ │ ├── stm32f1xx_ll_gpio.h │ │ │ ├── stm32f1xx_ll_i2c.h │ │ │ ├── stm32f1xx_ll_iwdg.h │ │ │ ├── stm32f1xx_ll_pwr.h │ │ │ ├── stm32f1xx_ll_rcc.h │ │ │ ├── stm32f1xx_ll_rtc.h │ │ │ ├── stm32f1xx_ll_sdmmc.h │ │ │ ├── stm32f1xx_ll_spi.h │ │ │ ├── stm32f1xx_ll_system.h │ │ │ ├── stm32f1xx_ll_tim.h │ │ │ ├── stm32f1xx_ll_usart.h │ │ │ ├── stm32f1xx_ll_usb.h │ │ │ ├── stm32f1xx_ll_utils.h │ │ │ └── stm32f1xx_ll_wwdg.h │ │ │ └── Src │ │ │ ├── Legacy │ │ │ └── stm32f1xx_hal_can.c │ │ │ ├── stm32f1xx_hal.c │ │ │ ├── stm32f1xx_hal_adc.c │ │ │ ├── stm32f1xx_hal_adc_ex.c │ │ │ ├── stm32f1xx_hal_can.c │ │ │ ├── stm32f1xx_hal_cec.c │ │ │ ├── stm32f1xx_hal_cortex.c │ │ │ ├── stm32f1xx_hal_crc.c │ │ │ ├── stm32f1xx_hal_dac.c │ │ │ ├── stm32f1xx_hal_dac_ex.c │ │ │ ├── stm32f1xx_hal_dma.c │ │ │ ├── stm32f1xx_hal_eth.c │ │ │ ├── stm32f1xx_hal_exti.c │ │ │ ├── stm32f1xx_hal_flash.c │ │ │ ├── stm32f1xx_hal_flash_ex.c │ │ │ ├── stm32f1xx_hal_gpio.c │ │ │ ├── stm32f1xx_hal_gpio_ex.c │ │ │ ├── stm32f1xx_hal_hcd.c │ │ │ ├── stm32f1xx_hal_i2c.c │ │ │ ├── stm32f1xx_hal_i2s.c │ │ │ ├── stm32f1xx_hal_irda.c │ │ │ ├── stm32f1xx_hal_iwdg.c │ │ │ ├── stm32f1xx_hal_mmc.c │ │ │ ├── stm32f1xx_hal_nand.c │ │ │ ├── stm32f1xx_hal_nor.c │ │ │ ├── stm32f1xx_hal_pccard.c │ │ │ ├── stm32f1xx_hal_pcd.c │ │ │ ├── stm32f1xx_hal_pcd_ex.c │ │ │ ├── stm32f1xx_hal_pwr.c │ │ │ ├── stm32f1xx_hal_rcc.c │ │ │ ├── stm32f1xx_hal_rcc_ex.c │ │ │ ├── stm32f1xx_hal_rtc.c │ │ │ ├── stm32f1xx_hal_rtc_ex.c │ │ │ ├── stm32f1xx_hal_sd.c │ │ │ ├── stm32f1xx_hal_smartcard.c │ │ │ ├── stm32f1xx_hal_spi.c │ │ │ ├── stm32f1xx_hal_sram.c │ │ │ ├── stm32f1xx_hal_tim.c │ │ │ ├── stm32f1xx_hal_tim_ex.c │ │ │ ├── stm32f1xx_hal_uart.c │ │ │ ├── stm32f1xx_hal_usart.c │ │ │ ├── stm32f1xx_hal_wwdg.c │ │ │ └── stm32f1xx_ll_usb.c │ ├── linkscripts │ │ └── STM32F103VE │ │ │ └── link.lds │ └── makefile.targets ├── stm32f405rg │ ├── .cproject │ ├── .gitignore │ ├── .project │ ├── .settings │ │ ├── language.settings.xml │ │ ├── org.eclipse.core.runtime.prefs │ │ ├── projcfg.ini │ │ ├── stm32f405.JLink.Debug.rttlaunch │ │ └── stm32f405.STLink.Debug.rttlaunch │ ├── README.md │ ├── RVMDK │ │ ├── .gitignore │ │ ├── FlashDB.uvoptx │ │ └── FlashDB.uvprojx │ ├── applications │ │ ├── fal_cfg.h │ │ ├── fdb_cfg.h │ │ ├── main.c │ │ ├── syscall_armlibc.c │ │ └── syscall_newlib.c │ ├── drivers │ │ ├── board.c │ │ ├── board.h │ │ ├── drv_clk.c │ │ ├── drv_common.c │ │ ├── drv_usart.c │ │ ├── stm32f4xx_hal_conf.h │ │ └── uart_config.h │ ├── libraries │ │ ├── CMSIS │ │ │ ├── Device │ │ │ │ └── ST │ │ │ │ │ └── STM32F4xx │ │ │ │ │ ├── Include │ │ │ │ │ ├── stm32f405xx.h │ │ │ │ │ ├── stm32f4xx.h │ │ │ │ │ └── system_stm32f4xx.h │ │ │ │ │ └── Source │ │ │ │ │ └── Templates │ │ │ │ │ ├── arm │ │ │ │ │ └── startup_stm32f405xx.s │ │ │ │ │ ├── gcc │ │ │ │ │ └── startup_stm32f405xx.S │ │ │ │ │ └── system_stm32f4xx.c │ │ │ ├── Include │ │ │ │ ├── cmsis_armcc.h │ │ │ │ ├── cmsis_armclang.h │ │ │ │ ├── cmsis_compiler.h │ │ │ │ ├── cmsis_gcc.h │ │ │ │ ├── cmsis_iccarm.h │ │ │ │ ├── cmsis_version.h │ │ │ │ ├── core_armv8mbl.h │ │ │ │ ├── core_armv8mml.h │ │ │ │ ├── core_cm0.h │ │ │ │ ├── core_cm0plus.h │ │ │ │ ├── core_cm1.h │ │ │ │ ├── core_cm23.h │ │ │ │ ├── core_cm3.h │ │ │ │ ├── core_cm33.h │ │ │ │ ├── core_cm4.h │ │ │ │ ├── core_cm7.h │ │ │ │ ├── core_sc000.h │ │ │ │ ├── core_sc300.h │ │ │ │ ├── mpu_armv7.h │ │ │ │ ├── mpu_armv8.h │ │ │ │ └── tz_context.h │ │ │ └── RTOS │ │ │ │ └── Template │ │ │ │ └── cmsis_os.h │ │ └── STM32F4xx_HAL_Driver │ │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ ├── stm32_hal_legacy.h │ │ │ │ └── stm32f4xx_hal_can_legacy.h │ │ │ ├── stm32_assert_template.h │ │ │ ├── stm32f4xx_hal.h │ │ │ ├── stm32f4xx_hal_adc.h │ │ │ ├── stm32f4xx_hal_adc_ex.h │ │ │ ├── stm32f4xx_hal_can.h │ │ │ ├── stm32f4xx_hal_cec.h │ │ │ ├── stm32f4xx_hal_conf_template.h │ │ │ ├── stm32f4xx_hal_cortex.h │ │ │ ├── stm32f4xx_hal_crc.h │ │ │ ├── stm32f4xx_hal_cryp.h │ │ │ ├── stm32f4xx_hal_cryp_ex.h │ │ │ ├── stm32f4xx_hal_dac.h │ │ │ ├── stm32f4xx_hal_dac_ex.h │ │ │ ├── stm32f4xx_hal_dcmi.h │ │ │ ├── stm32f4xx_hal_dcmi_ex.h │ │ │ ├── stm32f4xx_hal_def.h │ │ │ ├── stm32f4xx_hal_dfsdm.h │ │ │ ├── stm32f4xx_hal_dma.h │ │ │ ├── stm32f4xx_hal_dma2d.h │ │ │ ├── stm32f4xx_hal_dma_ex.h │ │ │ ├── stm32f4xx_hal_dsi.h │ │ │ ├── stm32f4xx_hal_eth.h │ │ │ ├── stm32f4xx_hal_exti.h │ │ │ ├── stm32f4xx_hal_flash.h │ │ │ ├── stm32f4xx_hal_flash_ex.h │ │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ │ ├── stm32f4xx_hal_fmpi2c.h │ │ │ ├── stm32f4xx_hal_fmpi2c_ex.h │ │ │ ├── stm32f4xx_hal_gpio.h │ │ │ ├── stm32f4xx_hal_gpio_ex.h │ │ │ ├── stm32f4xx_hal_hash.h │ │ │ ├── stm32f4xx_hal_hash_ex.h │ │ │ ├── stm32f4xx_hal_hcd.h │ │ │ ├── stm32f4xx_hal_i2c.h │ │ │ ├── stm32f4xx_hal_i2c_ex.h │ │ │ ├── stm32f4xx_hal_i2s.h │ │ │ ├── stm32f4xx_hal_i2s_ex.h │ │ │ ├── stm32f4xx_hal_irda.h │ │ │ ├── stm32f4xx_hal_iwdg.h │ │ │ ├── stm32f4xx_hal_lptim.h │ │ │ ├── stm32f4xx_hal_ltdc.h │ │ │ ├── stm32f4xx_hal_ltdc_ex.h │ │ │ ├── stm32f4xx_hal_mmc.h │ │ │ ├── stm32f4xx_hal_nand.h │ │ │ ├── stm32f4xx_hal_nor.h │ │ │ ├── stm32f4xx_hal_pccard.h │ │ │ ├── stm32f4xx_hal_pcd.h │ │ │ ├── stm32f4xx_hal_pcd_ex.h │ │ │ ├── stm32f4xx_hal_pwr.h │ │ │ ├── stm32f4xx_hal_pwr_ex.h │ │ │ ├── stm32f4xx_hal_qspi.h │ │ │ ├── stm32f4xx_hal_rcc.h │ │ │ ├── stm32f4xx_hal_rcc_ex.h │ │ │ ├── stm32f4xx_hal_rng.h │ │ │ ├── stm32f4xx_hal_rtc.h │ │ │ ├── stm32f4xx_hal_rtc_ex.h │ │ │ ├── stm32f4xx_hal_sai.h │ │ │ ├── stm32f4xx_hal_sai_ex.h │ │ │ ├── stm32f4xx_hal_sd.h │ │ │ ├── stm32f4xx_hal_sdram.h │ │ │ ├── stm32f4xx_hal_smartcard.h │ │ │ ├── stm32f4xx_hal_smbus.h │ │ │ ├── stm32f4xx_hal_spdifrx.h │ │ │ ├── stm32f4xx_hal_spi.h │ │ │ ├── stm32f4xx_hal_sram.h │ │ │ ├── stm32f4xx_hal_tim.h │ │ │ ├── stm32f4xx_hal_tim_ex.h │ │ │ ├── stm32f4xx_hal_uart.h │ │ │ ├── stm32f4xx_hal_usart.h │ │ │ ├── stm32f4xx_hal_wwdg.h │ │ │ ├── stm32f4xx_ll_adc.h │ │ │ ├── stm32f4xx_ll_bus.h │ │ │ ├── stm32f4xx_ll_cortex.h │ │ │ ├── stm32f4xx_ll_crc.h │ │ │ ├── stm32f4xx_ll_dac.h │ │ │ ├── stm32f4xx_ll_dma.h │ │ │ ├── stm32f4xx_ll_dma2d.h │ │ │ ├── stm32f4xx_ll_exti.h │ │ │ ├── stm32f4xx_ll_fmc.h │ │ │ ├── stm32f4xx_ll_fsmc.h │ │ │ ├── stm32f4xx_ll_gpio.h │ │ │ ├── stm32f4xx_ll_i2c.h │ │ │ ├── stm32f4xx_ll_iwdg.h │ │ │ ├── stm32f4xx_ll_lptim.h │ │ │ ├── stm32f4xx_ll_pwr.h │ │ │ ├── stm32f4xx_ll_rcc.h │ │ │ ├── stm32f4xx_ll_rng.h │ │ │ ├── stm32f4xx_ll_rtc.h │ │ │ ├── stm32f4xx_ll_sdmmc.h │ │ │ ├── stm32f4xx_ll_spi.h │ │ │ ├── stm32f4xx_ll_system.h │ │ │ ├── stm32f4xx_ll_tim.h │ │ │ ├── stm32f4xx_ll_usart.h │ │ │ ├── stm32f4xx_ll_usb.h │ │ │ ├── stm32f4xx_ll_utils.h │ │ │ └── stm32f4xx_ll_wwdg.h │ │ │ └── Src │ │ │ ├── Legacy │ │ │ └── stm32f4xx_hal_can.c │ │ │ ├── stm32f4xx_hal.c │ │ │ ├── stm32f4xx_hal_adc.c │ │ │ ├── stm32f4xx_hal_adc_ex.c │ │ │ ├── stm32f4xx_hal_can.c │ │ │ ├── stm32f4xx_hal_cec.c │ │ │ ├── stm32f4xx_hal_cortex.c │ │ │ ├── stm32f4xx_hal_crc.c │ │ │ ├── stm32f4xx_hal_cryp.c │ │ │ ├── stm32f4xx_hal_cryp_ex.c │ │ │ ├── stm32f4xx_hal_dac.c │ │ │ ├── stm32f4xx_hal_dac_ex.c │ │ │ ├── stm32f4xx_hal_dcmi.c │ │ │ ├── stm32f4xx_hal_dcmi_ex.c │ │ │ ├── stm32f4xx_hal_dfsdm.c │ │ │ ├── stm32f4xx_hal_dma.c │ │ │ ├── stm32f4xx_hal_dma2d.c │ │ │ ├── stm32f4xx_hal_dma_ex.c │ │ │ ├── stm32f4xx_hal_dsi.c │ │ │ ├── stm32f4xx_hal_eth.c │ │ │ ├── stm32f4xx_hal_exti.c │ │ │ ├── stm32f4xx_hal_flash.c │ │ │ ├── stm32f4xx_hal_flash_ex.c │ │ │ ├── stm32f4xx_hal_flash_ramfunc.c │ │ │ ├── stm32f4xx_hal_fmpi2c.c │ │ │ ├── stm32f4xx_hal_fmpi2c_ex.c │ │ │ ├── stm32f4xx_hal_gpio.c │ │ │ ├── stm32f4xx_hal_hash.c │ │ │ ├── stm32f4xx_hal_hash_ex.c │ │ │ ├── stm32f4xx_hal_hcd.c │ │ │ ├── stm32f4xx_hal_i2c.c │ │ │ ├── stm32f4xx_hal_i2c_ex.c │ │ │ ├── stm32f4xx_hal_i2s.c │ │ │ ├── stm32f4xx_hal_i2s_ex.c │ │ │ ├── stm32f4xx_hal_irda.c │ │ │ ├── stm32f4xx_hal_iwdg.c │ │ │ ├── stm32f4xx_hal_lptim.c │ │ │ ├── stm32f4xx_hal_ltdc.c │ │ │ ├── stm32f4xx_hal_ltdc_ex.c │ │ │ ├── stm32f4xx_hal_mmc.c │ │ │ ├── stm32f4xx_hal_nand.c │ │ │ ├── stm32f4xx_hal_nor.c │ │ │ ├── stm32f4xx_hal_pccard.c │ │ │ ├── stm32f4xx_hal_pcd.c │ │ │ ├── stm32f4xx_hal_pcd_ex.c │ │ │ ├── stm32f4xx_hal_pwr.c │ │ │ ├── stm32f4xx_hal_pwr_ex.c │ │ │ ├── stm32f4xx_hal_qspi.c │ │ │ ├── stm32f4xx_hal_rcc.c │ │ │ ├── stm32f4xx_hal_rcc_ex.c │ │ │ ├── stm32f4xx_hal_rng.c │ │ │ ├── stm32f4xx_hal_rtc.c │ │ │ ├── stm32f4xx_hal_rtc_ex.c │ │ │ ├── stm32f4xx_hal_sai.c │ │ │ ├── stm32f4xx_hal_sai_ex.c │ │ │ ├── stm32f4xx_hal_sd.c │ │ │ ├── stm32f4xx_hal_sdram.c │ │ │ ├── stm32f4xx_hal_smartcard.c │ │ │ ├── stm32f4xx_hal_smbus.c │ │ │ ├── stm32f4xx_hal_spdifrx.c │ │ │ ├── stm32f4xx_hal_spi.c │ │ │ ├── stm32f4xx_hal_sram.c │ │ │ ├── stm32f4xx_hal_tim.c │ │ │ ├── stm32f4xx_hal_tim_ex.c │ │ │ ├── stm32f4xx_hal_uart.c │ │ │ ├── stm32f4xx_hal_usart.c │ │ │ ├── stm32f4xx_hal_wwdg.c │ │ │ └── stm32f4xx_ll_usb.c │ ├── linkscripts │ │ └── STM32F405RG │ │ │ └── link.lds │ └── makefile.targets └── stm32f405rg_spi_flash │ ├── .cproject │ ├── .gitignore │ ├── .project │ ├── .settings │ ├── language.settings.xml │ ├── org.eclipse.core.runtime.prefs │ ├── projcfg.ini │ ├── stm32f405.JLink.Debug.rttlaunch │ └── stm32f405.STLink.Debug.rttlaunch │ ├── README.md │ ├── RVMDK │ ├── .gitignore │ ├── FlashDB.uvoptx │ └── FlashDB.uvprojx │ ├── applications │ ├── fal_cfg.h │ ├── fdb_cfg.h │ ├── main.c │ ├── syscall_armlibc.c │ └── syscall_newlib.c │ ├── drivers │ ├── board.c │ ├── board.h │ ├── drv_clk.c │ ├── drv_common.c │ ├── drv_spi_flash.c │ ├── drv_usart.c │ ├── stm32f4xx_hal_conf.h │ ├── stm32f4xx_hal_msp.c │ └── uart_config.h │ ├── libraries │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F4xx │ │ │ │ ├── Include │ │ │ │ ├── stm32f405xx.h │ │ │ │ ├── stm32f4xx.h │ │ │ │ └── system_stm32f4xx.h │ │ │ │ └── Source │ │ │ │ └── Templates │ │ │ │ ├── arm │ │ │ │ └── startup_stm32f405xx.s │ │ │ │ ├── gcc │ │ │ │ └── startup_stm32f405xx.S │ │ │ │ └── system_stm32f4xx.c │ │ ├── Include │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armclang.h │ │ │ ├── cmsis_compiler.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── cmsis_iccarm.h │ │ │ ├── cmsis_version.h │ │ │ ├── core_armv8mbl.h │ │ │ ├── core_armv8mml.h │ │ │ ├── core_cm0.h │ │ │ ├── core_cm0plus.h │ │ │ ├── core_cm1.h │ │ │ ├── core_cm23.h │ │ │ ├── core_cm3.h │ │ │ ├── core_cm33.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cm7.h │ │ │ ├── core_sc000.h │ │ │ ├── core_sc300.h │ │ │ ├── mpu_armv7.h │ │ │ ├── mpu_armv8.h │ │ │ └── tz_context.h │ │ └── RTOS │ │ │ └── Template │ │ │ └── cmsis_os.h │ └── STM32F4xx_HAL_Driver │ │ ├── Inc │ │ ├── Legacy │ │ │ ├── stm32_hal_legacy.h │ │ │ └── stm32f4xx_hal_can_legacy.h │ │ ├── stm32_assert_template.h │ │ ├── stm32f4xx_hal.h │ │ ├── stm32f4xx_hal_adc.h │ │ ├── stm32f4xx_hal_adc_ex.h │ │ ├── stm32f4xx_hal_can.h │ │ ├── stm32f4xx_hal_cec.h │ │ ├── stm32f4xx_hal_conf_template.h │ │ ├── stm32f4xx_hal_cortex.h │ │ ├── stm32f4xx_hal_crc.h │ │ ├── stm32f4xx_hal_cryp.h │ │ ├── stm32f4xx_hal_cryp_ex.h │ │ ├── stm32f4xx_hal_dac.h │ │ ├── stm32f4xx_hal_dac_ex.h │ │ ├── stm32f4xx_hal_dcmi.h │ │ ├── stm32f4xx_hal_dcmi_ex.h │ │ ├── stm32f4xx_hal_def.h │ │ ├── stm32f4xx_hal_dfsdm.h │ │ ├── stm32f4xx_hal_dma.h │ │ ├── stm32f4xx_hal_dma2d.h │ │ ├── stm32f4xx_hal_dma_ex.h │ │ ├── stm32f4xx_hal_dsi.h │ │ ├── stm32f4xx_hal_eth.h │ │ ├── stm32f4xx_hal_exti.h │ │ ├── stm32f4xx_hal_flash.h │ │ ├── stm32f4xx_hal_flash_ex.h │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ ├── stm32f4xx_hal_fmpi2c.h │ │ ├── stm32f4xx_hal_fmpi2c_ex.h │ │ ├── stm32f4xx_hal_gpio.h │ │ ├── stm32f4xx_hal_gpio_ex.h │ │ ├── stm32f4xx_hal_hash.h │ │ ├── stm32f4xx_hal_hash_ex.h │ │ ├── stm32f4xx_hal_hcd.h │ │ ├── stm32f4xx_hal_i2c.h │ │ ├── stm32f4xx_hal_i2c_ex.h │ │ ├── stm32f4xx_hal_i2s.h │ │ ├── stm32f4xx_hal_i2s_ex.h │ │ ├── stm32f4xx_hal_irda.h │ │ ├── stm32f4xx_hal_iwdg.h │ │ ├── stm32f4xx_hal_lptim.h │ │ ├── stm32f4xx_hal_ltdc.h │ │ ├── stm32f4xx_hal_ltdc_ex.h │ │ ├── stm32f4xx_hal_mmc.h │ │ ├── stm32f4xx_hal_nand.h │ │ ├── stm32f4xx_hal_nor.h │ │ ├── stm32f4xx_hal_pccard.h │ │ ├── stm32f4xx_hal_pcd.h │ │ ├── stm32f4xx_hal_pcd_ex.h │ │ ├── stm32f4xx_hal_pwr.h │ │ ├── stm32f4xx_hal_pwr_ex.h │ │ ├── stm32f4xx_hal_qspi.h │ │ ├── stm32f4xx_hal_rcc.h │ │ ├── stm32f4xx_hal_rcc_ex.h │ │ ├── stm32f4xx_hal_rng.h │ │ ├── stm32f4xx_hal_rtc.h │ │ ├── stm32f4xx_hal_rtc_ex.h │ │ ├── stm32f4xx_hal_sai.h │ │ ├── stm32f4xx_hal_sai_ex.h │ │ ├── stm32f4xx_hal_sd.h │ │ ├── stm32f4xx_hal_sdram.h │ │ ├── stm32f4xx_hal_smartcard.h │ │ ├── stm32f4xx_hal_smbus.h │ │ ├── stm32f4xx_hal_spdifrx.h │ │ ├── stm32f4xx_hal_spi.h │ │ ├── stm32f4xx_hal_sram.h │ │ ├── stm32f4xx_hal_tim.h │ │ ├── stm32f4xx_hal_tim_ex.h │ │ ├── stm32f4xx_hal_uart.h │ │ ├── stm32f4xx_hal_usart.h │ │ ├── stm32f4xx_hal_wwdg.h │ │ ├── stm32f4xx_ll_adc.h │ │ ├── stm32f4xx_ll_bus.h │ │ ├── stm32f4xx_ll_cortex.h │ │ ├── stm32f4xx_ll_crc.h │ │ ├── stm32f4xx_ll_dac.h │ │ ├── stm32f4xx_ll_dma.h │ │ ├── stm32f4xx_ll_dma2d.h │ │ ├── stm32f4xx_ll_exti.h │ │ ├── stm32f4xx_ll_fmc.h │ │ ├── stm32f4xx_ll_fsmc.h │ │ ├── stm32f4xx_ll_gpio.h │ │ ├── stm32f4xx_ll_i2c.h │ │ ├── stm32f4xx_ll_iwdg.h │ │ ├── stm32f4xx_ll_lptim.h │ │ ├── stm32f4xx_ll_pwr.h │ │ ├── stm32f4xx_ll_rcc.h │ │ ├── stm32f4xx_ll_rng.h │ │ ├── stm32f4xx_ll_rtc.h │ │ ├── stm32f4xx_ll_sdmmc.h │ │ ├── stm32f4xx_ll_spi.h │ │ ├── stm32f4xx_ll_system.h │ │ ├── stm32f4xx_ll_tim.h │ │ ├── stm32f4xx_ll_usart.h │ │ ├── stm32f4xx_ll_usb.h │ │ ├── stm32f4xx_ll_utils.h │ │ └── stm32f4xx_ll_wwdg.h │ │ └── Src │ │ ├── Legacy │ │ └── stm32f4xx_hal_can.c │ │ ├── stm32f4xx_hal.c │ │ ├── stm32f4xx_hal_adc.c │ │ ├── stm32f4xx_hal_adc_ex.c │ │ ├── stm32f4xx_hal_can.c │ │ ├── stm32f4xx_hal_cec.c │ │ ├── stm32f4xx_hal_cortex.c │ │ ├── stm32f4xx_hal_crc.c │ │ ├── stm32f4xx_hal_cryp.c │ │ ├── stm32f4xx_hal_cryp_ex.c │ │ ├── stm32f4xx_hal_dac.c │ │ ├── stm32f4xx_hal_dac_ex.c │ │ ├── stm32f4xx_hal_dcmi.c │ │ ├── stm32f4xx_hal_dcmi_ex.c │ │ ├── stm32f4xx_hal_dfsdm.c │ │ ├── stm32f4xx_hal_dma.c │ │ ├── stm32f4xx_hal_dma2d.c │ │ ├── stm32f4xx_hal_dma_ex.c │ │ ├── stm32f4xx_hal_dsi.c │ │ ├── stm32f4xx_hal_eth.c │ │ ├── stm32f4xx_hal_exti.c │ │ ├── stm32f4xx_hal_flash.c │ │ ├── stm32f4xx_hal_flash_ex.c │ │ ├── stm32f4xx_hal_flash_ramfunc.c │ │ ├── stm32f4xx_hal_fmpi2c.c │ │ ├── stm32f4xx_hal_fmpi2c_ex.c │ │ ├── stm32f4xx_hal_gpio.c │ │ ├── stm32f4xx_hal_hash.c │ │ ├── stm32f4xx_hal_hash_ex.c │ │ ├── stm32f4xx_hal_hcd.c │ │ ├── stm32f4xx_hal_i2c.c │ │ ├── stm32f4xx_hal_i2c_ex.c │ │ ├── stm32f4xx_hal_i2s.c │ │ ├── stm32f4xx_hal_i2s_ex.c │ │ ├── stm32f4xx_hal_irda.c │ │ ├── stm32f4xx_hal_iwdg.c │ │ ├── stm32f4xx_hal_lptim.c │ │ ├── stm32f4xx_hal_ltdc.c │ │ ├── stm32f4xx_hal_ltdc_ex.c │ │ ├── stm32f4xx_hal_mmc.c │ │ ├── stm32f4xx_hal_nand.c │ │ ├── stm32f4xx_hal_nor.c │ │ ├── stm32f4xx_hal_pccard.c │ │ ├── stm32f4xx_hal_pcd.c │ │ ├── stm32f4xx_hal_pcd_ex.c │ │ ├── stm32f4xx_hal_pwr.c │ │ ├── stm32f4xx_hal_pwr_ex.c │ │ ├── stm32f4xx_hal_qspi.c │ │ ├── stm32f4xx_hal_rcc.c │ │ ├── stm32f4xx_hal_rcc_ex.c │ │ ├── stm32f4xx_hal_rng.c │ │ ├── stm32f4xx_hal_rtc.c │ │ ├── stm32f4xx_hal_rtc_ex.c │ │ ├── stm32f4xx_hal_sai.c │ │ ├── stm32f4xx_hal_sai_ex.c │ │ ├── stm32f4xx_hal_sd.c │ │ ├── stm32f4xx_hal_sdram.c │ │ ├── stm32f4xx_hal_smartcard.c │ │ ├── stm32f4xx_hal_smbus.c │ │ ├── stm32f4xx_hal_spdifrx.c │ │ ├── stm32f4xx_hal_spi.c │ │ ├── stm32f4xx_hal_sram.c │ │ ├── stm32f4xx_hal_tim.c │ │ ├── stm32f4xx_hal_tim_ex.c │ │ ├── stm32f4xx_hal_uart.c │ │ ├── stm32f4xx_hal_usart.c │ │ ├── stm32f4xx_hal_wwdg.c │ │ └── stm32f4xx_ll_usb.c │ ├── linkscripts │ └── STM32F405RG │ │ └── link.lds │ ├── makefile.targets │ └── sfud │ ├── LICENSE │ ├── README.md │ ├── inc │ ├── sfud.h │ ├── sfud_cfg.h │ ├── sfud_def.h │ └── sfud_flash_def.h │ ├── port │ └── sfud_port.c │ └── src │ ├── sfud.c │ └── sfud_sfdp.c ├── docs ├── .nojekyll ├── README.md ├── _coverpage.md ├── _media │ ├── favicon.ico │ ├── flashdb.png │ ├── flashdb_framework.png │ ├── flashdb_logo.png │ └── flashdb_porting_layer.png ├── _navbar.md ├── _scripts │ ├── docsify.min.js │ ├── emoji.min.js │ ├── prism-c.min.js │ └── search.min.js ├── _sidebar.md ├── api.md ├── configuration.md ├── demo-details.md ├── demo-esp8266-spi-flash.md ├── demo-linux.md ├── demo-stm32f103ve.md ├── demo-stm32f405rg-spi-flash.md ├── demo-stm32f405rg.md ├── index.html ├── porting.md ├── quick-started.md ├── sample-kvdb-basic.md ├── sample-kvdb-traversal.md ├── sample-kvdb-type-blob.md ├── sample-kvdb-type-string.md ├── sample-tsdb-basic.md ├── vue.css └── zh-cn │ ├── README.md │ ├── _coverpage.md │ ├── _media │ ├── flashdb_framework.png │ ├── flashdb_porting_layer.png │ └── wechat_support.png │ ├── _navbar.md │ ├── _sidebar.md │ ├── api.md │ ├── configuration.md │ ├── demo-details.md │ ├── demo-esp8266-spi-flash.md │ ├── demo-linux.md │ ├── demo-stm32f103ve.md │ ├── demo-stm32f405rg-spi-flash.md │ ├── demo-stm32f405rg.md │ ├── porting.md │ ├── quick-started.md │ ├── sample-kvdb-basic.md │ ├── sample-kvdb-traversal.md │ ├── sample-kvdb-type-blob.md │ ├── sample-kvdb-type-string.md │ └── sample-tsdb-basic.md ├── inc ├── fdb_cfg_template.h ├── fdb_def.h ├── fdb_low_lvl.h └── flashdb.h ├── port └── fal │ ├── LICENSE │ ├── README.md │ ├── README_ZH.md │ ├── docs │ ├── fal_api.md │ ├── fal_api_en.md │ └── figures │ │ ├── fal-api-en.png │ │ ├── fal-api.png │ │ ├── fal-port-en.png │ │ ├── fal-port.png │ │ ├── fal_framework-en.png │ │ └── fal_framework.png │ ├── inc │ ├── fal.h │ └── fal_def.h │ ├── samples │ ├── README.md │ └── porting │ │ ├── README.md │ │ ├── fal_cfg.h │ │ ├── fal_flash_sfud_port.c │ │ ├── fal_flash_stm32f1_port.c │ │ ├── fal_flash_stm32f2_port.c │ │ ├── fal_flash_stm32f4.c │ │ └── fal_flash_stm32l4.c │ └── src │ ├── fal.c │ ├── fal_flash.c │ ├── fal_partition.c │ └── fal_rtt.c ├── samples ├── kvdb_basic_sample.c ├── kvdb_type_blob_sample.c ├── kvdb_type_string_sample.c └── tsdb_sample.c ├── src ├── fdb.c ├── fdb_file.c ├── fdb_kvdb.c ├── fdb_tsdb.c └── fdb_utils.c ├── tests ├── fdb_kvdb_tc.c └── fdb_tsdb_tc.c └── zephyr └── module.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.S text 4 | *.asm text 5 | *.c text 6 | *.cc text 7 | *.cpp text 8 | *.cxx text 9 | *.h text 10 | *.htm text 11 | *.html text 12 | *.in text 13 | *.ld text 14 | *.m4 text 15 | *.mak text 16 | *.mk text 17 | *.py text 18 | *.rb text 19 | *.s text 20 | *.sct text 21 | *.sh text 22 | *.txt text 23 | *.xml text 24 | Makefile text 25 | AUTHORS text 26 | COPYING text 27 | 28 | *.LZO -text 29 | *.Opt -text 30 | *.Uv2 -text 31 | *.ewp -text 32 | *.eww -text 33 | *.vcproj -text 34 | *.bat -text 35 | *.dos -text 36 | *.icf -text 37 | *.inf -text 38 | *.ini -text 39 | *.sct -text 40 | *.xsd -text 41 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: AutoTestCI 2 | on: [push, pull_request] 3 | jobs: 4 | test: 5 | name: AutoTest 6 | runs-on: ubuntu-latest 7 | env: 8 | TEST_BSP_ROOT: ../AutoTestBsp 9 | UTEST_RUNNER_PATH: ../UtestRunner 10 | RTT_EXEC_PATH: /opt/gcc-arm-none-eabi-10-2020-q4-major/bin 11 | steps: 12 | - uses: actions/checkout@v1 13 | - name: Prepare env 14 | run: | 15 | sudo apt-get update 16 | sudo apt-get -yqq install scons qemu-system git 17 | wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.3/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 18 | sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt 19 | git clone https://github.com/armink/UtestRunner.git $UTEST_RUNNER_PATH 20 | git clone https://github.com/armink/FlashDBAutoTestBSP.git $TEST_BSP_ROOT 21 | - name: Build bsp 22 | run: | 23 | cp -rf src/* $TEST_BSP_ROOT/packages/FlashDB/src 24 | cp -rf tests/* $TEST_BSP_ROOT/packages/FlashDB/tests 25 | cp -rf inc/fdb_def.h $TEST_BSP_ROOT/packages/FlashDB/inc/fdb_def.h 26 | cp -rf inc/fdb_low_lvl.h $TEST_BSP_ROOT/packages/FlashDB/inc/fdb_low_lvl.h 27 | cp -rf inc/flashdb.h $TEST_BSP_ROOT/packages/FlashDB/inc/flashdb.h 28 | /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version 29 | scons -j$(nproc) -C $TEST_BSP_ROOT 30 | - name: Start test 31 | run: | 32 | python3 $UTEST_RUNNER_PATH/qemu_runner.py --elf $TEST_BSP_ROOT/rtthread.elf --sd $TEST_BSP_ROOT/sd.bin 33 | cat rtt_console.log 34 | -------------------------------------------------------------------------------- /README_zh.md: -------------------------------------------------------------------------------- 1 | ![](docs/_media/flashdb.png) 2 | 3 | ![GitHub Action](https://github.com/armink/FlashDB/workflows/AutoTestCI/badge.svg) [![license](https://img.shields.io/github/license/armink/FlashDB)](https://raw.githubusercontent.com/armink/FlashDB/master/LICENSE) [![docs](https://img.shields.io/badge/docs-perfect-blue)](https://www.bookstack.cn/read/flashdb-2.1-zh/README.md ) 4 | 5 | [EN](README.md) | 中文 6 | 7 | ## 简介 8 | 9 | [FlashDB](http://armink.gitee.io/flashdb/#/zh-cn/) 是一款超轻量级的嵌入式数据库,专注于提供嵌入式产品的数据存储方案。FlashDB 不仅支持传统的基于文件系统的数据库模式,而且结合了 Flash 的特性,具有较强的性能及可靠性。并在保证极低的资源占用前提下,尽可能延长 Flash 使用寿命。 10 | 11 | FlashDB 提供两种数据库模式: 12 | 13 | - **键值数据库** :是一种非关系数据库,它将数据存储为键值(Key-Value)对集合,其中键作为唯一标识符。KVDB 操作简洁,可扩展性强。 14 | - **时序数据库** :时间序列数据库 (Time Series Database , 简称 TSDB),它将数据按照 **时间顺序存储** 。TSDB 数据具有时间戳,数据存储量大,插入及查询性能高。 15 | 16 | > 欢迎 Star&Fork :https://gitee.com/armink/FlashDB 17 | 18 | ## 使用场景 19 | 20 | 如今,物联网产品种类越来越多,运行时产生的数据种类及总量及也在不断变大。FlashDB 提供了多样化的数据存储方案,不仅资源占用小,并且存储容量大,非常适合用于物联网产品。下面是主要应用场景: 21 | 22 | - **键值数据库** : 23 | - 产品参数存储 24 | - 用户配置信息存储 25 | - 小文件管理 26 | - **时序数据库** : 27 | - 存储动态产生的结构化数据:如 温湿度传感器采集的环境监测信息,智能手环实时记录的人体健康信息等 28 | - 记录运行日志:存储产品历史的运行日志,异常告警的记录等 29 | 30 | ## 主要特性 31 | 32 | - 资源占用极低,内存占用几乎为 **0** ; 33 | - 支持 多分区,**多实例** 。数据量大时,可细化分区,降低检索时间; 34 | - 支持 **磨损平衡** ,延长 Flash 寿命; 35 | - 支持 **掉电保护** 功能,可靠性高; 36 | - 支持 字符串及 blob 两种 KV 类型,方便用户操作; 37 | - 支持 KV **增量升级** ,产品固件升级后, KVDB 内容也支持自动升级; 38 | - 支持 修改每条 TSDB 记录的状态,方便用户进行管理; 39 | 40 | ## 性能及资源占用 41 | 42 | ### TSDB 性能测试1 (nor flash W25Q64) 43 | 44 | ```shell 45 | msh />tsl bench 46 | Append 1250 TSL in 5 seconds, average: 250.00 tsl/S, 4.00 ms/per 47 | Query total spent 2218 (ms) for 1251 TSL, min 1, max 2, average: 1.77 ms/per 48 | ``` 49 | 50 | 插入平均:4 ms,查询平均:1.8 ms 51 | 52 | ### TSDB 性能测试2 (stm32f2 onchip flash) 53 | 54 | ```shell 55 | msh />tsl bench 56 | Append 13421 TSL in 5 seconds, average: 2684.20 tsl/S, 0.37 ms/per 57 | Query total spent 1475 (ms) for 13422 TSL, min 0, max 1, average: 0.11 ms/per 58 | ``` 59 | 60 | 插入平均:0.37 ms,查询平均:0.12 ms 61 | 62 | ### 资源占用 (stm32f4 IAR8.20) 63 | 64 | ```shell 65 | Module ro code ro data rw data 66 | ------ ------- ------- ------- 67 | fdb.o 276 232 1 68 | fdb_kvdb.o 4 584 356 1 69 | fdb_tsdb.o 1 160 236 70 | fdb_utils.o 418 1 024 71 | ``` 72 | 73 | 上面是 IAR 的 map 文件信息,可见 FlashDB 的资源占用非常低 74 | 75 | ## 如何使用 76 | 77 | FlashDB 提供了全面的文档说明,详见:https://www.bookstack.cn/read/flashdb-2.1-zh/README.md 78 | 79 | 快速访问: 80 | 81 | - [快速上手文档](https://www.bookstack.cn/read/flashdb-2.1-zh/quick-started.md) 82 | - [移植文档](https://www.bookstack.cn/read/flashdb-2.1-zh/porting.md) 83 | - [配置文档](https://www.bookstack.cn/read/flashdb-2.1-zh/configuration.md) 84 | - [API 文档](https://www.bookstack.cn/read/flashdb-2.1-zh/configuration.md) 85 | 86 | ## 支持 87 | 88 | ![support](docs/zh-cn/_media/wechat_support.png) 89 | 90 | 如果 FlashDB 解决了你的问题,不妨扫描上面二维码请我 **喝杯咖啡**~ 91 | 92 | ## 许可 93 | 94 | 采用 Apache-2.0 开源协议,细节请阅读项目中的 LICENSE 文件内容。 95 | -------------------------------------------------------------------------------- /demos/README.md: -------------------------------------------------------------------------------- 1 | | folder name | storage type | 2 | | :-------------------- | :------------------ | 3 | | stm32f103ve | stm32 on-chip flash | 4 | | stm32f405rg | stm32 on-chip flash | 5 | | stm32f405rg_spi_flash | spi flash | 6 | | esp8266_spi_flash | spi flash | 7 | | esp32_spi_flash | spi flash | 8 | | linux | posix file | 9 | 10 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | 3 | sdkconfig* 4 | !sdkconfig.defaults 5 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | 7 | list(APPEND EXTRA_COMPONENT_DIRS 8 | "${CMAKE_CURRENT_LIST_DIR}/components") 9 | 10 | add_compile_definitions(FDB_USING_TIMESTAMP_64BIT) 11 | project(esp32_spi_flash) 12 | idf_build_set_property(COMPILE_OPTIONS "-Wno-error=maybe-uninitialized" APPEND) 13 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := flashDB_demo 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/README.md: -------------------------------------------------------------------------------- 1 | # flashDB demo esp32 Example 2 | 3 | built with ESP IDF version 4.4.1 (v4.4.1-64-g4b2098bc58) using cmake. 4 | 5 | run `idf.py build` in this directory and then flash with `idf.py flash` and monitor 6 | the output with `idf.py monitor`. 7 | 8 | A custom partition table is required so that a partition can be created for the FlashDB. 9 | The size in the demo is set to 32K, see file `partitions.csv`. Custom partitions are 10 | enabled by default in `sdkconfig.defaults`. 11 | 12 | The file `sdkconfig.defaults` contains by default all values required for the demo to work, 13 | i.e. the custom partitions are configured. By default the SPI flash is configured to 14 | be 4MB. 15 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/components/FlashDB/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "porting/fal_flash_esp32_port.c" 2 | INCLUDE_DIRS "inc" "../../../../port/fal/inc" 3 | REQUIRES "spi_flash" "esp_partition" "esp_rom") 4 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/components/FlashDB/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | COMPONENT_ADD_INCLUDEDIRS += \ 5 | inc \ 6 | ../../../../inc \ 7 | ../../../../port/fal/inc 8 | 9 | COMPONENT_SRCDIRS += \ 10 | ../../../../src \ 11 | ../../../../samples \ 12 | ../../../../port/fal/src \ 13 | porting 14 | 15 | 16 | # COMPONENT_PRIV_INCLUDEDIRS += 17 | 18 | # COMPONENT_ADD_LDFLAGS += -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive 19 | 20 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/components/FlashDB/inc/fal_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, kaans, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef _FAL_CFG_H_ 8 | #define _FAL_CFG_H_ 9 | 10 | //#define FAL_DEBUG 1 11 | #define FAL_PART_HAS_TABLE_CFG 12 | #define NOR_FLASH_DEV_NAME "norflash0" 13 | 14 | //#define FAL_PART_TABLE_FLASH_DEV_NAME NOR_FLASH_DEV_NAME 15 | //#define FAL_PART_TABLE_END_OFFSET 65536 16 | 17 | /* ===================== Flash device Configuration ========================= */ 18 | extern const struct fal_flash_dev nor_flash0; 19 | 20 | /* flash device table */ 21 | #define FAL_FLASH_DEV_TABLE \ 22 | { \ 23 | &nor_flash0, \ 24 | } 25 | /* ====================== Partition Configuration ========================== */ 26 | #ifdef FAL_PART_HAS_TABLE_CFG 27 | /* partition table */ 28 | #define FAL_PART_TABLE \ 29 | { \ 30 | {FAL_PART_MAGIC_WORD, "fdb_kvdb1", NOR_FLASH_DEV_NAME, 0, 16 * 1024, 0}, \ 31 | {FAL_PART_MAGIC_WORD, "fdb_tsdb1", NOR_FLASH_DEV_NAME, 16 * 1024, 16 * 1024, 0}, \ 32 | } 33 | #endif /* FAL_PART_HAS_TABLE_CFG */ 34 | 35 | #endif /* _FAL_CFG_H_ */ 36 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/components/FlashDB/inc/fdb_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, kaans, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief configuration file 10 | */ 11 | 12 | #ifndef _FDB_CFG_H_ 13 | #define _FDB_CFG_H_ 14 | 15 | /* using KVDB feature */ 16 | #define FDB_USING_KVDB 17 | 18 | #ifdef FDB_USING_KVDB 19 | /* Auto update KV to latest default when current KVDB version number is changed. @see fdb_kvdb.ver_num */ 20 | /* #define FDB_KV_AUTO_UPDATE */ 21 | #endif 22 | 23 | /* using TSDB (Time series database) feature */ 24 | #define FDB_USING_TSDB 25 | 26 | /* Using FAL storage mode */ 27 | #define FDB_USING_FAL_MODE 28 | 29 | /* the flash write granularity, unit: bit 30 | * only support 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1) */ 31 | #define FDB_WRITE_GRAN 1 /* @note you must define it for a value */ 32 | 33 | /* MCU Endian Configuration, default is Little Endian Order. */ 34 | /* #define FDB_BIG_ENDIAN */ 35 | 36 | /* log print macro using ESP_LOG. 37 | * Need to include esp_log.h when setting FDB_PRINT to ESP_LOGI(). 38 | * default EF_PRINT macro is printf() */ 39 | //#include 40 | //#define FDB_PRINT(...) ESP_LOGI("fdb", __VA_ARGS__) 41 | 42 | /* print debug information */ 43 | #define FDB_DEBUG_ENABLE 44 | 45 | #endif /* _FDB_CFG_H_ */ 46 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/components/FlashDB/porting/fal_flash_esp32_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022, kaans, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include "esp_log.h" 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #define FLASH_ERASE_MIN_SIZE (4 * 1024) 14 | 15 | #define LOCKER_ENABLE 16 | #ifdef LOCKER_ENABLE 17 | #include "freertos/FreeRTOS.h" 18 | #include "freertos/semphr.h" 19 | 20 | static SemaphoreHandle_t s_lock = NULL; 21 | 22 | const static esp_partition_t *partition; 23 | 24 | #define LOCK() \ 25 | do \ 26 | { \ 27 | xSemaphoreTake(s_lock, portMAX_DELAY); \ 28 | } while (0) 29 | 30 | #define UNLOCK() \ 31 | do \ 32 | { \ 33 | xSemaphoreGive(s_lock); \ 34 | } while (0) 35 | #else 36 | #define LOCK() 37 | #define UNLOCK() 38 | #endif 39 | 40 | static int init(void) 41 | { 42 | #ifdef LOCKER_ENABLE 43 | if (s_lock == NULL) 44 | { 45 | s_lock = xSemaphoreCreateCounting(1, 1); 46 | assert(s_lock != NULL); 47 | } 48 | #endif 49 | 50 | // the values passed to esp_partition_find_first() must correspond to the 51 | // values set in partitions.csv for the partition named "flashdb". 52 | partition = esp_partition_find_first(0x40, 0x00, "flashdb"); 53 | 54 | assert(partition != NULL); 55 | 56 | return 1; 57 | } 58 | 59 | static int read(long offset, uint8_t *buf, size_t size) 60 | { 61 | esp_err_t ret; 62 | 63 | LOCK(); 64 | ret = esp_partition_read(partition, offset, buf, size); 65 | UNLOCK(); 66 | 67 | return ret; 68 | } 69 | 70 | static int write(long offset, const uint8_t *buf, size_t size) 71 | { 72 | esp_err_t ret; 73 | 74 | LOCK(); 75 | ret = esp_partition_write(partition, offset, buf, size); 76 | UNLOCK(); 77 | 78 | return ret; 79 | } 80 | 81 | static int erase(long offset, size_t size) 82 | { 83 | esp_err_t ret; 84 | int32_t erase_size = ((size - 1) / FLASH_ERASE_MIN_SIZE) + 1; 85 | 86 | LOCK(); 87 | ret = esp_partition_erase_range(partition, offset, erase_size * FLASH_ERASE_MIN_SIZE); 88 | UNLOCK(); 89 | 90 | return ret; 91 | } 92 | 93 | const struct fal_flash_dev nor_flash0 = 94 | { 95 | .name = NOR_FLASH_DEV_NAME, 96 | .addr = 0x0, // address is relative to beginning of partition; 0x0 is start of the partition 97 | .len = 32 * 1024, // size of the partition as specified in partitions.csv 98 | .blk_size = FLASH_ERASE_MIN_SIZE, // must be 4096 bytes 99 | .ops = {init, read, write, erase}, 100 | .write_gran = 1, // 1 byte write granularity 101 | }; 102 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (SOURCES) 2 | 3 | list (APPEND SOURCES "main.c") 4 | 5 | list (APPEND SOURCES "../../../src/fdb.c" "../../../src/fdb_file.c" "../../../src/fdb_kvdb.c" "../../../src/fdb_tsdb.c" "../../../src/fdb_utils.c") 6 | 7 | list (APPEND SOURCES "../../../port/fal/src/fal_flash.c" "../../../port/fal/src/fal_partition.c" "../../../port/fal/src/fal_rtt.c" "../../../port/fal/src/fal.c") 8 | 9 | list (APPEND SOURCES "../../../samples/kvdb_basic_sample.c" "../../../samples/kvdb_type_blob_sample.c" "../../../samples/kvdb_type_string_sample.c" "../../../samples/tsdb_sample.c") 10 | 11 | idf_component_register(SRCS "${SOURCES}" 12 | INCLUDE_DIRS "../components/FlashDB/inc" "../../../inc" "../../../port/fal/inc" 13 | REQUIRES "spi_flash") 14 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /demos/esp32_spi_flash/partitions.csv: -------------------------------------------------------------------------------- 1 | # The partition named "flashdb" will contain the partitions for the kvdb and tsdb. 2 | # Note that this partition must be at least as large as the sum of all partitions as 3 | # defined in FAL_PART_TABLE in fal_cfg.h. 4 | # The offsets are left blank intentionally so that the partitions will be arranged 5 | # automatically. 6 | # The partition type for the partition "flashdb" was set to 0x40, a custom type. 7 | # The subtype was set to 0x0. These values must correspond to the settings in the 8 | # init() function in fal_flash_esp32_port.c. 9 | 10 | # Name, Type, SubType, Offset, Size, Flags 11 | nvs, data, nvs, , 16k, 12 | phy_init, data, phy, , 4k, 13 | flashdb, 0x40, 0x00, , 32k, 14 | factory, app, factory, , 1M, 15 | -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's 2 | # CMakeLists in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | project(hello-world) -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | PROJECT_NAME := flashDB_demo 7 | 8 | include $(IDF_PATH)/make/project.mk 9 | 10 | -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/README.md: -------------------------------------------------------------------------------- 1 | # flashDB demo Example 2 | 3 | 启动一个freertos任务运行flashDB的例程,然后倒计时1000秒后重启。运行log,请看当前目录下的ESP8266_flashDB_log.rtf 日志 4 | 5 | # ESP8266开发环境 6 | 7 | * Ubuntu 16.04 64位 8 | * 用乐鑫IDF:ESP8266_RTOS_SDK(版本:ESP-IDF v3.2-252-g73bf28b-dirty),下载:https://github.com/espressif/ESP8266_RTOS_SDK.git 9 | * 安装交叉编译工具链,下载:https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz 10 | 11 | # ESP8266开发指南 12 | 13 | * 详细的安装开发教程,请参考:https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/index.html 14 | 15 | # 编译和下载 16 | 17 | * cd进入esp8266_spi_flash目录 18 | * make all 19 | * 使用串口线把8266开发板连接到PC 20 | * 使能串口,执行命令:sudo chmod 777 /dev/ttyUSB* 21 | * make flash 22 | * make monitor -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/components/FlashDB/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | COMPONENT_ADD_INCLUDEDIRS += \ 5 | inc \ 6 | ../../../../inc \ 7 | ../../../../port/fal/inc 8 | 9 | COMPONENT_SRCDIRS += \ 10 | ../../../../src \ 11 | ../../../../samples \ 12 | ../../../../port/fal/src \ 13 | porting 14 | 15 | 16 | # COMPONENT_PRIV_INCLUDEDIRS += 17 | 18 | # COMPONENT_ADD_LDFLAGS += -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive 19 | 20 | -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/components/FlashDB/inc/fal_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File : fal_cfg.h 3 | * This file is part of FAL (Flash Abstraction Layer) package 4 | * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License along 17 | * with this program; if not, write to the Free Software Foundation, Inc., 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | * 20 | * Change Logs: 21 | * Date Author Notes 22 | * 2018-05-17 armink the first version 23 | */ 24 | 25 | #ifndef _FAL_CFG_H_ 26 | #define _FAL_CFG_H_ 27 | 28 | //#include 29 | //#include 30 | 31 | //#define FAL_DEBUG 1 32 | #define FAL_PART_HAS_TABLE_CFG 33 | #define NOR_FLASH_DEV_NAME "norflash0" 34 | 35 | //#define FAL_PART_TABLE_FLASH_DEV_NAME NOR_FLASH_DEV_NAME 36 | //#define FAL_PART_TABLE_END_OFFSET 65536 37 | 38 | /* ===================== Flash device Configuration ========================= */ 39 | extern const struct fal_flash_dev nor_flash0; 40 | 41 | /* flash device table */ 42 | #define FAL_FLASH_DEV_TABLE \ 43 | { \ 44 | &nor_flash0, \ 45 | } 46 | /* ====================== Partition Configuration ========================== */ 47 | #ifdef FAL_PART_HAS_TABLE_CFG 48 | /* partition table */ 49 | #define FAL_PART_TABLE \ 50 | { \ 51 | {FAL_PART_MAGIC_WORD, "fdb_kvdb1", NOR_FLASH_DEV_NAME, 0, 16*1024, 0}, \ 52 | {FAL_PART_MAGIC_WORD, "fdb_tsdb1", NOR_FLASH_DEV_NAME, 16*1024 , 16*1024, 0}, \ 53 | } 54 | #endif /* FAL_PART_HAS_TABLE_CFG */ 55 | 56 | #endif /* _FAL_CFG_H_ */ 57 | -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/components/FlashDB/inc/fdb_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief configuration file 10 | */ 11 | 12 | #ifndef _FDB_CFG_H_ 13 | #define _FDB_CFG_H_ 14 | 15 | /* using KVDB feature */ 16 | #define FDB_USING_KVDB 17 | 18 | #ifdef FDB_USING_KVDB 19 | /* Auto update KV to latest default when current KVDB version number is changed. @see fdb_kvdb.ver_num */ 20 | /* #define FDB_KV_AUTO_UPDATE */ 21 | #endif 22 | 23 | /* using TSDB (Time series database) feature */ 24 | #define FDB_USING_TSDB 25 | 26 | /* Using FAL storage mode */ 27 | #define FDB_USING_FAL_MODE 28 | 29 | /* the flash write granularity, unit: bit 30 | * only support 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1) */ 31 | #define FDB_WRITE_GRAN 1 /* @note you must define it for a value */ 32 | 33 | /* MCU Endian Configuration, default is Little Endian Order. */ 34 | /* #define FDB_BIG_ENDIAN */ 35 | 36 | /* log print macro. default EF_PRINT macro is printf() */ 37 | /* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */ 38 | 39 | /* print debug information */ 40 | #define FDB_DEBUG_ENABLE 41 | 42 | #endif /* _FDB_CFG_H_ */ 43 | -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/components/FlashDB/porting/fal_flash_esp8266_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include "esp_spi_flash.h" 8 | 9 | #include 10 | #include 11 | 12 | #define FLASH_ERASE_MIN_SIZE (4 * 1024) 13 | 14 | #define LOCKER_ENABLE 15 | #ifdef LOCKER_ENABLE 16 | #include "FreeRTOS.h" 17 | #include "semphr.h" 18 | 19 | static SemaphoreHandle_t s_lock = NULL; 20 | 21 | #define LOCK() \ 22 | do { \ 23 | xSemaphoreTake(s_lock, portMAX_DELAY); \ 24 | } while(0) 25 | 26 | #define UNLOCK() \ 27 | do { \ 28 | xSemaphoreGive(s_lock); \ 29 | } while(0) 30 | #else 31 | #define LOCK() 32 | #define UNLOCK() 33 | #endif 34 | 35 | static int init(void) 36 | { 37 | #ifdef LOCKER_ENABLE 38 | if (s_lock == NULL) { 39 | s_lock = xSemaphoreCreateCounting(1, 1); 40 | assert(s_lock != NULL); 41 | } 42 | #endif 43 | return 1; 44 | } 45 | 46 | static int read(long offset, uint8_t *buf, size_t size) 47 | { 48 | //Xassert(size % 4 == 0); 49 | 50 | /* You can add your code under here. */ 51 | int32_t ret; 52 | uint32_t addr = nor_flash0.addr + offset; 53 | 54 | 55 | LOCK(); 56 | ret = spi_flash_read(addr, buf, size); 57 | UNLOCK(); 58 | 59 | return ret; 60 | } 61 | 62 | static int write(long offset, const uint8_t *buf, size_t size) 63 | { 64 | int32_t ret; 65 | uint32_t addr = nor_flash0.addr + offset; 66 | 67 | LOCK(); 68 | ret = spi_flash_write(addr, buf, size); 69 | UNLOCK(); 70 | 71 | return ret; 72 | } 73 | 74 | static int erase(long offset, size_t size) 75 | { 76 | int32_t ret; 77 | uint32_t addr = nor_flash0.addr + offset; 78 | 79 | int32_t erase_size = ((size - 1) / FLASH_ERASE_MIN_SIZE) + 1; 80 | 81 | LOCK(); 82 | ret = spi_flash_erase_range(addr, erase_size * FLASH_ERASE_MIN_SIZE); 83 | UNLOCK(); 84 | 85 | return ret; 86 | } 87 | 88 | /* 89 | "esp8266_onchip" : Flash 设备的名字。 90 | 0x08000000: 对 Flash 操作的起始地址。 91 | 1024*1024:Flash 的总大小(1MB)。 92 | 128*1024:Flash 块/扇区大小(因为 STM32F2 各块大小不均匀,所以擦除粒度为最大块的大小:128K)。 93 | {init, read, write, erase} :Flash 的操作函数。 如果没有 init 初始化过程,第一个操作函数位置可以置空。 94 | 8 : 设置写粒度,单位 bit, 0 表示未生效(默认值为 0 ),该成员是 fal 版本大于 0.4.0 的新增成员。各个 flash 写入粒度不尽相同,可通过该成员进行设置,以下列举几种常见 Flash 写粒度: 95 | nor flash: 1 bit 96 | stm32f2/f4: 8 bit 97 | stm32f1: 32 bit 98 | stm32l4: 64 bit 99 | */ 100 | 101 | //1.定义 flash 设备 102 | 103 | const struct fal_flash_dev nor_flash0 = 104 | { 105 | .name = "norflash0", 106 | .addr = 0x100000, 107 | .len = 50*1024, 108 | .blk_size = FLASH_ERASE_MIN_SIZE, 109 | .ops = {init, read, write, erase}, 110 | .write_gran = 1 111 | }; 112 | 113 | -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "hello_world_main.c" 2 | INCLUDE_DIRS "") -------------------------------------------------------------------------------- /demos/esp8266_spi_flash/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | -------------------------------------------------------------------------------- /demos/linux/Makefile: -------------------------------------------------------------------------------- 1 | CC = cc 2 | 3 | ROOTPATH=../.. 4 | INCLUDE = -I./applications -I$(ROOTPATH)/inc 5 | LIB=-lpthread 6 | 7 | OBJ += $(patsubst %.c, %.o, $(wildcard applications/*.c)) 8 | OBJ += $(patsubst %.c, %.o, $(wildcard $(ROOTPATH)/src/*.c)) 9 | OBJ += $(patsubst %.c, %.o, $(wildcard $(ROOTPATH)/samples/*.c)) 10 | 11 | CFLAGS = -O0 -g3 -Wall 12 | target = FlashDBLinuxDemo 13 | 14 | all:$(OBJ) 15 | $(CC) out/*.o -o $(target) $(LIB) 16 | mv $(target) out 17 | %.o:%.c 18 | $(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE) 19 | mv $@ out 20 | clean: 21 | rm -rf out/* 22 | -------------------------------------------------------------------------------- /demos/linux/README.md: -------------------------------------------------------------------------------- 1 | # linux demo 2 | 3 | ## What 4 | 5 | KVDB and TSDB demo on linux platform 6 | 7 | ## How 8 | 9 | ### Step1: build 10 | 11 | Run `make` command on terminal. The generated executable program is located in the `out` folder. 12 | 13 | ### Step2: run demo 14 | 15 | Switch to the `out` folder. Then run the `./FlashDBLinuxDemo` file multiple times. 16 | 17 | ### Step3: check the log 18 | 19 | This demo's log will output to terminal. -------------------------------------------------------------------------------- /demos/linux/applications/fdb_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief configuration file 10 | */ 11 | 12 | #ifndef _FDB_CFG_H_ 13 | #define _FDB_CFG_H_ 14 | 15 | /* using KVDB feature */ 16 | #define FDB_USING_KVDB 17 | 18 | #ifdef FDB_USING_KVDB 19 | /* Auto update KV to latest default when current KVDB version number is changed. @see fdb_kvdb.ver_num */ 20 | /* #define FDB_KV_AUTO_UPDATE */ 21 | #endif 22 | 23 | /* using TSDB (Time series database) feature */ 24 | #define FDB_USING_TSDB 25 | 26 | /* Using file storage mode by POSIX file API, like open/read/write/close */ 27 | #define FDB_USING_FILE_POSIX_MODE 28 | 29 | /* log print macro. default EF_PRINT macro is printf() */ 30 | /* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */ 31 | 32 | /* print debug information */ 33 | #define FDB_DEBUG_ENABLE 34 | 35 | #endif /* _FDB_CFG_H_ */ 36 | -------------------------------------------------------------------------------- /demos/linux/out/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.exe 3 | FlashDBLinuxDemo 4 | -------------------------------------------------------------------------------- /demos/stm32f103ve/.gitattributes: -------------------------------------------------------------------------------- 1 | # Sources 2 | *.c text diff=c 3 | *.cc text diff=cpp 4 | *.cxx text diff=cpp 5 | *.cpp text diff=cpp 6 | *.c++ text diff=cpp 7 | *.hpp text diff=cpp 8 | *.h text diff=c 9 | *.h++ text diff=cpp 10 | *.hh text diff=cpp 11 | 12 | # Compiled Object files 13 | *.slo binary 14 | *.lo binary 15 | *.o binary 16 | *.obj binary 17 | 18 | # Precompiled Headers 19 | *.gch binary 20 | *.pch binary 21 | 22 | # Compiled Dynamic libraries 23 | *.so binary 24 | *.dylib binary 25 | *.dll binary 26 | 27 | # Compiled Static libraries 28 | *.lai binary 29 | *.la binary 30 | *.a binary 31 | *.lib binary 32 | 33 | # Executables 34 | *.exe binary 35 | *.out binary 36 | *.app binary 37 | -------------------------------------------------------------------------------- /demos/stm32f103ve/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.map 3 | *.dblite 4 | *.elf 5 | *.bin 6 | *.hex 7 | *.axf 8 | *.pdb 9 | *.idb 10 | *.ilk 11 | *.old 12 | build 13 | Debug 14 | *~ 15 | *.o 16 | *.obj 17 | *.out 18 | *.bak 19 | *.dep 20 | *.lib 21 | *.i 22 | *.d 23 | .DS_Stor* 24 | .config 3 25 | .config 4 26 | .config 5 27 | *.uimg 28 | GPATH 29 | GRTAGS 30 | GTAGS 31 | .vscode 32 | JLinkLog.txt 33 | JLinkSettings.ini 34 | DebugConfig/ 35 | RTE/ 36 | settings/ 37 | *.uvguix* 38 | -------------------------------------------------------------------------------- /demos/stm32f103ve/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | FlashDB_STM32F103 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.rt-thread.studio.rttnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | 29 | fal 30 | 2 31 | $%7BPARENT-2-PROJECT_LOC%7D/port/fal 32 | 33 | 34 | flashdb 35 | 2 36 | virtual:/virtual 37 | 38 | 39 | flashdb/inc 40 | 2 41 | $%7BPARENT-2-PROJECT_LOC%7D/inc 42 | 43 | 44 | flashdb/samples 45 | 2 46 | $%7BPARENT-2-PROJECT_LOC%7D/samples 47 | 48 | 49 | flashdb/src 50 | 2 51 | $%257BPARENT-2-PROJECT_LOC%257D/src 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /demos/stm32f103ve/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /demos/stm32f103ve/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /demos/stm32f103ve/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | content-types/enabled=true 2 | content-types/org.eclipse.cdt.core.asmSource/file-extensions=s 3 | eclipse.preferences.version=1 -------------------------------------------------------------------------------- /demos/stm32f103ve/.settings/projcfg.ini: -------------------------------------------------------------------------------- 1 | #RT-Thread Studio Project Configuration 2 | #Sun Jul 12 17:36:45 CST 2020 3 | project_type=bare_metal 4 | chip_name=STM32F103VE 5 | cpu_name=None 6 | target_freq=72 7 | clock_source=hsi 8 | dvendor_name=STMicroelectronics 9 | rx_pin_name=PA10 10 | rtt_path= 11 | source_freq=0 12 | csp_path=repo/Extract/Chip_Support_Packages/RealThread/STM32F1/0.1.9 13 | sub_series_name=STM32F103 14 | cfg_version=v3.0 15 | tool_chain=gcc 16 | uart_name=uart1 17 | tx_pin_name=PA9 18 | rtt_nano_path= 19 | output_project_path=E\:/Program/STM32/FlashDB/demos 20 | hardware_adapter=J-Link 21 | project_name=FlashDB_STM32F103 22 | -------------------------------------------------------------------------------- /demos/stm32f103ve/README.md: -------------------------------------------------------------------------------- 1 | # stm32f103ve on-chip flash demo 2 | 3 | ## What 4 | 5 | KVDB and TSDB demo on STM32F10X chip 6 | 7 | - MCU: STM32F103VE 8 | - Flash Driver 9 | - STM32 on-chip flash 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | 15 | ## How 16 | 17 | ### Step1: connect the serial terminal 18 | 19 | Connect the board to PC by serial port and open the PC serial terminal. 20 | 21 | ### Step2: open demo project 22 | 23 | support 2 kinds of IDEs 24 | 25 | - Keil MDK: open `RVMDK\FlashDB.uvprojx` 26 | - [RT-Studio](https://www.rt-thread.io/studio.html): import this folder by import wizard 27 | 28 | ### Step3: build and download 29 | 30 | Download the firmware to your board when build successful. 31 | 32 | ### Step4: check the log 33 | 34 | This demo's log will output to PC serial. 35 | 36 | -------------------------------------------------------------------------------- /demos/stm32f103ve/RVMDK/.gitignore: -------------------------------------------------------------------------------- 1 | /Output 2 | /Listings 3 | /Objects 4 | /DebugConfig 5 | JLinkLog.txt 6 | JLinkSettings.ini 7 | *.bak 8 | *.dep 9 | *.uvguix* 10 | *.uvgui* 11 | *.scvd 12 | -------------------------------------------------------------------------------- /demos/stm32f103ve/applications/fal_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef _FAL_CFG_H_ 8 | #define _FAL_CFG_H_ 9 | 10 | #define FAL_DEBUG 1 11 | #define FAL_PART_HAS_TABLE_CFG 12 | 13 | /* ===================== Flash device Configuration ========================= */ 14 | extern const struct fal_flash_dev stm32_onchip_flash; 15 | 16 | /* flash device table */ 17 | #define FAL_FLASH_DEV_TABLE \ 18 | { \ 19 | &stm32_onchip_flash, \ 20 | } 21 | 22 | /* ====================== Partition Configuration ========================== */ 23 | #ifdef FAL_PART_HAS_TABLE_CFG 24 | /* partition table */ 25 | #define FAL_PART_TABLE \ 26 | { \ 27 | {FAL_PART_MAGIC_WORD, "fdb_tsdb1", "stm32_onchip", 104*1024, 8*1024, 0}, \ 28 | {FAL_PART_MAGIC_WORD, "fdb_kvdb1", "stm32_onchip", 112*1024, 16*1024, 0}, \ 29 | } 30 | #endif /* FAL_PART_HAS_TABLE_CFG */ 31 | 32 | #endif /* _FAL_CFG_H_ */ 33 | -------------------------------------------------------------------------------- /demos/stm32f103ve/applications/fdb_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief configuration file 10 | */ 11 | 12 | #ifndef _FDB_CFG_H_ 13 | #define _FDB_CFG_H_ 14 | 15 | /* using KVDB feature */ 16 | #define FDB_USING_KVDB 17 | 18 | #ifdef FDB_USING_KVDB 19 | /* Auto update KV to latest default when current KVDB version number is changed. @see fdb_kvdb.ver_num */ 20 | /* #define FDB_KV_AUTO_UPDATE */ 21 | #endif 22 | 23 | /* using TSDB (Time series database) feature */ 24 | #define FDB_USING_TSDB 25 | 26 | /* Using FAL storage mode */ 27 | #define FDB_USING_FAL_MODE 28 | 29 | /* the flash write granularity, unit: bit 30 | * only support 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1) */ 31 | #define FDB_WRITE_GRAN 32 32 | 33 | /* MCU Endian Configuration, default is Little Endian Order. */ 34 | /* #define FDB_BIG_ENDIAN */ 35 | 36 | /* log print macro. default EF_PRINT macro is printf() */ 37 | /* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */ 38 | 39 | /* print debug information */ 40 | #define FDB_DEBUG_ENABLE 41 | 42 | #endif /* _FDB_CFG_H_ */ 43 | -------------------------------------------------------------------------------- /demos/stm32f103ve/applications/syscall_armlibc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | 9 | int fputc(int ch, FILE *f) 10 | { 11 | extern void print_char(char); 12 | 13 | if (ch == '\n') { 14 | print_char('\r'); 15 | } 16 | 17 | print_char(ch); 18 | 19 | return ch; 20 | } 21 | -------------------------------------------------------------------------------- /demos/stm32f103ve/applications/syscall_newlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-05-31 RT-Thread first version 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #undef errno 18 | extern int errno; 19 | extern int _end; 20 | extern void print_char(char); 21 | caddr_t _sbrk(int incr) 22 | { 23 | static unsigned char *heap = NULL; 24 | unsigned char *prev_heap; 25 | 26 | if (heap == NULL) 27 | { 28 | heap = (unsigned char *) &_end; 29 | } 30 | prev_heap = heap; 31 | 32 | heap += incr; 33 | 34 | return (caddr_t) prev_heap; 35 | } 36 | 37 | int link(char *old, char *new) 38 | { 39 | return -1; 40 | } 41 | 42 | int _close(int file) 43 | { 44 | return -1; 45 | } 46 | 47 | int _fstat(int file, struct stat *st) 48 | { 49 | st->st_mode = S_IFCHR; 50 | return 0; 51 | } 52 | 53 | int _isatty(int file) 54 | { 55 | return 1; 56 | } 57 | 58 | int _lseek(int file, int ptr, int dir) 59 | { 60 | return 0; 61 | } 62 | 63 | int _read(int file, char *ptr, int len) 64 | { 65 | return 0; 66 | } 67 | 68 | void abort(void) 69 | { 70 | /* Abort called */ 71 | while (1) 72 | ; 73 | } 74 | 75 | int _write(int fd, char *pBuffer, int size) 76 | { 77 | for (int i = 0; i < size; i++) 78 | { 79 | if (pBuffer[i] == '\n') 80 | { 81 | print_char('\r'); 82 | } 83 | print_char(pBuffer[i]); 84 | } 85 | return size; 86 | } 87 | -------------------------------------------------------------------------------- /demos/stm32f103ve/drivers/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-12 RealThread the first version 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | static void rtthread_startup(void) 16 | { 17 | extern int main(void); 18 | extern int $Super$$main(void); 19 | extern void clk_init(char *clk_source, int source_freq, int target_freq); 20 | extern int uart_init(); 21 | 22 | clk_init(BSP_CLOCK_SOURCE, BSP_CLOCK_SOURCE_FREQ_MHZ, BSP_CLOCK_SYSTEM_FREQ_MHZ); 23 | uart_init(); 24 | 25 | setbuf(stdout, NULL); 26 | 27 | /* invoke system main function */ 28 | #if defined(__CC_ARM) || defined(__CLANG_ARM) 29 | $Super$$main(); /* for ARMCC. */ 30 | #elif defined(__ICCARM__) || defined(__GNUC__) 31 | main(); 32 | #endif 33 | 34 | while(1); 35 | } 36 | 37 | #if defined(__CC_ARM) || defined(__CLANG_ARM) 38 | extern int $Super$$main(void); 39 | /* re-define main function */ 40 | int $Sub$$main(void) 41 | { 42 | rtthread_startup(); 43 | return 0; 44 | } 45 | #elif defined(__ICCARM__) 46 | extern int main(void); 47 | /* __low_level_init will auto called by IAR cstartup */ 48 | extern void __iar_data_init3(void); 49 | int __low_level_init(void) 50 | { 51 | // call IAR table copy function. 52 | __iar_data_init3(); 53 | rtthread_startup(); 54 | return 0; 55 | } 56 | #elif defined(__GNUC__) 57 | /* Add -eentry to arm-none-eabi-gcc argument */ 58 | int entry(void) 59 | { 60 | rtthread_startup(); 61 | return 0; 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /demos/stm32f103ve/drivers/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-12 RealThread first version 9 | */ 10 | 11 | #ifndef __BOARD_H__ 12 | #define __BOARD_H__ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | /*-------------------------- CHIP CONFIG BEGIN --------------------------*/ 20 | 21 | #define CHIP_FAMILY_STM32 22 | #define CHIP_SERIES_STM32F1 23 | #define CHIP_NAME_STM32F103VE 24 | 25 | /*-------------------------- CHIP CONFIG END --------------------------*/ 26 | 27 | /*-------------------------- ROM/RAM CONFIG BEGIN --------------------------*/ 28 | 29 | #define ROM_START ((uint32_t)0x08000000) 30 | #define ROM_SIZE (512) 31 | #define ROM_END ((uint32_t)(ROM_START + ROM_SIZE * 1024)) 32 | 33 | #define RAM_START (0x20000000) 34 | #define RAM_SIZE (64) 35 | #define RAM_END (RAM_START + RAM_SIZE * 1024) 36 | 37 | /*-------------------------- ROM/RAM CONFIG END --------------------------*/ 38 | 39 | /*-------------------------- CLOCK CONFIG BEGIN --------------------------*/ 40 | 41 | #define BSP_CLOCK_SOURCE ("HSI") 42 | #define BSP_CLOCK_SOURCE_FREQ_MHZ ((int32_t)0) 43 | #define BSP_CLOCK_SYSTEM_FREQ_MHZ ((int32_t)72) 44 | 45 | /*-------------------------- CLOCK CONFIG END --------------------------*/ 46 | 47 | /*-------------------------- UART CONFIG BEGIN --------------------------*/ 48 | 49 | /** After configuring corresponding UART or UART DMA, you can use it. 50 | * 51 | * STEP 1, define macro define related to the serial port opening based on the serial port number 52 | * such as #define BSP_USING_UATR1 53 | * 54 | * STEP 2, according to the corresponding pin of serial port, define the related serial port information macro 55 | * such as #define BSP_UART1_TX_PIN "PA9" 56 | * #define BSP_UART1_RX_PIN "PA10" 57 | * 58 | */ 59 | 60 | #define BSP_USING_UART1 61 | #define BSP_UART1_TX_PIN "PA9" 62 | #define BSP_UART1_RX_PIN "PA10" 63 | 64 | /*-------------------------- UART CONFIG END --------------------------*/ 65 | extern void wait_ms(unsigned long ms_time); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __BOARD_H__ */ 72 | -------------------------------------------------------------------------------- /demos/stm32f103ve/drivers/drv_clk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2019-10-26 ChenYong first version 9 | * 2020-01-08 xiangxistu add HSI configuration 10 | * 2020-04-20 chenyaxing add system_clock_config frequency parameter 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | void _error_handler(char *s, int num); 17 | 18 | #ifndef Error_Handler 19 | #define Error_Handler() _error_handler(__FILE__, __LINE__) 20 | #endif 21 | 22 | void system_clock_config(int target_freq_Mhz) 23 | { 24 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 25 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 26 | 27 | /** Initializes the CPU, AHB and APB busses clocks 28 | */ 29 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 30 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 31 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 32 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 33 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; 34 | #if defined(STM32F100xB) || defined(STM32F100xE) 35 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; 36 | #endif 37 | #if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) 38 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; 39 | #endif 40 | #if defined(STM32F102x6) || defined(STM32F102xB) 41 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; 42 | #endif 43 | #if defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) 44 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; 45 | #endif 46 | #if defined(STM32F105xC) || defined(STM32F107xC) 47 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; 48 | #endif 49 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 50 | { 51 | Error_Handler(); 52 | } 53 | /** Initializes the CPU, AHB and APB busses clocks 54 | */ 55 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 56 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 57 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 58 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 59 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 60 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 61 | 62 | #if defined(STM32F100xB) || defined(STM32F100xE) 63 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) 64 | #endif 65 | #if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) 66 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) 67 | #endif 68 | #if defined(STM32F102x6) || defined(STM32F102xB) 69 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) 70 | #endif 71 | #if defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) 72 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 73 | #endif 74 | #if defined(STM32F105xC) || defined(STM32F107xC) 75 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 76 | #endif 77 | { 78 | Error_Handler(); 79 | } 80 | } 81 | 82 | int clock_information(void) 83 | { 84 | printf("System Clock information\n"); 85 | printf("SYSCLK_Frequency = %d\n", (int) HAL_RCC_GetSysClockFreq()); 86 | printf("HCLK_Frequency = %d\n", (int) HAL_RCC_GetHCLKFreq()); 87 | printf("PCLK1_Frequency = %d\n", (int) HAL_RCC_GetPCLK1Freq()); 88 | printf("PCLK2_Frequency = %d\n", (int) HAL_RCC_GetPCLK2Freq()); 89 | 90 | return 0; 91 | } 92 | 93 | void wait_ms(unsigned long ms_time) 94 | { 95 | HAL_Delay(ms_time); 96 | } 97 | -------------------------------------------------------------------------------- /demos/stm32f103ve/drivers/drv_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-04-20 chenyaxing first version 9 | */ 10 | 11 | #include 12 | 13 | extern int rt_hw_usart_init(void); 14 | extern void system_clock_config(int); 15 | extern int clock_information(void); 16 | 17 | void clk_init(char *clk_source, int source_freq, int target_freq) 18 | { 19 | HAL_Init(); 20 | 21 | /* disbale interrupt */ 22 | __set_PRIMASK(1); 23 | /* system clock config */ 24 | system_clock_config(target_freq); 25 | /* init system tick to 1KHz */ 26 | #if defined (SOC_SERIES_STM32H7) 27 | HAL_SYSTICK_Config((HAL_RCCEx_GetD1SysClockFreq()) / 1000); 28 | #else 29 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); 30 | #endif 31 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 32 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 33 | /* enable interrupt */ 34 | __set_PRIMASK(0); 35 | } 36 | 37 | int uart_init() 38 | { 39 | rt_hw_usart_init(); 40 | clock_information(); 41 | return 0; 42 | } 43 | 44 | void SysTick_Handler(void) 45 | { 46 | HAL_IncTick(); 47 | } 48 | 49 | void _error_handler(char *s, int num) 50 | { 51 | /* USER CODE BEGIN Error_Handler */ 52 | /* User can add his own implementation to report the HAL error return state */ 53 | while (1) 54 | { 55 | } 56 | /* USER CODE END Error_Handler */ 57 | } 58 | -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f103ve/libraries/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f103ve/libraries/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /** @addtogroup CMSIS 21 | * @{ 22 | */ 23 | 24 | /** @addtogroup stm32f10x_system 25 | * @{ 26 | */ 27 | 28 | /** 29 | * @brief Define to prevent recursive inclusion 30 | */ 31 | #ifndef __SYSTEM_STM32F10X_H 32 | #define __SYSTEM_STM32F10X_H 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** @addtogroup STM32F10x_System_Includes 39 | * @{ 40 | */ 41 | 42 | /** 43 | * @} 44 | */ 45 | 46 | 47 | /** @addtogroup STM32F10x_System_Exported_types 48 | * @{ 49 | */ 50 | 51 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 52 | extern const uint8_t AHBPrescTable[16U]; /*!< AHB prescalers table values */ 53 | extern const uint8_t APBPrescTable[8U]; /*!< APB prescalers table values */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/CMSIS/Lib/GCC/libarm_cortexM4l_math.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f103ve/libraries/CMSIS/Lib/GCC/libarm_cortexM4l_math.a -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/CMSIS/Lib/GCC/libarm_cortexM4lf_math.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f103ve/libraries/CMSIS/Lib/GCC/libarm_cortexM4lf_math.a -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/STM32F1xx_HAL_Driver/Inc/stm32_assert_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_assert.h 4 | * @author MCD Application Team 5 | * @brief STM32 assert template file. 6 | * This file should be copied to the application folder and renamed 7 | * to stm32_assert.h. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© Copyright (c) 2016 STMicroelectronics. 12 | * All rights reserved.

13 | * 14 | * This software component is licensed by ST under BSD 3-Clause license, 15 | * the "License"; You may not use this file except in compliance with the 16 | * License. You may obtain a copy of the License at: 17 | * opensource.org/licenses/BSD-3-Clause 18 | * 19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32_ASSERT_H 24 | #define __STM32_ASSERT_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | #ifdef USE_FULL_ASSERT 35 | /** 36 | * @brief The assert_param macro is used for function's parameters check. 37 | * @param expr If expr is false, it calls assert_failed function 38 | * which reports the name of the source file and the source 39 | * line number of the call that failed. 40 | * If expr is true, it returns no value. 41 | * @retval None 42 | */ 43 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 44 | /* Exported functions ------------------------------------------------------- */ 45 | void assert_failed(uint8_t* file, uint32_t line); 46 | #else 47 | #define assert_param(expr) ((void)0U) 48 | #endif /* USE_FULL_ASSERT */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __STM32_ASSERT_H */ 55 | 56 | 57 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 58 | -------------------------------------------------------------------------------- /demos/stm32f103ve/libraries/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pcd_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_pcd_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of PCD HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F1xx_HAL_PCD_EX_H 22 | #define STM32F1xx_HAL_PCD_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f1xx_hal_def.h" 30 | 31 | #if defined (USB) || defined (USB_OTG_FS) 32 | /** @addtogroup STM32F1xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup PCDEx 37 | * @{ 38 | */ 39 | /* Exported types ------------------------------------------------------------*/ 40 | /* Exported constants --------------------------------------------------------*/ 41 | /* Exported macros -----------------------------------------------------------*/ 42 | /* Exported functions --------------------------------------------------------*/ 43 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 44 | * @{ 45 | */ 46 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 47 | * @{ 48 | */ 49 | 50 | #if defined (USB_OTG_FS) 51 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 52 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 53 | #endif /* defined (USB_OTG_FS) */ 54 | 55 | #if defined (USB) 56 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 57 | uint16_t ep_addr, 58 | uint16_t ep_kind, 59 | uint32_t pmaadress); 60 | 61 | void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); 62 | #endif /* defined (USB) */ 63 | void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); 64 | void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /** 79 | * @} 80 | */ 81 | #endif /* defined (USB) || defined (USB_OTG_FS) */ 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | 88 | #endif /* STM32F1xx_HAL_PCD_EX_H */ 89 | 90 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 91 | -------------------------------------------------------------------------------- /demos/stm32f103ve/makefile.targets: -------------------------------------------------------------------------------- 1 | clean2: 2 | -$(RM) $(CC_DEPS)$(C++_DEPS)$(C_UPPER_DEPS)$(CXX_DEPS)$(SECONDARY_FLASH)$(SECONDARY_SIZE)$(ASM_DEPS)$(S_UPPER_DEPS)$(C_DEPS)$(CPP_DEPS) 3 | -$(RM) $(OBJS) *.elf 4 | -@echo ' ' -------------------------------------------------------------------------------- /demos/stm32f405rg/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.map 3 | *.dblite 4 | *.elf 5 | *.bin 6 | *.hex 7 | *.axf 8 | *.pdb 9 | *.idb 10 | *.ilk 11 | *.old 12 | build 13 | Debug 14 | *~ 15 | *.o 16 | *.obj 17 | *.out 18 | *.bak 19 | *.dep 20 | *.lib 21 | *.i 22 | *.d 23 | .DS_Stor* 24 | .config 3 25 | .config 4 26 | .config 5 27 | *.uimg 28 | GPATH 29 | GRTAGS 30 | GTAGS 31 | .vscode 32 | JLinkLog.txt 33 | JLinkSettings.ini 34 | DebugConfig/ 35 | RTE/ 36 | settings/ 37 | *.uvguix* 38 | -------------------------------------------------------------------------------- /demos/stm32f405rg/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | FlashDB_STM32F405 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.rt-thread.studio.rttnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | 29 | fal 30 | 2 31 | $%7BPARENT-2-PROJECT_LOC%7D/port/fal 32 | 33 | 34 | flashdb 35 | 2 36 | virtual:/virtual 37 | 38 | 39 | flashdb/inc 40 | 2 41 | $%7BPARENT-2-PROJECT_LOC%7D/inc 42 | 43 | 44 | flashdb/samples 45 | 2 46 | $%7BPARENT-2-PROJECT_LOC%7D/samples 47 | 48 | 49 | flashdb/src 50 | 2 51 | $%257BPARENT-2-PROJECT_LOC%257D/src 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /demos/stm32f405rg/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /demos/stm32f405rg/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | content-types/enabled=true 2 | content-types/org.eclipse.cdt.core.asmSource/file-extensions=s 3 | eclipse.preferences.version=1 -------------------------------------------------------------------------------- /demos/stm32f405rg/.settings/projcfg.ini: -------------------------------------------------------------------------------- 1 | #RT-Thread Studio Project Configuration 2 | #Sun May 31 14:09:00 CST 2020 3 | mcu_name=STM32F405RG 4 | hardware_adapter=J-Link 5 | selected_rtt_version= 6 | mcu_base_nano_proj=false 7 | project_base_bsp=true 8 | cfg_version=v2.0 9 | -------------------------------------------------------------------------------- /demos/stm32f405rg/README.md: -------------------------------------------------------------------------------- 1 | # stm32f405rg on-chip flash demo 2 | 3 | ## What 4 | 5 | KVDB and TSDB demo on STM32F4X chip 6 | 7 | - MCU: STM32F405RG 8 | - Flash Driver 9 | - STM32 on-chip flash 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | 15 | ## How 16 | 17 | ### Step1: connect the serial terminal 18 | 19 | Connect the board to PC by serial port and open the PC serial terminal. 20 | 21 | ### Step2: open demo project 22 | 23 | support 2 kinds of IDEs 24 | 25 | - Keil MDK: open `RVMDK\FlashDB.uvprojx` 26 | - [RT-Studio](https://www.rt-thread.io/studio.html): import this folder by import wizard 27 | 28 | ### Step3: build and download 29 | 30 | Download the firmware to your board when build successful. 31 | 32 | ### Step4: check the log 33 | 34 | This demo's log will output to PC serial. 35 | 36 | -------------------------------------------------------------------------------- /demos/stm32f405rg/RVMDK/.gitignore: -------------------------------------------------------------------------------- 1 | /Output 2 | /Listings 3 | /Objects 4 | /DebugConfig 5 | JLinkLog.txt 6 | JLinkSettings.ini 7 | *.bak 8 | *.dep 9 | *.uvguix* 10 | *.uvgui* 11 | *.scvd 12 | -------------------------------------------------------------------------------- /demos/stm32f405rg/applications/fal_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef _FAL_CFG_H_ 8 | #define _FAL_CFG_H_ 9 | 10 | #define FAL_DEBUG 1 11 | #define FAL_PART_HAS_TABLE_CFG 12 | 13 | /* ===================== Flash device Configuration ========================= */ 14 | extern const struct fal_flash_dev stm32_onchip_flash; 15 | 16 | /* flash device table */ 17 | #define FAL_FLASH_DEV_TABLE \ 18 | { \ 19 | &stm32_onchip_flash, \ 20 | } 21 | 22 | /* ====================== Partition Configuration ========================== */ 23 | #ifdef FAL_PART_HAS_TABLE_CFG 24 | /* partition table */ 25 | #define FAL_PART_TABLE \ 26 | { \ 27 | {FAL_PART_MAGIC_WORD, "fdb_tsdb1", "stm32_onchip", 256*1024, 256*1024, 0}, \ 28 | {FAL_PART_MAGIC_WORD, "fdb_kvdb1", "stm32_onchip", 512*1024, 256*1024, 0}, \ 29 | } 30 | #endif /* FAL_PART_HAS_TABLE_CFG */ 31 | 32 | #endif /* _FAL_CFG_H_ */ 33 | -------------------------------------------------------------------------------- /demos/stm32f405rg/applications/fdb_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief configuration file 10 | */ 11 | 12 | #ifndef _FDB_CFG_H_ 13 | #define _FDB_CFG_H_ 14 | 15 | /* using KVDB feature */ 16 | #define FDB_USING_KVDB 17 | 18 | #ifdef FDB_USING_KVDB 19 | /* Auto update KV to latest default when current KVDB version number is changed. @see fdb_kvdb.ver_num */ 20 | /* #define FDB_KV_AUTO_UPDATE */ 21 | #endif 22 | 23 | /* using TSDB (Time series database) feature */ 24 | #define FDB_USING_TSDB 25 | 26 | /* Using FAL storage mode */ 27 | #define FDB_USING_FAL_MODE 28 | 29 | /* the flash write granularity, unit: bit 30 | * only support 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1) */ 31 | #define FDB_WRITE_GRAN 8 32 | 33 | /* MCU Endian Configuration, default is Little Endian Order. */ 34 | /* #define FDB_BIG_ENDIAN */ 35 | 36 | /* log print macro. default EF_PRINT macro is printf() */ 37 | /* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */ 38 | 39 | /* print debug information */ 40 | #define FDB_DEBUG_ENABLE 41 | 42 | #endif /* _FDB_CFG_H_ */ 43 | -------------------------------------------------------------------------------- /demos/stm32f405rg/applications/syscall_armlibc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | 9 | int fputc(int ch, FILE *f) 10 | { 11 | extern void print_char(char); 12 | 13 | if (ch == '\n') { 14 | print_char('\r'); 15 | } 16 | 17 | print_char(ch); 18 | 19 | return ch; 20 | } 21 | -------------------------------------------------------------------------------- /demos/stm32f405rg/applications/syscall_newlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-05-31 RT-Thread first version 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #undef errno 18 | extern int errno; 19 | extern int _end; 20 | extern void print_char(char); 21 | caddr_t _sbrk(int incr) 22 | { 23 | static unsigned char *heap = NULL; 24 | unsigned char *prev_heap; 25 | 26 | if (heap == NULL) 27 | { 28 | heap = (unsigned char *) &_end; 29 | } 30 | prev_heap = heap; 31 | 32 | heap += incr; 33 | 34 | return (caddr_t) prev_heap; 35 | } 36 | 37 | int link(char *old, char *new) 38 | { 39 | return -1; 40 | } 41 | 42 | int _close(int file) 43 | { 44 | return -1; 45 | } 46 | 47 | int _fstat(int file, struct stat *st) 48 | { 49 | st->st_mode = S_IFCHR; 50 | return 0; 51 | } 52 | 53 | int _isatty(int file) 54 | { 55 | return 1; 56 | } 57 | 58 | int _lseek(int file, int ptr, int dir) 59 | { 60 | return 0; 61 | } 62 | 63 | int _read(int file, char *ptr, int len) 64 | { 65 | return 0; 66 | } 67 | 68 | void abort(void) 69 | { 70 | /* Abort called */ 71 | while (1) 72 | ; 73 | } 74 | 75 | int _write(int fd, char *pBuffer, int size) 76 | { 77 | for (int i = 0; i < size; i++) 78 | { 79 | if (pBuffer[i] == '\n') 80 | { 81 | print_char('\r'); 82 | } 83 | print_char(pBuffer[i]); 84 | } 85 | return size; 86 | } 87 | -------------------------------------------------------------------------------- /demos/stm32f405rg/drivers/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-05-31 yaxing.chen the first version 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | static void rtthread_startup(void) 16 | { 17 | extern int main(void); 18 | extern int $Super$$main(void); 19 | extern void clk_init(char *clk_source, int source_freq, int target_freq); 20 | extern int uart_init(); 21 | 22 | clk_init(BSP_CLOCK_SOURCE, BSP_CLOCK_SOURCE_FREQ_MHZ, BSP_CLOCK_SYSTEM_FREQ_MHZ); 23 | uart_init(); 24 | 25 | setbuf(stdout, NULL); 26 | 27 | /* invoke system main function */ 28 | #if defined(__CC_ARM) || defined(__CLANG_ARM) 29 | $Super$$main(); /* for ARMCC. */ 30 | #elif defined(__ICCARM__) || defined(__GNUC__) 31 | main(); 32 | #endif 33 | 34 | while(1); 35 | } 36 | 37 | #if defined(__CC_ARM) || defined(__CLANG_ARM) 38 | extern int $Super$$main(void); 39 | /* re-define main function */ 40 | int $Sub$$main(void) 41 | { 42 | rtthread_startup(); 43 | return 0; 44 | } 45 | #elif defined(__ICCARM__) 46 | extern int main(void); 47 | /* __low_level_init will auto called by IAR cstartup */ 48 | extern void __iar_data_init3(void); 49 | int __low_level_init(void) 50 | { 51 | // call IAR table copy function. 52 | __iar_data_init3(); 53 | rtthread_startup(); 54 | return 0; 55 | } 56 | #elif defined(__GNUC__) 57 | /* Add -eentry to arm-none-eabi-gcc argument */ 58 | int entry(void) 59 | { 60 | rtthread_startup(); 61 | return 0; 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /demos/stm32f405rg/drivers/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-07-12 RealThread first version 9 | */ 10 | 11 | #ifndef __BOARD_H__ 12 | #define __BOARD_H__ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif 18 | 19 | /*-------------------------- ROM/RAM CONFIG BEGIN --------------------------*/ 20 | 21 | #define ROM_START ((uint32_t)0x08000000) 22 | #define ROM_SIZE (1024) 23 | #define ROM_END ((uint32_t)(ROM_START + ROM_SIZE * 1024)) 24 | 25 | #define RAM_START (0x20000000) 26 | #define RAM_SIZE (128) 27 | #define RAM_END (RAM_START + RAM_SIZE * 1024) 28 | 29 | /*-------------------------- ROM/RAM CONFIG END --------------------------*/ 30 | 31 | /*-------------------------- CLOCK CONFIG BEGIN --------------------------*/ 32 | 33 | #define BSP_CLOCK_SOURCE ("HSI") 34 | #define BSP_CLOCK_SOURCE_FREQ_MHZ ((int32_t)0) 35 | #define BSP_CLOCK_SYSTEM_FREQ_MHZ ((int32_t)168) 36 | 37 | /*-------------------------- CLOCK CONFIG END --------------------------*/ 38 | 39 | /*-------------------------- UART CONFIG BEGIN --------------------------*/ 40 | 41 | /** After configuring corresponding UART or UART DMA, you can use it. 42 | * 43 | * STEP 1, define macro define related to the serial port opening based on the serial port number 44 | * such as #define BSP_USING_UATR1 45 | * 46 | * STEP 2, according to the corresponding pin of serial port, define the related serial port information macro 47 | * such as #define BSP_UART1_TX_PIN "PA9" 48 | * #define BSP_UART1_RX_PIN "PA10" 49 | * 50 | */ 51 | 52 | #define BSP_USING_UART1 53 | #define BSP_UART1_TX_PIN "PA9" 54 | #define BSP_UART1_RX_PIN "PA10" 55 | 56 | /*-------------------------- UART CONFIG END --------------------------*/ 57 | extern void wait_ms(unsigned long ms_time); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* __BOARD_H__ */ 64 | -------------------------------------------------------------------------------- /demos/stm32f405rg/drivers/drv_clk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2019-10-26 ChenYong first version 9 | * 2020-01-08 xiangxistu add HSI configuration 10 | * 2020-04-20 chenyaxing add system_clock_config frequency parameter 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | void _error_handler(char *s, int num); 17 | 18 | #ifndef Error_Handler 19 | #define Error_Handler() _error_handler(__FILE__, __LINE__) 20 | #endif 21 | 22 | void system_clock_config(int target_freq_mhz) 23 | { 24 | RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; 25 | RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; 26 | 27 | /** Configure the main internal regulator output voltage 28 | */ 29 | __HAL_RCC_PWR_CLK_ENABLE() 30 | ; 31 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 32 | /** Initializes the CPU, AHB and APB busses clocks 33 | */ 34 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 35 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 36 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 37 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 38 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 39 | RCC_OscInitStruct.PLL.PLLM = 8; 40 | RCC_OscInitStruct.PLL.PLLN = target_freq_mhz; 41 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 42 | RCC_OscInitStruct.PLL.PLLQ = 4; 43 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 44 | { 45 | Error_Handler(); 46 | } 47 | /** Initializes the CPU, AHB and APB busses clocks 48 | */ 49 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; 50 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 51 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 52 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 53 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 54 | 55 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) 56 | { 57 | Error_Handler(); 58 | } 59 | } 60 | 61 | int clock_information(void) 62 | { 63 | printf("System Clock information\n"); 64 | printf("SYSCLK_Frequency = %d\n", (int) HAL_RCC_GetSysClockFreq()); 65 | printf("HCLK_Frequency = %d\n", (int) HAL_RCC_GetHCLKFreq()); 66 | printf("PCLK1_Frequency = %d\n", (int) HAL_RCC_GetPCLK1Freq()); 67 | printf("PCLK2_Frequency = %d\n", (int) HAL_RCC_GetPCLK2Freq()); 68 | 69 | return 0; 70 | } 71 | 72 | void wait_ms(unsigned long ms_time) 73 | { 74 | HAL_Delay(ms_time); 75 | } 76 | -------------------------------------------------------------------------------- /demos/stm32f405rg/drivers/drv_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-04-20 chenyaxing first version 9 | */ 10 | 11 | #include 12 | 13 | extern int rt_hw_usart_init(void); 14 | extern void system_clock_config(int); 15 | extern int clock_information(void); 16 | 17 | void clk_init(char *clk_source, int source_freq, int target_freq) 18 | { 19 | HAL_Init(); 20 | 21 | /* disbale interrupt */ 22 | __set_PRIMASK(1); 23 | /* system clock config */ 24 | system_clock_config(target_freq); 25 | /* init system tick to 1KHz */ 26 | #if defined (SOC_SERIES_STM32H7) 27 | HAL_SYSTICK_Config((HAL_RCCEx_GetD1SysClockFreq()) / 1000); 28 | #else 29 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); 30 | #endif 31 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 32 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 33 | /* enable interrupt */ 34 | __set_PRIMASK(0); 35 | } 36 | 37 | int uart_init() 38 | { 39 | rt_hw_usart_init(); 40 | clock_information(); 41 | return 0; 42 | } 43 | 44 | void SysTick_Handler(void) 45 | { 46 | HAL_IncTick(); 47 | } 48 | 49 | void _error_handler(char *s, int num) 50 | { 51 | /* USER CODE BEGIN Error_Handler */ 52 | /* User can add his own implementation to report the HAL error return state */ 53 | while (1) 54 | { 55 | } 56 | /* USER CODE END Error_Handler */ 57 | } 58 | -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg/libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Inc/stm32_assert_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_assert.h 4 | * @author MCD Application Team 5 | * @brief STM32 assert template file. 6 | * This file should be copied to the application folder and renamed 7 | * to stm32_assert.h. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© Copyright (c) 2017 STMicroelectronics. 12 | * All rights reserved.

13 | * 14 | * This software component is licensed by ST under BSD 3-Clause license, 15 | * the "License"; You may not use this file except in compliance with the 16 | * License. You may obtain a copy of the License at: 17 | * opensource.org/licenses/BSD-3-Clause 18 | * 19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32_ASSERT_H 24 | #define __STM32_ASSERT_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | #ifdef USE_FULL_ASSERT 35 | /** 36 | * @brief The assert_param macro is used for function's parameters check. 37 | * @param expr If expr is false, it calls assert_failed function 38 | * which reports the name of the source file and the source 39 | * line number of the call that failed. 40 | * If expr is true, it returns no value. 41 | * @retval None 42 | */ 43 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 44 | /* Exported functions ------------------------------------------------------- */ 45 | void assert_failed(uint8_t* file, uint32_t line); 46 | #else 47 | #define assert_param(expr) ((void)0U) 48 | #endif /* USE_FULL_ASSERT */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __STM32_ASSERT_H */ 55 | 56 | 57 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 58 | -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_DMA_EX_H 22 | #define __STM32F4xx_HAL_DMA_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup DMAEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 41 | * @brief DMAEx Exported types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief HAL DMA Memory definition 47 | */ 48 | typedef enum 49 | { 50 | MEMORY0 = 0x00U, /*!< Memory 0 */ 51 | MEMORY1 = 0x01U /*!< Memory 1 */ 52 | }HAL_DMA_MemoryTypeDef; 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /* Exported functions --------------------------------------------------------*/ 59 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 60 | * @brief DMAEx Exported functions 61 | * @{ 62 | */ 63 | 64 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 65 | * @brief Extended features functions 66 | * @{ 67 | */ 68 | 69 | /* IO operation functions *******************************************************/ 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 72 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 73 | 74 | /** 75 | * @} 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Private functions ---------------------------------------------------------*/ 82 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 83 | * @brief DMAEx Private functions 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 103 | 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 22 | #define __STM32F4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | 33 | /** @addtogroup STM32F4xx_HAL_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup FLASH_RAMFUNC 38 | * @{ 39 | */ 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions --------------------------------------------------------*/ 44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 45 | * @{ 46 | */ 47 | 48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 49 | * @{ 50 | */ 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | 77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_i2c_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of I2C HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_I2C_EX_H 22 | #define __STM32F4xx_HAL_I2C_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF) 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f4xx_hal_def.h" 31 | 32 | /** @addtogroup STM32F4xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup I2CEx 37 | * @{ 38 | */ 39 | 40 | /* Exported types ------------------------------------------------------------*/ 41 | /* Exported constants --------------------------------------------------------*/ 42 | /** @defgroup I2CEx_Exported_Constants I2C Exported Constants 43 | * @{ 44 | */ 45 | 46 | /** @defgroup I2CEx_Analog_Filter I2C Analog Filter 47 | * @{ 48 | */ 49 | #define I2C_ANALOGFILTER_ENABLE 0x00000000U 50 | #define I2C_ANALOGFILTER_DISABLE I2C_FLTR_ANOFF 51 | /** 52 | * @} 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | /** @addtogroup I2CEx_Exported_Functions 62 | * @{ 63 | */ 64 | 65 | /** @addtogroup I2CEx_Exported_Functions_Group1 66 | * @{ 67 | */ 68 | /* Peripheral Control functions ************************************************/ 69 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter); 70 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter); 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | /* Private types -------------------------------------------------------------*/ 79 | /* Private variables ---------------------------------------------------------*/ 80 | /* Private constants ---------------------------------------------------------*/ 81 | /** @defgroup I2CEx_Private_Constants I2C Private Constants 82 | * @{ 83 | */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /* Private macros ------------------------------------------------------------*/ 90 | /** @defgroup I2CEx_Private_Macros I2C Private Macros 91 | * @{ 92 | */ 93 | #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \ 94 | ((FILTER) == I2C_ANALOGFILTER_DISABLE)) 95 | #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU) 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | #endif 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* __STM32F4xx_HAL_I2C_EX_H */ 115 | 116 | 117 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 118 | -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_ltdc_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_ltdc_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of LTDC HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F4xx_HAL_LTDC_EX_H 22 | #define STM32F4xx_HAL_LTDC_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #if defined (LTDC) && defined (DSI) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | #include "stm32f4xx_hal_dsi.h" 33 | 34 | /** @addtogroup STM32F4xx_HAL_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup LTDCEx 39 | * @{ 40 | */ 41 | 42 | /* Exported types ------------------------------------------------------------*/ 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* Exported functions --------------------------------------------------------*/ 46 | /** @addtogroup LTDCEx_Exported_Functions 47 | * @{ 48 | */ 49 | 50 | /** @addtogroup LTDCEx_Exported_Functions_Group1 51 | * @{ 52 | */ 53 | HAL_StatusTypeDef HAL_LTDCEx_StructInitFromVideoConfig(LTDC_HandleTypeDef *hltdc, DSI_VidCfgTypeDef *VidCfg); 54 | HAL_StatusTypeDef HAL_LTDCEx_StructInitFromAdaptedCommandConfig(LTDC_HandleTypeDef *hltdc, DSI_CmdCfgTypeDef *CmdCfg); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /* Private types -------------------------------------------------------------*/ 64 | /* Private variables ---------------------------------------------------------*/ 65 | /* Private constants ---------------------------------------------------------*/ 66 | /* Private macros ------------------------------------------------------------*/ 67 | /* Private functions ---------------------------------------------------------*/ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | #endif /* LTDC && DSI */ 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* STM32F4xx_HAL_LTDC_EX_H */ 84 | 85 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 86 | -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp.c -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp_ex.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp_ex.c -------------------------------------------------------------------------------- /demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_wwdg.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_wwdg.c -------------------------------------------------------------------------------- /demos/stm32f405rg/makefile.targets: -------------------------------------------------------------------------------- 1 | clean2: 2 | -$(RM) $(CC_DEPS)$(C++_DEPS)$(C_UPPER_DEPS)$(CXX_DEPS)$(SECONDARY_FLASH)$(SECONDARY_SIZE)$(ASM_DEPS)$(S_UPPER_DEPS)$(C_DEPS)$(CPP_DEPS) 3 | -$(RM) $(OBJS) *.elf 4 | -@echo ' ' -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.map 3 | *.dblite 4 | *.elf 5 | *.bin 6 | *.hex 7 | *.axf 8 | *.pdb 9 | *.idb 10 | *.ilk 11 | *.old 12 | build 13 | Debug 14 | *~ 15 | *.o 16 | *.obj 17 | *.out 18 | *.bak 19 | *.dep 20 | *.lib 21 | *.i 22 | *.d 23 | .DS_Stor* 24 | .config 3 25 | .config 4 26 | .config 5 27 | *.uimg 28 | GPATH 29 | GRTAGS 30 | GTAGS 31 | .vscode 32 | JLinkLog.txt 33 | JLinkSettings.ini 34 | DebugConfig/ 35 | RTE/ 36 | settings/ 37 | *.uvguix* 38 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | FlashDB_STM32F405_SPI_Flash 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.rt-thread.studio.rttnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | 29 | fal 30 | 2 31 | $%7BPARENT-2-PROJECT_LOC%7D/port/fal 32 | 33 | 34 | flashdb 35 | 2 36 | virtual:/virtual 37 | 38 | 39 | flashdb/inc 40 | 2 41 | $%7BPARENT-2-PROJECT_LOC%7D/inc 42 | 43 | 44 | flashdb/samples 45 | 2 46 | $%7BPARENT-2-PROJECT_LOC%7D/samples 47 | 48 | 49 | flashdb/src 50 | 2 51 | $%257BPARENT-2-PROJECT_LOC%257D/src 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/.settings/org.eclipse.core.runtime.prefs: -------------------------------------------------------------------------------- 1 | content-types/enabled=true 2 | content-types/org.eclipse.cdt.core.asmSource/file-extensions=s 3 | eclipse.preferences.version=1 -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/.settings/projcfg.ini: -------------------------------------------------------------------------------- 1 | #RT-Thread Studio Project Configuration 2 | #Fri Jun 26 23:30:41 CST 2020 3 | mcu_name=STM32F405RG 4 | output_project_path=E\:/Program/STM32/FlashDB/demos 5 | hardware_adapter=J-Link 6 | selected_rtt_version= 7 | mcu_base_nano_proj=false 8 | project_base_bsp=true 9 | cfg_version=v2.0 10 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/README.md: -------------------------------------------------------------------------------- 1 | # stm32f405rg demo 2 | 3 | ## What 4 | 5 | KVDB and TSDB demo on STM32F4X chip 6 | 7 | - MCU: STM32F405RG 8 | - Flash Driver 9 | - spi flash (W25Q64) by using [SFUD](https://github.com/armink/SFUD) 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | - SPI 15 | - CS: PB12 (software CS) 16 | - SCK: PB13 17 | - MISO: PB14 18 | - MOSI: PB15 19 | 20 | ## How 21 | 22 | ### Step1: connect the serial terminal 23 | 24 | Connect the board to PC by serial port and open the PC serial terminal. 25 | 26 | ### Step2: open demo project 27 | 28 | support 2 kinds of IDEs 29 | 30 | - Keil MDK: open `RVMDK\FlashDB.uvprojx` 31 | - [RT-Studio](https://www.rt-thread.io/studio.html): import this folder by import wizard 32 | 33 | ### Step3: build and download 34 | 35 | Download the firmware to your board when build successful. 36 | 37 | ### Step4: check the log 38 | 39 | This demo's log will output to PC serial. 40 | 41 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/RVMDK/.gitignore: -------------------------------------------------------------------------------- 1 | /Output 2 | /Listings 3 | /Objects 4 | /DebugConfig 5 | JLinkLog.txt 6 | JLinkSettings.ini 7 | *.bak 8 | *.dep 9 | *.uvguix* 10 | *.uvgui* 11 | *.scvd 12 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/applications/fal_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #ifndef _FAL_CFG_H_ 8 | #define _FAL_CFG_H_ 9 | 10 | #define FAL_DEBUG 1 11 | #define FAL_PART_HAS_TABLE_CFG 12 | #define FAL_USING_SFUD_PORT 13 | 14 | /* ===================== Flash device Configuration ========================= */ 15 | extern struct fal_flash_dev nor_flash0; 16 | 17 | /* flash device table */ 18 | #define FAL_FLASH_DEV_TABLE \ 19 | { \ 20 | &nor_flash0, \ 21 | } 22 | 23 | /* ====================== Partition Configuration ========================== */ 24 | #ifdef FAL_PART_HAS_TABLE_CFG 25 | /* partition table */ 26 | #define FAL_PART_TABLE \ 27 | { \ 28 | {FAL_PART_MAGIC_WORD, "fdb_tsdb1", "norflash0", 0, 1024*1024, 0}, \ 29 | {FAL_PART_MAGIC_WORD, "fdb_kvdb1", "norflash0", 1024*1024, 1024*1024, 0}, \ 30 | } 31 | #endif /* FAL_PART_HAS_TABLE_CFG */ 32 | 33 | #endif /* _FAL_CFG_H_ */ 34 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/applications/fdb_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief configuration file 10 | */ 11 | 12 | #ifndef _FDB_CFG_H_ 13 | #define _FDB_CFG_H_ 14 | 15 | /* using KVDB feature */ 16 | #define FDB_USING_KVDB 17 | 18 | #ifdef FDB_USING_KVDB 19 | /* Auto update KV to latest default when current KVDB version number is changed. @see fdb_kvdb.ver_num */ 20 | /* #define FDB_KV_AUTO_UPDATE */ 21 | #endif 22 | 23 | /* using TSDB (Time series database) feature */ 24 | #define FDB_USING_TSDB 25 | 26 | /* Using FAL storage mode */ 27 | #define FDB_USING_FAL_MODE 28 | 29 | /* the flash write granularity, unit: bit 30 | * only support 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1) */ 31 | #define FDB_WRITE_GRAN 8 32 | 33 | /* MCU Endian Configuration, default is Little Endian Order. */ 34 | /* #define FDB_BIG_ENDIAN */ 35 | 36 | /* log print macro. default EF_PRINT macro is printf() */ 37 | /* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */ 38 | 39 | /* print debug information */ 40 | #define FDB_DEBUG_ENABLE 41 | 42 | #endif /* _FDB_CFG_H_ */ 43 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/applications/syscall_armlibc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | 9 | int fputc(int ch, FILE *f) 10 | { 11 | extern void print_char(char); 12 | 13 | if (ch == '\n') { 14 | print_char('\r'); 15 | } 16 | 17 | print_char(ch); 18 | 19 | return ch; 20 | } 21 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/applications/syscall_newlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-05-31 RT-Thread first version 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #undef errno 18 | extern int errno; 19 | extern int _end; 20 | extern void print_char(char); 21 | caddr_t _sbrk(int incr) 22 | { 23 | static unsigned char *heap = NULL; 24 | unsigned char *prev_heap; 25 | 26 | if (heap == NULL) 27 | { 28 | heap = (unsigned char *) &_end; 29 | } 30 | prev_heap = heap; 31 | 32 | heap += incr; 33 | 34 | return (caddr_t) prev_heap; 35 | } 36 | 37 | int link(char *old, char *new) 38 | { 39 | return -1; 40 | } 41 | 42 | int _close(int file) 43 | { 44 | return -1; 45 | } 46 | 47 | int _fstat(int file, struct stat *st) 48 | { 49 | st->st_mode = S_IFCHR; 50 | return 0; 51 | } 52 | 53 | int _isatty(int file) 54 | { 55 | return 1; 56 | } 57 | 58 | int _lseek(int file, int ptr, int dir) 59 | { 60 | return 0; 61 | } 62 | 63 | int _read(int file, char *ptr, int len) 64 | { 65 | return 0; 66 | } 67 | 68 | void abort(void) 69 | { 70 | /* Abort called */ 71 | while (1) 72 | ; 73 | } 74 | 75 | int _write(int fd, char *pBuffer, int size) 76 | { 77 | for (int i = 0; i < size; i++) 78 | { 79 | if (pBuffer[i] == '\n') 80 | { 81 | print_char('\r'); 82 | } 83 | print_char(pBuffer[i]); 84 | } 85 | return size; 86 | } 87 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/drivers/board.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-05-31 yaxing.chen the first version 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | static void rtthread_startup(void) 16 | { 17 | extern int main(void); 18 | extern int $Super$$main(void); 19 | extern void clk_init(char *clk_source, int source_freq, int target_freq); 20 | extern int uart_init(); 21 | extern int spi_flash_init(void); 22 | 23 | clk_init(BSP_CLOCK_SOURCE, BSP_CLOCK_SOURCE_FREQ_MHZ, BSP_CLOCK_SYSTEM_FREQ_MHZ); 24 | uart_init(); 25 | spi_flash_init(); 26 | 27 | setbuf(stdout, NULL); 28 | 29 | /* invoke system main function */ 30 | #if defined(__CC_ARM) || defined(__CLANG_ARM) 31 | $Super$$main(); /* for ARMCC. */ 32 | #elif defined(__ICCARM__) || defined(__GNUC__) 33 | main(); 34 | #endif 35 | 36 | while(1); 37 | } 38 | 39 | #if defined(__CC_ARM) || defined(__CLANG_ARM) 40 | extern int $Super$$main(void); 41 | /* re-define main function */ 42 | int $Sub$$main(void) 43 | { 44 | rtthread_startup(); 45 | return 0; 46 | } 47 | #elif defined(__ICCARM__) 48 | extern int main(void); 49 | /* __low_level_init will auto called by IAR cstartup */ 50 | extern void __iar_data_init3(void); 51 | int __low_level_init(void) 52 | { 53 | // call IAR table copy function. 54 | __iar_data_init3(); 55 | rtthread_startup(); 56 | return 0; 57 | } 58 | #elif defined(__GNUC__) 59 | /* Add -eentry to arm-none-eabi-gcc argument */ 60 | int entry(void) 61 | { 62 | rtthread_startup(); 63 | return 0; 64 | } 65 | #endif 66 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/drivers/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2020, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2019-10-26 ChenYong first version 9 | * 2020-05-08 Chenyaxing add memory and clock information 10 | */ 11 | 12 | #ifndef __BOARD_H__ 13 | #define __BOARD_H__ 14 | 15 | #ifdef __cplusplus 16 | extern "C" 17 | { 18 | #endif 19 | 20 | /*-------------------------- ROM/RAM CONFIG BEGIN --------------------------*/ 21 | 22 | #define ROM_START ((uint32_t)0x08000000) 23 | #define ROM_SIZE (1024) 24 | #define ROM_END ((uint32_t)(ROM_START + ROM_SIZE * 1024)) 25 | 26 | #define RAM_START (0x20000000) 27 | #define RAM_SIZE (128) 28 | #define RAM_END (RAM_START + RAM_SIZE * 1024) 29 | 30 | /*-------------------------- ROM/RAM CONFIG END --------------------------*/ 31 | 32 | /*-------------------------- CLOCK CONFIG BEGIN --------------------------*/ 33 | 34 | #define BSP_CLOCK_SOURCE ("HSI") 35 | #define BSP_CLOCK_SOURCE_FREQ_MHZ ((int32_t)0) 36 | #define BSP_CLOCK_SYSTEM_FREQ_MHZ ((int32_t)168) 37 | 38 | /*-------------------------- CLOCK CONFIG END --------------------------*/ 39 | 40 | /*-------------------------- UART CONFIG BEGIN --------------------------*/ 41 | 42 | /** After configuring corresponding UART or UART DMA, you can use it. 43 | * 44 | * STEP 1, define macro define related to the serial port opening based on the serial port number 45 | * such as #define BSP_USING_UATR1 46 | * 47 | * STEP 2, according to the corresponding pin of serial port, define the related serial port information macro 48 | * such as #define BSP_UART1_TX_PIN "PA9" 49 | * #define BSP_UART1_RX_PIN "PA10" 50 | * 51 | * STEP 3, if you want using SERIAL DMA, you must open it in the RT-Thread Settings. 52 | * RT-Thread Setting -> Components -> Device Drivers -> Serial Device Drivers -> Enable Serial DMA Mode 53 | * 54 | * STEP 4, according to serial port number to define serial port tx/rx DMA function in the board.h file 55 | * such as #define BSP_UART1_RX_USING_DMA 56 | * 57 | */ 58 | 59 | #define BSP_USING_UART1 60 | #define BSP_UART1_TX_PIN "PA9" 61 | #define BSP_UART1_RX_PIN "PA10" 62 | 63 | /*-------------------------- UART CONFIG END --------------------------*/ 64 | extern void wait_ms(unsigned long ms_time); 65 | #endif /* __BOARD_H__ */ 66 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/drivers/drv_clk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2019-10-26 ChenYong first version 9 | * 2020-01-08 xiangxistu add HSI configuration 10 | * 2020-04-20 chenyaxing add system_clock_config frequency parameter 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | void _error_handler(char *s, int num); 17 | 18 | #ifndef Error_Handler 19 | #define Error_Handler() _error_handler(__FILE__, __LINE__) 20 | #endif 21 | 22 | void system_clock_config(int target_freq_mhz) 23 | { 24 | RCC_OscInitTypeDef RCC_OscInitStruct = { 0 }; 25 | RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 }; 26 | 27 | /** Configure the main internal regulator output voltage 28 | */ 29 | __HAL_RCC_PWR_CLK_ENABLE(); 30 | 31 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); 32 | /** Initializes the CPU, AHB and APB busses clocks 33 | */ 34 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 35 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 36 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; 37 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 38 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 39 | RCC_OscInitStruct.PLL.PLLM = 8; 40 | RCC_OscInitStruct.PLL.PLLN = target_freq_mhz; 41 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; 42 | RCC_OscInitStruct.PLL.PLLQ = 4; 43 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 44 | { 45 | Error_Handler(); 46 | } 47 | /** Initializes the CPU, AHB and APB busses clocks 48 | */ 49 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; 50 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 51 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 52 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 53 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; 54 | 55 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) 56 | { 57 | Error_Handler(); 58 | } 59 | } 60 | 61 | int clock_information(void) 62 | { 63 | printf("System Clock information\n"); 64 | printf("SYSCLK_Frequency = %d\n", (int) HAL_RCC_GetSysClockFreq()); 65 | printf("HCLK_Frequency = %d\n", (int) HAL_RCC_GetHCLKFreq()); 66 | printf("PCLK1_Frequency = %d\n", (int) HAL_RCC_GetPCLK1Freq()); 67 | printf("PCLK2_Frequency = %d\n", (int) HAL_RCC_GetPCLK2Freq()); 68 | 69 | return 0; 70 | } 71 | 72 | void wait_ms(unsigned long ms_time) 73 | { 74 | HAL_Delay(ms_time); 75 | } 76 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/drivers/drv_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2019, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2020-04-20 chenyaxing first version 9 | */ 10 | 11 | #include 12 | 13 | extern int rt_hw_usart_init(void); 14 | extern void system_clock_config(int); 15 | extern int clock_information(void); 16 | 17 | void clk_init(char *clk_source, int source_freq, int target_freq) 18 | { 19 | HAL_Init(); 20 | 21 | /* disbale interrupt */ 22 | __set_PRIMASK(1); 23 | /* system clock config */ 24 | system_clock_config(target_freq); 25 | /* init system tick to 1KHz */ 26 | #if defined (SOC_SERIES_STM32H7) 27 | HAL_SYSTICK_Config((HAL_RCCEx_GetD1SysClockFreq()) / 1000); 28 | #else 29 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); 30 | #endif 31 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 32 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 33 | /* enable interrupt */ 34 | __set_PRIMASK(0); 35 | } 36 | 37 | int uart_init() 38 | { 39 | rt_hw_usart_init(); 40 | clock_information(); 41 | return 0; 42 | } 43 | 44 | void SysTick_Handler(void) 45 | { 46 | HAL_IncTick(); 47 | } 48 | 49 | void _error_handler(char *s, int num) 50 | { 51 | /* USER CODE BEGIN Error_Handler */ 52 | /* User can add his own implementation to report the HAL error return state */ 53 | while (1) 54 | { 55 | } 56 | /* USER CODE END Error_Handler */ 57 | } 58 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/drivers/drv_spi_flash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | 9 | sfud_flash sfud_norflash0 = { 10 | .name = "norflash0", 11 | .spi.name = "SPI2", 12 | .chip = { "W25Q64FV", SFUD_MF_ID_WINBOND, 0x40, 0x17, 8L * 1024L * 1024L, SFUD_WM_PAGE_256B, 4096, 0x20 } }; 13 | 14 | int spi_flash_init(void) 15 | { 16 | /* SFUD initialize */ 17 | if (sfud_device_init(&sfud_norflash0) == SFUD_SUCCESS) { 18 | return 0; 19 | } else { 20 | return -1; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg_spi_flash/libraries/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Inc/stm32_assert_template.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32_assert.h 4 | * @author MCD Application Team 5 | * @brief STM32 assert template file. 6 | * This file should be copied to the application folder and renamed 7 | * to stm32_assert.h. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© Copyright (c) 2017 STMicroelectronics. 12 | * All rights reserved.

13 | * 14 | * This software component is licensed by ST under BSD 3-Clause license, 15 | * the "License"; You may not use this file except in compliance with the 16 | * License. You may obtain a copy of the License at: 17 | * opensource.org/licenses/BSD-3-Clause 18 | * 19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32_ASSERT_H 24 | #define __STM32_ASSERT_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Exported types ------------------------------------------------------------*/ 31 | /* Exported constants --------------------------------------------------------*/ 32 | /* Includes ------------------------------------------------------------------*/ 33 | /* Exported macro ------------------------------------------------------------*/ 34 | #ifdef USE_FULL_ASSERT 35 | /** 36 | * @brief The assert_param macro is used for function's parameters check. 37 | * @param expr If expr is false, it calls assert_failed function 38 | * which reports the name of the source file and the source 39 | * line number of the call that failed. 40 | * If expr is true, it returns no value. 41 | * @retval None 42 | */ 43 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 44 | /* Exported functions ------------------------------------------------------- */ 45 | void assert_failed(uint8_t* file, uint32_t line); 46 | #else 47 | #define assert_param(expr) ((void)0U) 48 | #endif /* USE_FULL_ASSERT */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __STM32_ASSERT_H */ 55 | 56 | 57 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 58 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_DMA_EX_H 22 | #define __STM32F4xx_HAL_DMA_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup DMAEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 41 | * @brief DMAEx Exported types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief HAL DMA Memory definition 47 | */ 48 | typedef enum 49 | { 50 | MEMORY0 = 0x00U, /*!< Memory 0 */ 51 | MEMORY1 = 0x01U /*!< Memory 1 */ 52 | }HAL_DMA_MemoryTypeDef; 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /* Exported functions --------------------------------------------------------*/ 59 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 60 | * @brief DMAEx Exported functions 61 | * @{ 62 | */ 63 | 64 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 65 | * @brief Extended features functions 66 | * @{ 67 | */ 68 | 69 | /* IO operation functions *******************************************************/ 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 72 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 73 | 74 | /** 75 | * @} 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Private functions ---------------------------------------------------------*/ 82 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 83 | * @brief DMAEx Private functions 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 103 | 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 22 | #define __STM32F4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | 33 | /** @addtogroup STM32F4xx_HAL_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup FLASH_RAMFUNC 38 | * @{ 39 | */ 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions --------------------------------------------------------*/ 44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 45 | * @{ 46 | */ 47 | 48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 49 | * @{ 50 | */ 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | 77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_i2c_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of I2C HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_I2C_EX_H 22 | #define __STM32F4xx_HAL_I2C_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #if defined(I2C_FLTR_ANOFF)&&defined(I2C_FLTR_DNF) 29 | /* Includes ------------------------------------------------------------------*/ 30 | #include "stm32f4xx_hal_def.h" 31 | 32 | /** @addtogroup STM32F4xx_HAL_Driver 33 | * @{ 34 | */ 35 | 36 | /** @addtogroup I2CEx 37 | * @{ 38 | */ 39 | 40 | /* Exported types ------------------------------------------------------------*/ 41 | /* Exported constants --------------------------------------------------------*/ 42 | /** @defgroup I2CEx_Exported_Constants I2C Exported Constants 43 | * @{ 44 | */ 45 | 46 | /** @defgroup I2CEx_Analog_Filter I2C Analog Filter 47 | * @{ 48 | */ 49 | #define I2C_ANALOGFILTER_ENABLE 0x00000000U 50 | #define I2C_ANALOGFILTER_DISABLE I2C_FLTR_ANOFF 51 | /** 52 | * @} 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /* Exported macro ------------------------------------------------------------*/ 60 | /* Exported functions --------------------------------------------------------*/ 61 | /** @addtogroup I2CEx_Exported_Functions 62 | * @{ 63 | */ 64 | 65 | /** @addtogroup I2CEx_Exported_Functions_Group1 66 | * @{ 67 | */ 68 | /* Peripheral Control functions ************************************************/ 69 | HAL_StatusTypeDef HAL_I2CEx_ConfigAnalogFilter(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter); 70 | HAL_StatusTypeDef HAL_I2CEx_ConfigDigitalFilter(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter); 71 | /** 72 | * @} 73 | */ 74 | 75 | /** 76 | * @} 77 | */ 78 | /* Private types -------------------------------------------------------------*/ 79 | /* Private variables ---------------------------------------------------------*/ 80 | /* Private constants ---------------------------------------------------------*/ 81 | /** @defgroup I2CEx_Private_Constants I2C Private Constants 82 | * @{ 83 | */ 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /* Private macros ------------------------------------------------------------*/ 90 | /** @defgroup I2CEx_Private_Macros I2C Private Macros 91 | * @{ 92 | */ 93 | #define IS_I2C_ANALOG_FILTER(FILTER) (((FILTER) == I2C_ANALOGFILTER_ENABLE) || \ 94 | ((FILTER) == I2C_ANALOGFILTER_DISABLE)) 95 | #define IS_I2C_DIGITAL_FILTER(FILTER) ((FILTER) <= 0x0000000FU) 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | #endif 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* __STM32F4xx_HAL_I2C_EX_H */ 115 | 116 | 117 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 118 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_ltdc_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_ltdc_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of LTDC HAL Extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2016 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef STM32F4xx_HAL_LTDC_EX_H 22 | #define STM32F4xx_HAL_LTDC_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #if defined (LTDC) && defined (DSI) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | #include "stm32f4xx_hal_dsi.h" 33 | 34 | /** @addtogroup STM32F4xx_HAL_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup LTDCEx 39 | * @{ 40 | */ 41 | 42 | /* Exported types ------------------------------------------------------------*/ 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* Exported functions --------------------------------------------------------*/ 46 | /** @addtogroup LTDCEx_Exported_Functions 47 | * @{ 48 | */ 49 | 50 | /** @addtogroup LTDCEx_Exported_Functions_Group1 51 | * @{ 52 | */ 53 | HAL_StatusTypeDef HAL_LTDCEx_StructInitFromVideoConfig(LTDC_HandleTypeDef *hltdc, DSI_VidCfgTypeDef *VidCfg); 54 | HAL_StatusTypeDef HAL_LTDCEx_StructInitFromAdaptedCommandConfig(LTDC_HandleTypeDef *hltdc, DSI_CmdCfgTypeDef *CmdCfg); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /* Private types -------------------------------------------------------------*/ 64 | /* Private variables ---------------------------------------------------------*/ 65 | /* Private constants ---------------------------------------------------------*/ 66 | /* Private macros ------------------------------------------------------------*/ 67 | /* Private functions ---------------------------------------------------------*/ 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | #endif /* LTDC && DSI */ 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* STM32F4xx_HAL_LTDC_EX_H */ 84 | 85 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 86 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp.c -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp_ex.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cryp_ex.c -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_wwdg.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg_spi_flash/libraries/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_wwdg.c -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/makefile.targets: -------------------------------------------------------------------------------- 1 | clean2: 2 | -$(RM) $(CC_DEPS)$(C++_DEPS)$(C_UPPER_DEPS)$(CXX_DEPS)$(SECONDARY_FLASH)$(SECONDARY_SIZE)$(ASM_DEPS)$(S_UPPER_DEPS)$(C_DEPS)$(CPP_DEPS) 3 | -$(RM) $(OBJS) *.elf 4 | -@echo ' ' -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/sfud/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2018 Armink (armink.ztl@gmail.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/sfud/inc/sfud_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the Serial Flash Universal Driver Library. 3 | * 4 | * Copyright (c) 2016-2018, Armink, 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining 7 | * a copy of this software and associated documentation files (the 8 | * 'Software'), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, 10 | * distribute, sublicense, and/or sell copies of the Software, and to 11 | * permit persons to whom the Software is furnished to do so, subject to 12 | * the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be 15 | * included in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | * 25 | * Function: It is the configure head file for this library. 26 | * Created on: 2016-04-23 27 | */ 28 | 29 | #ifndef _SFUD_CFG_H_ 30 | #define _SFUD_CFG_H_ 31 | 32 | #define SFUD_DEBUG_MODE 33 | 34 | #define SFUD_USING_SFDP 35 | 36 | #define SFUD_USING_FLASH_INFO_TABLE 37 | 38 | enum { 39 | SFUD_XXXX_DEVICE_INDEX = 0, 40 | }; 41 | 42 | #define SFUD_FLASH_DEVICE_TABLE \ 43 | { \ 44 | [SFUD_XXXX_DEVICE_INDEX] = {.name = "XXXX", .spi.name = "SPIX"}, \ 45 | } 46 | 47 | #endif /* _SFUD_CFG_H_ */ 48 | -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/sfud/port/sfud_port.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg_spi_flash/sfud/port/sfud_port.c -------------------------------------------------------------------------------- /demos/stm32f405rg_spi_flash/sfud/src/sfud_sfdp.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/demos/stm32f405rg_spi_flash/sfud/src/sfud_sfdp.c -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/.nojekyll -------------------------------------------------------------------------------- /docs/_coverpage.md: -------------------------------------------------------------------------------- 1 | ![FlashDB](_media/flashdb.png) 2 | 3 | > An ultra-lightweight embedded database. 4 | 5 | [![Build Status](https://travis-ci.com/armink/FlashDB.svg?branch=master)](https://travis-ci.com/armink/FlashDB) 6 | [![version](https://img.shields.io/github/release/armink/FlashDB.svg?style=flat-square)](https://github/license/armink/FlashDB/releases/latest) 7 | [![license](https://img.shields.io/github/license/armink/FlashDB)](https://raw.githubusercontent.com/armink/FlashDB/master/LICENSE) 8 | 9 | - Small footprint 10 | - Fast query speed 11 | - Key-Value database 12 | - Time series database 13 | 14 | [Introduction](/README.md) 15 | [Getting started](/quick-started) -------------------------------------------------------------------------------- /docs/_media/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/_media/favicon.ico -------------------------------------------------------------------------------- /docs/_media/flashdb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/_media/flashdb.png -------------------------------------------------------------------------------- /docs/_media/flashdb_framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/_media/flashdb_framework.png -------------------------------------------------------------------------------- /docs/_media/flashdb_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/_media/flashdb_logo.png -------------------------------------------------------------------------------- /docs/_media/flashdb_porting_layer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/_media/flashdb_porting_layer.png -------------------------------------------------------------------------------- /docs/_navbar.md: -------------------------------------------------------------------------------- 1 | - Translations 2 | - [:cn: 中文](/zh-cn/) 3 | - [:uk: English](/) -------------------------------------------------------------------------------- /docs/_scripts/prism-c.min.js: -------------------------------------------------------------------------------- 1 | Prism.languages.c=Prism.languages.extend("clike",{comment:{pattern:/\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},"class-name":{pattern:/(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+/,lookbehind:!0},keyword:/\b(?:__attribute__|_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/,function:/[a-z_]\w*(?=\s*\()/i,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/,number:/(?:\b0x(?:[\da-f]+\.?[\da-f]*|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)[ful]*/i}),Prism.languages.insertBefore("c","string",{macro:{pattern:/(^\s*)#\s*[a-z]+(?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,greedy:!0,alias:"property",inside:{string:[{pattern:/^(#\s*include\s*)<[^>]+>/,lookbehind:!0},Prism.languages.c.string],comment:Prism.languages.c.comment,directive:{pattern:/^(#\s*)[a-z]+/,lookbehind:!0,alias:"keyword"},"directive-hash":/^#/,punctuation:/##|\\(?=[\r\n])/,expression:{pattern:/\S[\s\S]*/,inside:Prism.languages.c}}},constant:/\b(?:__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|stdin|stdout|stderr)\b/}),delete Prism.languages.c.boolean; -------------------------------------------------------------------------------- /docs/_sidebar.md: -------------------------------------------------------------------------------- 1 | - Getting started 2 | - [Quick Started](quick-started.md) 3 | - Demo platforms 4 | - [stm32f103ve](demo-stm32f103ve.md) 5 | - [stm32f405rg](demo-stm32f405rg.md) 6 | - [stm32f405rg-spi-flash](demo-stm32f405rg-spi-flash.md) 7 | - [esp8266-spi-flash](demo-esp8266-spi-flash.md) 8 | - [linux](demo-linux.md) 9 | - [Demo details](demo-details.md) 10 | - Samples 11 | - KV database 12 | - [basic](sample-kvdb-basic.md) 13 | - [string type](sample-kvdb-type-string.md) 14 | - [blob type](sample-kvdb-type-blob.md) 15 | - [KV traversal](sample-kvdb-traversal.md) 16 | - Time series database 17 | - [basic](sample-tsdb-basic.md) 18 | - Development 19 | - [porting](porting.md) 20 | - [configuration](configuration.md) 21 | - [API](api.md) 22 | -------------------------------------------------------------------------------- /docs/configuration.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | When using FlashDB, you can configure its functions through `fdb_cfg.h`. The file template is located in the `inc` directory, or you can copy it in the specific demo project. Let's introduce the configuration details in detail below 4 | 5 | ## FDB_USING_KVDB 6 | 7 | Enable KVDB feature 8 | 9 | ### FDB_KV_AUTO_UPDATE 10 | 11 | Enable KV automatic upgrade function. After this function is enabled, `fdb_kvdb.ver_num` stores the version of the current database. If the version changes, it will automatically trigger an upgrade action and update the new default KV collection to the current database. 12 | 13 | ## FDB_USING_TSDB 14 | 15 | Enable TSDB feature 16 | 17 | ## FDB_USING_FAL_MODE 18 | 19 | Enable FAL mode, partition in FAL is used to store the database. In this mode, FlashDB directly operates Flash, so performance is better. 20 | 21 | ## FDB_USING_FILE_POSIX_MODE 22 | 23 | Using POSIX file mode, you need to provide an open/read/write/close related file access interface. 24 | 25 | ## FDB_USING_FILE_LIBC_MODE 26 | 27 | Using the file mode of the C standard library, you need to provide a fopen/fread/fwrte/fclose related file access interface. 28 | 29 | > FDB_USING_FILE_LIBC_MODE and FDB_USING_FILE_POSIX_MODE mode can ONLY be one. Compared to FAL mode, the storage location, size and quantity of the database in the file mode are not limited. 30 | 31 | ## FDB_WRITE_GRAN 32 | 33 | Flash write granularity, the unit is bit. Currently supports 34 | 35 | - 1: nor flash 36 | - 8: stm32f2/f4 on-chip Flash 37 | - 32: stm32f1 on-chip Flash 38 | 39 | If multiple Flash specifications are used in the database, for example: both nor flash and stm32f4 on-chip Flash, the maximum value is used as the configuration item, namely: 8 bit 40 | 41 | ## FDB_BIG_ENDIAN 42 | 43 | MCU small-endian configuration, when the default is not configured, the system automatically uses the small-endian configuration 44 | 45 | ## FDB_PRINT(...) 46 | 47 | The print function macro defines the configuration. When it is not configured by default, using `printf` as the print log is the output function. Users can also customize new print function macro definitions, for example: 48 | 49 | ```C 50 | #define FDB_PRINT(...) my_printf(__VA_ARGS__) 51 | ``` 52 | 53 | ## FDB_DEBUG_ENABLE 54 | 55 | Enable debugging information output. When this configuration is closed, the system will not output logs for debugging. -------------------------------------------------------------------------------- /docs/demo-esp8266-spi-flash.md: -------------------------------------------------------------------------------- 1 | # Based on ESP8266 off-chip SPI-Flash demo 2 | 3 | Start a freertos task to run the flashDB routine, and then restart after 1000 seconds. Run log, please see the ESP8266_flashDB_log.rtf log in the current directory 4 | 5 | # ESP8266 Development Environment 6 | 7 | - Ubuntu 16.04 64-bit 8 | - Use Espressif IDF: ESP8266_RTOS_SDK (version: ESP-IDF v3.2-252-g73bf28b-dirty), download: https://github.com/espressif/ESP8266_RTOS_SDK.git 9 | - Install the cross-compilation tool chain, download: https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz 10 | 11 | # ESP8266 Development Guide 12 | 13 | - For detailed installation and development tutorials, please refer to: https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/index.html 14 | 15 | # Compile and download 16 | 17 | - cd into the esp8266_spi_flash directory 18 | - make all 19 | - Use serial cable to connect 8266 development board to PC 20 | - Enable the serial port, execute the command: sudo chmod 777 /dev/ttyUSB* 21 | - make flash 22 | - make monitor -------------------------------------------------------------------------------- /docs/demo-linux.md: -------------------------------------------------------------------------------- 1 | # linux demo 2 | 3 | ## What 4 | 5 | KVDB and TSDB demo on linux platform 6 | 7 | ## How 8 | 9 | ### Step1: build 10 | 11 | Run `make` command on terminal. The generated executable program is located in the `out` folder. 12 | 13 | ### Step2: run demo 14 | 15 | Switch to the `out` folder. Then run the `./FlashDBLinuxDemo` file multiple times. 16 | 17 | ### Step3: check the log 18 | 19 | This demo's log will output to terminal. -------------------------------------------------------------------------------- /docs/demo-stm32f103ve.md: -------------------------------------------------------------------------------- 1 | # stm32f103ve on-chip flash demo 2 | 3 | ## What 4 | 5 | KVDB and TSDB demo on STM32F10X chip 6 | 7 | - MCU: STM32F103VE 8 | - Flash Driver 9 | - STM32 on-chip flash 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | 15 | ## How 16 | 17 | ### Step1: connect the serial terminal 18 | 19 | Connect the board to PC by serial port and open the PC serial terminal. 20 | 21 | ### Step2: open demo project 22 | 23 | support 2 kinds of IDEs 24 | 25 | - Keil MDK: open `RVMDK\FlashDB.uvprojx` 26 | - [RT-Studio](https://www.rt-thread.io/studio.html): import this folder by import wizard 27 | 28 | ### Step3: build and download 29 | 30 | Download the firmware to your board when build successful. 31 | 32 | ### Step4: check the log 33 | 34 | This demo's log will output to PC serial. 35 | 36 | > PS: Demo project code and log analysis, see: Getting Started -> [Demo details](demo-details.md) 37 | 38 | -------------------------------------------------------------------------------- /docs/demo-stm32f405rg-spi-flash.md: -------------------------------------------------------------------------------- 1 | # stm32f405rg demo 2 | 3 | ## What 4 | 5 | KVDB and TSDB demo on STM32F4X chip 6 | 7 | - MCU: STM32F405RG 8 | - Flash Driver 9 | - spi flash (W25Q64) by using [SFUD](https://github.com/armink/SFUD) 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | - SPI 15 | - CS: PB12 (software CS) 16 | - SCK: PB13 17 | - MISO: PB14 18 | - MOSI: PB15 19 | 20 | ## How 21 | 22 | ### Step1: connect the serial terminal 23 | 24 | Connect the board to PC by serial port and open the PC serial terminal. 25 | 26 | ### Step2: open demo project 27 | 28 | support 2 kinds of IDEs 29 | 30 | - Keil MDK: open `RVMDK\FlashDB.uvprojx` 31 | - [RT-Studio](https://www.rt-thread.io/studio.html): import this folder by import wizard 32 | 33 | ### Step3: build and download 34 | 35 | Download the firmware to your board when build successful. 36 | 37 | ### Step4: check the log 38 | 39 | This demo's log will output to PC serial. 40 | 41 | > PS: Demo project code and log analysis, see: Getting Started -> [Demo details](demo-details.md) -------------------------------------------------------------------------------- /docs/demo-stm32f405rg.md: -------------------------------------------------------------------------------- 1 | # stm32f405rg on-chip flash demo 2 | 3 | ## What 4 | 5 | KVDB and TSDB demo on STM32F4X chip 6 | 7 | - MCU: STM32F405RG 8 | - Flash Driver 9 | - STM32 on-chip flash 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | 15 | ## How 16 | 17 | ### Step1: connect the serial terminal 18 | 19 | Connect the board to PC by serial port and open the PC serial terminal. 20 | 21 | ### Step2: open demo project 22 | 23 | support 2 kinds of IDEs 24 | 25 | - Keil MDK: open `RVMDK\FlashDB.uvprojx` 26 | - [RT-Studio](https://www.rt-thread.io/studio.html): import this folder by import wizard 27 | 28 | ### Step3: build and download 29 | 30 | Download the firmware to your board when build successful. 31 | 32 | ### Step4: check the log 33 | 34 | This demo's log will output to PC serial. 35 | 36 | > PS: Demo project code and log analysis, see: Getting Started -> [Demo details](demo-details.md) -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | FlashDB 8 | 9 | 10 | 11 | 12 | 13 |
Loading ...
14 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /docs/sample-kvdb-basic.md: -------------------------------------------------------------------------------- 1 | # KVDB basic example 2 | 3 | This example mainly demonstrates the basic functions of KVDB, including KV acquisition and setting modification functions. 4 | 5 | ## Code description 6 | 7 | The sample code is located in `samples/kvdb_basic_sample.c`, the default KV table is defined in `main.c`, and there is `boot_count` KV in it. The KV is used to record the current system startup times. Each time the power is turned off and restarted, the KV will be automatically incremented by one and saved to KVDB. The general content is as follows: 8 | 9 | ```C 10 | void kvdb_basic_sample(fdb_kvdb_t kvdb) 11 | { 12 | struct fdb_blob blob; 13 | int boot_count = 0; 14 | 15 | FDB_INFO("==================== kvdb_basic_sample ====================\n"); 16 | 17 | { /* GET the KV value */ 18 | /* get the "boot_count" KV value */ 19 | fdb_kv_get_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); 20 | /* the blob.saved.len is more than 0 when get the value successful */ 21 | if (blob.saved.len > 0) { 22 | FDB_INFO("get the 'boot_count' value is %d\n", boot_count); 23 | } else { 24 | FDB_INFO("get the 'boot_count' failed\n"); 25 | } 26 | } 27 | 28 | { /* CHANGE the KV value */ 29 | /* increase the boot count */ 30 | boot_count ++; 31 | /* change the "boot_count" KV's value */ 32 | fdb_kv_set_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); 33 | FDB_INFO("set the 'boot_count' value to %d\n", boot_count); 34 | } 35 | 36 | FDB_INFO("===========================================================\n"); 37 | } 38 | ``` 39 | 40 | ## First run log 41 | 42 | The current `boot_count` is 0, after adding one, it is stored in the database. 43 | 44 | ``` 45 | [FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ==================== 46 | [FlashDB][sample][kvdb][basic] get the 'boot_count' value is 0 47 | [FlashDB][sample][kvdb][basic] set the 'boot_count' value to 1 48 | [FlashDB][sample][kvdb][basic] =========================================================== 49 | ``` 50 | 51 | ## Secondary run log 52 | 53 | The current `boot_count` is 1, indicating that the last save is effective, add one to it and save it for the next visit. 54 | 55 | ``` 56 | [FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ==================== 57 | [FlashDB][sample][kvdb][basic] get the 'boot_count' value is 1 58 | [FlashDB][sample][kvdb][basic] set the 'boot_count' value to 2 59 | [FlashDB][sample][kvdb][basic] =========================================================== 60 | ``` -------------------------------------------------------------------------------- /docs/sample-kvdb-traversal.md: -------------------------------------------------------------------------------- 1 | # Traverse all KV 2 | 3 | This example demonstrates that if you traverse all KVs in KVDB, users can add their own processing actions when traversing KVs. 4 | 5 | ## Code description 6 | 7 | In the following sample code, first initialize the iterator of KVDB, and then use the iterator API to traverse all KVs of KVDB one by one. 8 | 9 | The traversed KV object contains some attributes of KV, including: key name, value saved addr, value length, etc. The user can read it out through `fdb_blob_read` in cooperation with `fdb_kv_to_blob`, and do some business processing of his own. 10 | 11 | ```C 12 | void kvdb_tarversal_sample(fdb_kvdb_t kvdb) 13 | { 14 | struct fdb_kv_iterator iterator; 15 | fdb_kv_t cur_kv; 16 | struct fdb_blob blob; 17 | size_t data_size; 18 | uint8_t *data_buf; 19 | 20 | fdb_kv_iterator_init(kvdb, &iterator); 21 | 22 | while (fdb_kv_iterate(kvdb, &iterator)) { 23 | cur_kv = &(iterator.curr_kv); 24 | data_size = (size_t) cur_kv->value_len; 25 | data_buf = (uint8_t *) malloc(data_size); 26 | if (data_buf == NULL) { 27 | FDB_INFO("Error: malloc failed.\n"); 28 | break; 29 | } 30 | fdb_blob_read((fdb_db_t) kvdb, fdb_kv_to_blob(cur_kv, fdb_blob_make(&blob, data_buf, data_size))); 31 | /* 32 | * balabala do what ever you like with blob... 33 | */ 34 | free(data_buf); 35 | } 36 | } 37 | ``` 38 | 39 | -------------------------------------------------------------------------------- /docs/sample-kvdb-type-blob.md: -------------------------------------------------------------------------------- 1 | # blob type KV example 2 | 3 | This example mainly demonstrates the related functions of blob KV. Blob KV is a more commonly used type, and its value is a binary type without type restrictions. Functionally, blob KV is also compatible with string KV. In the use of API, blob KV has a set of independent APIs, which can quickly realize the storage of various types of KV to KVDB, such as basic types, arrays and structures. 4 | 5 | ## Code description 6 | 7 | The sample code is located in `samples/kvdb_type_blob.c`, and a KV named `"temp"` is used to store the temperature value, respectively demonstrating the whole process of blob KV from `create->read->modify->delete`. The general content is as follows: 8 | 9 | ```C 10 | void kvdb_type_blob_sample(fdb_kvdb_t kvdb) 11 | { 12 | struct fdb_blob blob; 13 | 14 | FDB_INFO("==================== kvdb_type_blob_sample ====================\n"); 15 | 16 | { /* CREATE new Key-Value */ 17 | int temp_data = 36; 18 | 19 | /* It will create new KV node when "temp" KV not in database. 20 | * fdb_blob_make: It's a blob make function, and it will return the blob when make finish. 21 | */ 22 | fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 23 | FDB_INFO("create the 'temp' blob KV, value is: %d\n", temp_data); 24 | } 25 | 26 | { /* GET the KV value */ 27 | int temp_data = 0; 28 | 29 | /* get the "temp" KV value */ 30 | fdb_kv_get_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 31 | /* the blob.saved.len is more than 0 when get the value successful */ 32 | if (blob.saved.len > 0) { 33 | FDB_INFO("get the 'temp' value is: %d\n", temp_data); 34 | } 35 | } 36 | 37 | { /* CHANGE the KV value */ 38 | int temp_data = 38; 39 | 40 | /* change the "temp" KV's value to 38 */ 41 | fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 42 | FDB_INFO("set 'temp' value to %d\n", temp_data); 43 | } 44 | 45 | { /* DELETE the KV by name */ 46 | fdb_kv_del(kvdb, "temp"); 47 | FDB_INFO("delete the 'temp' finish\n"); 48 | } 49 | 50 | FDB_INFO("===========================================================\n"); 51 | } 52 | ``` 53 | 54 | ## Running log 55 | 56 | It can be seen from the log: 57 | 58 | - First create a KV named `"temp"` and give the initial value 36℃ 59 | - Read the current value of `"temp"` KV and find that it is the same as the initial value 60 | - Modify the value of `"temp"` KV to 38℃ 61 | - Finally delete `"temp"` KV 62 | 63 | ``` 64 | [FlashDB][sample][kvdb][blob] ==================== kvdb_type_blob_sample ==================== 65 | [FlashDB][sample][kvdb][blob] create the 'temp' blob KV, value is: 36 66 | [FlashDB][sample][kvdb][blob] get the 'temp' value is: 36 67 | [FlashDB][sample][kvdb][blob] set 'temp' value to 38 68 | [FlashDB][sample][kvdb][blob] delete the 'temp' finish 69 | [FlashDB][sample][kvdb][blob] =========================================================== 70 | ``` 71 | 72 | -------------------------------------------------------------------------------- /docs/sample-kvdb-type-string.md: -------------------------------------------------------------------------------- 1 | # String type KV example 2 | 3 | This example mainly demonstrates the related functions of the string KV. As a special KV type, the Key and Value of the string KV are both strings, which are often used in scenarios with high readability requirements such as parameter storage and command storage. 4 | 5 | ## Code description 6 | 7 | The sample code is located in `samples/kvdb_type_string.c`, and a KV named `"temp"` is used to store the temperature value, which respectively demonstrates the whole process of the string KV from `create->read->modify->delete` . The general content is as follows: 8 | 9 | ```C 10 | void kvdb_type_string_sample(fdb_kvdb_t kvdb) 11 | { 12 | FDB_INFO("==================== kvdb_type_string_sample ====================\n"); 13 | { /* CREATE new Key-Value */ 14 | char temp_data[10] = "36C"; 15 | 16 | /* It will create new KV node when "temp" KV not in database. */ 17 | fdb_kv_set(kvdb, "temp", temp_data); 18 | FDB_INFO("create the 'temp' string KV, value is: %s\n", temp_data); 19 | } 20 | 21 | { /* GET the KV value */ 22 | char *return_value, temp_data[10] = { 0 }; 23 | 24 | /* Get the "temp" KV value. 25 | * NOTE: The return value saved in fdb_kv_get's buffer. Please copy away as soon as possible. 26 | */ 27 | return_value = fdb_kv_get(kvdb, "temp"); 28 | /* the return value is NULL when get the value failed */ 29 | if (return_value != NULL) { 30 | strncpy(temp_data, return_value, sizeof(temp_data)); 31 | FDB_INFO("get the 'temp' value is: %s\n", temp_data); 32 | } 33 | } 34 | 35 | { /* CHANGE the KV value */ 36 | char temp_data[10] = "38C"; 37 | 38 | /* change the "temp" KV's value to "38.1" */ 39 | fdb_kv_set(kvdb, "temp", temp_data); 40 | FDB_INFO("set 'temp' value to %s\n", temp_data); 41 | } 42 | 43 | { /* DELETE the KV by name */ 44 | fdb_kv_del(kvdb, "temp"); 45 | FDB_INFO("delete the 'temp' finish\n"); 46 | } 47 | 48 | FDB_INFO("===========================================================\n"); 49 | } 50 | ``` 51 | 52 | ## Run log 53 | 54 | It can be seen from the log: 55 | 56 | - First create a KV named `"temp"` and give the initial value 36℃ 57 | - Read the current value of `"temp"` KV and find that it is the same as the initial value 58 | - Modify the value of `"temp"` KV to 38℃ 59 | - Finally delete `"temp"` KV 60 | 61 | ``` 62 | [FlashDB][sample][kvdb][string] ==================== kvdb_type_string_sample ==================== 63 | [FlashDB][sample][kvdb][string] create the 'temp' string KV, value is: 36C 64 | [FlashDB][sample][kvdb][string] get the 'temp' value is: 36C 65 | [FlashDB][sample][kvdb][string] set 'temp' value to 38C 66 | [FlashDB][sample][kvdb][string] delete the 'temp' finish 67 | [FlashDB][sample][kvdb][string] =========================================================== 68 | ``` 69 | 70 | -------------------------------------------------------------------------------- /docs/zh-cn/README.md: -------------------------------------------------------------------------------- 1 | # FlashDB:超轻量级嵌入式数据库 2 | 3 | [![Build Status](https://travis-ci.com/armink/FlashDB.svg?branch=master)](https://travis-ci.com/armink/FlashDB) [![license](https://img.shields.io/github/license/armink/FlashDB)](https://raw.githubusercontent.com/armink/FlashDB/master/LICENSE) [![docs](https://img.shields.io/badge/docs-perfect-blue)](http://armink.gitee.io/flashdb/#/zh-cn/ ) 4 | ## 简介 5 | 6 | [FlashDB](http://armink.gitee.io/flashdb/#/zh-cn/) 是一款超轻量级的嵌入式数据库,专注于提供嵌入式产品的数据存储方案。与传统的基于文件系统的数据库不同,FlashDB 结合了 Flash 的特性,具有较强的性能及可靠性。并在保证极低的资源占用前提下,尽可能延长 Flash 使用寿命。 7 | 8 | FlashDB 提供两种数据库模式: 9 | 10 | - **键值数据库** :是一种非关系数据库,它将数据存储为键值(Key-Value)对集合,其中键作为唯一标识符。KVDB 操作简洁,可扩展性强。 11 | - **时序数据库** :时间序列数据库 (Time Series Database , 简称 TSDB),它将数据按照 **时间顺序存储** 。TSDB 数据具有时间戳,数据存储量大,插入及查询性能高。 12 | 13 | > 欢迎 Star&Fork :https://gitee.com/armink/FlashDB 14 | 15 | ## 使用场景 16 | 17 | 如今,物联网产品种类越来越多,运行时产生的数据种类及总量及也在不断变大。FlashDB 提供了多样化的数据存储方案,不仅资源占用小,并且存储容量大,非常适合用于物联网产品。下面是主要应用场景: 18 | 19 | - **键值数据库** : 20 | - 产品参数存储 21 | - 用户配置信息存储 22 | - 小文件管理 23 | - **时序数据库** : 24 | - 存储动态产生的结构化数据:如 温湿度传感器采集的环境监测信息,智能手环实时记录的人体健康信息等 25 | - 记录运行日志:存储产品历史的运行日志,异常告警的记录等 26 | 27 | ## 主要特性 28 | 29 | - 资源占用极低,内存占用几乎为 **0** ; 30 | - 支持 多分区,**多实例** 。数据量大时,可细化分区,降低检索时间; 31 | - 支持 **磨损平衡** ,延长 Flash 寿命; 32 | - 支持 **掉电保护** 功能,可靠性高; 33 | - 支持 字符串及 blob 两种 KV 类型,方便用户操作; 34 | - 支持 KV **增量升级** ,产品固件升级后, KVDB 内容也支持自动升级; 35 | - 支持 修改每条 TSDB 记录的状态,方便用户进行管理; 36 | 37 | ## 性能及资源占用 38 | 39 | ### TSDB 性能测试1 (nor flash W25Q64) 40 | 41 | ```shell 42 | msh />tsl bench 43 | Append 1250 TSL in 5 seconds, average: 250.00 tsl/S, 4.00 ms/per 44 | Query total spent 2218 (ms) for 1251 TSL, min 1, max 2, average: 1.77 ms/per 45 | ``` 46 | 47 | 插入平均:4 ms,查询平均:1.8 ms 48 | 49 | ### TSDB 性能测试2 (stm32f2 onchip flash) 50 | 51 | ```shell 52 | msh />tsl bench 53 | Append 13421 TSL in 5 seconds, average: 2684.20 tsl/S, 0.37 ms/per 54 | Query total spent 1475 (ms) for 13422 TSL, min 0, max 1, average: 0.11 ms/per 55 | ``` 56 | 57 | 插入平均:0.37 ms,查询平均:0.12 ms 58 | 59 | ### 资源占用 (stm32f4 IAR8.20) 60 | 61 | ```shell 62 | Module ro code ro data rw data 63 | ------ ------- ------- ------- 64 | fdb.o 276 232 1 65 | fdb_kvdb.o 4 584 356 1 66 | fdb_tsdb.o 1 160 236 67 | fdb_utils.o 418 1 024 68 | ``` 69 | 70 | 上面是 IAR 的 map 文件信息,可见 FlashDB 的资源占用非常低 71 | 72 | ## 支持 73 | 74 | ![support](_media/wechat_support.png) 75 | 76 | 如果 FlashDB 解决了你的问题,不妨扫描上面二维码请我 **喝杯咖啡**~ 77 | 78 | ## 许可 79 | 80 | 采用 Apache-2.0 开源协议,细节请阅读项目中的 LICENSE 文件内容。 -------------------------------------------------------------------------------- /docs/zh-cn/_coverpage.md: -------------------------------------------------------------------------------- 1 | ![FlashDB](../_media/flashdb.png) 2 | 3 | > 一款超轻量级的嵌入式数据库 4 | 5 | [![Build Status](https://travis-ci.com/armink/FlashDB.svg?branch=master)](https://travis-ci.com/armink/FlashDB) 6 | [![version](https://img.shields.io/github/release/armink/FlashDB.svg?style=flat-square)](https://github/license/armink/FlashDB/releases/latest) 7 | [![license](https://img.shields.io/github/license/armink/FlashDB)](https://raw.githubusercontent.com/armink/FlashDB/master/LICENSE) 8 | 9 | - 极低的资源占用 10 | - 飞快的检索速度 11 | - 键值数据库 12 | - 时序数据库 13 | 14 | [介绍](zh-cn/README.md) 15 | [开始使用](zh-cn/quick-started) -------------------------------------------------------------------------------- /docs/zh-cn/_media/flashdb_framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/zh-cn/_media/flashdb_framework.png -------------------------------------------------------------------------------- /docs/zh-cn/_media/flashdb_porting_layer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/zh-cn/_media/flashdb_porting_layer.png -------------------------------------------------------------------------------- /docs/zh-cn/_media/wechat_support.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/docs/zh-cn/_media/wechat_support.png -------------------------------------------------------------------------------- /docs/zh-cn/_navbar.md: -------------------------------------------------------------------------------- 1 | - Translations 2 | - [:cn: 中文](/zh-cn/) 3 | - [:uk: English](/) -------------------------------------------------------------------------------- /docs/zh-cn/_sidebar.md: -------------------------------------------------------------------------------- 1 | - 入门 2 | - [快速开始](zh-cn/quick-started.md) 3 | - 演示平台 4 | - [stm32f103ve](zh-cn/demo-stm32f103ve.md) 5 | - [stm32f405rg](zh-cn/demo-stm32f405rg.md) 6 | - [stm32f405rg-spi-flash](zh-cn/demo-stm32f405rg-spi-flash.md) 7 | - [esp8266-spi-flash](zh-cn/demo-esp8266-spi-flash.md) 8 | - [linux](zh-cn/demo-linux.md) 9 | - [演示说明](zh-cn/demo-details.md) 10 | - 示例 11 | - 键值数据库 12 | - [基础](zh-cn/sample-kvdb-basic.md) 13 | - [字符串类型](zh-cn/sample-kvdb-type-string.md) 14 | - [blob 类型](zh-cn/sample-kvdb-type-blob.md) 15 | - [遍历 KV](zh-cn/sample-kvdb-traversal.md) 16 | - 时序数据库 17 | - [基础](zh-cn/sample-tsdb-basic.md) 18 | - 开发 19 | - [移植](zh-cn/porting.md) 20 | - [配置](zh-cn/configuration.md) 21 | - [API](zh-cn/api.md) 22 | -------------------------------------------------------------------------------- /docs/zh-cn/configuration.md: -------------------------------------------------------------------------------- 1 | # 配置说明 2 | 3 | FlashDB 的使用时,可以通过 fdb_cfg.h 对其进行功能配置,该文件模板位于 `inc` 目录下,也可以去具体的 demo 工程里拷贝。下面详细介绍一下配置详情 4 | 5 | ## FDB_USING_KVDB 6 | 7 | 使能 KVDB 功能 8 | 9 | ### FDB_KV_AUTO_UPDATE 10 | 11 | 使能 KV 自动升级功能。该功能使能后, `fdb_kvdb.ver_num` 存储了当前数据库的版本,如果版本发生变化时,会自动触发升级动作,将更新新的默认 KV 集合至当前数据库中。 12 | 13 | ## FDB_USING_TSDB 14 | 15 | 使能 TSDB 功能 16 | 17 | ## FDB_USING_FAL_MODE 18 | 19 | 使能 FAL 模式,FAL 里的分区用于存储数据库。该模式下,FlashDB 直接操作 Flash,所以性能较好 20 | 21 | ## FDB_USING_FILE_POSIX_MODE 22 | 23 | 使用 POSIX 的文件模式,需要系统提供 open/read/write/close 相关文件访问接口。 24 | 25 | ## FDB_USING_FILE_LIBC_MODE 26 | 27 | 使用 C 标准库的文件模式,需要系统提供 fopen/fread/fwrite/fclose 相关文件访问接口。 28 | 29 | > FDB_USING_FILE_LIBC_MODE 与 FDB_USING_FILE_POSIX_MODE 模式只能二选一。相比 FAL 模式,文件模式下数据库的存储位置、大小及数量没有限制。 30 | 31 | ## FDB_WRITE_GRAN 32 | 33 | Flash 写粒度,单位为 bit。目前支持 34 | 35 | - 1: nor flash 36 | - 8: stm32f2/f4 片上 Flash 37 | - 32: stm32f1 片上 Flash 38 | 39 | 如果数据库中使用了多种 Flash 规格,例如:既有 nor flash,也有 stm32f4 片上 Flash ,此时取最大值作为配置项,即:8 bit 40 | 41 | ## FDB_BIG_ENDIAN 42 | 43 | MCU 大小端配置,默认不配置时,系统自动使用小端配置 44 | 45 | ## FDB_PRINT(...) 46 | 47 | 打印函数宏定义配置,默认不配置时,使用 printf 作为打印日志是输出函数。用户也可以自定义新的打印函数宏定义,例如: 48 | 49 | ```C 50 | #define FDB_PRINT(...) my_printf(__VA_ARGS__) 51 | ``` 52 | 53 | ## FDB_DEBUG_ENABLE 54 | 55 | 使能调试信息输出。关闭该配置时,系统将不会输出用于调试的日志。 -------------------------------------------------------------------------------- /docs/zh-cn/demo-esp8266-spi-flash.md: -------------------------------------------------------------------------------- 1 | # 基于 ESP8266 片外 SPI-Flash 的演示 2 | 3 | 启动一个freertos任务运行flashDB的例程,然后倒计时1000秒后重启。运行log,请看当前目录下的ESP8266_flashDB_log.rtf 日志 4 | 5 | # ESP8266开发环境 6 | 7 | - Ubuntu 16.04 64位 8 | - 用乐鑫IDF:ESP8266_RTOS_SDK(版本:ESP-IDF v3.2-252-g73bf28b-dirty),下载:https://github.com/espressif/ESP8266_RTOS_SDK.git 9 | - 安装交叉编译工具链,下载:https://dl.espressif.com/dl/xtensa-lx106-elf-linux64-1.22.0-100-ge567ec7-5.2.0.tar.gz 10 | 11 | # ESP8266开发指南 12 | 13 | - 详细的安装开发教程,请参考:https://docs.espressif.com/projects/esp8266-rtos-sdk/en/latest/get-started/index.html 14 | 15 | # 编译和下载 16 | 17 | - cd进入esp8266_spi_flash目录 18 | - make all 19 | - 使用串口线把8266开发板连接到PC 20 | - 使能串口,执行命令:sudo chmod 777 /dev/ttyUSB* 21 | - make flash 22 | - make monitor 23 | 24 | -------------------------------------------------------------------------------- /docs/zh-cn/demo-linux.md: -------------------------------------------------------------------------------- 1 | # linux demo 2 | 3 | ## 介绍 4 | 5 | 基于 Linux 平台的 KVDB 和 TSDB 演示。 6 | 7 | ## 使用 8 | 9 | ### 步骤1:构建 10 | 11 | 在终端中执行 `make` 命令,完成后,`out` 文件夹下将会生成可执行程序文件。 12 | 13 | ### 步骤2:运行演示 14 | 15 | 切换到 `out` 文件夹下,然后可多次执行 `./FlashDBLinuxDemo` 。 16 | 17 | ### 步骤3:检查日志 18 | 19 | 演示的日志将会输出在终端中,可以进行检查。 20 | 21 | > PS: 演示工程代码及日志分析,详见:入门 -> [演示说明文档](zh-cn/demo-details.md) -------------------------------------------------------------------------------- /docs/zh-cn/demo-stm32f103ve.md: -------------------------------------------------------------------------------- 1 | # 基于 STM32F10X 片上 flash 的演示 2 | 3 | ## 介绍 4 | 5 | 基于 STM32F10X 芯片片上 Flash 的 KVDB 及 TSDB 演示 6 | 7 | - MCU: STM32F103VE 8 | - Flash Driver 9 | - STM32 on-chip flash 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | 15 | ## 使用 16 | 17 | ### 步骤1:连接串口助手或终端 18 | 19 | 将开发板的串口连接至 PC,并打开串口助手或终端工具 20 | 21 | ### 步骤2:打开演示工程 22 | 23 | 支持下面两种 IDE 24 | 25 | - Keil MDK:打开 `RVMDK\FlashDB.uvprojx` 26 | - [RT-Studio](https://www.rt-thread.org/page/studio.html): 通过工程向导进行导入 27 | 28 | ### 步骤3:编译与下载 29 | 30 | 编译演示工程,如果编译成功,下载固件至开发板 31 | 32 | ### 步骤4:检查日志结果 33 | 34 | 演示工程的运行结果,将会输出至 PC 的串口工具上。 35 | 36 | > PS: 演示工程代码及日志分析,详见:入门 -> [演示说明文档](zh-cn/demo-details.md) -------------------------------------------------------------------------------- /docs/zh-cn/demo-stm32f405rg-spi-flash.md: -------------------------------------------------------------------------------- 1 | # 基于 STM32F40X 片外 SPI-Flash 的演示 2 | 3 | ## 介绍 4 | 5 | 基于 STM32F40X 芯片片上 Flash 的 KVDB 及 TSDB 演示 6 | 7 | - MCU: STM32F405RG 8 | - Flash Driver 9 | - spi flash (W25Q64) by using [SFUD](https://github.com/armink/SFUD) 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | - SPI 15 | - CS: PB12 (software CS) 16 | - SCK: PB13 17 | - MISO: PB14 18 | - MOSI: PB15 19 | 20 | ## 使用 21 | 22 | ### 步骤1:连接串口助手或终端 23 | 24 | 将开发板的串口连接至 PC,并打开串口助手或终端工具 25 | 26 | ### 步骤2:打开演示工程 27 | 28 | 支持下面两种 IDE 29 | 30 | - Keil MDK:打开 `RVMDK\FlashDB.uvprojx` 31 | - [RT-Studio](https://www.rt-thread.org/page/studio.html): 通过工程向导进行导入 32 | 33 | ### 步骤3:编译与下载 34 | 35 | 编译演示工程,如果编译成功,下载固件至开发板 36 | 37 | ### 步骤4:检查日志结果 38 | 39 | 演示工程的运行结果,将会输出至 PC 的串口工具上。 40 | 41 | > PS: 演示工程代码及日志分析,详见:入门 -> [演示说明文档](zh-cn/demo-details.md) 42 | 43 | -------------------------------------------------------------------------------- /docs/zh-cn/demo-stm32f405rg.md: -------------------------------------------------------------------------------- 1 | # 基于 STM32F40X 片上 flash 的演示 2 | 3 | ## 介绍 4 | 5 | 基于 STM32F40X 芯片片上 Flash 的 KVDB 及 TSDB 演示 6 | 7 | - MCU: STM32F405RG 8 | - Flash Driver 9 | - STM32 on-chip flash 10 | - IO 11 | - UART 12 | - TXD: PA9 13 | - RXD: PA10 14 | 15 | ## 使用 16 | 17 | ### 步骤1:连接串口助手或终端 18 | 19 | 将开发板的串口连接至 PC,并打开串口助手或终端工具 20 | 21 | ### 步骤2:打开演示工程 22 | 23 | 支持下面两种 IDE 24 | 25 | - Keil MDK:打开 `RVMDK\FlashDB.uvprojx` 26 | - [RT-Studio](https://www.rt-thread.org/page/studio.html): 通过工程向导进行导入 27 | 28 | ### 步骤3:编译与下载 29 | 30 | 编译演示工程,如果编译成功,下载固件至开发板 31 | 32 | ### 步骤4:检查日志结果 33 | 34 | 演示工程的运行结果,将会输出至 PC 的串口工具上。 35 | 36 | > PS: 演示工程代码及日志分析,详见:入门 -> [演示说明文档](zh-cn/demo-details.md) 37 | 38 | -------------------------------------------------------------------------------- /docs/zh-cn/quick-started.md: -------------------------------------------------------------------------------- 1 | # 快速开始 2 | 3 | 本文档将帮助用户快速的将 FlashDB 在演示平台上使用起来,体验 FlashDB 的实际使用效果 4 | 5 | ## 基本概念 6 | 7 | - **键值数据库(KVDB)**:是一种非关系数据库,它将数据存储为键值(Key-Value)对集合,其中键作为唯一标识符。KVDB 操作简洁,可扩展性强。 8 | - **时序数据(TSDB)** :时间序列数据库 (Time Series Database , 简称 TSDB),它将数据按照 **时间顺序存储** 。TSDB 数据具有时间戳,数据存储量大,插入及查询性能高。 9 | - **时序记录(TSL)** :TSL (Time series log),是 TSDB 中每条记录的简称。 10 | - **Blob** :在计算机中,blob 常常是数据库中用来存储二进制文件的字段类型。在 FlashDB 中, KV 和 TSL 都使用 blob 类型来存储,该类型可以兼容任意变量类型。 11 | - **迭代器(iterator)**:它可以让用户透过特定的接口巡访容器中的每一个元素,而不用了解底层的实现。 TSDB 和 KVDB 都支持通过迭代器对数据库进行遍历访问。 12 | 13 | ## 功能框图 14 | 15 | 通过下面的功能框图,可以大致了解 FlashDB 功能模块划分 16 | 17 | ![flashdb_framework](_media/flashdb_framework.png) 18 | 19 | ## 准备开发环境 20 | 21 | 使用前,需提前在 PC 上安装下面的开发软件 22 | 23 | ### 集成开发环境 24 | 25 | FlashDB 提供的演示工程默认支持两种工程: 26 | 27 | - **RT-Studio** :免费使用,支持中文,使用方便,下载地址:https://www.rt-thread.org/page/studio.html 28 | - **Keil MDK** :需安装 MDK v5 版本的集成开发环境 29 | 30 | ### 串口工具 31 | 32 | 准备 `串口调试助手` 或 `串口终端工具` ,后续需要在查看运行日志时使用 33 | 34 | ## 获取源码 35 | 36 | 最新代码目前托管在 GitHub 及 Gitee ,master 分支为开发版本,推荐下载已发布的版本 37 | 38 | - GitHub 下载:https://github.com/armink/FlashDB/releases 39 | - Gitee 下载:https://gitee.com/armink/FlashDB/releases 40 | 41 | ## 选择演示平台 42 | 43 | 在项目的 `demos` 目录下,目前已提供下面一些演示平台,可以选择一个平台,真机体验一下 FlashDB 的运行过程。 44 | 45 | 更多详细介绍,点击下方表格中的 **使用说明** 进行查看。 46 | 47 | | 硬件平台 | 路径 | 存储类型 | 使用说明 | 48 | | --------------------- | :---------------------------- | :------------------ | ----------------------------------------------- | 49 | | stm32f10x | `demos/stm32f103ve` | stm32 on-chip flash | [点击查看](zh-cn/demo-stm32f103ve.md) | 50 | | stm32f40x | `demos/stm32f405rg` | stm32 on-chip flash | [点击查看](zh-cn/demo-stm32f405rg.md) | 51 | | stm32f40x + spi flash | `demos/stm32f405rg_spi_flash` | spi flash | [点击查看](zh-cn/demo-stm32f405rg-spi-flash.md) | 52 | | esp8266 + spi flash | `demos/esp8266_spi_flash` | spi flash | [点击查看](zh-cn/demo-esp8266-spi-flash.md) | 53 | | linux | `demos/linux` | posix file | [点击查看](zh-cn/demo-linux.md) | 54 | 55 | ## 查看示例说明 56 | 57 | 如果上面没有合适自己的演示平台,也可以先查看一下感兴趣的示例说明。 58 | 59 | | 示例文件 | 说明 | 详解 | 60 | | ----------------------------------- | ------------------ | ----------------------------------------- | 61 | | `samples/kvdb_basic_sample.c` | KVDB 基础示例 | [点击查看](zh-cn/sample-kvdb-basic) | 62 | | `samples/kvdb_type_string_sample.c` | 字符串类型 KV 示例 | [点击查看](zh-cn/sample-kvdb-type-string) | 63 | | `samples/kvdb_type_blob_sample.c` | blob 类型 KV 示例 | [点击查看](zh-cn/sample-kvdb-type-blob) | 64 | | `samples/tsdb_sample.c` | TSDB 基础示例 | [点击查看](zh-cn/sample-tsdb-basic) | 65 | 66 | -------------------------------------------------------------------------------- /docs/zh-cn/sample-kvdb-basic.md: -------------------------------------------------------------------------------- 1 | # KVDB 基础示例 2 | 3 | 该示例主要演示了 KVDB 的基础功能,包括 KV 的获取及设置修改功能。 4 | 5 | ## 代码说明 6 | 7 | 示例代码位于 `samples/kvdb_basic_sample.c` ,在 `main.c` 有定义默认的 KV 集合表,在里面有 `boot_count` KV。通过该 KV 来记录当前系统的启动次数。每次掉电再启动时,该 KV 会自动加一,并保存至 KVDB 中。大致内容如下: 8 | 9 | ```C 10 | void kvdb_basic_sample(fdb_kvdb_t kvdb) 11 | { 12 | struct fdb_blob blob; 13 | int boot_count = 0; 14 | 15 | FDB_INFO("==================== kvdb_basic_sample ====================\n"); 16 | 17 | { /* GET the KV value */ 18 | /* get the "boot_count" KV value */ 19 | fdb_kv_get_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); 20 | /* the blob.saved.len is more than 0 when get the value successful */ 21 | if (blob.saved.len > 0) { 22 | FDB_INFO("get the 'boot_count' value is %d\n", boot_count); 23 | } else { 24 | FDB_INFO("get the 'boot_count' failed\n"); 25 | } 26 | } 27 | 28 | { /* CHANGE the KV value */ 29 | /* increase the boot count */ 30 | boot_count ++; 31 | /* change the "boot_count" KV's value */ 32 | fdb_kv_set_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); 33 | FDB_INFO("set the 'boot_count' value to %d\n", boot_count); 34 | } 35 | 36 | FDB_INFO("===========================================================\n"); 37 | } 38 | ``` 39 | 40 | ## 首次运行日志 41 | 42 | 当前 `boot_count` 为 0 ,对其加一后,存入数据库。 43 | 44 | ``` 45 | [FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ==================== 46 | [FlashDB][sample][kvdb][basic] get the 'boot_count' value is 0 47 | [FlashDB][sample][kvdb][basic] set the 'boot_count' value to 1 48 | [FlashDB][sample][kvdb][basic] =========================================================== 49 | ``` 50 | 51 | ## 二次运行日志 52 | 53 | 当前 `boot_count` 为 1 ,说明上次的保存生效了,再对其加一后保存,供下次访问使用。 54 | 55 | ``` 56 | [FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ==================== 57 | [FlashDB][sample][kvdb][basic] get the 'boot_count' value is 1 58 | [FlashDB][sample][kvdb][basic] set the 'boot_count' value to 2 59 | [FlashDB][sample][kvdb][basic] =========================================================== 60 | ``` -------------------------------------------------------------------------------- /docs/zh-cn/sample-kvdb-traversal.md: -------------------------------------------------------------------------------- 1 | # 遍历所有 KV 2 | 3 | 本示例演示了如果遍历 KVDB 中的所有 KV ,用户可以在遍历 KV 时增加自己的处理动作。 4 | 5 | ## 代码说明 6 | 7 | 下面的示例代码中,首先初始化了 KVDB 的迭代器,然后使用迭代器 API ,将 KVDB 的所有 KV 逐一遍历出来。 8 | 9 | 遍历出来的 KV 对象含有 KV 的一些属性,包括:key name, value saved addr, value length 等,用户通过 `fdb_blob_read` 配合 `fdb_kv_to_blob` 读取出来,做一些自己的业务处理。 10 | 11 | ```C 12 | void kvdb_tarversal_sample(fdb_kvdb_t kvdb) 13 | { 14 | struct fdb_kv_iterator iterator; 15 | fdb_kv_t cur_kv; 16 | struct fdb_blob blob; 17 | size_t data_size; 18 | uint8_t *data_buf; 19 | 20 | fdb_kv_iterator_init(kvdb, &iterator); 21 | 22 | while (fdb_kv_iterate(kvdb, &iterator)) { 23 | cur_kv = &(iterator.curr_kv); 24 | data_size = (size_t) cur_kv->value_len; 25 | data_buf = (uint8_t *) malloc(data_size); 26 | if (data_buf == NULL) { 27 | FDB_INFO("Error: malloc failed.\n"); 28 | break; 29 | } 30 | fdb_blob_read((fdb_db_t) kvdb, fdb_kv_to_blob(cur_kv, fdb_blob_make(&blob, data_buf, data_size))); 31 | /* 32 | * balabala do what ever you like with blob... 33 | */ 34 | free(data_buf); 35 | } 36 | } 37 | ``` 38 | 39 | -------------------------------------------------------------------------------- /docs/zh-cn/sample-kvdb-type-blob.md: -------------------------------------------------------------------------------- 1 | # blob 类型 KV 示例 2 | 3 | 该示例主要演示了blob KV 的相关功能,blob KV 是一个比较常用类型,其 value 是一个没有类型限制的二进制类型。在功能上,blob KV 也兼容字符串 KV 。在 API 的使用上, blob KV 拥有一套独立的 API ,可以很快速的实现各种类型 KV 到 KVDB 中的存储,比如:基本类型,数组以及结构体等。 4 | 5 | ## 代码说明 6 | 7 | 示例代码位于 `samples/kvdb_type_blob.c` ,使用一个名为 `"temp"` 的 KV 来存储温度值,分别演示了 blob KV 从 `创建->读取->修改->删除` 的全过程。大致内容如下: 8 | 9 | ```C 10 | void kvdb_type_blob_sample(fdb_kvdb_t kvdb) 11 | { 12 | struct fdb_blob blob; 13 | 14 | FDB_INFO("==================== kvdb_type_blob_sample ====================\n"); 15 | 16 | { /* CREATE new Key-Value */ 17 | int temp_data = 36; 18 | 19 | /* It will create new KV node when "temp" KV not in database. 20 | * fdb_blob_make: It's a blob make function, and it will return the blob when make finish. 21 | */ 22 | fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 23 | FDB_INFO("create the 'temp' blob KV, value is: %d\n", temp_data); 24 | } 25 | 26 | { /* GET the KV value */ 27 | int temp_data = 0; 28 | 29 | /* get the "temp" KV value */ 30 | fdb_kv_get_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 31 | /* the blob.saved.len is more than 0 when get the value successful */ 32 | if (blob.saved.len > 0) { 33 | FDB_INFO("get the 'temp' value is: %d\n", temp_data); 34 | } 35 | } 36 | 37 | { /* CHANGE the KV value */ 38 | int temp_data = 38; 39 | 40 | /* change the "temp" KV's value to 38 */ 41 | fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 42 | FDB_INFO("set 'temp' value to %d\n", temp_data); 43 | } 44 | 45 | { /* DELETE the KV by name */ 46 | fdb_kv_del(kvdb, "temp"); 47 | FDB_INFO("delete the 'temp' finish\n"); 48 | } 49 | 50 | FDB_INFO("===========================================================\n"); 51 | } 52 | ``` 53 | 54 | ## 运行日志 55 | 56 | 通过日志可以看出: 57 | 58 | - 首先创建了一个 KV 名为 `"temp"` ,并给予初值 36℃ 59 | - 读取 `"temp"` KV 当前的值,发现与初值相同 60 | - 修改 `"temp"` KV 的值为 38℃ 61 | - 最后删除 `"temp"` KV 62 | 63 | ``` 64 | [FlashDB][sample][kvdb][blob] ==================== kvdb_type_blob_sample ==================== 65 | [FlashDB][sample][kvdb][blob] create the 'temp' blob KV, value is: 36 66 | [FlashDB][sample][kvdb][blob] get the 'temp' value is: 36 67 | [FlashDB][sample][kvdb][blob] set 'temp' value to 38 68 | [FlashDB][sample][kvdb][blob] delete the 'temp' finish 69 | [FlashDB][sample][kvdb][blob] =========================================================== 70 | ``` 71 | 72 | -------------------------------------------------------------------------------- /docs/zh-cn/sample-kvdb-type-string.md: -------------------------------------------------------------------------------- 1 | # 字符串类型 KV 示例 2 | 3 | 该示例主要演示了字符串 KV 的相关功能,字符串 KV 作为一个特殊的 KV 类型,其 Key 与 Value 均为字符串,常被用于参数存储、命令存储等可读性要求较高的场景。 4 | 5 | ## 代码说明 6 | 7 | 示例代码位于 `samples/kvdb_type_string.c` ,使用一个名为 `"temp"` 的 KV 来存储温度值,分别演示了字符串 KV 从 `创建->读取->修改->删除` 的全过程。大致内容如下: 8 | 9 | ```C 10 | void kvdb_type_string_sample(fdb_kvdb_t kvdb) 11 | { 12 | FDB_INFO("==================== kvdb_type_string_sample ====================\n"); 13 | { /* CREATE new Key-Value */ 14 | char temp_data[10] = "36C"; 15 | 16 | /* It will create new KV node when "temp" KV not in database. */ 17 | fdb_kv_set(kvdb, "temp", temp_data); 18 | FDB_INFO("create the 'temp' string KV, value is: %s\n", temp_data); 19 | } 20 | 21 | { /* GET the KV value */ 22 | char *return_value, temp_data[10] = { 0 }; 23 | 24 | /* Get the "temp" KV value. 25 | * NOTE: The return value saved in fdb_kv_get's buffer. Please copy away as soon as possible. 26 | */ 27 | return_value = fdb_kv_get(kvdb, "temp"); 28 | /* the return value is NULL when get the value failed */ 29 | if (return_value != NULL) { 30 | strncpy(temp_data, return_value, sizeof(temp_data)); 31 | FDB_INFO("get the 'temp' value is: %s\n", temp_data); 32 | } 33 | } 34 | 35 | { /* CHANGE the KV value */ 36 | char temp_data[10] = "38C"; 37 | 38 | /* change the "temp" KV's value to "38C" */ 39 | fdb_kv_set(kvdb, "temp", temp_data); 40 | FDB_INFO("set 'temp' value to %s\n", temp_data); 41 | } 42 | 43 | { /* DELETE the KV by name */ 44 | fdb_kv_del(kvdb, "temp"); 45 | FDB_INFO("delete the 'temp' finish\n"); 46 | } 47 | 48 | FDB_INFO("===========================================================\n"); 49 | } 50 | ``` 51 | 52 | ## 运行日志 53 | 54 | 通过日志可以看出: 55 | 56 | - 首先创建了一个 KV 名为 `"temp"` ,并给予初值 36℃ 57 | - 读取 `"temp"` KV 当前的值,发现与初值相同 58 | - 修改 `"temp"` KV 的值为 38℃ 59 | - 最后删除 `"temp"` KV 60 | 61 | ``` 62 | [FlashDB][sample][kvdb][string] ==================== kvdb_type_string_sample ==================== 63 | [FlashDB][sample][kvdb][string] create the 'temp' string KV, value is: 36C 64 | [FlashDB][sample][kvdb][string] get the 'temp' value is: 36C 65 | [FlashDB][sample][kvdb][string] set 'temp' value to 38C 66 | [FlashDB][sample][kvdb][string] delete the 'temp' finish 67 | [FlashDB][sample][kvdb][string] =========================================================== 68 | ``` 69 | 70 | -------------------------------------------------------------------------------- /inc/fdb_cfg_template.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief configuration template file. You need to rename the file to "fbd_cfg.h" and modify the configuration items in it to suit your use. 10 | */ 11 | 12 | #ifndef _FDB_CFG_H_ 13 | #define _FDB_CFG_H_ 14 | 15 | /* using KVDB feature */ 16 | #define FDB_USING_KVDB 17 | 18 | #ifdef FDB_USING_KVDB 19 | /* Auto update KV to latest default when current KVDB version number is changed. @see fdb_kvdb.ver_num */ 20 | /* #define FDB_KV_AUTO_UPDATE */ 21 | #endif 22 | 23 | /* using TSDB (Time series database) feature */ 24 | #define FDB_USING_TSDB 25 | 26 | /* Using FAL storage mode */ 27 | #define FDB_USING_FAL_MODE 28 | 29 | #ifdef FDB_USING_FAL_MODE 30 | /* the flash write granularity, unit: bit 31 | * only support 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32f7)/ 128(stm32h5) */ 32 | #define FDB_WRITE_GRAN /* @note you must define it for a value */ 33 | #endif 34 | 35 | /* Using file storage mode by LIBC file API, like fopen/fread/fwrte/fclose */ 36 | /* #define FDB_USING_FILE_LIBC_MODE */ 37 | 38 | /* Using file storage mode by POSIX file API, like open/read/write/close */ 39 | /* #define FDB_USING_FILE_POSIX_MODE */ 40 | 41 | /* MCU Endian Configuration, default is Little Endian Order. */ 42 | /* #define FDB_BIG_ENDIAN */ 43 | 44 | /* log print macro. default EF_PRINT macro is printf() */ 45 | /* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */ 46 | 47 | /* print debug information */ 48 | #define FDB_DEBUG_ENABLE 49 | 50 | #endif /* _FDB_CFG_H_ */ 51 | -------------------------------------------------------------------------------- /inc/fdb_low_lvl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief low level API and definition 10 | */ 11 | 12 | #ifndef _FDB_LOW_LVL_H_ 13 | #define _FDB_LOW_LVL_H_ 14 | 15 | #include 16 | #include 17 | 18 | #if (FDB_WRITE_GRAN == 1) 19 | #define FDB_STATUS_TABLE_SIZE(status_number) ((status_number * FDB_WRITE_GRAN + 7)/8) 20 | #else 21 | #define FDB_STATUS_TABLE_SIZE(status_number) (((status_number - 1) * FDB_WRITE_GRAN + 7)/8) 22 | #endif 23 | 24 | /* the data is erased */ 25 | #define FDB_BYTE_ERASED 0xFF 26 | /* the data is written */ 27 | #define FDB_BYTE_WRITTEN 0x00 28 | 29 | /* Return the most contiguous size aligned at specified width. RT_ALIGN(13, 4) 30 | * would return 16. 31 | */ 32 | #define FDB_ALIGN(size, align) (((size) + (align) - 1) - (((size) + (align) -1) % (align))) 33 | /* align by write granularity */ 34 | #define FDB_WG_ALIGN(size) (FDB_ALIGN(size, ((FDB_WRITE_GRAN + 7)/8))) 35 | /** 36 | * Return the down number of aligned at specified width. RT_ALIGN_DOWN(13, 4) 37 | * would return 12. 38 | */ 39 | #define FDB_ALIGN_DOWN(size, align) (((size) / (align)) * (align)) 40 | /* align down by write granularity */ 41 | #define FDB_WG_ALIGN_DOWN(size) (FDB_ALIGN_DOWN(size, (FDB_WRITE_GRAN + 7)/8)) 42 | 43 | #define FDB_STORE_STATUS_TABLE_SIZE FDB_STATUS_TABLE_SIZE(FDB_SECTOR_STORE_STATUS_NUM) 44 | #define FDB_DIRTY_STATUS_TABLE_SIZE FDB_STATUS_TABLE_SIZE(FDB_SECTOR_DIRTY_STATUS_NUM) 45 | 46 | /* the data is unused */ 47 | #if (FDB_BYTE_ERASED == 0xFF) 48 | #define FDB_DATA_UNUSED 0xFFFFFFFF 49 | #else 50 | #define FDB_DATA_UNUSED 0x00000000 51 | #endif 52 | 53 | /* invalid address */ 54 | #define FDB_FAILED_ADDR 0xFFFFFFFF 55 | 56 | size_t _fdb_set_status(uint8_t status_table[], size_t status_num, size_t status_index); 57 | size_t _fdb_get_status(uint8_t status_table[], size_t status_num); 58 | uint32_t _fdb_continue_ff_addr(fdb_db_t db, uint32_t start, uint32_t end); 59 | fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *part_name, fdb_db_type type, void *user_data); 60 | void _fdb_init_finish(fdb_db_t db, fdb_err_t result); 61 | void _fdb_deinit(fdb_db_t db); 62 | const char *_fdb_db_path(fdb_db_t db); 63 | fdb_err_t _fdb_write_status(fdb_db_t db, uint32_t addr, uint8_t status_table[], size_t status_num, size_t status_index, bool sync); 64 | size_t _fdb_read_status(fdb_db_t db, uint32_t addr, uint8_t status_table[], size_t total_num); 65 | fdb_err_t _fdb_flash_read(fdb_db_t db, uint32_t addr, void *buf, size_t size); 66 | fdb_err_t _fdb_flash_erase(fdb_db_t db, uint32_t addr, size_t size); 67 | fdb_err_t _fdb_flash_write(fdb_db_t db, uint32_t addr, const void *buf, size_t size, bool sync); 68 | 69 | #endif /* _FDB_LOW_LVL_H_ */ 70 | -------------------------------------------------------------------------------- /inc/flashdb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief Public APIs. 10 | */ 11 | 12 | #ifndef _FLASHDB_H_ 13 | #define _FLASHDB_H_ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #ifdef FDB_USING_FAL_MODE 23 | #include 24 | #endif 25 | 26 | #include 27 | 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /* FlashDB database API */ 34 | fdb_err_t fdb_kvdb_init (fdb_kvdb_t db, const char *name, const char *path, struct fdb_default_kv *default_kv, 35 | void *user_data); 36 | void fdb_kvdb_control(fdb_kvdb_t db, int cmd, void *arg); 37 | fdb_err_t fdb_kvdb_check(fdb_kvdb_t db); 38 | fdb_err_t fdb_kvdb_deinit(fdb_kvdb_t db); 39 | fdb_err_t fdb_tsdb_init (fdb_tsdb_t db, const char *name, const char *path, fdb_get_time get_time, size_t max_len, 40 | void *user_data); 41 | void fdb_tsdb_control(fdb_tsdb_t db, int cmd, void *arg); 42 | fdb_err_t fdb_tsdb_deinit(fdb_tsdb_t db); 43 | 44 | /* blob API */ 45 | fdb_blob_t fdb_blob_make (fdb_blob_t blob, const void *value_buf, size_t buf_len); 46 | size_t fdb_blob_read (fdb_db_t db, fdb_blob_t blob); 47 | 48 | /* Key-Value API like a KV DB */ 49 | fdb_err_t fdb_kv_set (fdb_kvdb_t db, const char *key, const char *value); 50 | char *fdb_kv_get (fdb_kvdb_t db, const char *key); 51 | fdb_err_t fdb_kv_set_blob (fdb_kvdb_t db, const char *key, fdb_blob_t blob); 52 | size_t fdb_kv_get_blob (fdb_kvdb_t db, const char *key, fdb_blob_t blob); 53 | fdb_err_t fdb_kv_del (fdb_kvdb_t db, const char *key); 54 | fdb_kv_t fdb_kv_get_obj (fdb_kvdb_t db, const char *key, fdb_kv_t kv); 55 | fdb_blob_t fdb_kv_to_blob (fdb_kv_t kv, fdb_blob_t blob); 56 | fdb_err_t fdb_kv_set_default (fdb_kvdb_t db); 57 | void fdb_kv_print (fdb_kvdb_t db); 58 | fdb_kv_iterator_t fdb_kv_iterator_init(fdb_kvdb_t db, fdb_kv_iterator_t itr); 59 | bool fdb_kv_iterate (fdb_kvdb_t db, fdb_kv_iterator_t itr); 60 | 61 | /* Time series log API like a TSDB */ 62 | fdb_err_t fdb_tsl_append (fdb_tsdb_t db, fdb_blob_t blob); 63 | fdb_err_t fdb_tsl_append_with_ts(fdb_tsdb_t db, fdb_blob_t blob, fdb_time_t timestamp); 64 | void fdb_tsl_iter (fdb_tsdb_t db, fdb_tsl_cb cb, void *cb_arg); 65 | void fdb_tsl_iter_reverse(fdb_tsdb_t db, fdb_tsl_cb cb, void *cb_arg); 66 | void fdb_tsl_iter_by_time(fdb_tsdb_t db, fdb_time_t from, fdb_time_t to, fdb_tsl_cb cb, void *cb_arg); 67 | size_t fdb_tsl_query_count (fdb_tsdb_t db, fdb_time_t from, fdb_time_t to, fdb_tsl_status_t status); 68 | fdb_err_t fdb_tsl_set_status (fdb_tsdb_t db, fdb_tsl_t tsl, fdb_tsl_status_t status); 69 | void fdb_tsl_clean (fdb_tsdb_t db); 70 | fdb_blob_t fdb_tsl_to_blob (fdb_tsl_t tsl, fdb_blob_t blob); 71 | 72 | /* fdb_utils.c */ 73 | uint32_t fdb_calc_crc32(uint32_t crc, const void *buf, size_t size); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* _FLASHDB_H_ */ 80 | -------------------------------------------------------------------------------- /port/fal/docs/figures/fal-api-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/port/fal/docs/figures/fal-api-en.png -------------------------------------------------------------------------------- /port/fal/docs/figures/fal-api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/port/fal/docs/figures/fal-api.png -------------------------------------------------------------------------------- /port/fal/docs/figures/fal-port-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/port/fal/docs/figures/fal-port-en.png -------------------------------------------------------------------------------- /port/fal/docs/figures/fal-port.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/port/fal/docs/figures/fal-port.png -------------------------------------------------------------------------------- /port/fal/docs/figures/fal_framework-en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/port/fal/docs/figures/fal_framework-en.png -------------------------------------------------------------------------------- /port/fal/docs/figures/fal_framework.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armink/FlashDB/6710c6d57f235e0b679a3ac728d567a472a77b19/port/fal/docs/figures/fal_framework.png -------------------------------------------------------------------------------- /port/fal/samples/README.md: -------------------------------------------------------------------------------- 1 | | 文件夹 | 说明 | 2 | | :------ | :----------------------- | 3 | | porting | 移植相关的示例代码及文档 | 4 | 5 | -------------------------------------------------------------------------------- /port/fal/samples/porting/fal_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2018, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2018-05-17 armink the first version 9 | */ 10 | 11 | #ifndef _FAL_CFG_H_ 12 | #define _FAL_CFG_H_ 13 | 14 | #include 15 | #include 16 | 17 | #define NOR_FLASH_DEV_NAME "norflash0" 18 | 19 | /* ===================== Flash device Configuration ========================= */ 20 | extern const struct fal_flash_dev stm32f2_onchip_flash; 21 | extern struct fal_flash_dev nor_flash0; 22 | 23 | /* flash device table */ 24 | #define FAL_FLASH_DEV_TABLE \ 25 | { \ 26 | &stm32f2_onchip_flash, \ 27 | &nor_flash0, \ 28 | } 29 | /* ====================== Partition Configuration ========================== */ 30 | #ifdef FAL_PART_HAS_TABLE_CFG 31 | /* partition table */ 32 | #define FAL_PART_TABLE \ 33 | { \ 34 | {FAL_PART_MAGIC_WORD, "bl", "stm32_onchip", 0, 64*1024, 0}, \ 35 | {FAL_PART_MAGIC_WORD, "app", "stm32_onchip", 64*1024, 704*1024, 0}, \ 36 | {FAL_PART_MAGIC_WORD, "easyflash", NOR_FLASH_DEV_NAME, 0, 1024*1024, 0}, \ 37 | {FAL_PART_MAGIC_WORD, "download", NOR_FLASH_DEV_NAME, 1024*1024, 1024*1024, 0}, \ 38 | } 39 | #endif /* FAL_PART_HAS_TABLE_CFG */ 40 | 41 | #endif /* _FAL_CFG_H_ */ 42 | -------------------------------------------------------------------------------- /port/fal/samples/porting/fal_flash_sfud_port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2018, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2018-01-26 armink the first version 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | #ifdef FAL_USING_SFUD_PORT 15 | #ifdef RT_USING_SFUD 16 | #include 17 | #endif 18 | 19 | #ifndef FAL_USING_NOR_FLASH_DEV_NAME 20 | #define FAL_USING_NOR_FLASH_DEV_NAME "norflash0" 21 | #endif 22 | 23 | static int init(void); 24 | static int read(long offset, uint8_t *buf, size_t size); 25 | static int write(long offset, const uint8_t *buf, size_t size); 26 | static int erase(long offset, size_t size); 27 | 28 | static sfud_flash_t sfud_dev = NULL; 29 | struct fal_flash_dev nor_flash0 = 30 | { 31 | .name = FAL_USING_NOR_FLASH_DEV_NAME, 32 | .addr = 0, 33 | .len = 8 * 1024 * 1024, 34 | .blk_size = 4096, 35 | .ops = {init, read, write, erase}, 36 | .write_gran = 1 37 | }; 38 | 39 | static int init(void) 40 | { 41 | 42 | #ifdef RT_USING_SFUD 43 | /* RT-Thread RTOS platform */ 44 | sfud_dev = rt_sfud_flash_find_by_dev_name(FAL_USING_NOR_FLASH_DEV_NAME); 45 | #else 46 | /* bare metal platform */ 47 | extern sfud_flash sfud_norflash0; 48 | sfud_dev = &sfud_norflash0; 49 | #endif 50 | 51 | if (NULL == sfud_dev) 52 | { 53 | return -1; 54 | } 55 | 56 | /* update the flash chip information */ 57 | nor_flash0.blk_size = sfud_dev->chip.erase_gran; 58 | nor_flash0.len = sfud_dev->chip.capacity; 59 | 60 | return 0; 61 | } 62 | 63 | static int read(long offset, uint8_t *buf, size_t size) 64 | { 65 | assert(sfud_dev); 66 | assert(sfud_dev->init_ok); 67 | sfud_read(sfud_dev, nor_flash0.addr + offset, size, buf); 68 | 69 | return size; 70 | } 71 | 72 | static int write(long offset, const uint8_t *buf, size_t size) 73 | { 74 | assert(sfud_dev); 75 | assert(sfud_dev->init_ok); 76 | if (sfud_write(sfud_dev, nor_flash0.addr + offset, size, buf) != SFUD_SUCCESS) 77 | { 78 | return -1; 79 | } 80 | 81 | return size; 82 | } 83 | 84 | static int erase(long offset, size_t size) 85 | { 86 | assert(sfud_dev); 87 | assert(sfud_dev->init_ok); 88 | if (sfud_erase(sfud_dev, nor_flash0.addr + offset, size) != SFUD_SUCCESS) 89 | { 90 | return -1; 91 | } 92 | 93 | return size; 94 | } 95 | #endif /* FAL_USING_SFUD_PORT */ 96 | 97 | -------------------------------------------------------------------------------- /port/fal/src/fal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2018, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2018-05-17 armink the first version 9 | */ 10 | 11 | #include 12 | 13 | static uint8_t init_ok = 0; 14 | 15 | /** 16 | * FAL (Flash Abstraction Layer) initialization. 17 | * It will initialize all flash device and all flash partition. 18 | * 19 | * @return >= 0: partitions total number 20 | */ 21 | int fal_init(void) 22 | { 23 | extern int fal_flash_init(void); 24 | extern int fal_partition_init(void); 25 | 26 | int result; 27 | 28 | /* initialize all flash device on FAL flash table */ 29 | result = fal_flash_init(); 30 | 31 | if (result < 0) { 32 | goto __exit; 33 | } 34 | 35 | /* initialize all flash partition on FAL partition table */ 36 | result = fal_partition_init(); 37 | 38 | __exit: 39 | 40 | if ((result > 0) && (!init_ok)) 41 | { 42 | init_ok = 1; 43 | log_i("Flash Abstraction Layer (V%s) initialize success.", FAL_SW_VERSION); 44 | } 45 | else if(result <= 0) 46 | { 47 | init_ok = 0; 48 | log_e("Flash Abstraction Layer (V%s) initialize failed.", FAL_SW_VERSION); 49 | } 50 | 51 | return result; 52 | } 53 | 54 | /** 55 | * Check if the FAL is initialized successfully 56 | * 57 | * @return 0: not init or init failed; 1: init success 58 | */ 59 | int fal_init_check(void) 60 | { 61 | return init_ok; 62 | } 63 | -------------------------------------------------------------------------------- /port/fal/src/fal_flash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2018, RT-Thread Development Team 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Change Logs: 7 | * Date Author Notes 8 | * 2018-05-17 armink the first version 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | /* flash device table, must defined by user */ 15 | #if !defined(FAL_FLASH_DEV_TABLE) 16 | #error "You must defined flash device table (FAL_FLASH_DEV_TABLE) on 'fal_cfg.h'" 17 | #endif 18 | 19 | static const struct fal_flash_dev * const device_table[] = FAL_FLASH_DEV_TABLE; 20 | static const size_t device_table_len = sizeof(device_table) / sizeof(device_table[0]); 21 | static uint8_t init_ok = 0; 22 | 23 | /** 24 | * Initialize all flash device on FAL flash table 25 | * 26 | * @return result 27 | */ 28 | int fal_flash_init(void) 29 | { 30 | size_t i; 31 | 32 | if (init_ok) 33 | { 34 | return 0; 35 | } 36 | 37 | for (i = 0; i < device_table_len; i++) 38 | { 39 | assert(device_table[i]->ops.read); 40 | assert(device_table[i]->ops.write); 41 | assert(device_table[i]->ops.erase); 42 | /* init flash device on flash table */ 43 | if (device_table[i]->ops.init) 44 | { 45 | device_table[i]->ops.init(); 46 | } 47 | log_d("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.", 48 | FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, device_table[i]->len, 49 | device_table[i]->blk_size); 50 | } 51 | 52 | init_ok = 1; 53 | return 0; 54 | } 55 | 56 | /** 57 | * find flash device by name 58 | * 59 | * @param name flash device name 60 | * 61 | * @return != NULL: flash device 62 | * NULL: not found 63 | */ 64 | const struct fal_flash_dev *fal_flash_device_find(const char *name) 65 | { 66 | assert(init_ok); 67 | assert(name); 68 | 69 | size_t i; 70 | 71 | for (i = 0; i < device_table_len; i++) 72 | { 73 | if (!strncmp(name, device_table[i]->name, FAL_DEV_NAME_MAX)) { 74 | return device_table[i]; 75 | } 76 | } 77 | 78 | return NULL; 79 | } 80 | -------------------------------------------------------------------------------- /samples/kvdb_basic_sample.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief basic KV samples. 10 | * 11 | * basic Key-Value Database KV feature samples 12 | * get and show currnet boot counts 13 | */ 14 | 15 | #include 16 | 17 | #ifdef FDB_USING_KVDB 18 | 19 | #define FDB_LOG_TAG "[sample][kvdb][basic]" 20 | 21 | void kvdb_basic_sample(fdb_kvdb_t kvdb) 22 | { 23 | struct fdb_blob blob; 24 | int boot_count = 0; 25 | 26 | FDB_INFO("==================== kvdb_basic_sample ====================\n"); 27 | 28 | { /* GET the KV value */ 29 | /* get the "boot_count" KV value */ 30 | fdb_kv_get_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); 31 | /* the blob.saved.len is more than 0 when get the value successful */ 32 | if (blob.saved.len > 0) { 33 | FDB_INFO("get the 'boot_count' value is %d\n", boot_count); 34 | } else { 35 | FDB_INFO("get the 'boot_count' failed\n"); 36 | } 37 | } 38 | 39 | { /* CHANGE the KV value */ 40 | /* increase the boot count */ 41 | boot_count ++; 42 | /* change the "boot_count" KV's value */ 43 | fdb_kv_set_blob(kvdb, "boot_count", fdb_blob_make(&blob, &boot_count, sizeof(boot_count))); 44 | FDB_INFO("set the 'boot_count' value to %d\n", boot_count); 45 | } 46 | 47 | FDB_INFO("===========================================================\n"); 48 | } 49 | 50 | #endif /* FDB_USING_KVDB */ 51 | -------------------------------------------------------------------------------- /samples/kvdb_type_blob_sample.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief blob KV samples. 10 | * 11 | * Key-Value Database blob type KV feature samples 12 | */ 13 | 14 | #include 15 | 16 | #ifdef FDB_USING_KVDB 17 | 18 | #define FDB_LOG_TAG "[sample][kvdb][blob]" 19 | 20 | void kvdb_type_blob_sample(fdb_kvdb_t kvdb) 21 | { 22 | struct fdb_blob blob; 23 | 24 | FDB_INFO("==================== kvdb_type_blob_sample ====================\n"); 25 | 26 | { /* CREATE new Key-Value */ 27 | int temp_data = 36; 28 | 29 | /* It will create new KV node when "temp" KV not in database. 30 | * fdb_blob_make: It's a blob make function, and it will return the blob when make finish. 31 | */ 32 | fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 33 | FDB_INFO("create the 'temp' blob KV, value is: %d\n", temp_data); 34 | } 35 | 36 | { /* GET the KV value */ 37 | int temp_data = 0; 38 | 39 | /* get the "temp" KV value */ 40 | fdb_kv_get_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 41 | /* the blob.saved.len is more than 0 when get the value successful */ 42 | if (blob.saved.len > 0) { 43 | FDB_INFO("get the 'temp' value is: %d\n", temp_data); 44 | } 45 | } 46 | 47 | { /* CHANGE the KV value */ 48 | int temp_data = 38; 49 | 50 | /* change the "temp" KV's value to 38 */ 51 | fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data))); 52 | FDB_INFO("set 'temp' value to %d\n", temp_data); 53 | } 54 | 55 | { /* DELETE the KV by name */ 56 | fdb_kv_del(kvdb, "temp"); 57 | FDB_INFO("delete the 'temp' finish\n"); 58 | } 59 | 60 | FDB_INFO("===========================================================\n"); 61 | } 62 | 63 | #endif /* FDB_USING_KVDB */ 64 | -------------------------------------------------------------------------------- /samples/kvdb_type_string_sample.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Armink, 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /** 8 | * @file 9 | * @brief string KV samples. 10 | * 11 | * Key-Value Database string type KV feature samples source file. 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | #ifdef FDB_USING_KVDB 18 | 19 | #define FDB_LOG_TAG "[sample][kvdb][string]" 20 | 21 | void kvdb_type_string_sample(fdb_kvdb_t kvdb) 22 | { 23 | FDB_INFO("==================== kvdb_type_string_sample ====================\n"); 24 | 25 | { /* CREATE new Key-Value */ 26 | char temp_data[10] = "36C"; 27 | 28 | /* It will create new KV node when "temp" KV not in database. */ 29 | fdb_kv_set(kvdb, "temp", temp_data); 30 | FDB_INFO("create the 'temp' string KV, value is: %s\n", temp_data); 31 | } 32 | 33 | { /* GET the KV value */ 34 | char *return_value, temp_data[10] = { 0 }; 35 | 36 | /* Get the "temp" KV value. 37 | * NOTE: The return value saved in fdb_kv_get's buffer. Please copy away as soon as possible. 38 | */ 39 | return_value = fdb_kv_get(kvdb, "temp"); 40 | /* the return value is NULL when get the value failed */ 41 | if (return_value != NULL) { 42 | strncpy(temp_data, return_value, sizeof(temp_data)); 43 | FDB_INFO("get the 'temp' value is: %s\n", temp_data); 44 | } 45 | } 46 | 47 | { /* CHANGE the KV value */ 48 | char temp_data[10] = "38C"; 49 | 50 | /* change the "temp" KV's value to "38.1" */ 51 | fdb_kv_set(kvdb, "temp", temp_data); 52 | FDB_INFO("set 'temp' value to %s\n", temp_data); 53 | } 54 | 55 | { /* DELETE the KV by name */ 56 | fdb_kv_del(kvdb, "temp"); 57 | FDB_INFO("delete the 'temp' finish\n"); 58 | } 59 | 60 | FDB_INFO("===========================================================\n"); 61 | } 62 | 63 | #endif /* FDB_USING_KVDB */ 64 | -------------------------------------------------------------------------------- /zephyr/module.yml: -------------------------------------------------------------------------------- 1 | name: flashdb 2 | build: 3 | cmake-ext: True 4 | kconfig-ext: True 5 | --------------------------------------------------------------------------------