Date
1 - 6 of 6
DTS own node DT_N_S_ undeclared
Piotr Barszczewski <piotr@...>
Hello, I'm writing an application for nrf52832 based board ADC + voltage divider functionalty as in the great nRF battery example https://docs.zephyrproject.org/latest/samples/boards/nrf/battery/README.html. I'm adapting it to support multiple vbatt nodes from DTS and while on the code layer it's quite simple I'm struggling with the DTS. My board dts file contains this part:
The devicetree snippet seems ok /* Existence and alternate IDs: */ #define DT_N_S_vbatt_S_vbatt0_EXISTS 1 #define DT_N_INST_0_voltage_divider DT_N_S_vbatt_S_vbatt0 #define DT_N_NODELABEL_vbatt_lipo DT_N_S_vbatt_S_vbatt0 except for the DT_N_S_vbatt_S_vbatt0 which is not defined anywhere and as a result I'm getting: zephyr/include/devicetree.h:73:17: error: 'DT_N_S_vbatt_S_vbatt_lipo' undeclared here (not in a function); did you mean 'DT_N_S_vbatt_S_vbatt_lipo_ORD'? What else should I do to make my own DTS node be usable in the source file? I'm following the docs, referencing it by #define VBATT_LIPO DT_PATH(vbatt, vbatt_lipo) which is in line with the guides and docs but the DT_N_S_* is missing and I don't have a clue on how could I fix this. Did anyone experience this before and could point me to where I could find a solution? Been trying for days now without result. Best regards |
|
Kumar Gala
On Mar 5, 2021, at 9:55 AM, Piotr Barszczewski <piotr@...> wrote:That looks normal. What does the code you are building look like? What else should I do to make my own DTS node be usable in the source file? I'm following the docs, referencing it by #define VBATT_LIPO DT_PATH(vbatt, vbatt_lipo) which is in line with the guides and docs but the DT_N_S_* is missing and I don't have a clue on how could I fix this.I think the .dts you have looks reasonable, my guess is the issue is more on the code usage side. Your define of VBATT_LIPO will give you a node reference which by its self is not useful. Its useful only w/regards to the macros in include/devicetree.h If you can share a snip of what the code looks like will probably be easier to see what might be the issue. - k |
|
Kumar Gala
On Mar 5, 2021, at 9:55 AM, Piotr Barszczewski <piotr@...> wrote: Oh, noticed your DT_PATH(batt, vbatt_lipo) is not correct. Try: #define VBATT_LIPO DT_PATH(batt, vbatt0) or #define VBATT_LIPO DT_NODELABEL(vbatt_lipo) - k |
|
Piotr Barszczewski <piotr@...>
Hello, Thank you for your response. My code is very similar to https://github.com/zephyrproject-rtos/zephyr/blob/master/samples/boards/nrf/battery/src/battery.c with the change that I’ve refactored it to accept different instances instead of supporting single #define VBATT DT_PATH(vbatt) . It’s practically 1:1 with what I needed so it seemed more reasonable to approach this way. Regarding #define VBATT_LIPO DT_NODELABEL(vbatt_lipo) and #define VBATT_LIPO DT_PATH(vbatt, vbatt0) I’ve tried this but the result is that in the end /* Existence and alternate IDs: */ #define DT_N_S_vbatt_S_vbatt0_EXISTS 1 #define DT_N_INST_0_voltage_divider DT_N_S_vbatt_S_vbatt0 #define DT_N_NODELABEL_vbatt_lipo DT_N_S_vbatt_S_vbatt0 Always points to non-existing DT_N_S_vbatt_S_vbatt0. It’s not clear to me where it should it be defined if not from DTS. Best regards |
|
Kumar Gala
On Mar 5, 2021, at 11:26 AM, Piotr Barszczewski <piotr@...> wrote:So you are seeing correct behavior. The are several ways to get a NODE reference (DT_PATH and DT_NODELABEL) are 2 of them. They should expand to DT_N_S_vbatt_S_vbatt0. (This is meant to be concatenated with other identifies to resolve to an actual define in the generated header - via the macros on devicetree.h). It will not resolve to a meaningful value that can be compiled by itself. It has to be used in connection with another macro in devicetree.h to get some data from the dts node. For example if you wanted the "output-ohms” for vbatt0 you’d do something like: int out_ohms = DT_PROP(VBATT_LIPO, output_ohms); That would resolve to: int out_ohms = 3300000; - k |
|
Piotr Barszczewski <piotr@...>
Thank you very much. I understand more now and was able to find my mistake. I’ve focused too much on trying to get DT_N_S_vbatt_S_vbatt0 to be defined while the mistake was somewhere else - in my case it was a DEVICE_DT_GET(DT_IO_CHANNELS_CTLR(VBATT_LIPO)) further - as you previously indicated that there might be the source of the problem. Thank you again for your time and help!
Best regards |
|