Kaynağa Gözat

Merge branch 'master' of http://81.68.246.173:6680/embedded/owner-nrf52sdk into master

luochengPC 1 yıl önce
ebeveyn
işleme
f87c106a87

BIN
nRF5_SDK_15.3.0/external/micro-ecc/nrf52hf_armgcc/armgcc/micro_ecc_lib_nrf52.a


+ 41 - 0
nRF5_SDK_15.3.0/external/micro-ecc/nrf52nf_armgcc/armgcc/_build/micro_ecc_lib/uECC.c.d

@@ -0,0 +1,41 @@
+_build/micro_ecc_lib/uECC.c.o: ../../micro-ecc/uECC.c \
+ ../../micro-ecc/uECC.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\lib\gcc\arm-none-eabi\8.3.1\include\stdint.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\stdint.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\machine\_default_types.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\features.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\_newlib_version.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\_intsup.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\_stdint.h \
+ ../../micro-ecc/uECC_vli.h ../../micro-ecc/types.h \
+ ../../micro-ecc/platform-specific.inc ../../micro-ecc/asm_arm.inc \
+ ../../micro-ecc/asm_arm_mult_square_umaal.inc \
+ ../../micro-ecc/curve-specific.inc
+
+../../micro-ecc/uECC.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\lib\gcc\arm-none-eabi\8.3.1\include\stdint.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\stdint.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\machine\_default_types.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\features.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\_newlib_version.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\_intsup.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\_stdint.h:
+
+../../micro-ecc/uECC_vli.h:
+
+../../micro-ecc/types.h:
+
+../../micro-ecc/platform-specific.inc:
+
+../../micro-ecc/asm_arm.inc:
+
+../../micro-ecc/asm_arm_mult_square_umaal.inc:
+
+../../micro-ecc/curve-specific.inc:

BIN
nRF5_SDK_15.3.0/external/micro-ecc/nrf52nf_armgcc/armgcc/_build/micro_ecc_lib/uECC.c.o


BIN
nRF5_SDK_15.3.0/external/micro-ecc/nrf52nf_armgcc/armgcc/micro_ecc_lib_nrf52.a


+ 41 - 0
nRF5_SDK_15.3.0/external/micro-ecc/nrf52nf_keil/armgcc/_build/micro_ecc_lib/uECC.c.d

@@ -0,0 +1,41 @@
+_build/micro_ecc_lib/uECC.c.o: ../../micro-ecc/uECC.c \
+ ../../micro-ecc/uECC.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\lib\gcc\arm-none-eabi\8.3.1\include\stdint.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\stdint.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\machine\_default_types.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\features.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\_newlib_version.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\_intsup.h \
+ d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\_stdint.h \
+ ../../micro-ecc/uECC_vli.h ../../micro-ecc/types.h \
+ ../../micro-ecc/platform-specific.inc ../../micro-ecc/asm_arm.inc \
+ ../../micro-ecc/asm_arm_mult_square_umaal.inc \
+ ../../micro-ecc/curve-specific.inc
+
+../../micro-ecc/uECC.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\lib\gcc\arm-none-eabi\8.3.1\include\stdint.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\stdint.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\machine\_default_types.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\features.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\_newlib_version.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\_intsup.h:
+
+d:\program\ files\gnu\ tools\ arm\ embedded\8\ 2019-q3-update\arm-none-eabi\include\sys\_stdint.h:
+
+../../micro-ecc/uECC_vli.h:
+
+../../micro-ecc/types.h:
+
+../../micro-ecc/platform-specific.inc:
+
+../../micro-ecc/asm_arm.inc:
+
+../../micro-ecc/asm_arm_mult_square_umaal.inc:
+
+../../micro-ecc/curve-specific.inc:

BIN
nRF5_SDK_15.3.0/external/micro-ecc/nrf52nf_keil/armgcc/_build/micro_ecc_lib/uECC.c.o


BIN
nRF5_SDK_15.3.0/external/micro-ecc/nrf52nf_keil/armgcc/micro_ecc_lib_nrf52.lib


+ 1 - 1
nRF5_SDK_15.3.0/modules/nrfx/drivers/src/nrfx_uart.c

@@ -88,7 +88,7 @@ static void apply_config(nrfx_uart_t        const * p_instance,
     }
     if (p_config->pselrxd != NRF_UART_PSEL_DISCONNECTED)
     {
-        nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_NOPULL);
+        nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_PULLUP);
     }
 
     nrf_uart_baudrate_set(p_instance->p_reg, p_config->baudrate);

+ 1 - 1
nRF5_SDK_15.3.0/modules/nrfx/drivers/src/nrfx_uarte.c

@@ -119,7 +119,7 @@ static void apply_config(nrfx_uarte_t        const * p_instance,
     }
     if (p_config->pselrxd != NRF_UARTE_PSEL_DISCONNECTED)
     {
-        nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_NOPULL);
+        nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_PULLUP);
     }
 
     nrf_uarte_baudrate_set(p_instance->p_reg, p_config->baudrate);

+ 2 - 1
owned_server/inc/ble_peripheral.h

@@ -50,7 +50,7 @@ typedef struct
 
 typedef struct
 {
-	uint8_t dev_type;
+	uint8_t product_type;
 	uint8_t dev_version;
 	uint8_t dev_reg_stat;
 	uint8_t	bat_percent;
@@ -72,6 +72,7 @@ typedef struct
 uint32_t advertising_init(void);
 void Ble_Peripheral_Init(set_dfu_func func,uint16_t **conn_handle);
 void Peripheral_Start(void);
+void Peripheral_Stop(void);
 void ble_peripheral_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context);
 void user_ble_advertising_modes_config_set(ble_adv_modes_config_t const * const p_adv_modes_config);
 #if NRF_MODULE_ENABLED(BLE_DFU)

+ 11 - 5
owned_server/src/ble_peripheral.c

