Skip to content

Commit bd0b7ef

Browse files
committed
fix: AT can't run after ota from old version
1 parent dd79562 commit bd0b7ef

File tree

3 files changed

+87
-27
lines changed

3 files changed

+87
-27
lines changed

docs/ESP32_AT_Factory_Parameter_Bin.md

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Overview
2-
There are some differences between different development boards, and different countries also have different restrictions on RF. So we need a table to manage these differences.
2+
In order to adapt the AT firmware to different requirements, for example, different development board, different country code, different RF restriction, we make a table to configure those parameters.
33

4-
## Factory param type
5-
The factory param type is shown in the following table:
4+
5+
## Factory param type
6+
7+
The origin table is [`components/customized_partitions/raw_data/factory_param/factory_param_type.csv`](components/customized_partitions/raw_data/factory_param/factory_param_type.csv), and the factory parameter type is as the following table:
68

79
| param_name | offset | type | size |
810
| ------------- | ------ | ------- | ---- |
9-
| module_name | -1 | String | 0 |
11+
| module_name | -1 | String | 0 |
1012
| magic_flag | 0 | integer | 2 |
1113
| version | 2 | integer | 1 |
1214
| module_id | 3 | integer | 1 |
@@ -24,7 +26,7 @@ The factory param type is shown in the following table:
2426
- the version of factory param mangement
2527

2628
- module_id
27-
- the index of development boards
29+
- the index of development boards, it MUST be unique.
2830
- 1 - WROOM32
2931
- 2 - WROVER32
3032
- 3 - PICO-D4
@@ -46,24 +48,83 @@ The factory param type is shown in the following table:
4648
- uart baudrate
4749

4850
- uart\_tx_pin
49-
- tx pin
51+
- uart tx pin
5052

5153
- uart\_rx_pin
52-
- rx pin
54+
- uart rx pin
5355

5456
- uart\_ctx_pin
55-
- ctx pin
57+
- uart ctx pin
5658

5759
- uart\_rts_pin
58-
- rts pin
60+
- uart rts pin
5961

60-
## Factory param data
62+
## Factory param data
63+
64+
The origin table is [`components/customized_partitions/raw_data/factory_param/factory_param_data.csv`](components/customized_partitions/raw_data/factory_param/factory_param_data.csv), and the information each row contains is about one module. The factory parameter data is as the following table:
65+
66+
| module_name | magic_flag | version | module_id | tx_max_power | start_channel | channel_num | country_code | uart_baudrate | uart_tx_pin | uart_rx_pin | uart_ctx_pin | uart_rts_pin |
67+
|---|---|---|---|---|---|---| ---|---|---|---|---|---|
68+
| WROOM-32 |0xfcfc|1|1|1|1|13|CN|115200|17|16|15|14|
69+
| WROVER-32|0xfcfc|1|2|1|1|13|CN|115200|22|19|15|14|
70+
| PICO-D4 |0xfcfc|1|3|1|1|13|CN|115200|22|19|15|14|
71+
| SOLO-1 |0xfcfc|1|4|1|1|13|CN|115200|17|16|15|14|
72+
73+
<a name="Add_Customized_Module"></a>
74+
## Add customized module
6175

62-
Save the factory param date for each development boards in a table, it was organized as bellow:
76+
if you want to add a module named as "MY_MODULE", of which country code is JP, and Wi-Fi channel is from 1 to 14, the table should be as the following one:
6377

