{"id":287404,"date":"2018-08-16T14:08:29","date_gmt":"2018-08-16T10:08:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=287404"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=287404","title":{"rendered":"\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 FIFO \u0431\u0443\u0444\u0435\u0440\u0430 UART \u0432 ESP32"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/419955\/\" class=\"post__text post__text-html js-mediator-article\">\n<p>\u0423 ESP32 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 UART-\u0430. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442 FIFO \u0431\u0443\u0444\u0435\u0440 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 \u0438 FIFO \u0431\u0443\u0444\u0435\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a\u0430 \u0432 \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 1024 \u0431\u0430\u0439\u0442\u0430 (ESP32 technical reference manual 3.5):<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ws\/ld\/02\/wsld02i_kdjqn8vd_f1kajblb3k.png\"><\/div>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 FIFO \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a\u0430 UART2 \u0441 128 \u0434\u043e 256 \u0431\u0430\u0439\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0440\u0442\u0438\u043b\u0438 FIFO \u0431\u0443\u0444\u0435\u0440 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 UART0, \u0447\u0435\u0433\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0431\u044b\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 (ESP32 technical reference manual 3.5) \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 FIFO \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u0430\u0445 esp-idf (\u0432 uart_struct.h) \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0438\u0441\u044c:<\/p>\n<p>  <\/p>\n<p>1) \u0440\u0435\u0433\u0438\u0441\u0442\u0440 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f FIFO \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a\u0430 (\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 0x5c):<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">    union {         struct {             uint32_t status:24;             uint32_t reserved24:    8;         };         uint32_t val;     } mem_tx_status;<\/code><\/pre>\n<p>  <\/p>\n<p>2) \u0440\u0435\u0433\u0438\u0441\u0442\u0440 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f FIFO \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 (\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 0x60):<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">    union {         struct {             uint32_t status:      24;             uint32_t reserved24:   8;         };         struct {             uint32_t reserved0:     2;             uint32_t rd_addr:      11;              \/*This register stores the rx mem read address.*\/             uint32_t wr_addr:      11;              \/*This register stores the rx mem write address.*\/             uint32_t reserved:      8;         };         uint32_t val;     } mem_rx_status;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0430\u0433\u0430\u044f \u0447\u0442\u043e mem_tx_status \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0431\u0438\u0442 mem_rx_status \u043f\u0438\u0448\u0435\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u0434\u0440\u0435\u0441\u043e\u0432 FIFO \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include \"freertos\/FreeRTOS.h\" #include \"freertos\/task.h\" #include &lt;driver\/uart.h&gt;  void print_uart_st(uart_dev_t *u,int num) {     printf(\"UART%d:\\n\",num);     printf(\"rx_st=0x%X\\n\",(unsigned int)u-&gt;mem_rx_status.val);     printf(\"rx_rd=0x%X\\n\",(unsigned int)u-&gt;mem_rx_status.rd_addr);     printf(\"rx_wr=0x%X\\n\",(unsigned int)u-&gt;mem_rx_status.wr_addr);     uint32_t tx_s = u-&gt;mem_tx_status.val;     printf(\"tx_st=0x%X\\n\",tx_s);     printf(\"tx_rd=0x%X\\n\",(tx_s&gt;&gt;2)&amp;2047);     printf(\"tx_wr=0x%X\\n\",(tx_s&gt;&gt;13)&amp;2047); } uart_config_t uart_config = {     .baud_rate = 115200,     .data_bits = UART_DATA_8_BITS,     .parity    = UART_PARITY_DISABLE,     .stop_bits = UART_STOP_BITS_1,     .flow_ctrl = UART_HW_FLOWCTRL_DISABLE }; void UARTtest(void * param) {     uart_param_config(UART_NUM_1,&amp;uart_config);     uart_param_config(UART_NUM_2,&amp;uart_config);     uart_driver_install(UART_NUM_1, 256, 0, 0, NULL, 0);     uart_driver_install(UART_NUM_2, 256, 0, 0, NULL, 0);     uart_set_pin(UART_NUM_1, UART_PIN_NO_CHANGE, GPIO_NUM_16, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);     uart_set_pin(UART_NUM_2, UART_PIN_NO_CHANGE, GPIO_NUM_16, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);     vTaskDelay(1000\/portTICK_PERIOD_MS);     while (1)     {         print_uart_st(&amp;UART0,0);         print_uart_st(&amp;UART1,1);         print_uart_st(&amp;UART2,2);         vTaskDelay(2000\/portTICK_PERIOD_MS);         char s[256];         uart_write_bytes(UART_NUM_1, s, 1);         uart_write_bytes(UART_NUM_2, s, 2);         if(gets(s)!=NULL)         {             printf(\"recived=%s\\n\",s);         }     } } void app_main(void) {     xTaskCreate(UARTtest, \"UARTtest\",    4096, NULL, 5, NULL); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c:<\/p>\n<p>  <\/p>\n<blockquote><p>UART0:<br \/>  rx_st=0x300600<br \/>  rx_rd=0x180<br \/>  rx_wr=0x180<br \/>  tx_st=0xCE058<br \/>  tx_rd=0x16<br \/>  tx_wr=0x67<br \/>  UART1:<br \/>  rx_st=0x400800<br \/>  rx_rd=0x200<br \/>  rx_wr=0x200<br \/>  tx_st=0x100200<br \/>  tx_rd=0x80<br \/>  tx_wr=0x80<br \/>  UART2:<br \/>  rx_st=0x500A00<br \/>  rx_rd=0x280<br \/>  rx_wr=0x280<br \/>  tx_st=0x200400<br \/>  tx_rd=0x100<br \/>  tx_wr=0x100  <\/p><\/blockquote>\n<p>\u0412\u044b\u0432\u043e\u0434 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 UART0, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 tx_wr \u0438 tx_rd \u043e\u0442\u043b\u0438\u0447\u043d\u044b \u043e\u0442 0. \u0421\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 FIFO \u0431\u0443\u0444\u0435\u0440\u0430\u043c\u0438 UART0,1,2 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  <\/p>\n<table>\n<tr>\n<th>\u0410\u0434\u0440\u0435\u0441\u0430<\/th>\n<th>UART<\/th>\n<\/tr>\n<tr>\n<td>0x00&#8230;0x7F<\/td>\n<td>UART0 TX_FIFO<\/td>\n<\/tr>\n<tr>\n<td>0x80&#8230;0xFF<\/td>\n<td>UART1 TX_FIFO<\/td>\n<\/tr>\n<tr>\n<td>0x100&#8230;0x17F<\/td>\n<td>UART2 TX_FIFO<\/td>\n<\/tr>\n<tr>\n<td>0x180&#8230;0x1FF<\/td>\n<td>UART0 RX_FIFO<\/td>\n<\/tr>\n<tr>\n<td>0x200&#8230;0x27F<\/td>\n<td>UART1 RX_FIFO<\/td>\n<\/tr>\n<tr>\n<td>0x280&#8230;0x2FF<\/td>\n<td>UART2 RX_FIFO<\/td>\n<\/tr>\n<\/table>\n<p>  <\/p>\n<p>\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f FIFO \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u0438\u043c\u0435\u044e\u0442 \u0440\u0430\u0437\u0440\u044f\u0434\u043d\u043e\u0441\u0442\u044c 11 \u0431\u0438\u0442, \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0442\u0432\u043e\u0434\u0438\u043c\u043e\u0439 \u043f\u043e\u0434 FIFO \u0431\u0443\u0444\u0435\u0440\u0430 = 2\u041a\u0431. \u041f\u0440\u0438 \u0437\u0430\u0434\u0430\u043d\u0438\u0438 UART0.mem_conf.tx_size=15 (\u043f\u0430\u043c\u044f\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0443\u0441\u043a\u0430\u043c\u0438 \u0434\u043b\u0438\u043d\u043d\u043e\u0439 128 \u0431\u0430\u0439\u0442) \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e 1920 \u0431\u0430\u0439\u0442, \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 tx_wr \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0434\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0434\u043e 1919 \u0438 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u043c \u0447\u0435\u0440\u0435\u0437 0 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442 \u0441\u0447\u0435\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0430\u0434\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043b. 10 \u0431\u0438\u0442\u0430\u043c\u0438, \u0442.\u0435. \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043c \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0442\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0434 FIFO \u0431\u0443\u0444\u0435\u0440\u0430 = 1\u041a\u0431.<\/p>\n<p>  <\/p>\n<p><b>\u0418\u0442\u043e\u0433\u043e:<\/b><\/p>\n<ol>\n<li>\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u043e\u0442\u0432\u043e\u0434\u0438\u043c\u043e\u0439 ESP32 \u043f\u043e\u0434 FIFO UART \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0439 \u0432 technical reference manual 3.5;  <\/li>\n<li>\u041e\u0431\u044a\u0435\u043c \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 FIFO UART = 1\u041a\u0431.  <\/li>\n<\/ol>\n<p><\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <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:\/\/habr.com\/post\/419955\/\"> https:\/\/habr.com\/post\/419955\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/419955\/\" class=\"post__text post__text-html js-mediator-article\">\n<p>\u0423 ESP32 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 UART-\u0430. \u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442 FIFO \u0431\u0443\u0444\u0435\u0440 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 \u0438 FIFO \u0431\u0443\u0444\u0435\u0440 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a\u0430 \u0432 \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c 1024 \u0431\u0430\u0439\u0442\u0430 (ESP32 technical reference manual 3.5):<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ws\/ld\/02\/wsld02i_kdjqn8vd_f1kajblb3k.png\"><\/div>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 FIFO \u0431\u0443\u0444\u0435\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a\u0430 UART2 \u0441 128 \u0434\u043e 256 \u0431\u0430\u0439\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0440\u0442\u0438\u043b\u0438 FIFO \u0431\u0443\u0444\u0435\u0440 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 UART0, \u0447\u0435\u0433\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0431\u044b\u0442\u044c \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e.<\/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-287404","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287404","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=287404"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287404\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}