作業系統之前的程式 for stm32f4discovery (0.5) - newlib

https://github.com/jsnyder/arm-eabi-toolchain 這個 toolchain 會使用 newlib 來當作 standard c library, 我的版本是這個:
arm-eabi-toolchain/newlib-2013.05/

如何證明有使用 c lib 呢? 試著使用 setjmp/longjmp 並編譯程式, 可以參考以下範例:
https://github.com/descent/stm32f4_prog/tree/master/myjmp
執行後, 運作正確。我實在很驚訝, 作業系統之前的程式怎麼有 standard c library 可用, 我一直以為無法使用 standard c library, 雖然我知道有些和平台無關的 function 是可以拿來用的, ex: memset, strcpy ... 但我沒想到有這麼好的運氣可以使用 standard c library。當然有些底層的東西得要自己補完, 例如令人害怕的 printf。

我非常不建議寫 os kernel 的人使用 standard c library, 每行程式都儘可能由自己完成才是, 否則你就會在 os 技術拼圖上缺了一角, 都搞到這麼底層了, 把所有秘密掀開來, 知道所有一切的結果, 會讓人很充實、開心。

要怎麼完全不用 library 全部都自己手工寫呢? 加上 -nostdlib -nodefaultlibs 即可, 或不是使用任何不是你寫的 function, 這樣就要自己把 setjmp/longjmp 生出來, 成就感十足。

相關 gcc options:
  • -nodefaultlibs
  • -nostdlib
  • -ffreestanding
  • -nostartfiles

newlib 提供了很好的範例讓我們參考一個 standard c library 是怎麼做出來的, 不用和 glibc 這種大怪物奮鬥, 若能自己編譯起來執行, 相信底層功力會大增。newlib/newlib/libc/machine/i386/ 下有我們熟悉的 memcmp, memset 的 source code; arm 的部份在 newlib/newlib/libc/machine/arm, 當然, 有可能缺東缺西, 可參考 ref 5 裡的 Howto: Porting newlib A Simple Guide 補上自己所需要的 funcion。不過開發 os 倒不需要用上 standard c library, 相關所需要的 library 本來就要自己打造。

Bionic 是 Android C Library, 也可參考裡頭的實作。

newlib ref:
  1. http://sourceware.org/newlib/
  2. ftp://sourceware.org/pub/newlib/index.html
  3. http://blog.csdn.net/qb_2008/article/details/8228061
  4. http://wenku.baidu.com/view/e85042fa941ea76e58fa04ae.html
  5. Howto: Porting newlib A Simple Guide
Version: 2.15.0 (2020-09-28) Keil.STM32F4xx_DFP.2.15.0.pack Download Updated Pack to STM32Cube_FW_F4 Firmware Package version V1.25.1 using HAL Drivers V1.7.9. STM32CubeMX integration (Version 6.0.1): Added support for Timebase Source TIMx (FrameworkCubeMX_gpdsc.ftl). Removed non-existent include path. CMSIS Flash Algorithm: Corrected STM32F42xxx_43xxx_OPT Algorithm. CMSIS SVD: Updated STM32F42*.svd, STM32F43*.svd files. CMSIS-Driver: I2C: Corrected 2 byte reception in master mode. MCI: Replaced empty delay loops with _NOP(). SPI: Corrected PowerControl function (to return error if Initialize was not called, to abort active transfer if power off was requested). Updated GetDataCount function to give accurate count in DMA mode. Corrected Control function (abort in DMA mode, software controlled slave select in slave mode, TI Frame Format selection, ignore bus speed for slave mode). Corrected Uninitialize function (to power off the peripheral if it is powered). Corrected SPI3_SCK pin configuration. Corrected DMA MemDataAlignment configuration. USART: Corrected DMA MemDataAlignment configuration. USBD_HS/USBH_HS: OTG_HS ULPI clock disabled in low power if internal PHY is used to enable proper operation of OTG_HS port in FS mode during CPU sleep. CAN/EMAC/USBD/USBH: Removed macros already provided by cmsis_compiler.h. Updated Boards Examples: Migrated CubeMX projects to V6.0.1 and updated config files. Changed variant selection to "MDK-Plus" where possible. Updated all USB Host/Device examples with user templates from MDK-Middleware v7.11.1. Terminating app_main thread with osThreadExit() to avoid endless loop Updated MS Windows UBS driver files.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值