-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e177e7
commit f5b2858
Showing
36 changed files
with
4,706 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.pio | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
How to build PlatformIO based project | ||
===================================== | ||
|
||
Project converted from https://github.com/openwch/ch592/blob/main/Application/PDF_DataLogger/CH592_PDF_Logger_USB. | ||
|
||
1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) | ||
2. Download [development platform with examples](https://github.com/Community-PIO-CH32V/platform-ch32v/archive/develop.zip) | ||
3. Extract ZIP archive | ||
4. Run these commands: | ||
|
||
```shell | ||
# Change directory to example | ||
$ cd platform-ch32v/examples/usb-pdf-logger-none-os-ch592 | ||
|
||
# Build project | ||
$ pio run | ||
|
||
# Upload firmware | ||
$ pio run --target upload | ||
|
||
# Upload firmware for the specific environment | ||
$ pio run -e genericCH592F --target upload | ||
|
||
# Clean build files | ||
$ pio run --target clean | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
This directory is intended for project header files. | ||
|
||
A header file is a file containing C declarations and macro definitions | ||
to be shared between several project source files. You request the use of a | ||
header file in your project source file (C, C++, etc) located in `src` folder | ||
by including it, with the C preprocessing directive `#include'. | ||
|
||
```src/main.c | ||
|
||
#include "header.h" | ||
|
||
int main (void) | ||
{ | ||
... | ||
} | ||
``` | ||
|
||
Including a header file produces the same results as copying the header file | ||
into each source file that needs it. Such copying would be time-consuming | ||
and error-prone. With a header file, the related declarations appear | ||
in only one place. If they need to be changed, they can be changed in one | ||
place, and programs that include the header file will automatically use the | ||
new version when next recompiled. The header file eliminates the labor of | ||
finding and changing all the copies as well as the risk that a failure to | ||
find one copy will result in inconsistencies within a program. | ||
|
||
In C, the usual convention is to give header files names that end with `.h'. | ||
It is most portable to use only letters, digits, dashes, and underscores in | ||
header file names, and at most one dot. | ||
|
||
Read more about using header files in official GCC documentation: | ||
|
||
* Include Syntax | ||
* Include Operation | ||
* Once-Only Headers | ||
* Computed Includes | ||
|
||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html |
97 changes: 97 additions & 0 deletions
97
examples/usb-pdf-logger-none-os-ch592/include/peripheral.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/********************************** (C) COPYRIGHT ******************************* | ||
* File Name : peripheral.h | ||
* Author : WCH | ||
* Version : V1.0 | ||
* Date : 2018/12/11 | ||
* Description : | ||
********************************************************************************* | ||
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. | ||
* Attention: This software (modified or not) and binary are used for | ||
* microcontroller manufactured by Nanjing Qinheng Microelectronics. | ||
*******************************************************************************/ | ||
|
||
#ifndef PERIPHERAL_H | ||
#define PERIPHERAL_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/********************************************************************* | ||
* INCLUDES | ||
*/ | ||
|
||
/********************************************************************* | ||
* CONSTANTS | ||
*/ | ||
|
||
// Peripheral Task Events | ||
#define SBP_START_DEVICE_EVT 0x0001 | ||
#define SBP_PERIODIC_EVT 0x0002 | ||
#define SBP_READ_RSSI_EVT 0x0004 | ||
#define SBP_PARAM_UPDATE_EVT 0x0008 | ||
#define SBP_PHY_UPDATE_EVT 0x0010 | ||
#define SBP_ENABLE_ADV_EVT 0x0020 | ||
#define SBP_DISABLE_ADV_EVT 0x0040 | ||
|
||
/********************************************************************* | ||
* MACROS | ||
*/ | ||
typedef struct | ||
{ | ||
uint16_t connHandle; // Connection handle of current connection | ||
uint16_t connInterval; | ||
uint16_t connSlaveLatency; | ||
uint16_t connTimeout; | ||
} peripheralConnItem_t; | ||
|
||
extern uint8_t Peripheral_TaskID; // Task ID for internal task/event processing | ||
|
||
|
||
//#include "CONFIG.h" | ||
#include "pdfFile.h" | ||
#include "sw_udisk.h" | ||
#include "CHRV3UFI.h" | ||
|
||
typedef struct | ||
{ | ||
uint8_t pdf_data_buf[PDF_TMP_BUF_LEN_MAX+PDF_TMP_BUF_LEN_EXT]; | ||
uint8_t UDisk_Down_Buffer[DEF_FLASH_SECTOR_SIZE]; | ||
uint8_t UDisk_Pack_Buffer[DEF_UDISK_PACK_64]; | ||
uint8_t DISK_BASE_BUF[DISK_BASE_BUF_LEN]; /* 外部RAM的磁盘数据缓冲区,缓冲区长度为一个扇区的长度 */ | ||
uint8_t DISK_FAT_BUF[ DISK_BASE_BUF_LEN ]; /* 外部RAM的磁盘FAT数据缓冲区,缓冲区长度为一个扇区的长度 */ | ||
}PDF_BUFFER_t; | ||
|
||
|
||
typedef union | ||
{ | ||
// uint32_t MEM_BUF[BLE_MEMHEAP_SIZE / 4]; | ||
PDF_BUFFER_t PDF_BUFFER; | ||
|
||
}RAM_BUFFER_t; | ||
|
||
extern RAM_BUFFER_t RAM_BUFFER; | ||
|
||
|
||
/********************************************************************* | ||
* FUNCTIONS | ||
*/ | ||
|
||
/* | ||
* Task Initialization for the BLE Application | ||
*/ | ||
extern void Peripheral_Init(void); | ||
|
||
/* | ||
* Task Event Processor for the BLE Application | ||
*/ | ||
extern uint16_t Peripheral_ProcessEvent(uint8_t task_id, uint16_t events); | ||
|
||
/********************************************************************* | ||
*********************************************************************/ | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
182 changes: 182 additions & 0 deletions
182
examples/usb-pdf-logger-none-os-ch592/lib/FLASH/flash_info.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/********************************** (C) COPYRIGHT ******************************* | ||
* File Name : flash_info.c | ||
* Author : WCH | ||
* Version : V1.0 | ||
* Date : 2021/10/19 | ||
* Description : | ||
*******************************************************************************/ | ||
|
||
/******************************************************************************/ | ||
#include "flash_info.h" | ||
#include "spi_flash.h" | ||
|
||
//#define CONFIG_FLASH_INFO_DEBUG | ||
#ifdef CONFIG_FLASH_INFO_DEBUG | ||
#define LOG_INFO(...) PRINT(__VA_ARGS__) | ||
#else | ||
#define LOG_INFO(...) | ||
#endif | ||
|
||
/************************************************************************************************** | ||
* GLOBAL VARIABLES | ||
**************************************************************************************************/ | ||
DEVICE_INFO_t DeviceInfo; //Device Information | ||
|
||
/************************************************************************************************** | ||
* FUNCTIONS - Local | ||
**************************************************************************************************/ | ||
/************************************************************************************************** | ||
* @fn HAL_SaveBondInfo | ||
* | ||
* @brief Save bond information in flash | ||
* | ||
* @param None | ||
* | ||
* @return SUCCESS or FAILURE | ||
**************************************************************************************************/ | ||
uint8_t HAL_SaveDeviceInfo(void) | ||
{ | ||
uint32_t StartAddr; | ||
|
||
if (DeviceInfo.InfoNum == DEVICEINFO_MAX) //flashÒѾ´æ´¢Âú | ||
{ | ||
if (EEPROM_ERASE(DEVICEINFO_ADDR, DEVICEINFO_FLASH_SIZE) != SUCCESS) | ||
{ | ||
LOG_INFO("ERROR1\n"); | ||
return FAILURE; | ||
} | ||
DeviceInfo.InfoNum = 0; | ||
} | ||
|
||
StartAddr = DEVICEINFO_ADDR + DEVICEINFO_LEN * DeviceInfo.InfoNum; | ||
++DeviceInfo.InfoNum; //Add in advance and need to save it in flash | ||
DeviceInfo.Checksum = HAL_FlashChecksumCalculate((uint8_t*)&DeviceInfo, DEVICEINFO_LEN-1); | ||
if (EEPROM_WRITE(StartAddr, &DeviceInfo, DEVICEINFO_LEN) != SUCCESS) //дflash | ||
{ | ||
--DeviceInfo.InfoNum; | ||
LOG_INFO("ERROR2\n"); | ||
return FAILURE; | ||
} | ||
|
||
return SUCCESS; | ||
} | ||
|
||
/************************************************************************************************** | ||
* @fn HAL_ReadBondInfo | ||
* | ||
* @brief Read the bond information in the flash | ||
* | ||
* @param None | ||
* | ||
* @return SUCCESS or FAILURE | ||
**************************************************************************************************/ | ||
uint8_t HAL_ReadDeviceInfo(void) | ||
{ | ||
uint32_t StartAddr; | ||
uint16_t BufNum = 1; | ||
|
||
do | ||
{ | ||
StartAddr = DEVICEINFO_ADDR + BufNum * DEVICEINFO_LEN; | ||
EEPROM_READ(StartAddr, &DeviceInfo, 1); | ||
++BufNum; | ||
} while ((DeviceInfo.CheckFlag != 0xFF) && (BufNum <= DEVICEINFO_MAX)); //Poll flash until find where the device information is stored | ||
|
||
if (BufNum > (DEVICEINFO_MAX + 1)) | ||
{ | ||
LOG_INFO("ERROR3\n"); | ||
return FAILURE; | ||
} | ||
|
||
StartAddr = DEVICEINFO_ADDR + (BufNum - 2) * DEVICEINFO_LEN; | ||
EEPROM_READ(StartAddr, &DeviceInfo, DEVICEINFO_LEN); //Read device information in flash | ||
if ((DeviceInfo.CheckFlag != CHECK_VALUE) || (HAL_FlashChecksumCheck((uint8_t*)&DeviceInfo, DEVICEINFO_LEN-1))) //If device information has not been saved | ||
{ | ||
memset((uint8_t*)&DeviceInfo, 0, DEVICEINFO_LEN); | ||
DeviceInfo.CheckFlag = CHECK_VALUE; | ||
DeviceInfo.InfoNum = DEVICEINFO_MAX; | ||
DeviceInfo.PdfParam.MeasureInterval = DEFAULT_MEASURE_INTERVAL; //6min | ||
DeviceInfo.PdfParam.TempUnit = CELSIUS_UNIT; | ||
DeviceInfo.PdfParam.MaxTempAlarm = DEFAULT_TEMP_UPPER_LIMIT; | ||
DeviceInfo.PdfParam.MinTempAlarm = DEFAULT_TEMP_LOWER_LIMIT; | ||
DeviceInfo.PdfParam.MaxHumiAlarm = DEFAULT_HUMI_UPPER_LIMIT; | ||
DeviceInfo.PdfParam.MinHumiAlarm = DEFAULT_HUMI_LOWER_LIMIT; | ||
DeviceInfo.StartTime.Year = DEFAULT_START_YAER; | ||
DeviceInfo.StartTime.Month = DEFAULT_START_MONTH; | ||
DeviceInfo.StartTime.Day = DEFAULT_START_DAY; | ||
// DeviceInfo.StartTime.Hour = DEFAULT_START_HOUR; | ||
// DeviceInfo.StartTime.Minute = DEFAULT_START_MINUTE; | ||
// DeviceInfo.StartTime.Second = DEFAULT_START_SECOND; | ||
|
||
if (HAL_SaveDeviceInfo() != SUCCESS) | ||
{ | ||
LOG_INFO("ERROR4\n"); | ||
return FAILURE; | ||
} | ||
|
||
FLASH_ROM_ERASE(MEASURENT_DATA_ADDR, MEASURENT_DATA_FLASH_SIZE); | ||
|
||
for(uint16_t i=0; i<20; ++i) | ||
{ | ||
LOG_INFO("%d\n", i); | ||
FLASH_Erase_Sector(4096*i); | ||
} | ||
} | ||
|
||
return SUCCESS; | ||
} | ||
|
||
/************************************************************************************************** | ||
* @fn HAL_ChecksumCalculate | ||
* | ||
* @brief Calculate buffer checksum | ||
* | ||
* @param p_buf - address of buffer | ||
* len - length of buffer | ||
* | ||
* @return Checksum value | ||
**************************************************************************************************/ | ||
uint8_t HAL_FlashChecksumCalculate(uint8_t *p_buf, uint16_t len) | ||
{ | ||
uint16_t i; | ||
uint8_t check_sum = 0; | ||
|
||
for (i = 0; i < len; ++i) | ||
{ | ||
check_sum = (uint8_t)(check_sum + p_buf[i]); | ||
} | ||
|
||
return check_sum; | ||
} | ||
|
||
/************************************************************************************************** | ||
* @fn HAL_FlashChecksumCheck | ||
* | ||
* @brief Check buffer checksum | ||
* | ||
* @param p_buf - address of buffer | ||
* len - length of buffer | ||
* | ||
* @return SUCCESS or FAILURE | ||
**************************************************************************************************/ | ||
uint8_t HAL_FlashChecksumCheck(uint8_t *p_buf, uint16_t len) | ||
{ | ||
uint16_t i; | ||
uint8_t check_sum = 0; | ||
|
||
for (i = 0; i < len; ++i) | ||
{ | ||
check_sum = (uint8_t)(check_sum + p_buf[i]); | ||
} | ||
|
||
if (check_sum == p_buf[i]) | ||
{ | ||
return SUCCESS; | ||
} | ||
else | ||
{ | ||
return FAILURE; | ||
} | ||
} | ||
|
||
/******************************** endfile @ bond ******************************/ |
Oops, something went wrong.