Skip to content

Commit 9c19b1e

Browse files
donghengdongheng
dongheng
authored and
dongheng
committed
feat(factory_test): add factory test and document
1 parent f49b40e commit 9c19b1e

File tree

18 files changed

+1230
-6
lines changed

18 files changed

+1230
-6
lines changed

components/esp8266/Makefile.projbuild

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ CFLAGS += -D__ESP_FILE__='"null"'
8282
CXXFLAGS += -D__ESP_FILE__='"null"'
8383
endif
8484

85-
.PHONY: ota ota-clean
85+
.PHONY: ota ota-clean app2 app2-flash app2-flash-all
8686

8787
RAW_BIN := ./build/$(PROJECT_NAME).bin
8888
OTA_BIN := ./build/$(PROJECT_NAME).ota.bin
@@ -97,6 +97,20 @@ __COMBILE_OTA_BIN := 1
9797
endif
9898
endif
9999

100+
app2: all
101+
ifdef CONFIG_ESPTOOLPY_FLASHSIZE_1MB
102+
@rm -f ./build/esp8266/esp8266_out.ld
103+
@export CFLAGS= && export CXXFLAGS= && make APP_OFFSET=$(APP2_OFFSET) APP_SIZE=$(APP2_SIZE)
104+
endif
105+
@echo "To flash all build output, run 'make flash' or:"
106+
@echo $(ESPTOOLPY_WRITE_FLASH) $(APP2_OFFSET) $(APP_BIN)
107+
108+
app2-flash: app2
109+
@$(ESPTOOLPY_WRITE_FLASH) $(APP2_OFFSET) $(APP_BIN)
110+
111+
app2-flash-all: app2
112+
@$(ESPTOOLPY_WRITE_FLASH) $(patsubst $(APP_OFFSET),$(APP2_OFFSET),$(ESPTOOL_ALL_FLASH_ARGS))
113+
100114
$(OTA1_BIN): all_binaries
101115
@cp $(RAW_BIN) $(OTA1_BIN)
102116
@echo [GEN] $(OTA1_BIN)

components/freertos/port/esp8266/port.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,22 +248,42 @@ void show_critical_info(void)
248248
ets_printf("SWReq:%u\n", SWReq);
249249
}
250250

251+
#ifdef ESP_DPORT_CLOSE_NMI
252+
static int s_nmi_is_closed;
253+
254+
void esp_dport_close_nmi(void)
255+
{
256+
vPortEnterCritical();
257+
REG_WRITE(PERIPHS_DPORT_BASEADDR, REG_READ(PERIPHS_DPORT_BASEADDR) & ~0x1);
258+
s_nmi_is_closed = 1;
259+
vPortExitCritical();
260+
}
261+
262+
#define ESP_NMI_IS_CLOSED() s_nmi_is_closed
263+
#else
264+
#define ESP_NMI_IS_CLOSED() 0
265+
#endif
266+
251267
void IRAM_ATTR vPortETSIntrLock(void)
252268
{
253269
if (NMIIrqIsOn == 0) {
254270
vPortEnterCritical();
255-
do {
256-
REG_WRITE(INT_ENA_WDEV, WDEV_TSF0_REACH_INT);
257-
} while(REG_READ(INT_ENA_WDEV) != WDEV_TSF0_REACH_INT);
271+
if (!ESP_NMI_IS_CLOSED()) {
272+
do {
273+
REG_WRITE(INT_ENA_WDEV, WDEV_TSF0_REACH_INT);
274+
} while(REG_READ(INT_ENA_WDEV) != WDEV_TSF0_REACH_INT);
275+
}
258276
}
259277
}
260278

261279
void IRAM_ATTR vPortETSIntrUnlock(void)
262280
{
263281
if (NMIIrqIsOn == 0) {
264-
extern uint32_t WDEV_INTEREST_EVENT;
282+
if (!ESP_NMI_IS_CLOSED()) {
283+
extern uint32_t WDEV_INTEREST_EVENT;
265284

266-
REG_WRITE(INT_ENA_WDEV, WDEV_INTEREST_EVENT);
285+
REG_WRITE(INT_ENA_WDEV, WDEV_INTEREST_EVENT);
286+
}
267287
vPortExitCritical();
268288
}
269289
}

