no1wudi opened a new pull request, #18540:
URL: https://github.com/apache/nuttx/pull/18540
## Summary
This change adds a comprehensive sysctl driver for the Kendryte K210 SoC,
providing essential clock and reset control functionality. The driver enables
proper clock management, peripheral reset control, and configurable CPU
frequency.
* **Why:** The K210 SoC requires proper clock and reset management for
peripherals and CPU frequency configuration. Previously, the CPU frequency was
hardcoded to 400MHz with limited clock control capabilities. This driver
provides:
- Complete clock enable/disable with proper two-stage APB/peripheral
enable pattern
- Peripheral reset control with proper timing
- Clock frequency query for PLL, CPU, APB buses, and all peripherals
- PLL frequency calculation and runtime CPU frequency configuration
- Configurable CPU frequency via Kconfig (40-600 MHz range)
* **What:**
- **New driver**: `k210_sysctl.c` - Full sysctl implementation with
clock/reset control
- **New header**: `k210_sysctl.h` - Public API for clock and reset
operations
- **Extended hardware definitions**: `hardware/k210_sysctl.h` - Complete
register definitions
- **Kconfig option**: `K210_CPU_FREQ` - Target CPU frequency in Hz
(default 400MHz, range 40-600MHz)
- **Updated build files**: CMakeLists.txt and Make.defs to include new
driver
- **Updated clockconfig**: Modified to use new sysctl driver for CPU
frequency setup
* **How:**
- The sysctl driver is built unconditionally for K210 boards as it
provides essential functionality
- CPU frequency can be configured via `make menuconfig` → "K210 CPU target
frequency (Hz)"
- Runtime API available for peripheral clock/reset management
- PLL frequency calculation ensures accurate clock generation
## Impact
* Is new feature added? YES - Complete sysctl driver with clock/reset
control and configurable CPU frequency
* Is existing feature changed? YES - CPU frequency configuration moved from
hardcoded macro to Kconfig option
* Impact on user? NO - Default behavior unchanged (400MHz), but users now
have full clock control capabilities
* Impact on build? NO - New source files added to build system
* Impact on hardware? YES - K210 architecture only, enables proper
peripheral clock/reset management
* Impact on documentation? YES - Documentation update recommended to
describe new Kconfig option and sysctl API
* Impact on security? NO
* Impact on compatibility? NO - Fully backward compatible, existing
configurations continue to work
## Testing
I confirm that changes are verified on local setup and works as intended:
* Build Host(s): Linux x86_64, GCC 15.2.0, riscv-none-elf-gcc
* Target(s): RISC-V K210, maix-bit:nsh
### Build Verification
```bash
cmake -S nuttx -B build
-DBOARD_CONFIG=boards/risc-v/k210/maix-bit/configs/nsh
cmake --build build -j8
# Build successful, nuttx.bin generated
```
### CPU Frequency Testing
Tested CPU frequencies from 40MHz to 590MHz in 50MHz increments using
`getprime` benchmark to verify:
1. Kconfig configuration works correctly
2. CPU frequency changes take effect at runtime
3. Performance scales linearly with frequency
Testing results:
```
Frequency getprime time Performance
(MHz) (msec) (relative)
--------- ------------- ----------
40 9897 1.0x
90 4416 2.2x
140 2829 3.5x
190 2073 4.8x
240 1644 6.0x
290 1351 7.3x
340 1169 8.5x
390 1013 9.8x
440 894 11.1x
490 800 12.4x
540 724 13.7x
590 675 14.7x
```
Results demonstrate:
- CPU frequency configuration via Kconfig works correctly across full range
- Performance scales linearly with frequency (40MHz to 590MHz = ~14.7x
speedup)
- Full range of 40-600 MHz is functional and stable
### Runtime Verification
Verified on real K210 hardware (Maix Bit board):
- NSH shell boots successfully at all tested frequencies
- UART communication stable at 115200 baud
- `getprime` benchmark runs correctly
- No crashes or instability observed
## Files Changed
- `arch/risc-v/src/k210/CMakeLists.txt` - Add k210_sysctl.c to build
- `arch/risc-v/src/k210/Make.defs` - Add k210_sysctl.c to build
- `arch/risc-v/src/k210/Kconfig` - Add K210_CPU_FREQ configuration option
- `arch/risc-v/src/k210/hardware/k210_sysctl.h` - Extended register
definitions
- `arch/risc-v/src/k210/k210_clockconfig.c` - Use new sysctl driver
- `arch/risc-v/src/k210/k210_sysctl.c` - New sysctl driver implementation
- `arch/risc-v/src/k210/k210_sysctl.h` - New public API header
## PR verification Self-Check
* [x] This PR introduces only one functional change (sysctl driver with
clock/reset control).
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation.
* [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]