Unable to use compiler defines to define pioasm values #757
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk#757
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I have created a library where the definitions of which pins to use are controlled by compiler defines in the CMakeLists.txt file.
For most of the pins used by my various PIO programs this works fine as they are set in the initialisation code and therefore the code has access to the defines as it forms part of the .pio.h file (or even in the main body of the code.)
However, one pin that I wait on is a gpio pin (wait 0 gpio ) and therefore this is directly referenced in the PIO code, which does not have access to any of the compiler defines, so I cannot work out a clean way to be able to control this from the make file.
Suggestions on the forum include using the C preprocessor, which makes sense, but has issues as the pioasm syntax isn't particularly compatible. I've also looked at adding support for command line defines to pioasm, but that's also not clean as the complete list of compiler defines would probably also include non integer values which would need to be ignored.
So there doesn't seem to be a clean way to do this, at the moment I'm hardcoding that value into the pio files, but this make the library difficult to use by others.
I assume there's some reason you can't use
wait 0 pin?Section 3.3.1 of https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf talks about
.define ( PUBLIC ) <symbol> <value>- does that not do what you want? (Apologies if that's a stupid question, but I've not used pioasm myself)It's potentially possible, but the particular pin is one that has a gpout clock generated, so it's limited already, if I have to make it part of a consecutive sequence of other in-pins then it becomes very restrictive. I haven't actually tried to see if it's even possible.
This is kind of the wrong way around ... it allows you to define something in the pio file that's then available in the .h file. I want to define everything in the make file (as per PICO_DEFAULT_UART_TX_PIN for example) and then have it usable in the pio file.
Ahhh. So perhaps the most sensible option would be to add a pioasm flag that'd allow you to override a defined symbol?
e.g. if you had
.define WAIT_PIN 3in your.piofile, and then invokedpioasm -DWAIT_PIN=5 ...it'd behave as though you'd specified.define WAIT_PIN 5?Yes, that's one approach (and I did get a quick proof of concept working) but I would argue it doesn't need to necessarily override an existing value, it could create a completely new one.
However ... you then still need a way to pass the relevant defines to that process in the make file ... the easiest approach is to pass all of the COMPILER_DEFINITIONS, however this then would include non-integer based defines which would need to be excluded/ignored ... so still messy and somewhat counter-intuitive.
I actually prefer the idea that you used the C preprocessor to pre-process the file, that way any macros can be handled relatively cleanly ... however that doesn't work well with the syntax of pio files as it stands. Hence my concern about a lack of an obvious approach.
That's why I was suggesting only overriding existing
.definedirectives - that way e.g.pioasm -DPICO_SDK_PATH=../../pico-sdk ...would just be ignored (because there'd be no.define PICO_SDK_PATH 2in the.piofile), and you'd still have the "default".define WAIT_PIN 3being used. (no need for#ifndefetc.)But it sounds like you might have more experience with preprocessors and COMPILER_DEFINITIONS than me, so there might be subtleties that I'm overlooking 🤷♂️
consider for 1.6.0
Using "pico_generate_pio_header_pre" as I've implemented here:
https://github.com/visenri/pico_cmake_extras
allows the use of all c preprocessor features.
So it can be used to include other files or use preprocessor macros defined elsewhere.
@kilograham:
This should be easy to integrate into the next SDK release.
@visenri As already mentioned, I don't have much familiarity with preprocessors, but just out of curiosity how does your approach address the "that doesn't work well with the syntax of pio files as it stands" concern that @essele mentioned above?
@lurch:
I don't know what @essele was concerned about, maybe he/she meant that expressions defined in a preprocessor macro may not be valid for pio expressions, you must take into account that expressions used must be valid for pio asm:
VALID:
INVALID:
error: invalid character: >
in set x, (1 > 0)
Aside from that consideration, you can use the preprocessor as long as you keep the syntax valid.
VALID:
Including a configuration file:
"myConfig.h"
Preprocessor stuff only or "c" specific stuff hiding it using preprocessor macro __PIO_ASM_COMPILER
This file can be included in both c/c++ and pio files.
In myProgram.pio
Global compiler definitions are also available:
CMakeLists.txt
In myProgram.pio
When you understand how the preprocessor works, and what is valid syntax for pio asm there should be no problem or conflict.