@@ -361,9 +361,9 @@ uint32_t advertising_init(void)
 	//指向制造商自定义的数据
 	ble_adv_manuf_data adv_manuf_data={
 		.m_addr={0},
-		.dev_type=NRF_DEV_TYPE,
+		.product_type=NRF_DEV_PRODUCT,
 		.dev_version=(NRF_BLE_ADV_DEV_VERSION_MAIN<<4)| NRF_BLE_ADV_DEV_VERSION_SLAVE,
-		.dev_reg_stat=dev_reg_stat,
+		.dev_reg_stat=(NRF_DEV_TYPE<<4) | dev_reg_stat,
 		.bat_percent=bat_percent
 	};
 //#ifdef user_config_param
@@ -401,7 +401,7 @@ uint32_t advertising_init(void)
 	m_advertising.adv_modes_config.ble_adv_whitelist_enabled 				=		true;
 #endif
 	
-	if(ble_adv_duration==NRF_BLE_ADV_DURATION)
+	if(ble_adv_duration==0)
 	{
 		m_advertising.adv_modes_config.ble_adv_slow_interval 						= 	ble_adv_interval;		
 		m_advertising.adv_modes_config.ble_adv_slow_enabled							=		true;
@@ -673,7 +673,7 @@ void ble_peripheral_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
 		case BLE_GAP_EVT_ADV_SET_TERMINATED:
 			NRF_LOG_INFO("adv timeout!");
 			ble_adv_stat=false;
-			if(ble_adv_duration==NRF_BLE_ADV_DURATION)
+			if(ble_adv_duration == 0)
 			{
 				Peripheral_Start();
 			}
@@ -755,7 +755,7 @@ void Ble_Peripheral_Init(set_dfu_func func,uint16_t **conn_handle)
 #endif
   // Start execution.
 //  NRF_LOG_INFO("Blinky example started.");
-//	advertising_start();
+	advertising_start();
 }
 
 void set_ble_tx_power_level(int8_t rssi)
@@ -780,6 +780,12 @@ void Peripheral_Start(void)
 	ble_adv_stat=true;
 }
 
