{"id":20575190,"url":"https://github.com/mysterywolf/rt_vsnprintf_full","last_synced_at":"2025-04-14T17:52:21.350Z","repository":{"id":45883186,"uuid":"428565017","full_name":"mysterywolf/rt_vsnprintf_full","owner":"mysterywolf","description":"rt_vsnprintf完整功能版本 | Fully functional version of rt_vsnprintf","archived":false,"fork":false,"pushed_at":"2024-09-29T06:00:09.000Z","size":210,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T06:22:53.586Z","etag":null,"topics":["printf","rt-thread","snprintf","vsnprintf"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mysterywolf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-11-16T07:52:59.000Z","updated_at":"2024-12-09T13:45:52.000Z","dependencies_parsed_at":"2024-03-19T02:42:29.064Z","dependency_job_id":"948bb6bc-7408-4974-90c9-c473f99d73f1","html_url":"https://github.com/mysterywolf/rt_vsnprintf_full","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysterywolf%2Frt_vsnprintf_full","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysterywolf%2Frt_vsnprintf_full/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysterywolf%2Frt_vsnprintf_full/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mysterywolf%2Frt_vsnprintf_full/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mysterywolf","download_url":"https://codeload.github.com/mysterywolf/rt_vsnprintf_full/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248931386,"owners_count":21185173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["printf","rt-thread","snprintf","vsnprintf"],"created_at":"2024-11-16T05:38:27.004Z","updated_at":"2025-04-14T17:52:21.318Z","avatar_url":"https://github.com/mysterywolf.png","language":"C","funding_links":[],"categories":["Packages"],"sub_categories":["System"],"readme":"# rt_vsnprintf 完整功能版本\n\n在RT-Thread的kservice.c源码中的这些函数的实现是为了满足RT-Thread内核的自持能力，即在不依赖标准C库的情况下，RT-Thread核心代码也可以正常运行，因此rt_kprintf、rt_sprintf、rt_snprintf、rt_vsnprintf这类打印函数（或者称之为rt_kprintf家族函数）仅仅满足内核的使用需求，不会实现完整的、和标准C库一致的功能，以减少ROM占用。但是，很多社区小伙伴希望rt_kprintf家族函数可以支持上更多的功能（例如打印浮点数据等等）。因此，本软件包实现了该功能。\n\n本软件包实现了rt_kprintf家族函数的全功能版本，因为rt_kprintf家族函数的核心功能都是调用rt_vsnprintf函数，因此只需要重新实现rt_vsnprintf函数即可。本软件包基于开源项目[printf](https://github.com/eyalroz/printf)重新实现了rt_vsnprintf，在4.1.0以及以上的RT-Thread版本中，只需要安装本软件包即可。若RT-Thread低于4.1.0版本，需要手动将kservice.c内的rt_vsnprintf函数注释掉，再安装本软件包。\n\n关于newlib下使用自带printf函数的问题可以参考这边帖子的评论区：https://club.rt-thread.org/ask/article/2b0a1d202135b205.html\n\n## 接管标准C库的printf家族函数（仅支持4.1.0及以上版本）\n本软件包有三个功能宏开关，是否允许本软件包接管printf、sprintf以及snprintf函数，默认为yes，即接管。\n也就是说，安装本软件包后，即便没有使能libc(RT_USING_LIBC)，你可以正常的使用printf、sprintf以及snprintf函数，当你调用这三个函数时，会自动被rt_kprintf、rt_sprintf、rt_snprintf函数接管。你可以正常使用printf家族函数的所有功能。\n\n```c\n#include \u003cstdio.h\u003e\n\nprintf(\"hello world\\n\");\n```\n\n## ROM占用\nGCC下占用8.6KB, Keil下占用8KB。远小于开启标准C库的ROM占用。\n\n## 如何添加该软件包\n\n```\nRT-Thread online packages\n    system packages ---\u003e\n        enhanced kernel services ---\u003e\n            [*] rt_vsnprintf_full: fully functional version of rt_vsnprintf ---\u003e\n                    Version (latest)  ---\u003e\n```\n\n- 使用 `RT-Thread Studio` 打开 `RT-Thread Settings`, 点击添加软件包，输入关键字 `printf`, 添加 `rt_vsnprintf_full` 软件包，保存\n\n  ![1](figures/1.png)\n\n\n- 软件包目录下多出了一个  `rt_vsnprintf_full-latest` 包\n\n  ![2](figures/2.png)\n\n\n- 打开 rt_vsnprintf.c，发现其中也实现了 rt_vsnprintf\n\n  ```c\n  rt_int32_t rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)\n  {\n      return __vsnprintf(out_buffer, buf, size, fmt, args);\n  }\n  ```\n\n- 注释掉 kservice.c 中的  rt_vsnprintf **(只针对4.1.0版本以下)**\n\n- 重新编译并运行 `rt_kprintf ` 和 `LOG_I`, 浮点数打印正常\n  ![3](figures/3.png)\n\n\n\n## 维护\n\n[Meco Man](https://github.com/mysterywolf)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysterywolf%2Frt_vsnprintf_full","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmysterywolf%2Frt_vsnprintf_full","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmysterywolf%2Frt_vsnprintf_full/lists"}