6478
| module_name | magic_flag | version | module_id | tx_max_power | start_channel | channel_num | country_code | uart_baudrate | uart_tx_pin | uart_rx_pin | uart_ctx_pin | uart_rts_pin |
6579
|---|---|---|---|---|---|---| ---|---|---|---|---|---|
6680
| WROOM-32 |0xfcfc|1|1|1|1|13|CN|115200|17|16|15|14|
6781
| WROVER-32|0xfcfc|1|2|1|1|13|CN|115200|22|19|15|14|
6882
| PICO-D4 |0xfcfc|1|3|1|1|13|CN|115200|22|19|15|14|
69-
| SOLO-1 |0xfcfc|1|4|1|1|13|CN|115200|17|16|15|14|
83+
| SOLO-1 |0xfcfc|1|4|1|1|13|CN|115200|17|16|15|14|
84+
| MY_MODULE|0xfcfc|1|5|1|1|14|JP|115200|17|16|15|14|
85+
86+
Then add module information in `esp_at_module_info` in `at_default_config.c`, like
87+
88+
```
89+
static const esp_at_module_info_t esp_at_module_info[] = {
90+
{"WROOM-32", CONFIG_ESP_AT_OTA_TOKEN_WROOM32, CONFIG_ESP_AT_OTA_SSL_TOKEN_WROOM32 }, // default:ESP32-WROOM-32 // Unknown
91+
{"WROOM-32", CONFIG_ESP_AT_OTA_TOKEN_WROOM32, CONFIG_ESP_AT_OTA_SSL_TOKEN_WROOM32 }, // ESP32-WROOM-32
92+
{"WROVER-32", CONFIG_ESP_AT_OTA_TOKEN_WROVER32, CONFIG_ESP_AT_OTA_SSL_TOKEN_WROVER32 }, // ESP32-WROVER
93+
{"PICO-D4", CONFIG_ESP_AT_OTA_TOKEN_ESP32_PICO_D4, CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32_PICO_D4}, // ESP32-PICO-D4
94+
{"SOLO-1", CONFIG_ESP_AT_OTA_TOKEN_ESP32_SOLO_1, CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32_SOLO_1 }, // ESP32-SOLO-1
95+
{"MY_MODULE", CONFIG_ESP_AT_OTA_TOKEN_ MY_MODULE, CONFIG_ESP_AT_OTA_SSL_TOKEN_ MY_MODULE }, // MY_MODULE
96+
};
97+
```
98+
## Add customized data
99+
100+
If you want to add more parameter, for example, add a string "20181225" as the date, you need to add the type of date in the `factory_param_type.csv`, as the following table.
101+
102+
| param_name | offset | type | size |
103+
| ------------- | ------ | ------- | ---- |
104+
| module_name | - | String | 0 |
105+
| magic_flag | 0 | integer | 2 |
106+
| version | 2 | integer | 1 |
107+
| module_id | 3 | integer | 1 |
108+
| tx_max_power | 4 | integer | 1 |
109+
| start_channel | 6 | integer | 1 |
110+
| channel_num | 7 | integer | 1 |
111+
| country_code | 8 | String | 4 |
112+
| uart_baudrate | 12 | integer | 4 |
113+
| uart_tx_pin | 16 | integer | 1 |
114+
| uart_rx_pin | 17 | integer | 1 |
115+
| uart_ctx_pin | 18 | integer | 1 |
116+
| uart_rts_pin | 19 | integer | 1 |
117+
| date | 20 | String | 8 |
118+
119+
Edit `factory_param_data.csv` with reference to
120+
[Add customized module](#Add_Customized_Module), and add the date into the last column, as the following table,
121+
122+
| module_name | magic_flag | version | module_id | tx_max_power | start_channel | channel_num | country_code | uart_baudrate | uart_tx_pin | uart_rx_pin | uart_ctx_pin | uart_rts_pin | date |
123+
|---|---|---|---|---|---|---| ---|---|---|---|---|---|---|
124+
| WROOM-32 |0xfcfc|1|1|1|1|13|CN|115200|17|16|15|14| |
125+
| WROVER-32|0xfcfc|1|2|1|1|13|CN|115200|22|19|15|14| |
126+
| PICO-D4 |0xfcfc|1|3|1|1|13|CN|115200|22|19|15|14| |
127+
| SOLO-1 |0xfcfc|1|4|1|1|13|CN|115200|17|16|15|14| |
128+
| MY_MODULE|0xfcfc|1|5|1|1|14|JP|115200|17|16|15|14|20181225|
129+
130+
Then, you can add code to parse `date` in `esp_at_factory_parameter_init` or other api.

main/at_default_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct {
5050
} esp_at_module_info_t;
5151

5252
static const esp_at_module_info_t esp_at_module_info[] = {
53-
{"Unknown", "Unknown", "Unknown" }, // Unknown
53+
{"WROOM-32", CONFIG_ESP_AT_OTA_TOKEN_WROOM32, CONFIG_ESP_AT_OTA_SSL_TOKEN_WROOM32 }, // default:ESP32-WROOM-32 // Unknown
5454
{"WROOM-32", CONFIG_ESP_AT_OTA_TOKEN_WROOM32, CONFIG_ESP_AT_OTA_SSL_TOKEN_WROOM32 }, // ESP32-WROOM-32
5555
{"WROVER-32", CONFIG_ESP_AT_OTA_TOKEN_WROVER32, CONFIG_ESP_AT_OTA_SSL_TOKEN_WROVER32 }, // ESP32-WROVER
5656
{"PICO-D4", CONFIG_ESP_AT_OTA_TOKEN_ESP32_PICO_D4, CONFIG_ESP_AT_OTA_SSL_TOKEN_ESP32_PICO_D4}, // ESP32-PICO-D4

main/interface/uart/at_uart_task.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -585,23 +585,23 @@ void at_task_init(void)
585585
{
586586
const esp_partition_t * partition = esp_at_custom_partition_find(0x40,8,"factory_param");
587587
char* data = NULL;
588+
uint32_t module_id = 0;
588589

589-
if (!partition) {
590+
if (partition) {
591+
data = (char*)malloc(ESP_AT_FACTORY_PARAMETER_SIZE); // Notes
592+
assert(data != NULL);
593+
if(esp_partition_read(partition, 0, data, ESP_AT_FACTORY_PARAMETER_SIZE) != ESP_OK){
594+
free(data);
595+
printf("esp_partition_read failed\r\n");
596+
return ;
597+
} else {
598+
module_id = data[3];
599+
free(data);
600+
}
601+
} else {
590602
printf("factory_parameter partition missed\r\n");
591-
return ;
592-
}
593-
594-
data = (char*)malloc(ESP_AT_FACTORY_PARAMETER_SIZE); // Notes
595-
assert(data != NULL);
596-
if(esp_partition_read(partition, 0, data, ESP_AT_FACTORY_PARAMETER_SIZE) != ESP_OK){
597-
free(data);
598-
printf("esp_partition_read failed\r\n");
599-
return ;
600603
}
601604

602-
uint32_t module_id = data[3];
603-
free(data);
604-
605605
const char* module_name = esp_at_get_module_name_by_id(module_id);
606606
uint8_t *version = (uint8_t *)malloc(192);
607607
esp_at_device_ops_struct esp_at_device_ops = {
@@ -623,7 +623,6 @@ void at_task_init(void)
623623

624624
nvs_flash_init();
625625
at_uart_init();
626-
627626
sprintf((char*)version, "compile time:%s %s\r\n", __DATE__, __TIME__);
628627
#ifdef CONFIG_ESP_AT_FW_VERSION
629628
if ((strlen(CONFIG_ESP_AT_FW_VERSION) > 0) && (strlen(CONFIG_ESP_AT_FW_VERSION) <= 128)){

0 commit comments

Comments
 (0)