docs/en/api-guides/factory-test.rst

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
Factory Test
2+
************
3+
4+
1. Overview
5+
===========
6+
7+
The document introduces how to develop, compile, download and run the factory test firmware.
8+
9+
The factory test software development kit is also an example of the SDK, and it is located at :example:`examples/system/factory-test`.
10+
11+
2. Development
12+
==============
13+
14+
Users can use ready-to-use applications directly, or can also add custom application code into the factory test software development kit.
15+
16+
More details of adding customer components, please refer to :doc:`Documentation for the GNU Make based build system <build-system>`.
17+
18+
Users can just develop the factory test application as normal examples of the SDK.
19+
20+
2.1 Application code
21+
--------------------
22+
23+
Just like other applications, the entry function of factory test application is ``app_main``. It should be added into the source code file of users.
24+
For example, users can add the ``app_main`` into ``main.c`` of the above sample project.
25+
26+
Users can refer to the source code in file :idf_file:`/examples/system/factory-test/main/main.c` to build custom project.
27+
28+
29+
2.2 Linking address
30+
-------------------
31+
32+
The SDK's partition only supports two applications that named as ``ota_0`` and ``ota_1``.
33+
34+
In this case, we link the factory test firmware to the partition of ``ota_1``.
35+
So, please do not flash the factory test firmware into the partition of ``ota_0``.
36+
37+
38+
3. Compile
39+
==========
40+
41+
To make the bootloader run the ``ota_1(factory test firmware)``,
42+
please enable the ``GPIO triggers boot from test app partition`` and set the ``correct`` GPIO of your development board in menuconfig::
43+
44+
Bootloader config --->
45+
[*] GPIO triggers boot from test app partition
46+
(12) Number of the GPIO input to boot TEST partition
47+
48+
Using the partition table file which has two "OTA" definitions partition::
49+
50+
Partition Table --->
51+
Partition Table (Factory app, two OTA definitions) --->
52+
(X) Factory app, two OTA definitions
53+
54+
Enable the console which is used for human-computer interaction::
55+
56+
Component config --->
57+
Virtual file system --->
58+
[*] Using espressif VFS
59+
60+
Enable pthread for this function::
61+
62+
Component config --->
63+
PThreads --->
64+
[*] Enable pthread
65+
66+
Then call command ``make app2`` in the terminal to compile the firmware which is able to run at ``ota_1`` partition.
67+
The ``Make System`` will start compiling bootloader, partition table file, factory test firmware and so on one by one.
68+
69+
70+
3.1 Special Commands
71+
====================
72+
73+
1. ``make app2``: only compile factory test firmware which is able to run at ``ota_1``, ``with`` bootloader, partition table file and so on
74+
75+
2. ``make app2-flash``: flash(download) only the factory test firmware which is able to run at ``ota_1``, ``without`` bootloader, partition table file and so on
76+
77+
3. ``make app2-flash-all``: flash(download) the factory test firmware which is able to run at ``ota_1``, ``with`` bootloader, partition table file and so on
78+
79+
80+
4. Download
81+
===========
82+
83+
Input command ``make app2-flash-all`` in the terminal to download bootloader, partition table file and factory test firmware which is located at ``ota_1`` one by one.
84+
85+
If users only want to download factory test firmware, please use command ``make app2-flash`` instead.
86+
87+
88+
5. Run
89+
======
90+
91+
Please hold the ``correct`` GPIO, which is configured in the menuconfig in Section 3 ``Compile``, to be low level and power on.
92+
Input command ``make monitor`` in the terminal, and then logs will appear like following::
93+
94+
ets Jan 8 2013,rst cause:1, boot mode:(3,6)
95+
96+
load 0x40100000, len 7872, room 16
97+
0x40100000: _stext at ??:?
98+
99+
tail 0
100+
chksum 0xf1
101+
load 0x3ffe8408, len 24, room 8
102+
tail 0
103+
chksum 0x78
104+
load 0x3ffe8420, len 3604, room 8
105+
tail 12
106+
chksum 0x1b
107+
I (64) boot: ESP-IDF v3.2-dev-354-gba1f90cd-dirty 2nd stage bootloader
108+
I (64) boot: compile time 13:56:17
109+
I (72) qio_mode: Enabling default flash chip QIO
110+
I (73) boot: SPI Speed : 40MHz
111+
I (80) boot: SPI Mode : QIO
112+
I (86) boot: SPI Flash Size : 2MB
113+
I (92) boot: Partition Table:
114+
I (98) boot: ## Label Usage Type ST Offset Length
115+
I (109) boot: 0 nvs WiFi data 01 02 00009000 00004000
116+
I (120) boot: 1 otadata OTA data 01 00 0000d000 00002000
117+
I (132) boot: 2 phy_init RF data 01 01 0000f000 00001000
118+
I (144) boot: 3 ota_0 OTA app 00 10 00010000 000f0000
119+
I (155) boot: 4 ota_1 OTA app 00 11 00110000 000f0000
120+
I (167) boot: End of partition table
121+
I (173) boot: No factory image, trying OTA 0
122+
I (5180) boot: Detect a boot condition of the test firmware
123+
I (5180) esp_image: segment 0: paddr=0x00110010 vaddr=0x40210010 size=0x37b18 (228120) map
124+
I (5263) esp_image: segment 1: paddr=0x00147b30 vaddr=0x3ffe8000 size=0x00718 ( 1816) load
125+
I (5264) esp_image: segment 2: paddr=0x00148250 vaddr=0x3ffe8718 size=0x0019c ( 412) load
126+
I (5275) esp_image: segment 3: paddr=0x001483f4 vaddr=0x40100000 size=0x084b0 ( 33968) load
127+
0x40100000: _stext at ??:?
128+
129+
I (5299) boot: Loaded app from partition at offset 0x110000
130+
I (5340) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
131+
I (5340) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
132+
I (5530) phy_init: phy ver: 1055_12
133+
I (5530) reset_reason: RTC reset 1 wakeup 0 store 0, reason is 1
134+
I (5530) factory-test: SDK factory test firmware version:v3.2-dev-354-gba1f90cd-dirty
135+
136+
Then users can input test commands to start factory testing.
137+
138+
6. Test Commands
139+
================
140+
141+
1. ``rftest_init``::
142+
143+
parameters: no
144+
145+
function: initialize RF to prepare for test
146+
147+
2. ``tx_contin_func <parameter 1>``::
148+
149+
parameter 1: value 1 means that chip transmits packets continuously with 92% duty cycle,
150+
value 0 means that "iqview" test mode
151+
152+
function: set test mode
153+
154+
3. ``esp_tx <parameter 1> <parameter 2> <parameter 3>``::
155+
156+
parameter 1: transmit channel which ranges from 1 to 14
157+
parameter 2: transmit rate which ranges from 0 to 23
158+
parameter 2: transmit power attenuation which ranges from -127 to 127, unit is 0.25dB
159+
160+
function: start transmitting Wi-Fi packets
161+
162+
note 1: command "wifitxout" is the same as "esp_tx"
163+
note 2: the function can be stopped by command "cmdstop"
164+
165+
4. ``esp_rx <parameter 1> <parameter 2>``::
166+
167+
parameter 1: transmit channel which ranges from 1 to 14
168+
parameter 2: transmit rate which ranges from 0 to 23
169+
170+
function: start receiving Wi-Fi packets
171+
172+
note 1: the function can be stopped by command "cmdstop"
173+
174+
5. ``wifiscwout <parameter 1> <parameter 2> <parameter 3>``::
175+
176+
parameter 1: enable signal, value 1 means enable, value 0 means disable
177+
parameter 2: transmit channel which ranges from 1 to 14
178+
parameter 3: transmit power attenuation which ranges from -127 to 127, unit is 0.25dB
179+
180+
function: start transmitting single carrier Wi-Fi packets
181+
182+
note 1: the function can be stopped by command "cmdstop"
183+
184+
6. ``cmdstop``::
185+
186+
parameters: no
187+
188+
function: stop transmitting or receiving Wi-Fi packets
189+
190+
note 1: command "CmdStop" is the same as "cmdstop"

