Skip to content

Commit 11987a1

Browse files
Migrate CLion page (needs update still) and doc tips page
1 parent badacc9 commit 11987a1

File tree

7 files changed

+321
-3
lines changed

7 files changed

+321
-3
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ site/
44

55
# Python venv
66
.venv/
7-
venv/
7+
venv/
8+
9+
# Mac stuff
10+
.DS_Store

docs/.nav.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ nav:
99
- contributing.md
1010
- maintainers.md
1111
- mbed-history-and-mbed-ce.md
12-
- For Developers: for-developers
12+
- For Mbed CE Developers: for-developers
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# Doxygen Documentation Tips
2+
3+
This page will collect some tips on how to write and structure documentation so that it fits into the Mbed CE docs.
4+
5+
## Running Doxygen Locally
6+
If you have created or edited significant amounts of documentation, it's recommended to run Doxygen locally to check your docs. After installing Doxygen (>=1.9.1), docs can be generated by opening a terminal in the `mbed-os` root folder and running:
7+
8+
```
9+
$ doxygen ./doxyfile_options
10+
```
11+
12+
Docs will be generated in the BUILD folder, and any errors will be printed to the screen.
13+
14+
## File Header
15+
16+
At minimum, each file should contain a block like this near the top:
17+
18+
```cpp
19+
/**
20+
* \file
21+
*
22+
* Copyright (c) 202X SOME-NAME
23+
* SPDX-License-Identifier: Apache-2.0
24+
*
25+
* \brief <one-sentence description of what's in this file>
26+
*/
27+
```
28+
29+
The [\file](https://www.doxygen.nl/manual/commands.html#cmdfile) command tells Doxygen to include stuff from this file in the output docs. The \brief command sets the description of the file.
30+
31+
## Groups
32+
In order to organize the documentation into manageable chunks, Doxygen groups have been used. These group commands create a hierarchy in the output docs:
33+
34+
![Doc Group Hierarchy](img/docs-hierarchy.png)
35+
36+
The top-level group is mbed-os-public ("Public API"), which is defined in AnalogIn.h (for some reason). All public code should be defined in this group or one of its subgroups. For instance, if you wanted to add a new driver API alongside I2C and SPI, you'd add that into the `drivers-public-api` group, which would put it under "Public API" &gt; "Drivers" in the hierarchy.
37+
38+
### Adding Code to an Existing Group
39+
To add entities (defines, functions, classes) in code to an existing group, they need to be surrounded by a structure like this:
40+
41+
```cpp
42+
/**
43+
* \ingroup drivers-public-api
44+
* @{
45+
*/
46+
47+
/**
48+
* \brief Description of SomeFunction
49+
*/
50+
void SomeFunction();
51+
52+
/**
53+
* \brief Description of MyNewDriver
54+
*/
55+
class MyNewDriver
56+
{
57+
...
58+
};
59+
60+
/// @}
61+
```
62+
63+
Note: You must be careful that "@}" and "@{" are correctly matched within a file, or a doxygen error will be produced. Additionally, note that Doxygen groups **cannot span namespace boundaries**.
64+
65+
For example, the following is incorrect and will create a (hard to diagnose) error:
66+
67+
```cpp
68+
/**
69+
* \ingroup drivers-public-api-gpio
70+
* @{
71+
*/
72+
73+
namespace mbed {
74+
75+
class SomeClass
76+
{
77+
...
78+
};
79+
80+
/// @}
81+
82+
}
83+
```
84+
85+
Instead, the Doxygen commands must be inside the namespace boundaries:
86+
87+
```cpp
88+
89+
namespace mbed {
90+
91+
/**
92+
* \ingroup drivers-public-api-gpio
93+
* @{
94+
*/
95+
96+
class SomeClass
97+
{
98+
...
99+
};
100+
101+
/// @}
102+
103+
}
104+
```
105+
106+
This is, similarly, not OK:
107+
108+
```cpp
109+
110+
namespace mbed {
111+
112+
/**
113+
* \ingroup drivers-public-api-gpio
114+
* @{
115+
*/
116+
117+
void foo();
118+
119+
namespace detail
120+
{
121+
void bar();
122+
}
123+
124+
void baz();
125+
126+
/// @}
127+
128+
}
129+
```
130+
131+
Tedious though it is, you must do:
132+
133+
```cpp
134+
135+
namespace mbed {
136+
137+
/**
138+
* \ingroup drivers-public-api-gpio
139+
* @{
140+
*/
141+
142+
void foo();
143+
144+
/// @}
145+
146+
namespace detail
147+
{
148+
void bar();
149+
}
150+
151+
/**
152+
* \ingroup drivers-public-api-gpio
153+
* @{
154+
*/
155+
156+
void baz();
157+
158+
/// @}
159+
160+
}
161+
```
162+
163+
Thankfully, if your file contains only a single class, you can completely skip the @{ and @} and just add the class to the group directly:
164+
```cpp
165+
/**
166+
* \brief Description of MyNewDriver
167+
* \ingroup drivers-public-api
168+
*/
169+
class MyNewDriver
170+
{
171+
...
172+
};
173+
```
174+
175+
### Adding Code to a New Group
176+
If, instead, you want to create a new group for your new driver, you'd use the defgroup command:
177+
178+
```cpp
179+
/**
180+
* \defgroup my-driver-group My Driver Human-Readable Name
181+
* \ingroup drivers-public-api
182+
* @{
183+
*/
184+
185+
class MyNewDriver
186+
{
187+
...
188+
};
189+
190+
/// @}
191+
```
192+
193+
This will create a new group in your code. It can be referenced by \ingroup commands as `my-driver-group`, and will show as "My Driver Human-Readable Name" in the output docs.
194+
195+
Note: A group name should only be defined by a \defgroup command **in one place**.
196+
197+
## Rules for Extraction
198+
There are several rules that control whether a given entity (function, constant, class, etc) in code is or is not extracted into the documentation. Missing something? Check that all of the following conditions are satisfied:
199+
200+
1. The code file containing the entity is not excluded by `EXCLUDE_PATTERNS` in doxyfile_options
201+
1. The code file containing the entity has a Doxygen comment somewhere with an `\file` command in it.
202+
2. The section of code containing the entity is not inside an `#ifdef` block, or, if it is, that the relevant define is included in the `PREDEFINED` block in doxyfile_options. Currently this has to be updated manually :(
203+
3. The specific entity is documented. Since doxygen is configured with `EXTRACT_ALL` as false, only entities with a `/**` or `///` comment will be included in the docs.
204+
205+
Note: for documenting one-line things like macros and enum entries, the `///<` construct is helpful. The following:
206+
207+
```cpp
208+
#define MY_DEFINE_1 1 ///< Docs for define one
209+
#define MY_DEFINE_2 2 ///< Docs for define two
210+
```
211+
212+
is equivalent to:
213+
214+
```cpp
215+
/// Docs for define one
216+
#define MY_DEFINE_1 1
217+
218+
/// Docs for define two
219+
#define MY_DEFINE_2 2
220+
```
221+
222+
## Documenting Overridden Functions
223+
If you've used Javadoc, you might be familiar with the "@inheritDoc" directive, which is used to copy the documentation from a superclass function to a function in a subclass that overrides it. Doxygen, in contrast, does not have this directive. Instead, if you override a superclass function, just don't add any docs to it at all. This will cause Doxygen to copy the docs from the superclass.
17.8 KB
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# CLI Setup
2+
3+
This page will show you how to take an existing Mbed CE project, build it, and debug it using command line tools.
4+
5+
## Building
6+
1. Open a terminal in the project directory.
7+
2. Create and enter a build directory: `mkdir build && cd build`
8+
3. Run CMake: `cmake .. -GNinja -DCMAKE_BUILD_TYPE=Develop -DMBED_TARGET=<your mbed target>`
9+
- Valid options for the MBED_TARGET option are any supported Mbed OS board target, such as `LPC1768` or `NUCLEO_F429ZI`
10+
- The Develop build type is recommended for normal development work, but there is also the Debug build type which disables optimizations, and the Release build type which disables debug information.
11+
4. Build the project by running `ninja`
12+
5. If the project has an executable which can be flashed, and you have an upload method configured (see below), run `ninja flash-<executable>` to upload it to a connected device.
13+
14+
## Debugging
15+
16+
Suppose you want to debug an executable by the name of MyProgram.
17+
18+
1. First, if you haven't already, you will need to make sure the project is configured to use an upload method that supports debugging. Read about upload methods on the [Upload Methods page](../../upload-methods.md), and select a method to use using the `-DUPLOAD_METHOD=<method>` flag to CMake.
19+
2. Now, plug in your target and start a GDB server for it by running `ninja gdbserver` in the build directory.
20+
3. Finally, open another terminal in the build directory and run `ninja debug-MyProgram`. You should be dropped into a GDB session connected to your target!
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# CLion Setup
2+
3+
This page will show you how to take an existing Mbed CE project and use it with the CLion IDE.
4+
5+
## Installing CLion
6+
7+
Note: CLion is a paid product for commercial use, costing about $100 yearly (there's a subscription, but if you cancel it you can keep using your current version forever). However, it is free for students if you fill out the application [here](https://www.jetbrains.com/community/education/#students). There is also a free 30-day trial available for everyone. I (Jamie) can say that it's the best C++ IDE I've personally used, and I highly recommend giving it a shot.
8+
9+
1. Download the CLion installer from the [download page](https://www.jetbrains.com/clion/download/).
10+
a. You can also use the [JetBrains Toolbox](https://www.jetbrains.com/toolbox-app/) app to make installing and updating multiple JetBrains IDEs easier.
11+
2. On Windows/Mac, run the installer and go through the install. You can then run CLion from your OS menu. On Linux, you'll get a tar file instead. Extract the tar file to Downloads, and move the folder to /opt/. Then, you will be able to run CLion by executing `/opt/clion-20xx.x.x/bin/clion.sh` in a terminal.
12+
3. The first time you open CLion you will get a license screen. You can use the "start trial" button to just use the 30 day trial, or if you have a license you should log in with your JetBrains account.
13+
4. You should now be at the IDE start screen!
14+
15+
![image](https://user-images.githubusercontent.com/2099358/187101127-f3cdba83-2932-4c56-8eba-8e96ec781c1b.png)
16+
17+
## Importing the Project
18+
1. Now, in CLion, click on Open, then browse to the root folder of your project. Then, click OK.
19+
20+
![image](https://user-images.githubusercontent.com/2099358/187101223-2e95b918-11b6-4275-9dc8-d4e063f83f45.png)
21+
22+
2. You'll likely get the below trust dialog box. Click on Trust Project.
23+
24+
![image](https://user-images.githubusercontent.com/2099358/187101279-83d64ed6-0e80-4671-93bf-ac8b935d6f67.png)
25+
26+
3. If this is your first project, CLion will ask about setting up a toolchain. You can accept the defaults here and click Next, because the Mbed build system overrides the compiler selection.
27+
28+
![image](https://user-images.githubusercontent.com/2099358/187101341-b8bb3788-61be-4182-b44e-979d81f223a4.png)
29+
30+
4. Now, you will get a wizard to create a build profile. For now, change the "Name" and "Build type" settings to "Develop". Also, in the "CMake Options" field, set MBED_TARGET to match your board name (e.g. `-DMBED_TARGET=NUCLEO_L452RE_P` for the Nucleo L452RE board). Also, optionally you can specify the [upload method](https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods) to use. Or, leave this unset to use the Mbed OS defaults for your board.
31+
- If you need Debug or Release configurations, you can come back here later and create them following the same process.
32+
33+
![Build Profiles Screen](https://user-images.githubusercontent.com/2099358/188508936-ed9958f1-ae2c-472d-b507-ef7bec556419.png)
34+
35+
Finally, hit Finish.
36+
37+
5. If all goes well, you should see the CMake project successfully configure and load. If not, you may need to double-check the [toolchain setup guide](https://github.com/mbed-ce/mbed-os/wiki/Toolchain-Setup-Guide) to make sure everything is set up OK.
38+
39+
NOTE: When working with Mbed projects, the Tools > CMake > Reset Cache and Reload Project option is your friend if things break. If your project did not find the compilers successfully, things moved on the disk, or you're getting other errors, make it your first recourse to try this option.
40+
41+
![image](https://user-images.githubusercontent.com/2099358/187102104-81c52e9c-dbd8-435c-82fa-20eb68a25dc7.png)
42+
43+
## Flashing Code
44+
45+
To flash code, find the entry labeled `flash-<your target>` in the menu at the top right. Then, click the hammer button (NOT the play button).
46+
47+
![image](https://user-images.githubusercontent.com/2099358/187102170-dfa3beb1-9d19-4333-8d67-a5e92c3a07d0.png)
48+
49+
Note: Mbed OS tends to clutter this menu up with its own targets. To find your target quickly, you can just start typing with the menu open, and it will search the list. Maybe this is obvious to you but it took me like 4 years to find this...
50+
51+
![image](https://user-images.githubusercontent.com/2099358/187102307-85664d9f-78ee-4c06-8503-9cec7c4cc232.png)
52+
53+
## Debugging
54+
1. First, if you haven't already, you will need to make sure the project is configured to use an upload method that supports debugging. Read about upload methods on the [Upload Methods page](https://github.com/mbed-ce/mbed-os/wiki/Upload-Methods), and select a method to use using the -DUPLOAD_METHOD=<method> flag to CMake. Note: you can edit the CMake flags that you initially configured by going to Settings > Build, Execution, Deployment > CMake.
55+
2. Additionally, you will need to set the `MBED_CLION_PROFILE_NAME` CMake variable to match the exact name of the profile. This is needed in order to generate debug configuration files correctly.
56+
![image](https://user-images.githubusercontent.com/2099358/220048699-4a22c44a-ccac-49db-9e2e-c9a003c2405b.png)
57+
3. In CLion, find the GDB debug configuration for your executable in the targets menu. This will be near the bottom and start with "GDB", then your target name. Make sure to select the one that matches your build type too -- if you are working in the Develop configuration, don't pick the Debug one!
58+
59+
![image](https://user-images.githubusercontent.com/2099358/220049391-a89dc7b4-188a-48fd-96fa-446c8263ad68.png)
60+
61+
4. With the configuration selected, click the green bug button at the top. If source files have been modified, the code will be rebuilt and downloaded to the target. Then, GDB will start.
62+
63+
Note: If you wish to have the code stop at main(), you must set a breakpoint there before starting the debug session.
64+
65+
Note: With CLion, the GDB command line console is available by going to the GDB tab in the Debug panel. You can use this console in parallel with the GUI to evaluate expressions and set breakpoints.
66+
67+
![image](https://user-images.githubusercontent.com/2099358/187105850-0632954a-6ecb-44ae-960d-d848ef732cc8.png)
68+
69+
Note: To reset the MCU, press the R-with-a-bar-over-it button.
70+
71+
### Tips
72+
- **Increasing GDB Timeout:** Sometimes, on Mbed, when you have deeply nested stack frames and lots of local variables, GDB can take a very long time to load after you hit a breakpoint, on the order of a minute. This can cause CLion to time out and terminate the debugger session. You can change the timeout by following [these instructions](https://www.jetbrains.com/help/clion/configuring-debugger-options.html#gdb-startup). I'd recommend at least 120000 ms.

docs/getting-started/ide_cli_setup/vscode_setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ You can watch this part in video version - [Youtube guide](https://youtu.be/9ZDH
123123
5. Click on the bottom bar where it says "No Kit Selected". Then, choose "[Unspecified]" from the menu (the Mbed build scripts will find the compilers).
124124
![VS Code Unspecified Kit](img/vs-code-unspecified-kit.png)
125125

126-
7. Now, select your variant. Use Ctrl-Shift-P and find CMake: Select Variant or use same on bottom bar. Then choose the variant you want. I'd recommend starting with the Develop one for general use.
126+
7. Now, select your variant. Use Ctrl-Shift-P and find CMake: Select Variant or use same on bottom bar. Then choose the variant you want. I'd recommend starting with the Develop one for general use.
127127
![VS Code Selecting a Variant](img/vs-code-select-variant.png)
128128
![VS Code Variant Dialog](img/vs-code-variant-dialog.png)
129129

0 commit comments

Comments
 (0)