{"id":283772,"date":"2017-03-23T00:00:03","date_gmt":"2017-03-22T21:00:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=283772"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=283772","title":{"rendered":"Rust, Eclipse \u0438 STM32"},"content":{"rendered":"<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f:  <\/p>\n<ul>\n<li>\u0421\u0432\u0435\u0436\u0438\u0439 <a href=\"https:\/\/launchpad.net\/gcc-arm-embedded\">GNU ARM Embedded Toolchain<\/a><\/li>\n<li><a href=\"http:\/\/www.st.com\/en\/development-tools\/sw4stm32.html\">System Workbench for STM32<\/a> (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e) <\/li>\n<li><a href=\"https:\/\/eclipse.org\/cdt\/\">\u0421\u0432\u0435\u0436\u0438\u0439 Eclipse CDT<\/a><\/li>\n<li><a href=\"http:\/\/gnuarmeclipse.github.io\/\">GNU ARM Eclipse Plugin<\/a> <\/li>\n<li><a href=\"https:\/\/www.rust-lang.org\/en-US\/install.html\">Rust<\/a><\/li>\n<li><a href=\"https:\/\/marketplace.eclipse.org\/content\/rustdt\">RustDT<\/a>. \u0414\u043b\u044f \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c <a href=\"https:\/\/github.com\/RustDT\/RustDT\/blob\/master\/documentation\/UserGuide.md\">Racer, Rainicorn \u0438 rustfmt<\/a>.<\/li>\n<\/ul>\n<p>  \u0418\u0434\u0435\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043d\u0430 Rust \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0438\u043d\u043a\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0443\u043b\u0447\u0435\u0439\u043d\u0430 \u0434\u043b\u044f ARM. <br \/>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u043e \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Rust \u0438 \u0421.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>1. \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430 C<\/h3>\n<p>  \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 STM32CubeMX. \u0414\u043b\u044f \u0434\u0435\u043c\u043e-\u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:   <\/p>\n<ul>\n<li>SYS = Serial Wire (\u0435\u0441\u043b\u0438 \u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043f\u043e SWD) \u043b\u0438\u0431\u043e JTAG<\/li>\n<li>USART2 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Asynchronous<\/li>\n<li>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0438\u043d\u043e\u0432 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0440\u0442\u0443 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 GPIO_Output (\u043d\u0430\u0437\u043e\u0432\u0435\u043c \u0438\u0445 LED_R, LED_G, LED_B)<\/li>\n<\/ul>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/729\/eda\/bf6\/729edabf636fcdd62689fce1310d137a.png\" alt=\"image\"\/><\/p>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0422\u0443\u0442 \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043a\u0432\u0430\u0440\u0446\u0430 \u0438 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u043e\u0442\u0443.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b50\/bd3\/85a\/b50bd385ada4f3ae8e08aa82f6959b94.png\" alt=\"image\"\/><\/p>\n<p>  \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442. \u041d\u0430\u0437\u043e\u0432\u0435\u043c \u0435\u0433\u043e \u201cHwApi\u201d, \u0442.\u043a. \u044d\u0442\u043e\u0442 \u0441\u043b\u043e\u0439 \u043a\u043e\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u043d\u0430\u0434 \u0436\u0435\u043b\u0435\u0437\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043a\u043e\u0434\u0430 \u043d\u0430 Rust. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 IDE \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c SW4STM32.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/725\/f21\/98a\/725f2198af0a5978015b085e9e99275f.png\" alt=\"image\"\/><\/p>\n<p>  \u0415\u0441\u043b\u0438 Workbench \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f.<\/p>\n<p>   <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a6c\/bc2\/149\/a6cbc21490ea5ebd14b6f1b0491cba02.png\" alt=\"image\"\/><\/p>\n<h3>2. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0434\u043b\u044f \u0441\u0432\u0435\u0436\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Eclipse<\/h3>\n<p>  \u0425\u043e\u0442\u044c System Workbench \u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 Eclipse, \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0432 \u0441\u0432\u0435\u0436\u0435\u0439 \u043c\u0430\u0436\u043e\u0440\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Eclipse (Neon), \u0442.\u043a. RustDT \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 \u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 Eclipse. <br \/>  \u0422\u0430\u043a\u0436\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 GNU ARM Eclipse Plugin. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/226\/eb8\/e26\/226eb8e26d1095f2a78d87f4113cd2da.png\" alt=\"image\"\/><\/p>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0441\u043b\u0438\u043d\u043a\u043e\u0432\u0430\u0442\u044c \u043b\u0438\u0431\u0443, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e rust \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0441\u0432\u0435\u0436\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f GNU ARM Embedded Toolchain.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/2a7\/1d7\/c4d\/2a71d7c4d4c2fffacd67fb2b76566649.png\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438\u0437 System Workbench \u0432 Eclipse CDT. \u0412 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0443\u044e\u0442, \u043d\u043e \u044f \u0431\u0443\u0434\u0443 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u0442.\u043a. \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0441\u044c \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c HwApiLib \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445, \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043d\u0430 Rust \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430.<br \/>  \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u043f\u043a\u0438\/\u0444\u0430\u0439\u043b\u044b \u0432 \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442:  <\/p>\n<ul>\n<li>Drivers<\/li>\n<li>Inc<\/li>\n<li>Src<\/li>\n<li>startup<\/li>\n<li>STM32F103C8Tx_FLASH.ld<\/li>\n<\/ul>\n<p>  \u0415\u0441\u043b\u0438 Workbench \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d, \u0442\u043e \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u043e\u043a\u043d\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043a \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 (\u0438\u0437 \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0438 \u043d\u043e\u0432\u043e\u0433\u043e Eclipse) \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u043a\u043d\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0435. \u041e\u043a\u043d\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438 \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u0444\u043b\u0430\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u044b \u0432 \u0441\u043a\u043e\u0431\u043a\u0430\u0445.<br \/>  \u0415\u0441\u043b\u0438 Workbench \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u043e \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u043e\u0432, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043d\u0438\u0436\u0435. <\/p>\n<p>  \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c Defined Symbols:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/4ad\/c39\/092\/4adc39092e438882a39057bc2dc9715d.png\" alt=\"image\"\/><\/p>\n<p>  \u041f\u0443\u0442\u0438 \u043a \u043f\u0430\u043f\u043a\u0430\u043c, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 *.h \u0444\u0430\u0439\u043b\u044b:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/46c\/d76\/b50\/46cd76b501a805271a1bab32ae0f407e.png\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 \u201cOptimization\u201d \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e Optimize size(-Os).<br \/>  \u0414\u0430\u043b\u0435\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/56a\/b2d\/e21\/56ab2de21706a31015d738fa7564e4d5.png\" alt=\"image\"\/><\/p>\n<p>  \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u0441\u043a\u0440\u0438\u043f\u0442\u0443 \u043b\u0438\u043d\u043a\u0435\u0440\u0430 + \u043e\u0442\u043c\u0435\u0447\u0430\u0435\u043c \u0447\u0435\u043a\u0431\u043e\u043a\u0441 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043b\u0438\u043d\u043a\u043e\u0432\u043a\u0438 \u043d\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u043a\u043e\u0434\u0435 \u0441\u0435\u043a\u0446\u0438\u0439:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/af0\/189\/0ab\/af01890aba95439cbf0ed3d1d71c2d5f.png\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0432\u043a\u043b\u0430\u0434\u043a\u0435 \u0432\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0435\u043a\u0431\u043e\u043a\u0441 \u201cUse newlib-nano\u201d \u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0444\u043b\u0430\u0433 <code>-specs=nosys.specs<\/code>:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/cd9\/0c9\/94b\/cd90c994bdf81cfeb5335741c92ddb1d.png\" alt=\"image\"\/><\/p>\n<p>  \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0443\u0442\u0438 \u043a \u043f\u0430\u043f\u043a\u0430\u043c \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e31\/303\/b47\/e31303b478754208a9d52a873d60ace2.png\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u041e\u043a. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u0435\u043d\u044f\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 startup \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u0437\u0430\u0433\u043b\u0430\u0432\u043d\u0443\u044e .S, \u0447\u0442\u043e\u0431\u044b \u0444\u0430\u0439\u043b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u0438\u043b\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0435\u043a\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f8f\/43d\/649\/f8f43d64951bce512f1c9ce3e072282b.png\" alt=\"image\"\/><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440 (Run \u2014 Debug Configurations \u2014 GDB OpenOCD Debugging). \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043b\u044f OpenOCD \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0436\u0435\u043b\u0435\u0437\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 (\u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u0439\u043b \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f STM32F103C8x_SWD.cfg):<\/p>\n<p>  <code>source [find interface\/stlink-v2.cfg]<\/p>\n<p>  set WORKAREASIZE 0x5000<br \/>  transport select &quot;hla_swd&quot;<br \/>  set CHIPNAME STM32F103C8Tx<\/p>\n<p>  source [find target\/stm32f1x.cfg]<\/p>\n<p>  # use hardware reset, connect under reset<br \/>  reset_config none<\/code><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u043d\u0435\u043c\u0443, \u0442\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u043b\u044f OpenOCD \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 Workbench (\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Debugging options \u2014 Ac6).<br \/>  \u0412 Config options \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u043b\u0430\u0433 -f \u0438 \u043f\u0443\u0442\u044c \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0448\u0430\u0433\u0435 \u0444\u0430\u0439\u043b\u0443.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/834\/db0\/25a\/834db025a064bdd65ebb7c08f7ac8abb.png\" alt=\"image\"\/><\/p>\n<p>  \u0416\u043c\u0435\u043c Debug. \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0437\u0430\u043b\u0438\u043b \u043a\u043e\u0434 \u0432 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438 \u043d\u0430\u0447\u0430\u043b\u0430\u0441\u044c \u043e\u0442\u043b\u0430\u0434\u043a\u0430.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/39e\/87b\/cc9\/39e87bcc9abd157a0d54bdb567cb79c6.png\" alt=\"image\"\/><\/p>\n<p>  \u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c Rust \u043f\u0440\u043e\u0435\u043a\u0442.<br \/>  \u0422.\u043a. \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 stable \u0432\u0435\u0440\u0441\u0438\u0438, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u043c nightly \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430, \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u0432 cmd \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<p>  <code>rustup update<br \/>  rustup default nightly<\/code><\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430:<br \/>  <code>rustc -v --version<\/code><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/92f\/951\/a80\/92f951a806fda5964a85b6ab9a0f8150.png\" alt=\"image\"\/><\/p>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 rust \u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u043c\u043c\u0438\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 (\u0443\u043a\u0430\u0437\u0430\u043d \u0432 commit-hash). <\/p>\n<p>  <code>git clone git@github.com:rust-lang\/rust.git<br \/>  cd rust<br \/>  git checkout cab4bff3de1a61472f3c2e7752ef54b87344d1c9<\/code><\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e\u0434 ARM.<br \/>  <code>mkdir libs-arm<br \/>  rustc -C opt-level=2 -Z no-landing-pads --target thumbv7m-none-eabi -g src\/libcore\/lib.rs --out-dir libs-arm --emit obj,link<br \/>  rustc -C opt-level=2 -Z no-landing-pads --target thumbv7m-none-eabi -g src\/liballoc\/lib.rs --out-dir libs-arm -L libs-arm --emit obj,link<br \/>  rustc -C opt-level=2 -Z no-landing-pads --target thumbv7m-none-eabi -g src\/libstd_unicode\/lib.rs --out-dir libs-arm -L libs-arm --emit obj,link<br \/>  rustc -C opt-level=2 -Z no-landing-pads --target thumbv7m-none-eabi -g src\/libcollections\/lib.rs --out-dir libs-arm -L libs-arm --emit obj,link<\/code><\/p>\n<p>  \u0412 \u0431\u0443\u0434\u0443\u0449\u0435\u043c, \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 (rustup update) \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 \u0438 \u043f\u0435\u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f ARM, \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 rust.<\/p>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0441\u043e\u0437\u0434\u0430\u044e\u0442 Rust-\u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432 eclipse.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/bdc\/1a3\/3e4\/bdc1a33e4ed1c6277a53710a18ca784b.png\" alt=\"image\"\/><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1c8\/dca\/aac\/1c8dcaaac46251623fc661d8b1a4d505.png\" alt=\"image\"\/><\/p>\n<p>  Eclipse \u043f\u0440\u043e\u0441\u0438\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443, \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c \u0438 \u0443\u0442\u0438\u043b\u0438\u0442\u0430\u043c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 rust-\u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fc9\/f8a\/b25\/fc9f8ab2589ee4e0fbd67eabc97860df.png\" alt=\"image\"\/><\/p>\n<p>  \u041e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 C:\\Users\\%username%\\.cargo.<br \/>  Rust src \u2014 \u043f\u0443\u0442\u044c \u043a \u043f\u0430\u043f\u043a\u0435 src \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043a\u0430\u0447\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434:<br \/>  lib.rs  <\/p>\n<pre><code class=\"rust\">#![feature(macro_reexport)] #![feature(unboxed_closures)] #![feature(lang_items, asm)]  #![no_std] #![feature(alloc, collections)]  #![allow(dead_code)] #![allow(non_snake_case)]   extern crate alloc;  pub mod runtime_support; pub mod api;  #[macro_reexport(vec, format)] pub extern crate collections;  use api::*;   #[no_mangle] pub extern fn demo_main_loop() -&gt; ! { \tlet usart2 = Stm32Usart::new(Stm32UsartDevice::Usart2);  \tloop {   \t\tlet u2_byte = usart2.try_read_byte(); \t\tmatch u2_byte { \t\t\tSome(v) =&gt; { \t\t\t\tlet c = v as char; \t\t\t\t match c { \t\t\t\t\t'r' =&gt; { toggle_led(Stm32Led::Red); } \t\t\t\t\t'g' =&gt; { toggle_led(Stm32Led::Green); } \t\t\t\t\t'b' =&gt; { toggle_led(Stm32Led::Blue); }  \t\t\t\t\t_ =&gt; { usart2.print(&quot;cmd not found&quot;); } \t\t\t\t}\t\t \t\t\t} \t\t\t_ =&gt; {} \t\t}  \t\tdelay(1); \t} } <\/code><\/pre>\n<p>  api.rs \u2014 \u043f\u0440\u043e\u0441\u043b\u043e\u0439\u043a\u0430 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 Rust \u0438 C \u043a\u043e\u0434\u0430  <\/p>\n<pre><code class=\"rust\">use collections::Vec;  extern { \tfn stm32_delay(millis: u32); \tfn usart2_send_string(str: *const u8, len: u16); \tfn usart2_send_byte(byte: u8); \tfn usart2_try_get_byte() -&gt; i16; \tfn stm32_toggle_led(led: u8); \tfn stm32_enable_led(led: u8); \tfn stm32_disable_led(led: u8); }  pub fn delay(millis: u32) { \tunsafe { \t\tstm32_delay(millis); \t} }   #[derive(Copy, Clone)] pub enum Stm32UsartDevice { \tUsart2 }  #[derive(Copy, Clone)] pub struct Stm32Usart { \tdevice: Stm32UsartDevice }   impl Stm32Usart { \tpub fn new(device: Stm32UsartDevice) -&gt; Stm32Usart { \t\tStm32Usart { \t\t\tdevice: device \t\t} \t}  \tpub fn print(&self, str: &str) { \t\tlet bytes = str.bytes().collect::&lt;Vec&lt;u8&gt;&gt;(); \t\tself.print_bytes(bytes.as_slice()); \t}  \tpub fn print_bytes(&self, bytes: &[u8]) { \t\tunsafe { \t\t\tmatch self.device { \t\t\t\tStm32UsartDevice::Usart2 =&gt; usart2_send_string(bytes.as_ptr(), bytes.len() as u16) \t\t\t} \t\t} \t}  \tpub fn println(&self, str: &str) { \t\tself.print(str); \t\tself.print(&quot;\\r\\n&quot;); \t}  \tpub fn send_byte(&self, byte: u8) { \t\tunsafe { \t\t\tmatch self.device { \t\t\t\tStm32UsartDevice::Usart2 =&gt; usart2_send_byte(byte) \t\t\t} \t\t} \t}  \tpub fn try_read_byte(&self) -&gt; Option&lt;u8&gt; { \t\tunsafe { \t\t\tlet r = usart2_try_get_byte(); \t\t\tif r == -1 { return None; } \t\t\treturn Some(r as u8); \t\t} \t} }   pub enum Stm32Led { \tRed, \tGreen, \tBlue, \tOrange }  impl Stm32Led { \tfn to_api(&self) -&gt; u8 { \t\tmatch *self { \t\t\tStm32Led::Green =&gt; 2,  \t\t\tStm32Led::Blue =&gt; 3, \t\t\tStm32Led::Red =&gt; 1, \t\t\tStm32Led::Orange =&gt; 0 \t\t} \t} }  pub fn toggle_led(led: Stm32Led) { \tunsafe { \t\tstm32_toggle_led(led.to_api()); \t} }  pub fn enable_led(led: Stm32Led) { \tunsafe { \t\tstm32_enable_led(led.to_api()); \t} }  pub fn disable_led(led: Stm32Led) { \tunsafe { \t\tstm32_disable_led(led.to_api()); \t} } <\/code><\/pre>\n<p>  runtime_support.rs \u2014 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 Rust  <\/p>\n<pre><code class=\"rust\">extern crate core;  \/\/\/ Call the debugger and halts execution. #[no_mangle] pub extern &quot;C&quot; fn abort() -&gt; ! {     loop {} }  #[cfg(not(test))] #[inline(always)] \/\/\/ NOP instruction pub fn nop() {     unsafe {         asm!(&quot;nop&quot; :::: &quot;volatile&quot;);     } }  #[cfg(test)] \/\/\/ NOP instruction (mock) pub fn nop() {}  #[cfg(not(test))] #[inline(always)] \/\/\/ WFI instruction pub fn wfi() {     unsafe {         asm!(&quot;wfi&quot; :::: &quot;volatile&quot;);     } }  #[cfg(test)] \/\/\/ WFI instruction (mock) pub fn wfi() {}  #[lang = &quot;panic_fmt&quot;] fn panic_fmt(_: core::fmt::Arguments, _: &(&'static str, usize)) -&gt; ! {     loop {} }  #[lang = &quot;eh_personality&quot;] extern &quot;C&quot; fn eh_personality() {}   \/\/ Memory allocator support, via C's stdlib   #[repr(u8)] #[allow(non_camel_case_types)] pub enum c_void {     __variant1,     __variant2, }  extern &quot;C&quot; {     pub fn malloc(size: u32) -&gt; *mut c_void;     pub fn realloc(p: *mut c_void, size: u32) -&gt; *mut c_void;     pub fn free(p: *mut c_void); }  #[no_mangle] #[allow(unused_variables)] pub unsafe extern &quot;C&quot; fn __rust_allocate(size: usize, align: usize) -&gt; *mut u8 {     malloc(size as u32) as *mut u8 }  #[no_mangle] #[allow(unused_variables)] pub unsafe extern &quot;C&quot; fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {     free(ptr as *mut c_void); }  #[no_mangle] #[allow(unused_variables)] pub unsafe extern &quot;C&quot; fn __rust_reallocate(ptr: *mut u8,                                            old_size: usize,                                            size: usize,                                            align: usize)                                            -&gt; *mut u8 {     realloc(ptr as *mut c_void, size as u32) as *mut u8 } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b<br \/>  thumbv7m-none-eabi.json  <\/p>\n<pre><code>{     &quot;arch&quot;: &quot;arm&quot;,     &quot;cpu&quot;: &quot;cortex-m3&quot;,     &quot;data-layout&quot;: &quot;e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:64-v128:64:128-a:0:32-n32-S64&quot;,     &quot;disable-redzone&quot;: true,     &quot;executables&quot;: true,     &quot;llvm-target&quot;: &quot;thumbv7m-none-eabi&quot;,     &quot;morestack&quot;: false,     &quot;os&quot;: &quot;none&quot;,     &quot;relocation-model&quot;: &quot;static&quot;,     &quot;target-endian&quot;: &quot;little&quot;,     &quot;target-pointer-width&quot;: &quot;32&quot; } <\/code><\/pre>\n<p>  \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0432 \u043f\u0430\u043f\u043a\u0443 Rust \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u0430\u043f\u043a\u0443 libs-arm \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0434 ARM \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Rust.<\/p>\n<p>  \u0418\u0437\u043c\u0435\u043d\u044f\u0435\u043c Debug target, \u0442\u0430\u043a \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044e \u0441 \u043d\u0443\u0436\u043d\u044b\u043c\u0438 \u043d\u0430\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438<br \/>  <code>rustc -C opt-level=2 -Z no-landing-pads --target thumbv7m-none-eabi -g --crate-type lib -L libs-arm src\/lib.rs --emit obj,link<\/code><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b8a\/d21\/a4b\/b8ad21a4b52b46632c525ad5447d97ee.png\" alt=\"image\"\/><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/098\/0f4\/752\/0980f47524beeef25524a6b4ba81d801.png\" alt=\"image\"\/><\/p>\n<p>  \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c Rust-\u043f\u0440\u043e\u0435\u043a\u0442. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432 \u043f\u0430\u043f\u043a\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u0444\u0430\u0439\u043b lib.o.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u0421-\u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u044b api.h\/api.c, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 api.rs.<\/p>\n<p>  api.h<br \/>  <code>#ifndef SERIAL_DEMO_API_H_<br \/>  #define SERIAL_DEMO_API_H_<\/p>\n<p>  #include &quot;stm32f1xx_hal.h&quot;<\/p>\n<p>  void stm32_delay(uint32_t milli);<br \/>  void usart2_send_string(uint8_t* str, uint16_t len);<br \/>  void usart2_send_byte(uint8_t byte);<br \/>  int16_t usart2_try_get_byte(void);<\/p>\n<p>  void stm32_toggle_led(uint8_t led);<br \/>  void stm32_enable_led(uint8_t led);<br \/>  void stm32_disable_led(uint8_t led);<\/p>\n<p>  #endif<br \/>  <\/code><\/p>\n<p>  api.c<br \/>  <code>#include &quot;api.h&quot;<br \/>  #include &quot;stm32f1xx_hal.h&quot;<br \/>  #include &quot;stm32f1xx_hal_uart.h&quot;<br \/>  #include &quot;main.h&quot;<\/p>\n<p>  void stm32_delay(uint32_t milli) {<br \/>   HAL_Delay(milli);<br \/>  }<\/p>\n<p>  extern UART_HandleTypeDef huart2;<\/p>\n<p>  void usart2_send_string(uint8_t* str, uint16_t len) {<br \/>   HAL_UART_Transmit(&huart2, str, len, 1000);<br \/>  }<\/p>\n<p>  void usart2_send_byte(uint8_t byte) {<br \/>   while (!(USART2-&gt;SR & UART_FLAG_TXE));<br \/>   USART2-&gt;DR = (byte & 0xFF);<br \/>  }<\/p>\n<p>  int16_t usart2_try_get_byte(void) {<br \/>   volatile unsigned int vsr;<br \/>   vsr = USART2-&gt;SR;<br \/>   if (vsr & UART_FLAG_RXNE) {<br \/>   USART2-&gt;SR &= ~(UART_FLAG_RXNE);<br \/>   return (USART2-&gt;DR & 0x1FF);<br \/>   }<\/p>\n<p>  return -1;<br \/>  }<\/p>\n<p>  uint16_t stm32_led_to_pin(uint8_t led);<\/p>\n<p>  void stm32_toggle_led(uint8_t led) {<br \/>   HAL_GPIO_TogglePin(LED_R_GPIO_Port, stm32_led_to_pin(led));<br \/>  }<\/p>\n<p>  void stm32_enable_led(uint8_t led) {<br \/>   HAL_GPIO_WritePin(LED_R_GPIO_Port, stm32_led_to_pin(led), GPIO_PIN_SET);<br \/>  }<\/p>\n<p>  void stm32_disable_led(uint8_t led) {<br \/>   HAL_GPIO_WritePin(LED_R_GPIO_Port, stm32_led_to_pin(led), GPIO_PIN_RESET);<br \/>  }<\/p>\n<p>  uint16_t stm32_led_to_pin(uint8_t led) {<br \/>   switch (led) {<br \/>   case 1:<br \/>   return LED_R_Pin;<br \/>   case 2:<br \/>   return LED_G_Pin;<br \/>   case 3:<br \/>   return LED_B_Pin;<br \/>   default:<br \/>   return LED_B_Pin;<br \/>   }<br \/>  }<br \/>  <\/code><\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u044b\u0437\u043e\u0432 demo_main_loop() \u0432\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 main.<\/p>\n<p>  main.c<br \/>  <code>...<br \/>   \/* Infinite loop *\/<br \/>   \/* USER CODE BEGIN WHILE *\/<br \/>   while (1)<br \/>   {<br \/>   \/* USER CODE END WHILE *\/<\/p>\n<p>  \/* USER CODE BEGIN 3 *\/<br \/>   demo_main_loop();<br \/>   }<br \/>   \/* USER CODE END 3 *\/<br \/>  ...<br \/>  <\/code><\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0451 \u0441\u043b\u0438\u043d\u043a\u043e\u0432\u0430\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043d\u0430 C \u0438 \u0443\u043a\u0430\u0436\u0435\u043c \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a\u0443 \u0433\u0434\u0435 \u0432\u0437\u044f\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 obj \u0444\u0430\u0439\u043b\u044b.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/823\/ec6\/726\/823ec67268d95ed4033d75358cbdcc37.png\" alt=\"image\"\/><\/p>\n<p>  \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c. \u0411\u0438\u043d\u0430\u0440\u043d\u0438\u043a \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u0430\u0432\u0438\u043b \u0432 \u0432\u0435\u0441\u0435, \u043d\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u0443\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 STM32F103C8.<br \/>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Debug \u0438 \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e Eclipse \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0438\u0437 C-\u043a\u043e\u0434\u0430 \u0432 Rust.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/20c\/b42\/e84\/20cb42e844e117ece5911f014d7a1b27.png\" alt=\"image\"\/><\/p>\n<p>  \u0412 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u0445\u043e\u0447\u0443 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432, \u0431\u0435\u0437 \u043d\u0438\u0445 \u044f \u0431\u044b \u043d\u0435 \u043e\u0441\u0438\u043b\u0438\u043b \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441:<br \/>  <a href=\"http:\/\/www.hashmismatch.net\/pragmatic-bare-metal-rust\/\">www.hashmismatch.net\/pragmatic-bare-metal-rust<\/a><br \/>  <a href=\"https:\/\/spin.atomicobject.com\/2015\/02\/20\/rust-language-c-embedded\/\">spin.atomicobject.com\/2015\/02\/20\/rust-language-c-embedded<\/a><br \/>  <a href=\"https:\/\/github.com\/japaric\/rust-cross\">github.com\/japaric\/rust-cross<\/a><\/p>\n<p>  \u0421\u0442\u0430\u0442\u044c\u044e \u043f\u0438\u0441\u0430\u043b \u0441 \u043d\u0430\u0434\u0435\u0436\u0434\u043e\u0439 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0443\u0436\u0438\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u0432 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u044c\u044e\u043d\u0438\u0442\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0430 Rust \u043f\u043e\u0434 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b, \u0442.\u043a. \u044d\u0442\u043e\u0442 \u044f\u0437\u044b\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u0435\u043d, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043d\u0435\u0433\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u043f\u043e\u0440\u043e\u0433 \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/324646\/\"> https:\/\/habrahabr.ru\/post\/324646\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f:  <\/p>\n<ul>\n<li>\u0421\u0432\u0435\u0436\u0438\u0439 <a href=\"https:\/\/launchpad.net\/gcc-arm-embedded\">GNU ARM Embedded Toolchain<\/a><\/li>\n<li><a href=\"http:\/\/www.st.com\/en\/development-tools\/sw4stm32.html\">System Workbench for STM32<\/a> (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e) <\/li>\n<li><a href=\"https:\/\/eclipse.org\/cdt\/\">\u0421\u0432\u0435\u0436\u0438\u0439 Eclipse CDT<\/a><\/li>\n<li><a href=\"http:\/\/gnuarmeclipse.github.io\/\">GNU ARM Eclipse Plugin<\/a> <\/li>\n<li><a href=\"https:\/\/www.rust-lang.org\/en-US\/install.html\">Rust<\/a><\/li>\n<li><a href=\"https:\/\/marketplace.eclipse.org\/content\/rustdt\">RustDT<\/a>. \u0414\u043b\u044f \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c <a href=\"https:\/\/github.com\/RustDT\/RustDT\/blob\/master\/documentation\/UserGuide.md\">Racer, Rainicorn \u0438 rustfmt<\/a>.<\/li>\n<\/ul>\n<p>  \u0418\u0434\u0435\u044f \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043d\u0430 Rust \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0438\u043d\u043a\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0443\u043b\u0447\u0435\u0439\u043d\u0430 \u0434\u043b\u044f ARM. <br \/>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0434\u0430\u0436\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043a\u043e\u043c\u0444\u043e\u0440\u0442\u043d\u043e \u0434\u0435\u0431\u0430\u0436\u0438\u0442\u044c \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 Rust \u0438 \u0421.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-283772","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/283772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=283772"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/283772\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=283772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=283772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=283772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}