{"action":"created","issue":{"url":"https://api.github.com/repos/jeelabs/embello/issues/83","repository_url":"https://api.github.com/repos/jeelabs/embello","labels_url":"https://api.github.com/repos/jeelabs/embello/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/jeelabs/embello/issues/83/comments","events_url":"https://api.github.com/repos/jeelabs/embello/issues/83/events","html_url":"https://github.com/jeelabs/embello/issues/83","id":235000034,"number":83,"title":"UART IRQ hangs - is there anything to take care of ?","user":{"login":"movingfox","id":1317888,"avatar_url":"https://avatars1.githubusercontent.com/u/1317888?v=4","gravatar_id":"","url":"https://api.github.com/users/movingfox","html_url":"https://github.com/movingfox","followers_url":"https://api.github.com/users/movingfox/followers","following_url":"https://api.github.com/users/movingfox/following{/other_user}","gists_url":"https://api.github.com/users/movingfox/gists{/gist_id}","starred_url":"https://api.github.com/users/movingfox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/movingfox/subscriptions","organizations_url":"https://api.github.com/users/movingfox/orgs","repos_url":"https://api.github.com/users/movingfox/repos","events_url":"https://api.github.com/users/movingfox/events{/privacy}","received_events_url":"https://api.github.com/users/movingfox/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-06-10T12:32:10Z","updated_at":"2018-03-06T10:23:03Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI encountered a strange problem while using mecrisp-stellaris with Forth libraries slightly modified from embello: UART IRQ would hang after receiving some bytes. The following is my code running on STM32F429 Discovery, I believe you could repeat it on other STM32 boards by appending similar code.\r\n\r\nI loopback PC10 and PC11 together to run the following IRQ experiment. Can't figure out the problem because it hangs without any clue.\r\n\r\n```\r\n\\ interrupt-based USART3 with input ring buffer\r\n\\ needs ring.fs,cond.fs,stm32f4/io.h\r\n\r\n$40020800 constant GPIOC  \r\n\r\n$40004800 constant USART3\r\n   USART3 $00 + constant USART3-SR\r\n   USART3 $04 + constant USART3-DR\r\n   USART3 $08 + constant USART3-BRR\r\n   USART3 $0C + constant USART3-CR1\r\n\\  USART3 $10 + constant USART3-CR2\r\n\\  USART3 $14 + constant USART3-CR3\r\n\\  USART3 $18 + constant USART3-GPTR\r\n\r\n: usart3-baud!  ( baud -- )\r\n    clock-hz @ swap /  2 rshift USART3-BRR ! ;  \\ APB1 clock is equal to 1/4 system clock\r\n\r\n: usart3-init ( -- )  \r\n    2 bit RCC-AHB1ENR bis!                  \\ IO port C clock enabled\r\n    OMODE-AF-PP OMODE-SLOW + PC10 io-mode!  \\ PC10 -> Alternate function mode\r\n    OMODE-AF-PP OMODE-SLOW + PC11 io-mode!  \\ PC11 -> Alternate function mode\r\n    $0700 GPIO.AFRH GPIOC + bis!            \\ PC10 -> Alternate function: %0111: AF7 (USART3 TX) \r\n    $7000 GPIO.AFRH GPIOC + bis!            \\ PC11 -> Alternate function: %0111: AF7 (USART3 RX) \r\n\r\n    18 bit RCC-APB1ENR bis!     \\ Enable clock for USART3\r\n     2 bit USART3-CR1 bis!      \\ Receiver enable\r\n     3 bit USART3-CR1 bis!      \\ Transmitter enable\r\n    13 bit USART3-CR1 bis!      \\ USART enable\r\n    2400 usart3-baud!           \\ 2400 baud\r\n;\r\n\r\n: usart3Txe? ( -- f )\r\n    7 bit USART3-SR bit@ inline ;   \\ TXE\r\n\r\n: usart3Rxne? ( -- f )\r\n    5 bit USART3-SR bit@ inline ;   \\ RXNE\r\n\r\n\\ transmit a byte to USART\r\n: >usart3 ( byte -- )\r\n    begin pause usart3Txe? until    \\ wait until transmit buffer is empty\r\n    USART3-DR h!                    \\ send byte\r\n;\r\n\r\n\\ read a byte from USART\r\n: usart3> (  --  byte )\r\n    begin pause usart3Rxne? until   \\ wait until receive buffer is not empty\r\n    USART3-DR h@                    \\ fetch data\r\n;\r\n\r\n$E000E104 constant NVIC-EN1R        \\ IRQ 32 to 63 Set Enable Register\r\n\r\n128 4 + buffer: usart3-ring\r\n\r\n: usart3-irq-handler ( -- )         \\ handle the USART receive interrupt\r\n  USART3-DR @   \\ will drop input when there is no room left\r\n  usart3-ring dup ring? if >ring else 2drop then\r\n;\r\n\r\n: usart3-irq-init ( -- )    \\ initialise the USART3 using a receive ring buffer\r\n  usart3-ring 128 init-ring\r\n  ['] usart3-irq-handler irq-usart3 !\r\n  7 bit NVIC-EN1R !         \\ enable USART3 interrupt 39\r\n  5 bit USART3-CR1 bis!     \\ set RXNEIE\r\n;\r\n\r\n: usart3-irq-key? ( -- f )  \\ input check for interrupt-driven ring buffer\r\n  pause usart3-ring ring# 0<> ;\r\n: usart3-irq-key ( -- c )   \\ input read from interrupt-driven ring buffer\r\n  begin usart3-irq-key? until  usart3-ring ring> ;\r\n\r\n\\ : init ( -- )\r\n\\   [ifdef] init init [then] \\ run previous init if it exists\r\n\\   usart3-irq-init\r\n\\   ['] usart3-irq-key? hook-key?  !\r\n\\   ['] usart3-irq-key  hook-key   !\r\n\\   ;\r\n\r\ntask: sender-task\r\n\r\n: sender&\r\n    sender-task activate\r\n    begin\r\n        1 ms\r\n        [CHAR] A >usart3\r\n    again\r\n;\r\n\r\ntask: catcher-task\r\n\r\n: catcher&\r\n    catcher-task activate  begin  usart3-irq-key emit  again\r\n;\r\n\r\ntask: blinker-task\r\n\r\n: blinker&\r\n    OMODE-PP PG13 io-mode!\r\n    blinker-task activate\r\n    begin\r\n        500 ms\r\n        PG13 iox!\r\n    again\r\n;\r\n\r\n: launch\r\n    usart3-init\r\n    usart3-irq-init\r\n    lowpower&\r\n    blinker&\r\n    catcher&\r\n    sender& ;\r\n```"},"comment":{"url":"https://api.github.com/repos/jeelabs/embello/issues/comments/370734689","html_url":"https://github.com/jeelabs/embello/issues/83#issuecomment-370734689","issue_url":"https://api.github.com/repos/jeelabs/embello/issues/83","id":370734689,"user":{"login":"gerey73","id":6214976,"avatar_url":"https://avatars3.githubusercontent.com/u/6214976?v=4","gravatar_id":"","url":"https://api.github.com/users/gerey73","html_url":"https://github.com/gerey73","followers_url":"https://api.github.com/users/gerey73/followers","following_url":"https://api.github.com/users/gerey73/following{/other_user}","gists_url":"https://api.github.com/users/gerey73/gists{/gist_id}","starred_url":"https://api.github.com/users/gerey73/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gerey73/subscriptions","organizations_url":"https://api.github.com/users/gerey73/orgs","repos_url":"https://api.github.com/users/gerey73/repos","events_url":"https://api.github.com/users/gerey73/events{/privacy}","received_events_url":"https://api.github.com/users/gerey73/received_events","type":"User","site_admin":false},"created_at":"2018-03-06T10:23:03Z","updated_at":"2018-03-06T10:23:03Z","author_association":"NONE","body":"Have you been able to solve this problem? I have a similar problem. Until I understood, that uart-irq and multitask together not want work. Although separately work normally!"}}
{"actor":{"display_login":"gerey73"}}