Skip to content

Commit 27b172f

Browse files
committed
finished the writeup and appeased the linter
1 parent f83271a commit 27b172f

File tree

2 files changed

+116
-24
lines changed

2 files changed

+116
-24
lines changed

FprimeZephyrReference/ReferenceDeployment/Top/ReferenceDeploymentTopology.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ void configureTopology() {
6565
rateGroup10Hz.configure(rateGroup10HzContext, FW_NUM_ARRAY_ELEMENTS(rateGroup10HzContext));
6666
rateGroup1Hz.configure(rateGroup1HzContext, FW_NUM_ARRAY_ELEMENTS(rateGroup1HzContext));
6767

68-
gpioDriver.open(ledGpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
69-
gpioBurnwire0.open(burnwire0Gpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
70-
gpioBurnwire1.open(burnwire1Gpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
68+
// gpioDriver.open(ledGpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
69+
// gpioBurnwire0.open(burnwire0Gpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
70+
// gpioBurnwire1.open(burnwire1Gpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
7171
}
7272

7373
// Public functions for use in main program are namespaced with deployment name ReferenceDeployment

README.md

Lines changed: 113 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,51 +70,143 @@ make gds
7070

7171
# How to add a component
7272

73-
1. Overlay
73+
Note: This guide has not been confirmed for UART and I2C connections yet, please edit and add clarification as needed
7474

75+
### 1. Update the Board Overlay (TODO Change this if we are using the dtsi instead)
7576

76-
you also want to add aliases
7777

78+
Declare your hardware devices in the Zephyr device tree overlay or .dts file
79+
80+
81+
GPIO examples:
82+
```
7883
aliases {
7984
burnwire0 = &burnwire0;
8085
burnwire1 = &burnwire1;
8186
};
8287
88+
burnwire0: burnwire0 {
89+
gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>;
90+
label = "Burnwire 0, 28";
91+
};
92+
93+
...
94+
```
95+
96+
I2C Example
97+
98+
```
99+
/ {
100+
aliases {
101+
myi2c = &i2c1; // alias for the I²C bus
102+
mysensor = &sensor0; // alias for the device on the bus
103+
};
104+
};
105+
106+
&i2c1 {
107+
status = "okay";
108+
mysensor: sensor0@48 {
109+
compatible = "myvendor,my-sensor";
110+
reg = <0x48>; // I²C address of the sensor
111+
};
112+
};
113+
```
114+
For GPIOs, the alias points to a pin node.
115+
116+
For I²C, you can alias either the bus or a device on the bus.
117+
118+
For UART, the alias points to the UART hardware peripheral.
119+
120+
### 2. Pull the device tree nodes into C++ structs that Zephyr can use. Zephyr drivers require a handle to the hardware node; this step binds your C++ driver to the actual hardware configuration from the overlay.
121+
122+
TODO: Check if the open step needs to happen (can't find clear documentation on it!@@@@@@@@)
123+
124+
125+
In RefereneceDeploymentTopology.cpp, you want to get it from the device tree.
83126

84-
2.
127+
Start by creating a node identifier https://docs.zephyrproject.org/latest/build/dts/api-usage.html#dt-node-identifiers. In this example we use DT_ALIAS because we assume you used ALIAS from step 1, but you can create the node identifier however you want.
85128

86-
In RefereneceDeploymentTopology.cpp
87-
static const struct gpio_dt_spec burnwireGpio = GPIO_DT_SPEC_GET(DT_ALIAS(burnwire0), gpios);
129+
#### For GPIO:
130+
https://docs.zephyrproject.org/apidoc/latest/structgpio__dt__spec.html
88131

89-
gpioBurnwire0.open(burnwire0Gpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
90-
gpioBurnwire1.open(burnwire1Gpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
132+
```
133+
static const struct gpio_dt_spec burnwire0Gpio = GPIO_DT_SPEC_GET(DT_ALIAS(burnwire0), gpios);
134+
```
135+
- GPIO_DT_SPEC_GET → Reads pin number, port, and flags from device tree.
136+
137+
138+
#### For a I2C, you would use a i2c_dt_spec instead. https://docs.zephyrproject.org/apidoc/latest/structi2c__dt__spec.html
139+
```
140+
static const struct i2c_dt_spec sensor =
141+
I2C_DT_SPEC_GET(DT_ALIAS(mysensor));
142+
```
91143

144+
- I2C_DT_SPEC_GET → Gets I²C bus, address, and speed.
92145

93-
and
146+
#### For UART:
147+
https://docs.zephyrproject.org/latest/build/dts/howtos.html
148+
```
149+
const struct device *const uart_dev =
150+
DEVICE_DT_GET(DT_ALIAS(myuart));
151+
```
94152

95-
gpioDriver.open(burnwire0Gpio, Zephyr::ZephyrGpioDriver::GpioConfiguration::OUT);
153+
- DEVICE_DT_GET → Retrieves the UART peripheral.
96154

97-
in topology.fpp
155+
### 3. Declare each driver in the F´ topology and connect it to your component.
98156

99-
connections burnwire1 {
100-
burnwire1.gpioSet -> gpioDriver.gpioWrite
101-
}
157+
The topology defines how components communicate (ports) and ensures F´ can route commands/events between drivers and components.
102158

159+
#### In Topology.fpp
103160

161+
```
162+
# GPIO drivers
163+
instance gpioBurnwire0
164+
instance gpioBurnwire1
165+
166+
167+
# Connect burnwire to GPIOs
168+
connections burnwire {
169+
burnwire0.gpioSet -> gpioBurnwire0.gpioWrite
170+
}
171+
172+
# Connect sensor to I²C driver
173+
connections mysensor {
174+
mySensor.i2cSend -> i2cDriver.i2cWrite
175+
i2cDriver.i2cRead -> mySensor.i2cReceive
176+
}
177+
178+
# Connect UART to communication component
179+
connections comms {
180+
comms.tx -> uartDriver.write
181+
uartDriver.read -> comms.rx
182+
}
183+
```
104184

105185

106-
in instances.fpp
186+
4. Add Component Instances
187+
188+
Assign Base IDs and create instances of each driver/component. Base IDs are used internally by F´ to route commands/events. Every component must have a unique Base ID.
189+
190+
in instances.fpp create an instance of your new pin. Get the base Id by looking at the instructions for the number at the top of file under Base ID Convention of the instances.fpp
191+
192+
```
107193
instance gpioBurnwire0: Zephyr.ZephyrGpioDriver base id 0x10015100
194+
```
108195

109-
instance gpioBurnwire1: Zephyr.ZephyrGpioDriver base id 0x10015200
196+
5. Make a new component in the components folder. Use the command
110197

198+
fprime-util new --component Components/New_Component
111199

112-
in topology.fpp
200+
6. Add the component (not the port) to the instances.fpp and topology.fpp folder
113201

114-
instance gpioBurnwire0
115-
instance gpioBurnwire1
202+
In topology.fpp:
116203

117-
3. Make a new component in the components folder
118-
4. Add the component to the instances and topology folder
204+
```
205+
instance burnwire
206+
```
119207

120-
in topology.fpp also instance burnwire
208+
In instances.fpp:
209+
```
210+
instance burnwire: Components.Burnwire base id 0x10017000
211+
```
212+
Get the base Id by looking at the insrtecutions for the number at the top of file under Base ID Convention of the instances.fpp

0 commit comments

Comments
 (0)