Skip to content

Commit e4612d7

Browse files
authored
Merge pull request #10073 from Scavanger/USB-Rescue
Building a USB-Rescue firmware without editing sources
2 parents 34baebb + 39bd781 commit e4612d7

File tree

5 files changed

+28
-45
lines changed

5 files changed

+28
-45
lines changed

cmake/at32.cmake

+5
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ function(target_at32)
326326

327327
math(EXPR hse_value "${hse_mhz} * 1000000")
328328
list(APPEND target_definitions "HSE_VALUE=${hse_value}")
329+
330+
if (MSP_UART)
331+
list(APPEND target_definitions "MSP_UART=${MSP_UART}")
332+
endif()
333+
329334
if(args_COMPILE_DEFINITIONS)
330335
list(APPEND target_definitions ${args_COMPILE_DEFINITIONS})
331336
endif()

cmake/sitl.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ function (target_sitl name)
9999
math(EXPR hse_value "${hse_mhz} * 1000000")
100100
list(APPEND target_definitions "HSE_VALUE=${hse_value}")
101101

102+
if (MSP_UART)
103+
list(APPEND target_definitions "MSP_UART=${MSP_UART}")
104+
endif()
105+
102106
string(TOLOWER ${PROJECT_NAME} lowercase_project_name)
103107
set(binary_name ${lowercase_project_name}_${FIRMWARE_VERSION}_${name})
104108
if(DEFINED BUILD_SUFFIX AND NOT "" STREQUAL "${BUILD_SUFFIX}")

cmake/stm32.cmake

+5
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ function(target_stm32)
333333

334334
math(EXPR hse_value "${hse_mhz} * 1000000")
335335
list(APPEND target_definitions "HSE_VALUE=${hse_value}")
336+
337+
if (MSP_UART)
338+
list(APPEND target_definitions "MSP_UART=${MSP_UART}")
339+
endif()
340+
336341
if(args_COMPILE_DEFINITIONS)
337342
list(APPEND target_definitions ${args_COMPILE_DEFINITIONS})
338343
endif()

docs/Broken USB recovery.md

+6-45
Original file line numberDiff line numberDiff line change
@@ -53,55 +53,16 @@ The following procedure describes the process under Windows 10/11:
5353
Please read [Building in Windows 2010 or 11 with Linux Subsystem](https://github.com/iNavFlight/inav/blob/master/docs/development/Building%20in%20Windows%2010%20or%2011%20with%20Linux%20Subsystem.md)
5454
and follow the instructions up to "Building with Make".
5555

56-
To activate MSP by default, go to the directory `src/main/target/[your target]`.
57-
If no config.c exists, create a new text file with this name and the following content:
58-
59-
```
60-
/*
61-
* This file is part of INAV.
62-
*
63-
* INAV is free software: you can redistribute it and/or modify
64-
* it under the terms of the GNU General Public License as published by
65-
* the Free Software Foundation, either version 3 of the License, or
66-
* (at your option) any later version.
67-
*
68-
* INAV is distributed in the hope that it will be useful,
69-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
70-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71-
* GNU General Public License for more details.
72-
*
73-
* You should have received a copy of the GNU General Public License
74-
* along with INAV. If not, see <http://www.gnu.org/licenses/>.
75-
*/
76-
77-
#include <stdint.h>
78-
79-
#include "platform.h"
80-
#include "io/serial.h"
81-
82-
void targetConfiguration(void)
83-
{
84-
serialConfigMutable()->portConfigs[findSerialPortIndexByIdentifier(SERIAL_PORT_USARTX)].functionMask = FUNCTION_MSP;
85-
serialConfigMutable()->portConfigs[findSerialPortIndexByIdentifier(SERIAL_PORT_USARTX)].msp_baudrateIndex = BAUD_115200;
86-
}
87-
88-
```
89-
90-
If the file already exists, add the following lines in the function `void targetConfiguration(void)` (before the last `}`)
91-
92-
```
93-
serialConfigMutable()->portConfigs[findSerialPortIndexByIdentifier(SERIAL_PORT_USARTX)].functionMask = FUNCTION_MSP;
94-
serialConfigMutable()->portConfigs[findSerialPortIndexByIdentifier(SERIAL_PORT_USARTX)].msp_baudrateIndex = BAUD_115200;
95-
```
96-
97-
Replace the X in SERIAL_PORT_USARTX (in both lines) with the number of UART/serial port on which MSP is to be activated.
56+
In the step 'prepare build environment' add the option `-DMSP_UART=SERIAL_PORT_USARTX` to `cmake`
57+
58+
Replace the X in SERIAL_PORT_USARTX with the number of UART/serial port on which MSP is to be activated.
9859

9960
Example:
100-
For UART 2: `SERIAL_PORT_USART2`
101-
For UART 3: `SERIAL_PORT_USART3`
61+
For UART 2: `cmake -DMSP_UART=SERIAL_PORT_USART2 ..`
62+
For UART 3: `cmake -DMSP_UART=SERIAL_PORT_USART3 ..`
10263
etc.
10364

104-
Save the file and build the firmware as described in the document above.
65+
Build the firmware as described in the document above (`make [YOUR_TARGET]`).
10566

10667
## Flashing via Uart:
10768

src/main/fc/config.c

+8
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ void createDefaultConfig(void)
284284
featureSet(FEATURE_AIRMODE);
285285

286286
targetConfiguration();
287+
288+
#ifdef MSP_UART
289+
int port = findSerialPortIndexByIdentifier(MSP_UART);
290+
if (port) {
291+
serialConfigMutable()->portConfigs[port].functionMask = FUNCTION_MSP;
292+
serialConfigMutable()->portConfigs[port].msp_baudrateIndex = BAUD_115200;
293+
}
294+
#endif
287295
}
288296

289297
void resetConfigs(void)

0 commit comments

Comments
 (0)