cpu/native: introduce periph_i2c_mock#20430
Conversation
c94e3ff to
e5e81d1
Compare
865c036 to
f66aa4c
Compare
|
There's still a build error left, and I'd appreciated if the mocking part was somehow shown / tested. I've done both, but can't push directly to this branch, but you can pick the commits from cogip#1. |
fc45e56 to
333dc02
Compare
Thx for patches @chrysn . Applied and tested: > i2c_write_bytes 0 10 0 0 1 0 1 2
i2c_write_bytes 0 10 0 0 1 0 1 2
Command: i2c_write_bytes(0, 0x0a, 0x00, [0x00, 0x01, 0x00, 0x01, 0x02])
Mock write intercepted; this write of 5 byte(s) is still ignored.
Success: i2c_0 wrote 5 bytes |
chrysn
left a comment
There was a problem hiding this comment.
Great, let's go with this.
The failing test appears to expose an issue with the si1133 driver (missing includes), can you fix that in passing?
done 🤞 |
|
Awesome, thanks! |
crasbe
left a comment
There was a problem hiding this comment.
Just some small style related comments.
|
Thank you for getting back to this :) |
fef5ed6 to
f899055
Compare
I second this. The changes in the |
Activating Since this is just a mock implementation, there is no real benefit to building all those tests, as they are not relevant without real hardware. The alternative would be to blacklist native boards for those tests, but I am not a fan of this solution because:
I kept commits atomic for easier review, but I'm happy to squash related ones (e.g., all printf fixes) if you prefer. Let me know! 😉 |
crasbe
left a comment
There was a problem hiding this comment.
Just two small changes to get rid of two static erros.
Fix duplicate GPIO mode values on native platform when using Linux kernel 5.5 or later. The kernel renamed GPIOHANDLE_REQUEST_PULL_* flags to GPIOHANDLE_REQUEST_BIAS_PULL_* in version 5.5. Without this fix, both GPIO_IN_PU and GPIO_OD_PU would have the same fallback value (0xFF), causing compilation errors in switch statements. Error: "duplicate case value" Signed-off-by: Gilles DOFFE <[email protected]>
This allows I2C emulation on native architecture in the same way than periph_gpio_mock. All I2C functions from this driver are set as weak to be easily overridden in each application. Signed-off-by: Gilles DOFFE <[email protected]>
- Add missing modules.h include for IS_USED macro in atca.h - Fix printf format specifiers in psa_atca_se_driver.c: use %zu for size_t parameters instead of %d to prevent warnings on native platform Signed-off-by: Gilles DOFFE <[email protected]>
Native boards fail to link due to an upstream bug in cryptoauthlib's
test infrastructure. The file build/pkg/cryptoauthlib/test/cmd-processor.c
has incorrect conditional compilation logic:
#if defined(_WIN32) || defined(__linux__) || defined(__APPLE__)
int main(int argc, char* argv[]) { ... }
#elif defined(RIOT_APPLICATION)
int atca_run_cmd(char *command, size_t len) { ... }
#endif
On native boards, __linux__ is defined, so the code compiles a main()
function instead of atca_run_cmd(). This conflicts with RIOT's main()
and causes linker errors:
- multiple definition of 'main'
- undefined reference to 'atca_run_cmd'
On ARM boards, none of these platform macros are defined, so the code
correctly falls through to the RIOT_APPLICATION branch and compiles
atca_run_cmd() instead.
The fix would require patching cryptoauthlib to check RIOT_APPLICATION
before checking platform macros, or reporting this upstream to Microchip.
Signed-off-by: Gilles DOFFE <[email protected]>
Fix compilation errors on native boards caused by missing modules.h
include in driver headers that use IS_USED() in preprocessor directives.
The IS_USED macro is defined in modules.h and must be included in any
header file that uses it in #if directives.
Error: "missing binary operator before token '('"
Signed-off-by: Gilles DOFFE <[email protected]>
Fix compilation errors on native boards caused by missing ARRAY_SIZE macro definition. The macro is defined in container.h which is included by kernel_defines.h. On ARM/Cortex-M platforms, kernel_defines.h is indirectly included via cpu/cortexm_common/include/irq_arch.h, making ARRAY_SIZE available. On native platform, no CPU header includes kernel_defines.h, requiring explicit inclusion. Error: "implicit declaration of function 'ARRAY_SIZE'" Signed-off-by: Gilles DOFFE <[email protected]>
Signed-off-by: Gilles DOFFE <[email protected]>
Signed-off-by: Gilles DOFFE <[email protected]>
Signed-off-by: Gilles DOFFE <[email protected]>
Security warnings (telnet, stdio_udp, psa_crypto) were displayed even for info-* targets, polluting the output and breaking tools that parse make output (e.g., compile_and_test_for_board.py). These warnings are only relevant when actually building/running code, not when querying build system information. Signed-off-by: Gilles DOFFE <[email protected]>
f899055 to
ecc8bda
Compare
| #include <stdio.h> | ||
| #include <inttypes.h> |
There was a problem hiding this comment.
| #include <stdio.h> | |
| #include <inttypes.h> | |
| #include <stdio.h> | |
| #include <stdbool.h> | |
| #include <inttypes.h> |
I'm not sure why this error is triggered by adding kernel_defines.h tbh 🤔
There was a problem hiding this comment.
Because stdbool.h is included in various low-level headers according to the platform.
For example in irq_arch.h for all cortexm:
$ grep "stdbool.h" -r cpu/cortexm_common/
cpu/cortexm_common/include/irq_arch.h:#include <stdbool.h>
cpu/cortexm_common/include/mpu.h:#include <stdbool.h>So everything in "upper" code benefits from that includes.
There was a problem hiding this comment.
There should be more than expected, I try to find them with:
./dist/tools/compile_and_test_for_board/compile_and_test_for_board.py . native64 --no-test -j10
I will repush a bit later
Fix compilation error on native platform where bool type is used but stdbool.h is not explicitly included. On many platforms (ARM, AVR, etc.), stdbool.h is indirectly included via CPU headers, but on native this is not the case. Signed-off-by: Gilles DOFFE <[email protected]>
Fix compilation error on native platform where bool type is used but stdbool.h is not explicitly included. On many platforms, stdbool.h is indirectly included via CPU headers, but on native this is not the case. Signed-off-by: Gilles DOFFE <[email protected]>
Contribution description
This allows I2C emulation on native architecture in the same way than periph_gpio_mock.
All I2C function from this driver are set as weak to be easily overridden in each application.
Testing procedure