{"id":309841,"date":"2020-09-12T21:00:31","date_gmt":"2020-09-12T21:00:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309841"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309841","title":{"rendered":"\u041e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f: STM32 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/518832\/\">\u0412\u0441\u0435\u0445 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e!<br \/>  \u042d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0445\u0430\u0431\u0440\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0448\u0443 \u043d\u0435 \u043a\u0438\u0434\u0430\u0442\u044c\u0441\u044f \u0442\u044f\u0436\u0435\u043b\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c\u0438. \u0417\u0430\u0440\u0430\u043d\u0435\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e.<br \/>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u0438. \u041a\u043e\u0433\u0434\u0430-\u0442\u043e \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b ARM \u0444\u0438\u0440\u043c\u044b ST. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e PIC \u0438 AVR \u0443\u0436\u0435 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0418\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u0432 \u0445\u043b\u0435\u0431\u043e\u0431\u0443\u043b\u043e\u0447\u043d\u044b\u0445 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430\u0445 \u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u043e \u00ab\u0431\u044b\u0441\u0442\u0440\u043e\u043c \u0441\u0442\u0430\u0440\u0442\u0435\u00bb \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 STM32F100.<br \/>  \u042f \u043f\u0440\u0438\u0432\u044b\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 IAR. \u0414\u0430, \u0435\u0441\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 IDE, \u043d\u043e \u043c\u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 IAR: \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440, \u043d\u0435 \u043f\u043b\u043e\u0445\u043e\u0439 \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<br \/>  \u041a\u043e\u0433\u0434\u0430 \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b\u043e \u0440\u0430\u0437\u043e\u0447\u0430\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 CMSIS! \u041a\u043e\u043c\u0443 \u043a\u0430\u043a, \u043d\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u0431\u044b\u043b\u043e (\u0438 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f) \u0443\u0436\u0430\u0441\u043e\u043c: \u043c\u043d\u043e\u0433\u043e \u0431\u0443\u043a\u043e\u0432, \u0434\u043b\u0438\u043d\u043d\u044b\u0435 \u0438 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0412\u043d\u0438\u043a\u0430\u0442\u044c \u0432\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u041f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438 \u043f\u043e\u043d\u044f\u043b \u2014 \u044d\u0442\u043e \u043d\u0435 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041d\u0435\u0443\u0436\u0435\u043b\u0438 \u043d\u0435\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432? \u0415\u0441\u0442\u044c. \u0422\u043e\u0442, \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 IAR: iostm32f10xx4.h \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0438\u043d\u043a\u043b\u0443\u0434\u043d\u0438\u043a\u0438. \u0412\u043f\u043e\u043b\u043d\u0435 \u043d\u0435 \u043f\u043b\u043e\u0445\u043e:  <\/p>\n<pre><code class=\"cpp\">RCC_APB2ENR_bit.ADC1EN = 1; \/\/ \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 ADC<\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0437\u0430\u043f\u0438\u0445\u043d\u0443\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u0422\u0430\u043a \u0438 \u0441\u0434\u0435\u043b\u0430\u043b. \u0427\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043b\u044f STM32f4xx. \u0418 \u0442\u0443\u0442 \u0441\u043d\u043e\u0432\u0430 \u0437\u0430\u0441\u0430\u0434\u0430 \u2014 \u043d\u0435\u0442 \u0438\u043d\u043a\u043b\u0443\u0434\u0438\u043a\u043e\u0432. \u0427\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c? \u2014 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443. \u041f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0440\u0435\u0448\u0438\u043b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443. \u0412\u043e\u0442 \u043e\u0431 \u044d\u0442\u043e\u043c \u0438 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437.<\/p>\n<h3>\u041d\u0430\u0447\u0430\u043b\u043e<\/h3>\n<p>  \u041f\u0440\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 IAR \u0438 \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u0442.\u043a. \u0437\u0434\u0435\u0441\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e. \u0423 \u043c\u0435\u043d\u044f \u0441\u0442\u043e\u0438\u0442 IAR 8 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0435\u043c \u043a\u043e\u0434\u0430 \u0432 32\u043a\u0411. \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0432\u044b\u0431\u0440\u0430\u043d \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 STM32F103, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u043b\u0430\u0442\u0435 plue pill.<br \/>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c IAR, \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 c++, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bc\/zi\/8i\/bczi8i6y-jmi7zfhiwgsmziosts.jpeg\" alt=\"image\"><br \/>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u2014 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u041d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c Reference manual RM0008. \u0422\u0430\u043c \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c.<br \/>  \u0412\u043e\u043e\u0431\u0449\u0435, \u043a\u043e\u0433\u0434\u0430 \u044f \u043e\u0431\u0443\u0447\u0430\u043b \u0441\u0432\u043e\u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u043d\u0438\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u044f \u0434\u0430\u0432\u0430\u043b \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u2014 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 (\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 \u043a \u043d\u043e\u0436\u043a\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430), \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u0435\u0431\u0430\u0433\u0435\u0440, \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b \u0438 \u0447\u0438\u0442\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e.<\/p>\n<h3>\u041c\u043e\u0434\u0443\u043b\u044c RCC. \u0422\u0430\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p>  \u041f\u0440\u043e \u044d\u0442\u043e\u0442 \u043c\u043e\u0434\u0443\u043b\u044c \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u0431\u044b\u0432\u0430\u044e\u0442. \u0412\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u0438\u0433\u043d\u0443\u0442\u044c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c.<br \/>  \u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435! \u0427\u0442\u043e \u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u0430\u043a\u0443\u044e-\u043b\u0438\u0431\u043e \u043f\u0435\u0440\u0438\u0444\u0435\u0440\u0438\u044e, \u043d\u0430 \u043d\u0435\u0435 \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u0442\u043e\u0432\u044b\u0435 \u0438\u043c\u043f\u0443\u043b\u044c\u0441\u044b! \u0411\u0435\u0437 \u044d\u0442\u043e\u0433\u043e \u043d\u0438\u043a\u0430\u043a.<br \/>  \u041f\u043e\u0440\u0442\u044b \u0432\u0432\u043e\u0434\u0430-\u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u0438\u0434\u044f\u0442 \u043d\u0430 \u0448\u0438\u043d\u0435 APB2. \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0440\u0435\u0433\u0438\u0441\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0439 \u0448\u0438\u043d\u044b, \u044d\u0442\u043e RCC_APB2ENR:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/-a\/dz\/9y\/-adz9y0qj8ebtzgk_8ip2cfdcfs.jpeg\"><br \/>  \u0427\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0440\u0442\u0430 C (\u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u043a\u0430\u043a \u0440\u0430\u0437 \u043f\u0440\u0438\u043f\u0430\u044f\u043d \u043a PC13), \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0431\u0438\u0442 IOPCEN \u0435\u0434\u0438\u043d\u0438\u0447\u043a\u0443.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0439\u0434\u0435\u043c \u0430\u0434\u0440\u0435\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 RCC_APB2ENR. \u0421\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0443 \u043d\u0435\u0433\u043e 0x18, \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 RCC 0x40021000.<br \/>  \u0427\u0442\u043e\u0431\u044b \u0443\u0434\u043e\u0431\u043d\u043e \u0431\u044b\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u0442\u0430\u043c\u0438, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:  <\/p>\n<pre><code class=\"cpp\">typedef struct {   uint32_t  AFIOEN         : 1;   uint32_t                 : 1;   uint32_t  IOPAEN         : 1;   uint32_t  IOPBEN         : 1;   uint32_t  IOPCEN         : 1;   uint32_t  IOPDEN         : 1;   uint32_t  IOPEEN         : 1;   uint32_t                 : 2;   uint32_t  ADC1EN         : 1;   uint32_t  ADC2EN         : 1;   uint32_t  TIM1EN         : 1;   uint32_t  SPI1EN         : 1;   uint32_t                 : 1;   uint32_t  USART1EN       : 1;   uint32_t                 :17; } RCC_APB2ENR_b; <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u043e\u043c \u043d\u0435 \u043c\u0443\u0447\u0430\u0442\u044c\u0441\u044f, \u0441\u0440\u0430\u0437\u0443 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043c \u0432\u0441\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432  <\/p>\n<pre><code class=\"cpp\">enum AddrRCC {   RCC_CR          = 0x40021000,   RCC_CFGR        = 0x40021004,   RCC_CIR         = 0x40021008,   RCC_APB2RSTR    = 0x4002100C,   RCC_APB1RSTR    = 0x40021010,   RCC_AHBENR      = 0x40021014,   RCC_APB2ENR     = 0x40021018,   RCC_APB1ENR     = 0x4002101C,   RCC_BDCR        = 0x40021020,   RCC_CSR         = 0x40021024 }; <\/code><\/pre>\n<p>  \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0438\u0444\u0435\u0440\u0438\u0438  <\/p>\n<pre><code class=\"cpp\">static void EnablePort(uint8_t port_name) {   volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);   switch (port_name)   {     case 'A': apb2enr-&gt;IOPAEN = 1; break;     case 'a': apb2enr-&gt;IOPAEN = 1; break;     case 'B': apb2enr-&gt;IOPBEN = 1; break;     case 'b': apb2enr-&gt;IOPBEN = 1; break;     case 'C': apb2enr-&gt;IOPCEN = 1; break;     case 'c': apb2enr-&gt;IOPCEN = 1; break;     case 'D': apb2enr-&gt;IOPDEN = 1; break;     case 'd': apb2enr-&gt;IOPDEN = 1; break;     case 'E': apb2enr-&gt;IOPEEN = 1; break;     case 'e': apb2enr-&gt;IOPEEN = 1; break;   } } <\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e <b>volatile<\/b>, \u0438\u043d\u0430\u0447\u0435 \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0434\u043e\u043b\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0440\u0443\u0433\u0430\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430.<br \/>  \u0422\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0442\u0438\u0440\u0432\u0430\u043d\u0438\u044f \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0435\u0440\u0438\u0444\u0435\u0440\u0438\u0438.<br \/>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 (\u043d\u0435 \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043e)  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">STM32F1xx_RCC.h<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\"> #pragma once #include &quot;stdint.h&quot; namespace STM32F1xx {   class RCC   {   protected:     enum AddrRCC     {       RCC_CR          = 0x40021000,       RCC_CFGR        = 0x40021004,       RCC_CIR         = 0x40021008,       RCC_APB2RSTR    = 0x4002100C,       RCC_APB1RSTR    = 0x40021010,       RCC_AHBENR      = 0x40021014,       RCC_APB2ENR     = 0x40021018,       RCC_APB1ENR     = 0x4002101C,       RCC_BDCR        = 0x40021020,       RCC_CSR         = 0x40021024     };          typedef struct {       uint32_t  HSION          : 1;       uint32_t  HSIRDY         : 1;       uint32_t                 : 1;       uint32_t  HSI_TRIM       : 5;       uint32_t  HSI_CAL        : 8;       uint32_t  HSEON          : 1;       uint32_t  HSERDY         : 1;       uint32_t  HSEBYP         : 1;       uint32_t  CSSON          : 1;       uint32_t                 : 4;       uint32_t  PLLON          : 1;       uint32_t  PLLRDY         : 1;       uint32_t                 : 6;     } RCC_CR_b; \t\t     typedef struct {       uint32_t  SW             : 2;       uint32_t  SWS            : 2;       uint32_t  HPRE           : 4;       uint32_t  PPRE1          : 3;       uint32_t  PPRE2          : 3;       uint32_t  ADC_PRE        : 2;       uint32_t  PLLSRC         : 1;       uint32_t  PLLXTPRE       : 1;       uint32_t  PLLMUL         : 4;       uint32_t  USBPRE         : 1;       uint32_t                 : 1;       uint32_t  MCO            : 3;       uint32_t                 : 5;     } RCC_CFGR_b;      typedef struct     {       uint32_t  TIM2EN         : 1;       uint32_t  TIM3EN         : 1;       uint32_t  TIM4EN         : 1;       uint32_t                 : 8;       uint32_t  WWDGEN         : 1;       uint32_t                 : 2;       uint32_t  SPI2EN         : 1;       uint32_t                 : 2;       uint32_t  USART2EN       : 1;       uint32_t  USART3EN       : 1;       uint32_t                 : 2;       uint32_t  I2C1EN         : 1;       uint32_t  I2C2EN         : 1;       uint32_t  USBEN          : 1;       uint32_t                 : 1;       uint32_t  CANEN          : 1;       uint32_t                 : 1;       uint32_t  BKPEN          : 1;       uint32_t  PWREN          : 1;       uint32_t                 : 3;     } RCC_APB1ENR_b; \t\t     typedef struct     {       uint32_t  AFIOEN         : 1;       uint32_t                 : 1;       uint32_t  IOPAEN         : 1;       uint32_t  IOPBEN         : 1;       uint32_t  IOPCEN         : 1;       uint32_t  IOPDEN         : 1;       uint32_t  IOPEEN         : 1;       uint32_t                 : 2;       uint32_t  ADC1EN         : 1;       uint32_t  ADC2EN         : 1;       uint32_t  TIM1EN         : 1;       uint32_t  SPI1EN         : 1;       uint32_t                 : 1;       uint32_t  USART1EN       : 1;       uint32_t                 :17;     } RCC_APB2ENR_b;      typedef struct {       uint32_t  DMAEN          : 1;       uint32_t                 : 1;       uint32_t  SRAMEN         : 1;       uint32_t                 : 1;       uint32_t  FLITFEN        : 1;       uint32_t                 : 1;       uint32_t  CRCEN          : 1;       uint32_t                 :25;     } RCC_AHBENR_r;        public:     static void EnablePort(uint8_t port_name)     {       volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);       switch (port_name)       {         case 'A': apb2enr-&gt;IOPAEN = 1; break;         case 'a': apb2enr-&gt;IOPAEN = 1; break;         case 'B': apb2enr-&gt;IOPBEN = 1; break;         case 'b': apb2enr-&gt;IOPBEN = 1; break;         case 'C': apb2enr-&gt;IOPCEN = 1; break;         case 'c': apb2enr-&gt;IOPCEN = 1; break;         case 'D': apb2enr-&gt;IOPDEN = 1; break;         case 'd': apb2enr-&gt;IOPDEN = 1; break;         case 'E': apb2enr-&gt;IOPEEN = 1; break;         case 'e': apb2enr-&gt;IOPEEN = 1; break;       }     }      static void DisablePort(char port_name)     {       volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);       switch (port_name)       {         case 'A': apb2enr-&gt;IOPAEN = 0; break;         case 'a': apb2enr-&gt;IOPAEN = 0; break;         case 'B': apb2enr-&gt;IOPBEN = 0; break;         case 'b': apb2enr-&gt;IOPBEN = 0; break;         case 'C': apb2enr-&gt;IOPCEN = 0; break;         case 'c': apb2enr-&gt;IOPCEN = 0; break;         case 'D': apb2enr-&gt;IOPDEN = 0; break;         case 'd': apb2enr-&gt;IOPDEN = 0; break;         case 'E': apb2enr-&gt;IOPEEN = 0; break;         case 'e': apb2enr-&gt;IOPEEN = 0; break;       }     }      static void EnableAFIO()     {       volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);       apb2enr-&gt;AFIOEN = 1;     }      static void DisableAFIO()     {       volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);       apb2enr-&gt;AFIOEN = 0;     }          static void EnableI2C(int PortNumber)     {       switch (PortNumber)       {         case 1:         {           volatile RCC_APB1ENR_b* apb1enr = reinterpret_cast&lt;RCC_APB1ENR_b*&gt;(RCC_APB1ENR);           apb1enr-&gt;I2C1EN = 1;           break;         }         case 2:         {           volatile RCC_APB1ENR_b* apb1enr = reinterpret_cast&lt;RCC_APB1ENR_b*&gt;(RCC_APB1ENR);           apb1enr-&gt;I2C2EN = 1;           break;         }        }     }      static void EnableUART(int PortNumber)     {       switch (PortNumber)       {         case 1:         {           volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);           apb2enr-&gt;USART1EN = 1;           break;         }         case 2:         {           volatile RCC_APB1ENR_b* apb1enr = reinterpret_cast&lt;RCC_APB1ENR_b*&gt;(RCC_APB1ENR);           apb1enr-&gt;USART2EN = 1;           break;         }         case 3:         {           volatile RCC_APB1ENR_b* apb1enr = reinterpret_cast&lt;RCC_APB1ENR_b*&gt;(RCC_APB1ENR);           apb1enr-&gt;USART3EN = 1;           break;         }        }     }          static void DisableUART(int PortNumber)     {       switch (PortNumber)       {         case 1:         {           volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);           apb2enr-&gt;USART1EN = 0;           break;         }         case 2:         {           volatile RCC_APB1ENR_b* apb1enr = reinterpret_cast&lt;RCC_APB1ENR_b*&gt;(RCC_APB1ENR);           apb1enr-&gt;USART2EN = 0;           break;         }         case 3:         {           volatile RCC_APB1ENR_b* apb1enr = reinterpret_cast&lt;RCC_APB1ENR_b*&gt;(RCC_APB1ENR);           apb1enr-&gt;USART3EN = 0;           break;         }       }     }          static void EnableSPI(int PortNumber)     {       switch (PortNumber)       {         case 1:         {           volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);           apb2enr-&gt;SPI1EN = 1;           break;         }         case 2:         {           volatile RCC_APB1ENR_b* apb1enr = reinterpret_cast&lt;RCC_APB1ENR_b*&gt;(RCC_APB1ENR);           apb1enr-&gt;SPI2EN = 1;           break;         }       }     }      static void DisableSPI(int PortNumber)     {       switch (PortNumber)       {         case 1:         {           volatile RCC_APB2ENR_b* apb2enr = reinterpret_cast&lt;RCC_APB2ENR_b*&gt;(RCC_APB2ENR);           apb2enr-&gt;SPI1EN = 0;           break;         }         case 2:         {           volatile RCC_APB1ENR_b* apb1enr = reinterpret_cast&lt;RCC_APB1ENR_b*&gt;(RCC_APB1ENR);           apb1enr-&gt;SPI2EN = 0;           break;         }       }     }          static void EnableDMA()     {       volatile RCC_AHBENR_r* ahbenr = reinterpret_cast&lt;RCC_AHBENR_r*&gt;(RCC_AHBENR);       ahbenr-&gt;DMAEN = 1;     }          static void DisableDMA()     {       volatile RCC_AHBENR_r* ahbenr = reinterpret_cast&lt;RCC_AHBENR_r*&gt;(RCC_AHBENR);       ahbenr-&gt;DMAEN = 0;     }   }; } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0432 main.cpp \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f:  <\/p>\n<pre><code class=\"cpp\">#include &quot;STM32F1xx_RCC.h&quot;  using namespace STM32F1xx;  int main() {   RCC::EnablePort('c');   return 0; } <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0438 \u0441 \u043f\u043e\u0440\u0442\u0430\u043c\u0438 \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c. GPIO<\/h3>\n<p>  \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u0434\u0435\u043b General-purpose and alternate-function I\/Os. \u041d\u0430\u0445\u043e\u0434\u0438\u043c Port bit configuration table:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/m8\/as\/ez\/m8asezmgpfvjgxxthbnq1rkpbxq.jpeg\"><br \/>  \u0411\u0438\u0442\u0430\u043c\u0438 CNF[1:0] \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0436\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0440\u0442\u0430 (\u0430\u043d\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0432\u0445\u043e\u0434, \u0446\u0438\u0444\u0440\u043e\u0432\u043e\u0439 \u0432\u0445\u043e\u0434, \u0432\u044b\u0445\u043e\u0434), \u0431\u0438\u0442\u044b MODE[1:0] \u043e\u0442\u0432\u0435\u0447\u0430\u0442 \u0437\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0440\u0442\u0430 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0432\u044b\u0445\u043e\u0434.<br \/>  \u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b GPIOx_CRL \u0438 GPIOx_CRH (x=A, B, C,&#8230;)<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/fi\/e5\/kh\/fie5khvmvuritwpu0lz3zm_gndu.jpeg\"><br \/>  \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0431\u0438\u0442\u044b \u0438\u0434\u0443\u0442 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e:<br \/>  CNF[1:0], MODE[1:0]<br \/>  \u0442\u043e\u0433\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b \u0441 \u0440\u0435\u0436\u0438\u043c\u0430\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0440\u0442\u043e\u0432  <\/p>\n<pre><code class=\"cpp\">enum mode_e {   ANALOGINPUT             = 0,   INPUT                   = 4,   INPUTPULLED             = 8,    OUTPUT_10MHZ            = 1,   OUTPUT_OD_10MHZ         = 5,   ALT_OUTPUT_10MHZ        = 9,   ALT_OUTPUT_OD_10MHZ     = 13,    OUTPUT_50MHZ            = 3,   OUTPUT_OD_50MHZ         = 7,   ALT_OUTPUT_50MHZ        = 11,   ALT_OUTPUT_OD_50MHZ     = 15,    OUTPUT_2MHZ             = 2,   OUTPUT_OD_2MHZ          = 6,   ALT_OUTPUT_2MHZ         = 10,   ALT_OUTPUT_OD_2MHZ      = 14,    OUTPUT                  = 3,   OUTPUT_OD               = 7,   ALT_OUTPUT              = 11,   ALT_OUTPUT_OD           = 15 };<\/code><\/pre>\n<p>  \u0442\u043e\u0433\u0434\u0430 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cpp\">\/\/ pin_number - \u043d\u043e\u043c\u0435\u0440 \u043f\u043e\u0440\u0442\u0430 void Mode(mode_e mode) {   uint32_t* addr;   if(pin_number &gt; 7)     addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_CRH);   else     addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_CRL);      int bit_offset;   if(pin_number &gt; 7)     bit_offset = (pin_number - 8) * 4;   else     bit_offset = pin_number * 4;    uint32_t mask = ~(15 &lt;&lt; bit_offset);   *addr &amp;= mask;   *addr |= ((int)mode) &lt;&lt; bit_offset; }<\/code><\/pre>\n<p>  \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0440\u0435\u0436\u0438\u043c\u0430:  <\/p>\n<pre><code class=\"cpp\">    void ModeInput()              { Mode(INPUT);         }     void ModeAnalogInput()        { Mode(ANALOGINPUT);   }     void ModeInputPulled()        { Mode(INPUTPULLED);   }     void ModeOutput()             { Mode(OUTPUT);        }     void ModeOutputOpenDrain()    { Mode(OUTPUT_OD);     }     void ModeAlternate()          { Mode(ALT_OUTPUT);    }     void ModeAlternateOpenDrain() { Mode(ALT_OUTPUT_OD); }<\/code><\/pre>\n<p>  \u0412 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0430\u0434\u0440\u0435\u0441\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0440\u0442\u043e\u0432 \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043c  <\/p>\n<pre><code class=\"cpp\">enum AddrGPIO {   PortA           = 0x40010800,   GPIOA_CRL       = 0x40010800,   GPIOA_CRH       = 0x40010804,   GPIOA_IDR       = 0x40010808,   GPIOA_ODR       = 0x4001080C,   GPIOA_BSRR      = 0x40010810,   GPIOA_BRR       = 0x40010814,   GPIOA_LCKR      = 0x40010818,   PortB           = 0x40010C00,   PortC           = 0x40011000,   PortD           = 0x40011400,   PortE           = 0x40011800,   PortF           = 0x40011C00,   PortG           = 0x40012000 };<\/code><\/pre>\n<p>  \u0414\u043e\u043b\u0433\u043e \u0434\u0443\u043c\u0430\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0438 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c. \u042d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437\u0434\u0435\u0440\u0436\u043a\u0438, \u043d\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0443\u0434\u043e\u0431\u043d\u0435\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.<br \/>  \u041c\u043e\u0434\u0435\u0440\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434  <\/p>\n<pre><code class=\"cpp\">if(pin_number &gt; 7)   addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_CRH - PortA + PortAddr); else   addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_CRL - PortA + PortAddr);<\/code><\/pre>\n<p>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0443 \u043a\u043e\u0433\u043e-\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0433\u043b\u0430\u0437 \u0434\u0435\u0440\u0433\u0430\u0442\u044c\u0441\u044f, \u043d\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435 \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043b.<br \/>  \u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u043d\u043e\u0436\u043a\u0443 \u0432 \u043d\u0443\u0436\u043d\u043e\u0435 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0431\u0438\u0442 \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 ODRx. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"cpp\">void Set(bool st) {   uint32_t* addr;   addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_ODR - PortA + PortAddr);    if(st)     *addr |= 1 &lt;&lt; pin_number;   else   {     int mask = ~(1 &lt;&lt; pin_number);     *addr &amp;= mask;   }  }<\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438 GPIOx_BSRR.<br \/>  \u041f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0434\u0435\u043b\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u0430, \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435). \u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0440\u0442\u0430\u043c\u0438  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">STM32F1xx_Pin.h<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">#pragma once #include &lt;stdint.h&gt; #include &quot;STM32F1xx_RCC.h&quot;  namespace STM32F1xx {   class Pin   {   public:     enum mode_e     {       ANALOGINPUT             = 0,       INPUT                   = 4,       INPUTPULLED             = 8,        OUTPUT_10MHZ            = 1,       OUTPUT_OD_10MHZ         = 5,       ALT_OUTPUT_10MHZ        = 9,       ALT_OUTPUT_OD_10MHZ     = 13,        OUTPUT_50MHZ            = 3,       OUTPUT_OD_50MHZ         = 7,       ALT_OUTPUT_50MHZ        = 11,       ALT_OUTPUT_OD_50MHZ     = 15,        OUTPUT_2MHZ             = 2,       OUTPUT_OD_2MHZ          = 6,       ALT_OUTPUT_2MHZ         = 10,       ALT_OUTPUT_OD_2MHZ      = 14,        OUTPUT                  = 3,       OUTPUT_OD               = 7,       ALT_OUTPUT              = 11,       ALT_OUTPUT_OD           = 15     };        private:     enum AddrGPIO     {       PortA           = 0x40010800,       GPIOA_CRL       = 0x40010800,       GPIOA_CRH       = 0x40010804,       GPIOA_IDR       = 0x40010808,       GPIOA_ODR       = 0x4001080C,       GPIOA_BSRR      = 0x40010810,       GPIOA_BRR       = 0x40010814,       GPIOA_LCKR      = 0x40010818,       PortB           = 0x40010C00,       PortC           = 0x40011000,       PortD           = 0x40011400,       PortE           = 0x40011800,       PortF           = 0x40011C00,       PortG           = 0x40012000     };        private:     int   pin_number;     int   PortAddr;        public:     Pin()                               { }     Pin(char port_name, int pin_number) { Init(port_name, pin_number); }     ~Pin()     {       Off();       ModeAnalogInput();     }   public:     void Init(char port_name, int pin_number)     {       this-&gt;pin_number = pin_number;       RCC::EnablePort(port_name);       switch (port_name)       {         case 'A': PortAddr = PortA; break;         case 'a': PortAddr = PortA; break;         case 'B': PortAddr = PortB; break;         case 'b': PortAddr = PortB; break;         case 'C': PortAddr = PortC; break;         case 'c': PortAddr = PortC; break;         case 'D': PortAddr = PortD; break;         case 'd': PortAddr = PortD; break;         case 'E': PortAddr = PortE; break;         case 'e': PortAddr = PortE; break;       }     }      void ModeInput()              { Mode(INPUT);         }     void ModeAnalogInput()        { Mode(ANALOGINPUT);   }     void ModeInputPulled()        { Mode(INPUTPULLED);   }     void ModeOutput()             { Mode(OUTPUT);        }     void ModeOutputOpenDrain()    { Mode(OUTPUT_OD);     }     void ModeAlternate()          { Mode(ALT_OUTPUT);    }     void ModeAlternateOpenDrain() { Mode(ALT_OUTPUT_OD); }      void NoPullUpDown()     {       uint32_t* addr;       if(pin_number &gt; 7)         addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_CRH - PortA + PortAddr);       else         addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_CRL - PortA + PortAddr);        int bit_offset;       if(pin_number &gt; 7)         bit_offset = (pin_number - 8) * 4;       else          bit_offset = pin_number * 4;        int mask = ~((1 &lt;&lt; 3) &lt;&lt; bit_offset);       *addr &amp;= mask;     }          void Mode(mode_e mode)     {       uint32_t* addr;       if(pin_number &gt; 7)         addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_CRH - PortA + PortAddr);       else         addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_CRL - PortA + PortAddr);              int bit_offset;       if(pin_number &gt; 7)         bit_offset = (pin_number - 8) * 4;       else         bit_offset = pin_number * 4;        uint32_t mask = ~(15 &lt;&lt; bit_offset);       *addr &amp;= mask;       *addr |= ((int)mode) &lt;&lt; bit_offset;     }      void Set(bool st)     {       uint32_t* addr;       addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_ODR - PortA + PortAddr);        if(st)         *addr |= 1 &lt;&lt; pin_number;       else       {         int mask = ~(1 &lt;&lt; pin_number);         *addr &amp;= mask;       }      }      void On()     {       uint32_t* addr;       addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_ODR - PortA + PortAddr);       int bit_offset = pin_number;       *addr |= 1 &lt;&lt; bit_offset;     }      void Off()     {       uint32_t* addr;       addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_ODR - PortA + PortAddr);       int bit_offset = pin_number;       int mask = ~(1 &lt;&lt; bit_offset);       *addr &amp;= mask;     }      bool Get()     {       uint32_t* addr = reinterpret_cast&lt;uint32_t*&gt;(GPIOA_IDR - PortA + PortAddr);       int bit_offset = pin_number;       int mask = (1 &lt;&lt; bit_offset);       bool ret_val = (*addr &amp; mask);       return ret_val;     }   }; }; <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041d\u0443 \u0447\u0442\u043e, \u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c:  <\/p>\n<pre><code class=\"cpp\">#include &quot;STM32F1xx_Pin.h&quot;  using namespace STM32F1xx;  Pin led('c', 13);  int main() {   led.ModeOutput();   led.On();   led.Off();   return 0; } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u0434\u0435\u0431\u0430\u0433\u0435\u0440\u043e\u043c \u0438 \u0443\u0431\u0435\u0436\u0434\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0437\u0430\u0433\u043e\u0440\u0430\u0435\u0442\u0441\u044f (\u043f\u043e\u0441\u043b\u0435 led.ModeOutput();), \u043f\u043e\u0442\u043e\u043c \u0433\u0430\u0441\u043d\u0435\u0442 (led.On();) \u0438 \u0441\u043d\u043e\u0432\u0430 \u0437\u0430\u0433\u043e\u0440\u0430\u0435\u0442\u0441\u044f (led.Off();). \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u043f\u043e\u0434\u043a\u043b\u0447\u0435\u043d \u043a \u043d\u043e\u0436\u043a\u0435 \u0447\u0435\u0440\u0435\u0437 \u043b\u0438\u043d\u0438\u044e \u043f\u0438\u0442\u0430\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430 \u0432\u044b\u0432\u043e\u0434\u0435 \u043d\u0438\u0437\u043a\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c, \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 \u0437\u0430\u0433\u043e\u0440\u0430\u0435\u0442\u0441\u044f.<\/p>\n<h3>\u041d\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0438\u0442\u043e\u0433\u0438<\/h3>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f (\u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c) \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u0436\u0438\u0437\u043d\u044c, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c. \u0418\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u2014 \u043a\u0430\u043a \u043d\u0435\u043b\u044c\u0437\u044f \u0434\u0435\u043b\u0430\u0442\u044c. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0435\u0448\u0438\u0442 \u0441\u0430\u043c.<br \/>  \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0440\u0430\u043f\u0435\u0440\u044b \u0434\u043b\u044f CMSIS, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e.<br \/>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0443\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. \u0415\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u2014 \u0434\u0430\u0439\u0442\u0435 \u0437\u043d\u0430\u0442\u044c.<\/div>\n<p> \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:\/\/habr.com\/ru\/post\/518832\/\"> https:\/\/habr.com\/ru\/post\/518832\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/518832\/\">\u0412\u0441\u0435\u0445 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e!<br \/>  \u042d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430 \u0445\u0430\u0431\u0440\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u043e\u0448\u0443 \u043d\u0435 \u043a\u0438\u0434\u0430\u0442\u044c\u0441\u044f \u0442\u044f\u0436\u0435\u043b\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u0430\u043c\u0438. \u0417\u0430\u0440\u0430\u043d\u0435\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e.<br \/>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u0438. \u041a\u043e\u0433\u0434\u0430-\u0442\u043e \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0430 \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b ARM \u0444\u0438\u0440\u043c\u044b ST. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e PIC \u0438 AVR \u0443\u0436\u0435 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u0438 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0418\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0433\u043e \u0432 \u0445\u043b\u0435\u0431\u043e\u0431\u0443\u043b\u043e\u0447\u043d\u044b\u0445 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430\u0445 \u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0430\u0442\u0435\u0439 \u043e \u00ab\u0431\u044b\u0441\u0442\u0440\u043e\u043c \u0441\u0442\u0430\u0440\u0442\u0435\u00bb \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 STM32F100.<br \/>  \u042f \u043f\u0440\u0438\u0432\u044b\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 IAR. \u0414\u0430, \u0435\u0441\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 IDE, \u043d\u043e \u043c\u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 IAR: \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440, \u043d\u0435 \u043f\u043b\u043e\u0445\u043e\u0439 \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u043c\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438.<br \/>  \u041a\u043e\u0433\u0434\u0430 \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u043c\u0435\u043d\u044f \u0436\u0434\u0430\u043b\u043e \u0440\u0430\u0437\u043e\u0447\u0430\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 CMSIS! \u041a\u043e\u043c\u0443 \u043a\u0430\u043a, \u043d\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u044d\u0442\u043e \u0431\u044b\u043b\u043e (\u0438 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f) \u0443\u0436\u0430\u0441\u043e\u043c: \u043c\u043d\u043e\u0433\u043e \u0431\u0443\u043a\u043e\u0432, \u0434\u043b\u0438\u043d\u043d\u044b\u0435 \u0438 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0412\u043d\u0438\u043a\u0430\u0442\u044c \u0432\u043e \u0432\u0441\u0435 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u041f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0438 \u043f\u043e\u043d\u044f\u043b \u2014 \u044d\u0442\u043e \u043d\u0435 \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434.  <\/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-309841","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309841","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=309841"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309841\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}