docs/en/api-guides/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ API Guides
99
System Task <system-tasks>
1010
PWM and Sniffer Coexists <pwm-and-sniffer-coexists>
1111
FOTA from an Old SDK to the New ESP8266 RTOS SDK (IDF Style) <fota-from-old-new>
12+
Factory Test <factory-test>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
menu "Factory-test config"
2+
3+
config FACTORY_TEST
4+
bool "Enable factory test"
5+
default n
6+
select BOOTLOADER_INIT_SPI_FLASH
7+
help
8+
Enable this option, project compiling script will generate factory test firmware.
9+
10+
endmenu

examples/system/factory-test/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
PROJECT_NAME := factory-test
3+
4+
include $(IDF_PATH)/make/project.mk
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# Important
3+
4+
Please refer to the document at *docs/en/api-guides/factory-test.rst*.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
menu "Nano Console"
2+
3+
config NC_ECHO_CMD
4+
bool "echo input command"
5+
default y
6+
help
7+
Enable this option, the console terminal will echo the input command.
8+
9+
endmenu
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
CFLAGS += -DESP_DPORT_CLOSE_NMI
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Component Makefile
3+
#
4+
5+
LIBS := rftest
6+
7+
COMPONENT_ADD_LDFLAGS += -L$(COMPONENT_PATH)/lib $(addprefix -l,$(LIBS))
8+
COMPONENT_ADD_LINKER_DEPS += $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2019-2020 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <stdint.h>
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
/**
24+
* @brief Initialize RF test module
25+
*/
26+
void rftest_init(void);
27+
28+
/**
29+
* @brief Set TX testing mode
30+
*
31+
* @param mode testing mode, 1 means continuous Wi-Fi packets transmission with 92% duty cycle
32+
* 0 means default mode for iqview testing
33+
*/
34+
void tx_contin_func(uint8_t mode);
35+
36+
/**
37+
* @brief TX testing function, continuously sending Wi-Fi packets at "while(1)" loop
38+
*
39+
* @param channel Wi-Fi TX channel, it ranges from 1 to 14
40+
* @param rate Wi-Fi TX rate, it ranges from 1 to 23
41+
* @param attenuation Wi-Fi TX power attenuation, it ranges from 1 to 127 and its unit is 0.25dB.
42+
* For example, 1 means 0.25dB, 2 means 0.5 dB and so on.
43+
*/
44+
void esp_tx_func(uint32_t channel, uint32_t rate, uint32_t attenuation);
45+
46+
/**
47+
* @brief RX testing function, continuously receiving Wi-Fi packets at "while(1)" loop
48+
*
49+
* @param channel Wi-Fi RX channel, it ranges from 1 to 14
50+
* @param rate Wi-Fi RX rate, it ranges from 1 to 23
51+
*/
52+
void esp_rx_func(uint32_t channel, uint32_t rate);
53+
54+
/**
55+
* @brief Single carrier TX testing function
56+
*
57+
* @param enable enable signal, 1 means starting sending, 0 means stopping sending
58+
* @param channel Wi-Fi RX channel, it ranges from 1 to 14
59+
* @param attenuation Wi-Fi TX power attenuation, it ranges from 1 to 127 and its unit is 0.25dB.
60+
* For example, 1 means 0.25dB, 2 means 0.5 dB and so on.
61+
*/
62+
void wifiscwout_func(uint32_t enable, uint32_t channel, uint32_t attenuation);
63+
64+
/**
65+
* @brief Stop sending or recieving Wi-Fi packets
66+
*
67+
* @return
68+
* - 0 receiving stop TX commands "cmdstop" or "CmdStop" and TX is stopped
69+
* - 2 receiving error commands and TX will not stop
70+
* - 3 receiving no commands
71+
*/
72+
int cmdstop_callback(void);
73+
74+
/**
75+
* @brief Register RF test command for console
76+
*/
77+
void esp_console_register_rftest_command(void);
78+
79+
#ifdef __cplusplus
80+
}
81+
#endif

0 commit comments

Comments
 (0)