Repository navigation
Port for Tricore tc1.6.2 - #841
s3neubauer wants to merge 5 commits into
Conversation
The port adds ThreadX support for the Infineon AURIX TC3xx family. It keeps thread contexts in CSA chains. Threads enter the scheduler through a system call, and interrupt handlers request the switch through a GPSR software interrupt at the lowest priority. It relies on the Infineon iLLD 1.22.0, which is not included; AURIX_ILLD_DIR names it at build time. The example runs the ThreadX demo on CPU0 of the TC375 Lite Kit.
…ample The port uses the intrinsics of the AURIX GCC and its own register definitions. The example uses the start-up code of the AURIX GCC with its own linker script and trap table.
The test runs the regression suite on the TC375 Lite Kit as one image and reports over the UART. It builds on the example of the port.
The regression BSP now contains its own tx_initialize_low_level.c, and testcontrol.c takes the size and placement of its test memories from TEST_CONTROL_MEMORY_SIZE, TESTS_MEMORY_SIZE and TEST_MEMORY_PLACEMENT, whose defaults leave other builds unchanged. The README of the test names the AURIX GCC version the tests ran with and its download link. The example and the regression test build without warnings with AURIX GCC 03_2026 on Linux and Windows.
|
Hi @s3neubauer. Thank you for this important contribution. I am on the road this week, but I will try to review it. Worst case, you will hear from me early next week. I authorised the CI run, so please keep your eyes on the result. |
There was a problem hiding this comment.
Hi @s3neubauer.
Overall, a strong first contribution. Thanks again.
All 13 TriCore regression configurations built and linked without warnings with AURIX GCC 03_2026. The GCC 14 Linux regression run passed 123/123 tests. I did not run the TriCore images on hardware.
Please address the idle low-power path and the unoptimized Release settings in the inline comments. Measured line and branch coverage for the new port code is also missing. The supplied AURIX GCC has no-op __gcov_init and __gcov_dump routines and no __gcov_exit; a --coverage regression build fails to link. Please provide coverage results using another target collection method, and identify any uncovered paths with their justification.
| break; | ||
| } | ||
| #ifdef TX_LOW_POWER | ||
| tx_low_power_enter(); |
There was a problem hiding this comment.
The idle loop clears ICR.IE before calling tx_low_power_enter(). Its TX_RESTORE restores that disabled posture, so TX_LOW_POWER_USER_ENTER runs with interrupts disabled. A callback waiting for the timer cannot receive its wake ISR. tx_low_power_exit() also runs immediately, before a wake interrupt is handled. Please allow wake interrupts during the user callback and handle exit on the wake path.
There was a problem hiding this comment.
Fixed. The idle loop now calls tx_low_power_enter() with interrupts enabled, so a WAIT in TX_LOW_POWER_USER_ENTER wakes on the timer interrupt. _tx_timer_interrupt calls tx_low_power_exit() before before processing the interrupt. The idle loop calls it only when no interrupt has done so. A new configuration low_power_wait_build test the Low Power Mode by using the wait instruction. All regression tests passed.
| set(CMAKE_C_FLAGS "-mcpu=tc38xx -std=c99 -fno-common -fstrict-volatile-bitfields -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags") | ||
| set(CMAKE_EXE_LINKER_FLAGS "-mcpu=tc38xx -Wl,--gc-sections" CACHE INTERNAL "exe link flags") | ||
| set(CMAKE_C_FLAGS_DEBUG "-O0 -g3" CACHE INTERNAL "c debug compiler flags") | ||
| set(CMAKE_C_FLAGS_RELEASE "-O0" CACHE INTERNAL "c release compiler flags") |
There was a problem hiding this comment.
Release, RelWithDebInfo, and MinSizeRel all use -O0, so production builds are unoptimized. Please set appropriate optimization flags and verify the context-switch tests with those settings.
There was a problem hiding this comment.
I have changed the build flags accordingly. The TriCore regression test has 2 new configurations, release_build and minsizerel_build. Both run the full ThreadX regression suite on the TC375 Lite Kit and pass 97/0/0.
The toolchain file compiled the build types Release, RelWithDebInfo and MinSizeRel with -O0. The idle loop called tx_low_power_enter() with interrupts disabled, so TX_LOW_POWER_USER_ENTER could not wait for an interrupt, and it called tx_low_power_exit() before a wake interrupt ran. The toolchain file now compiles Release with -O2, RelWithDebInfo with -O2 -g3 and MinSizeRel with -Os. The idle loop calls tx_low_power_enter() with interrupts enabled. _tx_timer_interrupt calls tx_low_power_exit() before it counts the tick, and the idle loop calls it when no interrupt has done so. The regression test adds the configurations low_power_wait_build, which waits with the WAIT instruction, release_build (-O2) and minsizerel_build (-Os). Its coverage build (TX_TRICORE_COVERAGE) instruments the ThreadX library with gcov; bsp/tx_gcov.c provides the runtime that the AURIX GCC lacks, and a debugger reads the counters from RAM. Section 11 of the port readme justifies the port code that the tests do not execute. All configurations of the regression test pass 97/0/0 on the TC375 Lite Kit. Assisted-by: Claude Code (claude-opus-5-5) <noreply@anthropic.com>
fdesbiens
left a comment
There was a problem hiding this comment.
Hi @s3neubauer, thanks for updating the port and running the tests on the TC375 Lite Kit. The Release-family builds now use optimization, and the low-power hook now runs with wake interrupts enabled. I ran the current merge candidate with GCC 14 on Linux and all 135 tests passed. Before merging, I’d like to confirm the wake timing case below on the TC375 and get measured line and branch coverage for the new port.
| set(low_power_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_LOW_POWER) | ||
| # The low-power callback waits for the next interrupt. | ||
| set(low_power_wait_build -DTX_QUEUE_MESSAGE_MAX_SIZE=32 -DTX_LOW_POWER | ||
| "-DTX_LOW_POWER_USER_ENTER=__asm__ volatile (\"wait\")") |
There was a problem hiding this comment.
This hook executes WAIT unconditionally. If an interrupt makes a thread runnable and returns just before WAIT, the scheduler can still wait until the next interrupt. The periodic timer can mask that delay. Could you add a focused TC375 Lite Kit test that forces this ordering and checks that the ready thread runs without a second interrupt?
There was a problem hiding this comment.
You are absolutely right. What exact behavior do you expect here?
The timer ISR can fire right before WAIT is executed. If that ISR makes a thread ready, the event is not lost because the core goes to sleep afterwards. The ready state persists, and the next interrupt wakes the CPU. At that point the scheduler sees every thread that became ready, both from the first and the second interrupt, and schedules them. No event is lost. Would that be OK?
The only difference is timing. Without WAIT, the thread runs immediately after the first interrupt. With WAIT, it runs only after the second one.
The provided implementation was for testing only, therefore it was provided as simple DEFINE.
There was a problem hiding this comment.
A more general question about low power: should this be part of the port, or is it left to the end user to implement?
One possible approach: the timer ISR checks its return address to determine whether it interrupted the idle loop just before entering sleep. If so, the ISR modifies the return address to skip the sleep instruction. Whether this works depends on how tx_low_power_enter() is implemented. With this approach, it would make sense to call tx_low_power_enter() with interrupts disabled. The function would then be responsible for setting everything up so that the core reliably wakes up again.
__asm__ volatile (" enable\n" \
".globl tx_port_tricore_low_power_wait\n" \
"tx_port_tricore_low_power_wait:\n" \
" wait\n" \
".globl tx_port_tricore_low_power_end\n" \
"tx_port_tricore_low_power_end:\n" \
::: "memory"); | `test_control_failed_tests` and `test_control_system_errors` shall be 0. | ||
| 2. Save DSPR0, for example with TRACE32: | ||
| `Data.SAVE.Binary dspr0.bin D:0x70000000++0x3BFFF`. | ||
| 3. Write the `.gcda` files from the dump and the ELF file with a host tool |
There was a problem hiding this comment.
Could you share the measured line and branch coverage for the TriCore port, including the uncovered paths and why they remain uncovered? I built a prototype exporter and verified it with a 32-bit GCC 11 debugger dump. If you share the DSPR0 dumps and the matching regression.elf and .gcno files, I can use them to generate the report.
There was a problem hiding this comment.
Yes, no problem I can share both. I run this for all configuration. I can double check if all port related parts get covered with one configuration. I can also share the final report if this is easier for you.
Summary
This pull request adds a ThreadX port for the Infineon AURIX TC3xx family (TriCore TC1.6.2 core) with the AURIX GCC, an example for the AURIX TC375 Lite Kit, and a build that runs the ThreadX regression suite on that board.
Port
Thread contexts are kept in CSA chains. Threads enter the scheduler through a system call; interrupt handlers request a context switch through a GPSR software interrupt at the lowest priority. The port uses no driver library: it relies on the intrinsics and the start-up code (crt0-tc38xx.o) of the AURIX GCC. TX_PORT_USE_CCPN, TX_NOT_INTERRUPTABLE, TX_TIMER_PROCESS_IN_ISR, TX_EXECUTION_PROFILE_ENABLE and TX_LOW_POWER have port-specific code.
Change to shared test code
test/tx/regression/testcontrol.c takes the size and placement of its test memories from TEST_CONTROL_MEMORY_SIZE, TESTS_MEMORY_SIZE and TEST_MEMORY_PLACEMENT. The defaults keep the previous values, so other builds are unchanged. The TC375 needs smaller memories placed in DSPR1.
Verification
Hardware: AURIX TC375 Lite Kit (KIT_A2G_TC375_LITE) with AURIX GCC 03_2026 (GCC 11.3.1, Binutils 2.40.50).
The regression suite ran on the board in 13 configurations (the 7 of test/tx/cmake plus 6 for port options); each passed 97 tests with 0 failures and 0 system errors.
The example and the regression test build without warnings on Linux and Windows.
AI assistance
The development was assisted by Claude Code (Claude Opus 5.5). Files with AI-assisted changes carry the AI disclosure line. Code was reviewed and verified on the TC375 Lite Kit.
PR checklist