You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
summary: "This guide demonstrates how to integrate external libraries into NuttX applications using static libraries and cross-compilation. Learn how to build a library on x86, integrate it into the NuttX simulation environment, and cross-compile for RISC-V targets like the ESP32-C6, all without moving your codebase into the NuttX directory structure."
8
+
summary: "This guide demonstrates how to integrate external libraries into NuttX applications using static libraries and cross-compilation. Learn how to build a library on x86, integrate it into the NuttX simulation environment, and cross-compile for RISC-V targets like the ESP32-C6, all without moving your entire codebase into the NuttX directory structure."
9
9
---
10
10
11
11
## Introduction
12
12
13
-
When moving your application to NuttX, you often need to add your existing software stack to the NuttX image. This software may run on a different RTOS or even on an x86 environment, but sometimes it must run on multiple target devices. This article shows how to build NuttX with your custom application without moving your entire stack to the NuttX directory. You use a static library and cross-compilation to achieve this.
13
+
When moving your application to NuttX, you may need to add your existing codebase to the NuttX build environment. That is a common scenario where the user application does not interact with hardware (such as data processing and analysis) but must run on the target devices. Those applications are usually tested on a x86 computer and adapted to run on a RTOS.
14
14
15
-
This article is divided into three parts. The first part introduces and builds the sample library on x86. Then, a second part decribes how to add the library to the NuttX simulation environment and finally, the last part cross-compiles to RISC-V and runs the example on the ESP32-C6.
15
+
This article shows how to build NuttX with your custom application without moving your entire stack to the NuttX directory. You use a static library and cross-compilation to achieve this.
16
+
17
+
This article is divided into three parts. The first part introduces and builds the sample library on x86. Then, a second part decribes how to add the library to the NuttX simulation environment. The third part cross-compiles to RISC-V and runs the example on the ESP32-C6. Finally, the fourth part concludes the article.
16
18
17
19
## Using an example library
18
20
@@ -34,15 +36,19 @@ The reference project is available in [this repository](https://github.com/fdcav
34
36
The `hex-converter` library exposes one single function called `hex_to_rgb`. The user provides a pointer to a string representing the hex color and a pointer
35
37
to an array where the R, G, and B values are copied. It is a simple application but very useful as an example.
36
38
37
-
Clone the repository and build it according to the steps in the README file to produce the static library. To confirm that everything works, run the provided `main` example program. This program accepts a hexadecimal color string as input.
39
+
Now, we should use the library on our x86 machine and see how it operates.
40
+
41
+
1. Clone the repository
42
+
2. Build the library according to the steps in the README file
43
+
3. Execute the provided `main` example program:
38
44
39
45
```bash
40
46
$ ./main "#1A2B3C"
41
47
Input: #1A2B3C
42
48
RGB: (26, 43, 60)
43
49
```
44
50
45
-
At this point, the directory should contain a static library called `libhex_to_rgb.a` that will be added to the NuttX build system.
51
+
At this point, the directory should contain a static library called `libhex_to_rgb.a`.
46
52
47
53
## Testing on NuttX Simulation
48
54
@@ -53,8 +59,9 @@ The simplest way to test this library on NuttX is to modify the ready-to-use Hel
53
59
54
60
With your NuttX environment ready, follow these steps:
55
61
56
-
1. Copy `libhex_to_rgb.a` from the hex-converter repository to `apps/examples/hello` (the Hello World example directory).
57
-
2. In `apps/hello/Make.defs`, add the hex library, library path, and include path.
62
+
1. Clone the example repository and build `libhex_to_rgb.a` as discussed in `Using an example library`
63
+
2. Copy `libhex_to_rgb.a` to `apps/examples/hello` (the Hello World example directory)
64
+
3. In `apps/hello/Make.defs`, add the hex library, library path, and include path
58
65
59
66
The Make.defs file should look like this:
60
67
```
@@ -134,7 +141,7 @@ Success! We can compile our library externally, link it to a NuttX application,
134
141
## Using the library on ESP32C6
135
142
136
143
Now that simulation works, we must look into a real use case that requires the same code to work on hardware.
137
-
For this, we must compile the library to be supported on our RISC-V target.
144
+
For this, we should recompile the library to be supported on our RISC-V target.
138
145
139
146
### Cross-compilation
140
147
@@ -190,7 +197,7 @@ This article demonstrates how to integrate external libraries into NuttX applica
190
197
191
198
The static library approach offers several advantages. You can develop and test your code on an x86 machine without flashing the target device. The same library works across different architectures with minimal changes, requiring only a recompilation step. This workflow saves development time and simplifies the porting process.
192
199
193
-
By following these steps, you can add existing software stacks to NuttX without moving your entire codebase into the NuttX directory structure. This approach maintains separation between your application code and the RTOS, making maintenance and updates easier.
200
+
By following these steps, you can add existing applications to NuttX without moving your entire codebase into the NuttX directory structure. This approach maintains separation between your application code and the RTOS, making maintenance and updates easier.
0 commit comments