+void Peripheral_Stop(void)
+{
+	advertising_stop();
+	ble_adv_stat=false;
+}
+
 void user_ble_advertising_modes_config_set(ble_adv_modes_config_t const * const p_adv_modes_config)
 {
 	ble_advertising_modes_config_set(&m_advertising, p_adv_modes_config);

+ 2 - 0
owned_server/src/ble_user.c

@@ -1,6 +1,8 @@
 #include "ble_user.h"
 #include "ble_peripheral.h"
+#if NRF_MODULE_ENABLED(OWNED_C_SERVER)
 #include "ble_central.h"
+#endif
 //DFU需要引用的头文件
 #if NRF_MODULE_ENABLED(BLE_DFU)
 #include "nrf_power.h"

+ 6 - 5
std/camera/driver/private_include/xclk.h

@@ -1,9 +1,10 @@
-#pragma once
+#ifndef XCLK_H
+#define XCLK_H
 
 #include "define.h"
 
-int xclk_timer_conf(int ledc_timer, int xclk_freq_hz);
-
-int camera_enable_out_clock();
-
+ret_code_t xclk_timer_conf(void);
+void camera_enable_out_clock(void);
 void camera_disable_out_clock();
+
+#endif

+ 159 - 10
std/camera/sensors/ov2640.c

@@ -1,13 +1,19 @@
 /* Includes ------------------------------------------------------------------*/
 #include "ov2640.h"
+#include "xclk.h"
 #include "nrf_drv_gpiote.h"
 #include "app_scheduler.h"
 #include "user_twim.h"
 #include "app_timer.h"
+#include "action.h"
 
 static custome_event ov2640_event;
 static void Set_Ov2640_Queue(OV2640_QUEUE_TYPE type);
 static ov2640_work_e ov2640_work = OV2640_WORK_RST;
+static uint32_t ov2640_data_Array[8] = {
+	CAM_D0_PIN, CAM_D1_PIN, CAM_D2_PIN, CAM_D3_PIN,
+	CAM_D4_PIN, CAM_D5_PIN, CAM_D6_PIN, CAM_D7_PIN
+};
 
 APP_TIMER_DEF(ov2640_timer_id);
 static uint32_t ov2640_timer_tick = 0;
@@ -531,6 +537,15 @@ void ov2640_timers_init(void)
   */
 void OV2640_Gpio_Init(void)
 {
+	xclk_timer_conf();
+	nrf_gpio_cfg(
+        CAM_PW_PIN,
+        NRF_GPIO_PIN_DIR_OUTPUT,
+        NRF_GPIO_PIN_INPUT_DISCONNECT,
+        NRF_GPIO_PIN_NOPULL,
+        NRF_GPIO_PIN_S0S1,
+        NRF_GPIO_PIN_NOSENSE);
+	CAM_PW_OFF;
 	nrf_gpio_cfg_input(CAM_D0_PIN,NRF_GPIO_PIN_NOPULL);
 	nrf_gpio_cfg_input(CAM_D1_PIN,NRF_GPIO_PIN_NOPULL);
 	nrf_gpio_cfg_input(CAM_D2_PIN,NRF_GPIO_PIN_NOPULL);
@@ -557,9 +572,9 @@ void OV2640_CaptureGpioInit(nrf_drv_gpiote_in_config_t *config,nrfx_gpiote_evt_h
   APP_ERROR_CHECK(err_code);
 	
 	//使能事件模式
-	nrf_drv_gpiote_in_event_enable(CAM_PCLK_PIN,true);
-	nrf_drv_gpiote_in_event_enable(CAM_VSYNC_PIN,true);
-	nrf_drv_gpiote_in_event_enable(CAM_HREF_PIN,true);	
+//	nrf_drv_gpiote_in_event_enable(CAM_PCLK_PIN,true);
+//	nrf_drv_gpiote_in_event_enable(CAM_VSYNC_PIN,true);
+//	nrf_drv_gpiote_in_event_enable(CAM_HREF_PIN,true);	
 }
 
 static void ov2640_i2s_done(void)
@@ -937,15 +952,24 @@ static uint8_t get_ov2640_data(void)
 //	OV2640_BrightnessConfig(0x20);
 //	OV2640_AutoExposure(2);
 //}
+static uint8_t vsync_count = 0;
+static bool vsync_stat = false;
+static uint8_t jpg_array[512] = {0};
+static int jpg_count = 0;
+static uint16_t head_value = 0;
+static bool jpg_stat = false;
+
 
 static void ov2640_pro(void)
 {
 	switch(ov2640_work)
 	{
 		case OV2640_WORK_I2C_INIT:{
+			CAM_PW_ON;
+			camera_enable_out_clock();
 			OV2640_i2s_init();
 			ov2640_work = OV2640_WORK_RST;
-			ov2640_timers_work(1);
+			ov2640_timers_work(10);
 		}break;
 		case OV2640_WORK_RST:{
 			OV2640_Reset();
@@ -979,25 +1003,149 @@ static void ov2640_pro(void)
 		}break;
 		case OV2640_WORK_AUTOEXP:{
 			OV2640_AutoExposure(2);
-			ov2640_work = OV2640_WORK_I2C_UNINIT;
-			ov2640_timers_work(1);
+			ov2640_work = OV2640_WORK_START;
+			ov2640_timers_work(10);
+		}break;
+		case OV2640_WORK_START:{
+			ov2640_work = OV2640_WORK_DELAY;
+			vsync_count = 0;
+			nrf_drv_gpiote_in_event_enable(CAM_VSYNC_PIN,true);
 		}break;
 		case OV2640_WORK_VSYNC:{
-			
+			if(jpg_count > 256 || jpg_count == 0)
+			{
+				camera_jpg_pro(&jpg_array[256], (jpg_count == 0)?256:jpg_count-256, true);
+			}
+			else{
+				camera_jpg_pro(jpg_array, jpg_count, false);
+			}
+			ov2640_work = OV2640_WORK_DELAY;
+			ov2640_timers_work(60000);
 		}break;
 		case OV2640_WORK_PCLK:{
-			
+			if(jpg_count >= 256)
+			{
+				camera_jpg_pro(jpg_array, 256, false);
+			}
+			else{
+				camera_jpg_pro(&jpg_array[256], 256, false);
+			}
+			ov2640_work = OV2640_WORK_DELAY;
 		}break;
-		case OV2640_WORK_HREF:{
-			
+		case OV2640_WORK_DELAY:{
+			ov2640_work = OV2640_WORK_I2C_UNINIT;
+			ov2640_timers_work(100);
 		}break;
 		case OV2640_WORK_I2C_UNINIT:{
+			camera_disable_out_clock();
 			OV2640_i2s_uninit();
 			ov2640_work = OV2640_WORK_I2C_INIT;
+			CAM_PW_OFF;
 		}break;
 	}
 }
 
+static bool href_pin_stat = false;
+void ov2640_href_pro(void)
+{
+	uint32_t flag = nrf_gpio_pin_read(CAM_HREF_PIN);
+	if(flag != 0)
+	{
+		href_pin_stat = true;
+	}
+	else{
+		href_pin_stat = false;
+	}
+}
+
+void ov2640_vsync_pro(void)
+{
+	uint32_t flag = nrf_gpio_pin_read(CAM_VSYNC_PIN);
+	if(flag != 0)
+	{
+		vsync_stat = true;
+		if(vsync_count == 0)
+		{
+			vsync_count = 1;
+		}
+	}
+	else{
+		if(vsync_stat == true)
+		{
+			if(vsync_count == 1)
+			{
+				nrf_drv_gpiote_in_event_enable(CAM_PCLK_PIN,true);
+				nrf_drv_gpiote_in_event_enable(CAM_HREF_PIN,true);	
+				vsync_count = 2;
+			}
+			else if(vsync_count == 2 && head_value == 0xFFD9)
+			{
+				nrf_drv_gpiote_in_event_disable(CAM_PCLK_PIN);
+				nrf_drv_gpiote_in_event_disable(CAM_VSYNC_PIN);
+				nrf_drv_gpiote_in_event_disable(CAM_HREF_PIN);
+				ov2640_work = OV2640_WORK_VSYNC;
+				Set_Ov2640_Queue(OV2640_QUEUE_INT);
+			}
+		}
+		vsync_stat = false;
+	}
+}
+
+static uint8_t ov2640_dat_value(void)
+{
+	uint8_t data = 0x00;
+	
+	for(int i = 0; i < 8; i++)
+	{
+		data <<= 1;
+		uint32_t flag = nrf_gpio_pin_read(ov2640_data_Array[i]);
+		if(flag != 0)
+		{
+			data |= 0x01;
+		}
+	}
+	
+	return data;
+}
+
+void ov2640_pclk_pro(void)
+{
+	uint32_t flag = nrf_gpio_pin_read(CAM_PCLK_PIN);
+	if(flag != 0)
+	{
+		if(href_pin_stat == true)
+		{
+			if(jpg_stat == true)
+			{
+				uint8_t dat = ov2640_dat_value();
+				head_value <<= 8;
+				head_value |= dat;
+				jpg_array[jpg_count++] = dat;
+				if(jpg_count == 256)
+				{
+					ov2640_work = OV2640_WORK_PCLK;
+					Set_Ov2640_Queue(OV2640_QUEUE_INT);
+				}
+				else if(jpg_count == 512)
+				{
+					ov2640_work = OV2640_WORK_PCLK;
+					Set_Ov2640_Queue(OV2640_QUEUE_INT);
+					jpg_count = 0;
+				}
+			}
+			else{
+				uint8_t dat = ov2640_dat_value();
+				head_value <<= 8;
+				head_value |= dat;
+				if(head_value == 0xFFD8)
+				{
+					jpg_stat = true;
+				}
+			}
+		}
+	}
+}
+
 static void ov2640_queue(void *p_event_data, uint16_t event_size)    
 {
 	custome_event *evt = (custome_event*)p_event_data;
@@ -1015,6 +1163,7 @@ static void ov2640_queue(void *p_event_data, uint16_t event_size)
 
 static void Set_Ov2640_Queue(OV2640_QUEUE_TYPE type)
 {
+	
 	ov2640_event.flag |= (1<<type);
 	ret_code_t err_code = app_sched_event_put(&ov2640_event, sizeof(ov2640_event), ov2640_queue);
 }

+ 16 - 10
std/camera/target/xclk.c

@@ -9,15 +9,22 @@
 #include "nrf_log_ctrl.h"
 #include "nrf_log_default_backends.h"
 #include "xclk.h"
-#include "nrf_camera.h"
 
 static nrf_drv_pwm_t pwm_instance = NRF_DRV_PWM_INSTANCE(0);
 
-static void xclk_init(camera_config_t* config)
+static void pwm_handler(nrf_drv_pwm_evt_type_t event_type)
+{
+	if(event_type == NRF_DRV_PWM_EVT_FINISHED)
+	{
+			
+	}
+}
+
+static ret_code_t xclk_init(void)
 {
 	nrfx_pwm_config_t const pwm_cfg = {
 		.output_pins = {
-			config->pin_xclk | NRF_DRV_PWM_PIN_INVERTED,				//将pwm0的通道0映射到引脚17
+			CAM_XCLK_PIN | NRF_DRV_PWM_PIN_INVERTED,						//将pwm0的通道0映射到引脚17
 			NRF_DRV_PWM_PIN_NOT_USED,
 			NRF_DRV_PWM_PIN_NOT_USED,					
 			NRF_DRV_PWM_PIN_NOT_USED,														//其他通道不使用
@@ -38,10 +45,10 @@ static void xclk_init(camera_config_t* config)
  */
 static void xclk_play(void)
 {	
-	static nrf_pwm_values_common_t seq0_values = 8;
+	static const nrf_pwm_values_common_t seq0_values = 8;
 	//设置pwm播放设置
 	nrf_pwm_sequence_t const seq0 = {
-		.values.p_individual = &seq0_values,			//指向pwm占空比序列
+		.values.p_common = &seq0_values,			//指向pwm占空比序列
 		.length = NRF_PWM_VALUES_LENGTH(seq0_values),	//计算pwm包含周期数200
 		.repeats = 0,									//序列中周期重复数为0
 		.end_delay = 0									//序列后不插入延时
@@ -60,19 +67,18 @@ static void xclk_uninit(void)
 	nrfx_pwm_uninit(&pwm_instance);
 }
 
-ret_code_t xclk_timer_conf(camera_config_t* config)
+ret_code_t xclk_timer_conf(void)
 {
-	ret_code_t err = xclk_init(&timer_conf);
+	ret_code_t err = xclk_init();
 	if (err != NRF_SUCCESS) {
 			NRF_LOG_INFO("xclk pwm failed for rc=%x", err);
 	}
 	return err;
 }
 
-ret_code_t camera_enable_out_clock(camera_config_t* config)
+void camera_enable_out_clock(void)
 {
-    xclk_play();
-    return ESP_OK;
+	xclk_play();
 }
 
 void camera_disable_out_clock()

+ 34 - 15
std/inc/nrf_usr_uart.h

@@ -12,11 +12,17 @@ extern "C" {
 
 #define UART_TX_BUF_SIZE 																		USER_UART_SEND_LEN       	//串口发送缓存大小(字节数)
 #define UART_RX_BUF_SIZE 																		1       									//串口接收缓存大小(字节数)
-	
+
+#ifdef MODUBS_USED
 typedef void (*modbus_rec_func)(uint8_t *data,uint8_t *len,bool *stat);
+#endif
+#ifdef UART_STR_USED
 typedef void (*uart_rec_func)(char *data);
+#endif
+#ifdef UART_HEX_USED
 typedef void (*hex_rec_func)(void);
 typedef void (*single_hex_rec_func)(uint8_t data);
+#endif
 	
 typedef enum{
 	UART_STR,
@@ -28,6 +34,14 @@ typedef enum{
 typedef struct{
 	bool uart_init_stat;
 	uart_work_stat uart_work;
+#ifdef MODUBS_USED
+	uint8_t recv_modbus_size;
+	uint8_t *modbus_receive;				
+	uint8_t modbus_len;
+	bool modbus_rec;
+	modbus_rec_func m_modbus_rec_func;
+#endif
+#ifdef UART_STR_USED
 	bool uart_rx_stat;													//uart接收完成标志
 	char uart_re_Byte[USER_UART_REBYTE_LEN];		//模块返回信息存储
 	char uart_tx_Byte[USER_UART_SEND_LEN];			//模块返回信息存储
@@ -38,12 +52,8 @@ typedef struct{
 	uint8_t uart_re_count_array[10];						//存放的数据数量
 	uint8_t uart_re_point;											//当前存放内存数组位置
 	uart_rec_func m_uart_rec_func;
-	
-	uint8_t modbus_receive[MODBUS_REC_LEN];				
-	uint8_t modbus_len;
-	bool modbus_rec;
-	modbus_rec_func m_modbus_rec_func;
-	
+#endif
+#ifdef UART_HEX_USED	
 	uint8_t *hex_receive;
 	bool hex_pro;																//false:接收固定长度数据后处理,true:实时处理
 	uint8_t hex_len;
@@ -51,30 +61,39 @@ typedef struct{
 	bool hex_rec;
 	hex_rec_func m_hex_rec_func;
 	single_hex_rec_func m_single_hex_rec_func;
+#endif
 }user_uart_s;
 	
 typedef enum
 {
-	USER_UART_QUEUE_TIME=0,
-	USER_UART_QUEUE_INT=1,
+	USER_UART_QUEUE_TIME = 0,
+	USER_UART_QUEUE_INT = 1,
 }USER_UART_QUEUE_TYPE;
 
-void uart_open_9600(void);
+
 void uart_open(void);
 void uart_close(void);
 void UartSendString(char *pBuffer);
 void UartSendHex(uint8_t *hex,uint16_t len,bool space);
 void UartSendData(uint8_t *ch,uint16_t len);
-void Modbus_Set_Init(void);
+void set_uart_pin(uint32_t tx,uint32_t rx);
+void Set_User_Uart_Queue(USER_UART_QUEUE_TYPE type);
+#ifdef MODUBS_USED
+void Modbus_Set_Init(uint8_t size);
+void Modbus_Data_Init(void);
+void set_modbus_rec_func(modbus_rec_func func);
+#endif
+#ifdef UART_STR_USED
 void Uart_Set_Init(void);
 void Uart_ReData_Pro(void);
+void set_string_rec_func(uart_rec_func func);
+void set_terminal_rec_func(uart_rec_func func);
+#endif
+#ifdef UART_HEX_USED	
 void Hex_Set_Init(uint8_t *buffer,uint8_t size);
-void set_uart_pin(uint32_t tx,uint32_t rx);
 void set_hex_rec_func(hex_rec_func func);
 void set_single_hex_rec_func(single_hex_rec_func func);
-void set_string_rec_func(uart_rec_func func);
-void set_terminal_rec_func(uart_rec_func func);
-void Set_User_Uart_Queue(USER_UART_QUEUE_TYPE type);
+#endif
 
 extern user_uart_s usr_uart;
 	

+ 217 - 209
std/src/nrf_usr_uart.c

@@ -2,33 +2,38 @@
 #include "_string.h"
 #include "app_scheduler.h"
 
-static uint32_t rx_pin=RX_PIN_NUMBER;
-static uint32_t tx_pin=TX_PIN_NUMBER;
+static uint32_t rx_pin = RX_PIN_NUMBER;
+static uint32_t tx_pin = TX_PIN_NUMBER;
 static custome_event user_uart_event;
 
-user_uart_s usr_uart={
-	.uart_init_stat=false,
-	.uart_work=UART_STR,
-	.uart_rx_stat=false,																						//uart接收完成标志
-	.uart_re_Byte={0},																							//模块返回信息存储
-	.uart_re_addr_count=0,																					//存储位置计数
-	.uart_re_addr=usr_uart.uart_re_Byte,														//当前保存的位置
-	.uart_re_addr_begin=usr_uart.uart_re_Byte,											//当前区域的首地址
-	.uart_re_array={usr_uart.uart_re_Byte,0,0,0,0,0,0,0,0,0},				//存放的内存地址位置
-	.uart_re_count_array={0},																				//存放的数据数量
-	.uart_re_point=0,																								//当前存放内存数组位置
-	
-	.modbus_receive={0},			
-	.modbus_len=0,
-	.modbus_rec=false,
-	.m_modbus_rec_func=NULL,
-	
-	.hex_receive=NULL,
-	.hex_pro=false,
-	.hex_len=0,
-	.hex_size=0,
-	.hex_rec=false,
-	.m_hex_rec_func=NULL,
+user_uart_s usr_uart = {
+	.uart_init_stat = false,
+#ifdef MODUBS_USED
+	.recv_modbus_size = 9,
+	.modbus_receive = NULL,			
+	.modbus_len = 0,
+	.modbus_rec = false,
+	.m_modbus_rec_func = NULL,
+#endif
+#ifdef UART_STR_USED
+	.uart_work = UART_STR,
+	.uart_rx_stat = false,																						//uart接收完成标志
+	.uart_re_Byte = {0},																							//模块返回信息存储
+	.uart_re_addr_count = 0,																					//存储位置计数
+	.uart_re_addr = usr_uart.uart_re_Byte,														//当前保存的位置
+	.uart_re_addr_begin = usr_uart.uart_re_Byte,											//当前区域的首地址
+	.uart_re_array = {usr_uart.uart_re_Byte,0,0,0,0,0,0,0,0,0},				//存放的内存地址位置
+	.uart_re_count_array = {0},																				//存放的数据数量
+	.uart_re_point = 0,																								//当前存放内存数组位置
+#endif
+#ifdef UART_HEX_USED
+	.hex_receive = NULL,
+	.hex_pro = false,
+	.hex_len = 0,
+	.hex_size = 0,
+	.hex_rec = false,
+	.m_hex_rec_func = NULL,
+#endif
 };
 
 /**
@@ -39,7 +44,7 @@ user_uart_s usr_uart={
 static void UartSendChar(uint8_t ch)
 {
 	uint32_t err_code;
-	if(usr_uart.uart_init_stat!=true)
+	if(usr_uart.uart_init_stat != true)
 	{
 		uart_open();
 	}
@@ -65,7 +70,7 @@ void UartSendHex(uint8_t *hex,uint16_t len,bool space)
 		UartSendChar(_get_HexChar(*hex>>4));
 		UartSendChar(_get_HexChar(*hex&0x0F));
 		hex++;
-		if(space==true)
+		if(space == true)
 		{
 			UartSendChar(' ');
 		}
@@ -74,12 +79,60 @@ void UartSendHex(uint8_t *hex,uint16_t len,bool space)
 
 void UartSendString(char *pBuffer)
 {
-  while(*pBuffer!='\0'){
+  while(*pBuffer != '\0'){
 		UartSendChar(*pBuffer);
     pBuffer++;
   }	
 }
 
+#ifdef MODUBS_USED
+void Modbus_Set_Init(uint8_t size)
+{
+	usr_uart.uart_work = UART_MODBUS;
+	usr_uart.modbus_rec = false;
+	usr_uart.modbus_len = 0;
+	if(usr_uart.modbus_receive == NULL)
+	{
+		usr_uart.recv_modbus_size = size;
+		usr_uart.modbus_receive = malloc(usr_uart.recv_modbus_size+2);
+	}
+	else if(usr_uart.recv_modbus_size != size){
+		usr_uart.recv_modbus_size = size;
+		usr_uart.modbus_receive = realloc(usr_uart.modbus_receive, usr_uart.recv_modbus_size+2);
+	}
+	memset(usr_uart.modbus_receive,0,usr_uart.recv_modbus_size+2);
+}
+
+void Modbus_Data_Init(void)
+{
+	usr_uart.modbus_rec = false;
+	usr_uart.modbus_len = 0;
+	memset(usr_uart.modbus_receive,0,usr_uart.recv_modbus_size+2);
+}
+
+static void Modbus_Data_Pro(uint8_t temp)
+{
+	if(usr_uart.modbus_rec == false)
+	{
+		usr_uart.modbus_receive[usr_uart.modbus_len++] = temp;
+		if(usr_uart.modbus_len >= usr_uart.recv_modbus_size)
+		{
+			usr_uart.modbus_rec = true;
+			if(usr_uart.m_modbus_rec_func != NULL)
+			{
+				usr_uart.m_modbus_rec_func(usr_uart.modbus_receive,&usr_uart.modbus_len,&usr_uart.modbus_rec);
+			}
+		}
+	}
+}
+
+void set_modbus_rec_func(modbus_rec_func func)
+{
+	usr_uart.uart_work = UART_MODBUS;
+	usr_uart.m_modbus_rec_func = func;
+}
+#endif
+#ifdef UART_STR_USED
 static void uart_re_add_set(void)
 {
 	usr_uart.uart_re_count_array[usr_uart.uart_re_point]++;
@@ -126,72 +179,49 @@ static void Uart_Receive_Str(uint8_t c)
 	}
 }
 
-void Hex_Set_Init(uint8_t *buffer,uint8_t size)
-{
-	usr_uart.hex_rec=false;
-	usr_uart.hex_len=0;
-	usr_uart.hex_receive=buffer;
-	usr_uart.hex_size=size;
-	memset(usr_uart.hex_receive,0,usr_uart.hex_size);
-}
-
-void Modbus_Set_Init(void)
-{
-	usr_uart.modbus_rec=false;
-	usr_uart.modbus_len=0;
-	memset(usr_uart.modbus_receive,0,MODBUS_REC_LEN);
-}
-
-void Uart_Set_Init(void)
-{
-	usr_uart.uart_rx_stat=false,								
-	memset(usr_uart.uart_re_Byte,0,USER_UART_REBYTE_LEN);		
-	usr_uart.uart_re_addr_count=0;
-	usr_uart.uart_re_addr=usr_uart.uart_re_Byte;
-	usr_uart.uart_re_addr_begin=usr_uart.uart_re_Byte;
-	memset(usr_uart.uart_re_array,0,10);	
-	usr_uart.uart_re_array[0]=usr_uart.uart_re_Byte;
-	memset(usr_uart.uart_re_count_array,0,10);													
-	usr_uart.uart_re_point=0;																			
-}
-
-static void Modbus_Data_Pro(uint8_t temp)
-{
-	if(usr_uart.modbus_rec==false)
-	{
-		usr_uart.modbus_receive[usr_uart.modbus_len++]=temp;
-		if(usr_uart.modbus_len>=MODBUS_REC_LEN)
-		{
-			usr_uart.modbus_rec=true;
-			if(usr_uart.m_modbus_rec_func!=NULL)
-			{
-				usr_uart.m_modbus_rec_func(usr_uart.modbus_receive,&usr_uart.modbus_len,&usr_uart.modbus_rec);
-			}
-		}
-	}
-}
- 
-static void Hex_Data_Pro(uint8_t temp)
+/*******************************************************************************
+  * @函数名称		Uart_ReData_Pro
+  * @函数说明   检查Uart返回数据
+  * @输入参数   无
+  * @输出参数   无
+  * @返回参数   无
+*******************************************************************************/
+void Uart_ReData_Pro(void)
 {
-	if(usr_uart.hex_pro==true)
-	{
-		if(usr_uart.m_single_hex_rec_func!=NULL)
-		{
-			usr_uart.m_single_hex_rec_func(temp);
-		}
-	}
-	else{
-		if(usr_uart.hex_rec==false)
+//	char str[30]={0};
+	uint8_t i=0;
+	char data[128]={0};
+//	uint8_t *data;
+	char *idx;
+	uint16_t len=0;
+	uint16_t len_diff=0;
+	
+	for(i=0;i<10;i++){
+		if(usr_uart.uart_re_array[i]!=0)
 		{
-			usr_uart.hex_receive[usr_uart.hex_len++]=temp;
-			if(usr_uart.hex_len>=usr_uart.hex_size)
+			len_diff=&usr_uart.uart_re_Byte[USER_UART_REBYTE_LEN-1]-usr_uart.uart_re_array[i]+1;
+			
+//			data=(uint8_t *)malloc(bc95_re_count_array[i]*sizeof(uint8_t));
+			idx=usr_uart.uart_re_array[i];
+			len=0;
+			while(usr_uart.uart_re_count_array[i])
 			{
-				usr_uart.hex_rec=true;
-				if(usr_uart.m_hex_rec_func!=NULL)
+				data[len++]=*idx++;
+				if(len==len_diff)
 				{
-					usr_uart.m_hex_rec_func();
+					idx=usr_uart.uart_re_Byte;
 				}
+				usr_uart.uart_re_count_array[i]--;
 			}
+			data[len]='\0';
+			
+			usr_uart.m_uart_rec_func(data);
+//#ifdef DEBUG
+//			printf(data);
+//			printf("\r\n");
+//#endif
+			usr_uart.uart_re_array[i]=0;
+	//		free(data);
 		}
 	}
 }
@@ -241,22 +271,114 @@ static void Terminal_Data_Pro(uint8_t temp)
 	}
 }
 
+void Uart_Set_Init(void)
+{
+	usr_uart.uart_rx_stat=false,								
+	memset(usr_uart.uart_re_Byte,0,USER_UART_REBYTE_LEN);		
+	usr_uart.uart_re_addr_count=0;
+	usr_uart.uart_re_addr=usr_uart.uart_re_Byte;
+	usr_uart.uart_re_addr_begin=usr_uart.uart_re_Byte;
+	memset(usr_uart.uart_re_array,0,10);	
+	usr_uart.uart_re_array[0]=usr_uart.uart_re_Byte;
+	memset(usr_uart.uart_re_count_array,0,10);													
+	usr_uart.uart_re_point=0;																			
+}
+
+void set_string_rec_func(uart_rec_func func)
+{
+	usr_uart.uart_work=UART_STR;
+	usr_uart.m_uart_rec_func=func;
+}
+
+void set_terminal_rec_func(uart_rec_func func)
+{
+	usr_uart.uart_work=UART_TERMINAL;
+	usr_uart.m_uart_rec_func=func;
+}
+
+static void user_uart_pro(void)
+{
+	if(usr_uart.uart_rx_stat==true)
+	{
+		Uart_ReData_Pro();
+		usr_uart.uart_rx_stat=false;
+	}
+}
+#endif
+#ifdef UART_HEX_USED
+void set_hex_rec_func(hex_rec_func func)
+{
+	usr_uart.uart_work=UART_HEX;
+	usr_uart.m_hex_rec_func=func;
+	usr_uart.hex_pro=false;
+}
+
+void set_single_hex_rec_func(single_hex_rec_func func)
+{
+	usr_uart.uart_work=UART_HEX;
+	usr_uart.m_single_hex_rec_func=func;
+	usr_uart.hex_pro=true;
+}
+
+void Hex_Set_Init(uint8_t *buffer,uint8_t size)
+{
+	usr_uart.hex_rec=false;
+	usr_uart.hex_len=0;
+	usr_uart.hex_receive=buffer;
+	usr_uart.hex_size=size;
+	memset(usr_uart.hex_receive,0,usr_uart.hex_size);
+}
+
+static void Hex_Data_Pro(uint8_t temp)
+{
+	if(usr_uart.hex_pro==true)
+	{
+		if(usr_uart.m_single_hex_rec_func!=NULL)
+		{
+			usr_uart.m_single_hex_rec_func(temp);
+		}
+	}
+	else{
+		if(usr_uart.hex_rec==false)
+		{
+			usr_uart.hex_receive[usr_uart.hex_len++]=temp;
+			if(usr_uart.hex_len>=usr_uart.hex_size)
+			{
+				usr_uart.hex_rec=true;
+				if(usr_uart.m_hex_rec_func!=NULL)
+				{
+					usr_uart.m_hex_rec_func();
+				}
+			}
+		}
+	}
+}
+#endif
+
 static void Uart_Data_Pro(uint8_t c)
 {
-	if(usr_uart.uart_work==UART_MODBUS)
+	if(usr_uart.uart_work == UART_MODBUS)
 	{
+#ifdef MODUBS_USED
 		Modbus_Data_Pro(c);
+#endif
 	}
-	else if(usr_uart.uart_work==UART_HEX)
+	else if(usr_uart.uart_work == UART_HEX)
 	{
+#ifdef UART_HEX_USED
 		Hex_Data_Pro(c);
+#endif
 	}
-	else if(usr_uart.uart_work==UART_TERMINAL)
+	else if(usr_uart.uart_work == UART_TERMINAL)
 	{
+#ifdef UART_STR_USED
 		Terminal_Data_Pro(c);
+#endif
 	}
 	else{
+#ifdef UART_STR_USED
 		Uart_Receive_Str(c);
+#endif
 	}
 }
 
@@ -275,7 +397,7 @@ void uart_event_handle(app_uart_evt_t * p_event)
 			break;
 			//通讯错误事件,进入错误处理
 		case APP_UART_COMMUNICATION_ERROR:
-//			APP_ERROR_HANDLER(p_event->data.error_communication);
+			APP_ERROR_HANDLER(p_event->data.error_communication);
 			break;
 			//FIFO错误事件,进入错误处理
 		case APP_UART_FIFO_ERROR:
@@ -286,52 +408,7 @@ void uart_event_handle(app_uart_evt_t * p_event)
 	}
 }
 
-/*******************************************************************************
-  * @函数名称		Uart_ReData_Pro
-  * @函数说明   检查Uart返回数据
-  * @输入参数   无
-  * @输出参数   无
-  * @返回参数   无
-*******************************************************************************/
-void Uart_ReData_Pro(void)
-{
-//	char str[30]={0};
-	uint8_t i=0;
-	char data[128]={0};
-//	uint8_t *data;
-	char *idx;
-	uint16_t len=0;
-	uint16_t len_diff=0;
-	
-	for(i=0;i<10;i++){
-		if(usr_uart.uart_re_array[i]!=0)
-		{
-			len_diff=&usr_uart.uart_re_Byte[USER_UART_REBYTE_LEN-1]-usr_uart.uart_re_array[i]+1;
-			
-//			data=(uint8_t *)malloc(bc95_re_count_array[i]*sizeof(uint8_t));
-			idx=usr_uart.uart_re_array[i];
-			len=0;
-			while(usr_uart.uart_re_count_array[i])
-			{
-				data[len++]=*idx++;
-				if(len==len_diff)
-				{
-					idx=usr_uart.uart_re_Byte;
-				}
-				usr_uart.uart_re_count_array[i]--;
-			}
-			data[len]='\0';
-			
-			usr_uart.m_uart_rec_func(data);
-//#ifdef DEBUG
-//			printf(data);
-//			printf("\r\n");
-//#endif
-			usr_uart.uart_re_array[i]=0;
-	//		free(data);
-		}
-	}
-}
+
 
 //串口配置
 void uart_config(void)
@@ -359,32 +436,6 @@ void uart_config(void)
 
   APP_ERROR_CHECK(err_code);
 }
-	
-void set_hex_rec_func(hex_rec_func func)
-{
-	usr_uart.uart_work=UART_HEX;
-	usr_uart.m_hex_rec_func=func;
-	usr_uart.hex_pro=false;
-}
-
-void set_single_hex_rec_func(single_hex_rec_func func)
-{
-	usr_uart.uart_work=UART_HEX;
-	usr_uart.m_single_hex_rec_func=func;
-	usr_uart.hex_pro=true;
-}
-
-void set_string_rec_func(uart_rec_func func)
-{
-	usr_uart.uart_work=UART_STR;
-	usr_uart.m_uart_rec_func=func;
-}
-
-void set_terminal_rec_func(uart_rec_func func)
-{
-	usr_uart.uart_work=UART_TERMINAL;
-	usr_uart.m_uart_rec_func=func;
-}
 
 void uart_open(void)
 {
@@ -406,63 +457,20 @@ void uart_close(void)
 	}
 }
 
-static void uart_config_9600(void)
-{
-	uint32_t err_code;
-	
-	//定义串口通讯参数配置结构体并初始化
-  const app_uart_comm_params_t comm_params =
-  {
-    rx_pin,//定义uart接收引脚
-    tx_pin,//定义uart发送引脚
-    RTS_PIN_NUMBER,//定义uart RTS引脚,流控关闭后虽然定义了RTS和CTS引脚,但是驱动程序会忽略,不会配置这两个引脚,两个引脚仍可作为IO使用
-    CTS_PIN_NUMBER,//定义uart CTS引脚
-    APP_UART_FLOW_CONTROL_DISABLED,//关闭uart硬件流控
-    false,//禁止奇偶检验
-    2576384//uart波特率设置为9600bps
-  };
-  //初始化串口,注册串口事件回调函数
-  APP_UART_FIFO_INIT(&comm_params,
-                         UART_RX_BUF_SIZE,
-                         UART_TX_BUF_SIZE,
-                         uart_event_handle,
-                         APP_IRQ_PRIORITY_MID,
-                         err_code);
-
-  APP_ERROR_CHECK(err_code);
-}
-
-void uart_open_9600(void)
-{
-	if(usr_uart.uart_init_stat==false)
-	{
-		NRF_LOG_INFO("uart for 9600 open!");
-		uart_config_9600();
-		usr_uart.uart_init_stat=true;
-	}
-}
-
 void set_uart_pin(uint32_t tx,uint32_t rx)
 {
 	rx_pin=rx;
 	tx_pin=tx;
 }
 
-static void user_uart_pro(void)
-{
-	if(usr_uart.uart_rx_stat==true)
-	{
-		Uart_ReData_Pro();
-		usr_uart.uart_rx_stat=false;
-	}
-}
-
 static void user_uart_queue(void *p_event_data, uint16_t event_size)    
 {
 	custome_event *evt = (custome_event*)p_event_data;
 	if((user_uart_event.flag & (1<<USER_UART_QUEUE_INT))!=0)
 	{
+#ifdef UART_STR_USED
 		user_uart_pro();
+#endif
 		user_uart_event.flag&=(~(1<<USER_UART_QUEUE_INT));
 	}
 	if((user_uart_event.flag & (1<<USER_UART_QUEUE_TIME))!=0)

+ 36 - 13
std/src/user_config.c

@@ -83,22 +83,30 @@ static void user_config_read_ok(void);
 static void user_config_read_timeout(void);
 static void user_config_read(void)
 {
-	uint8_t data[4096]={0};
+//	uint8_t data[4096]={0};
+	uint8_t *data = malloc(sizeof(user_config_param));
 	flash_init(p_fs_api);
-	ret_code_t ret=flash_read_data(USER_FLASH_START_ADDR,data,4096);
+	ret_code_t ret = flash_read_data(USER_FLASH_START_ADDR,data,sizeof(user_config_param));
 //	ret_code_t ret=flash_read_data(USER_FLASH_START_ADDR,(uint8_t *)&user_config_param,sizeof(user_config_param));
-	if(ret==NRF_SUCCESS)
+	if(ret == NRF_SUCCESS)
 	{
 		memcpy((uint8_t *)&user_config_param,data,sizeof(user_config_param));
-		if(user_config_work.user_config_data!=NULL)
+
+		if(user_config_work.user_config_data!=NULL && user_config_work.user_config_data_len > 0)
 		{
-			memcpy(user_config_work.user_config_data,&data[1024],user_config_work.user_config_data_len);
+			data = realloc(data, user_config_work.user_config_data_len);
+			ret = flash_read_data(USER_FLASH_START_ADDR+1024,data,sizeof(user_config_param));
+			if(ret == NRF_SUCCESS)
+			{
+				memcpy(user_config_work.user_config_data,data,user_config_work.user_config_data_len);
+			}
 		}
 		user_config_read_ok();
 	}
 	else{
 		user_config_read_timeout();
 	}
+	free(data);
 //	user_config_timers_start(1000);
 }
 
@@ -124,18 +132,22 @@ static void user_config_read_ok(void)
 	}
 }
 
+static bool user_config_data_stat = true;
+
 static void user_config_write(void)
 {
-	uint8_t data[4096]={0xFF};
+	uint8_t *data = malloc(sizeof(user_config_param));
+	memset(data, 0, sizeof(user_config_param));
 	
 	memcpy(data,(uint8_t *)&user_config_param,sizeof(user_config_param));
 	if(user_config_work.user_config_data!=NULL)
 	{
-		memcpy(&data[1024],user_config_work.user_config_data,user_config_work.user_config_data_len);
+		user_config_data_stat = false;
 	}
 		
-	flash_write_data(USER_FLASH_START_ADDR,data,4096);
+	flash_write_data(USER_FLASH_START_ADDR,data,sizeof(user_config_param));
 	user_config_timers_start(1000);
+	free(data);
 }
 
 static void user_config_write_timeout(void)
@@ -151,12 +163,23 @@ static void user_config_write_timeout(void)
 
 static void user_config_write_ok(void)
 {
-	flash_uninit(p_fs_api);
-	user_config_work.timeout_count=0;
-	user_config_work.work_stat=USER_CONFIG_NULL;
-	if(user_config_work.write_finish_func!=NULL)
+	if(user_config_data_stat == true)
 	{
-		user_config_work.write_finish_func(true);
+		flash_uninit(p_fs_api);
+		user_config_work.timeout_count=0;
+		user_config_work.work_stat=USER_CONFIG_NULL;
+		if(user_config_work.write_finish_func!=NULL)
+		{
+			user_config_work.write_finish_func(true);
+		}
+	}
+	else{
+		user_config_data_stat = true;
+		uint8_t *data = malloc(user_config_work.user_config_data_len);
+		memset(data, 0, user_config_work.user_config_data_len);
+		flash_write_data(USER_FLASH_START_ADDR,data,sizeof(user_config_param));
+		user_config_timers_start(1000);
+		free(data);
 	}
 }
 

+ 1 - 1
std/src/user_spim.c

@@ -10,7 +10,7 @@ user_spim_s user_spim1_s=
 };
 
 //定义SPI驱动程序实例,名称为m_spi
-static const nrf_drv_spi_t m_spim1 = NRF_DRV_SPI_INSTANCE(1);
+static const nrf_drv_spi_t m_spim1 = NRF_DRV_SPI_INSTANCE(0);
 
 //定义并初始化TWI配置结构体
 static nrf_drv_spi_config_t spim1_config = NRF_DRV_SPI_DEFAULT_CONFIG;