{"action":"created","issue":{"url":"https://api.github.com/repos/msalau/rl78flash/issues/7","repository_url":"https://api.github.com/repos/msalau/rl78flash","labels_url":"https://api.github.com/repos/msalau/rl78flash/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/msalau/rl78flash/issues/7/comments","events_url":"https://api.github.com/repos/msalau/rl78flash/issues/7/events","html_url":"https://github.com/msalau/rl78flash/issues/7","id":183473542,"number":7,"title":"FT232RL causes 'Synchronization failed' error with -b 250000 or 500000 or 1000000 option (Windows)","user":{"login":"mon80","id":22886334,"avatar_url":"https://avatars.githubusercontent.com/u/22886334?v=3","gravatar_id":"","url":"https://api.github.com/users/mon80","html_url":"https://github.com/mon80","followers_url":"https://api.github.com/users/mon80/followers","following_url":"https://api.github.com/users/mon80/following{/other_user}","gists_url":"https://api.github.com/users/mon80/gists{/gist_id}","starred_url":"https://api.github.com/users/mon80/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mon80/subscriptions","organizations_url":"https://api.github.com/users/mon80/orgs","repos_url":"https://api.github.com/users/mon80/repos","events_url":"https://api.github.com/users/mon80/events{/privacy}","received_events_url":"https://api.github.com/users/mon80/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-10-17T17:09:50Z","updated_at":"2016-10-20T00:54:50Z","closed_at":null,"body":"I am facing following error while using FT232RL under Windows environment.\r\n\r\n&gt;rl78flash -m 2 -b 250000 -iav COM14 cotton_sketch.mot\r\nFAILED\r\nSynchronization failed\r\n\r\nor\r\n\r\n&gt;rl78flash -m 4 -b 250000 -iav COM14 cotton_sketch.mot\r\nFAILED\r\nSynchronization failed\r\n\r\nI debugged this problem for a while and I get an idea to solve it.\r\n\r\nport_handle_t serial_open(const char *port)\r\n{\r\n&nbsp;&nbsp;&nbsp;&nbsp;...\r\n&nbsp;&nbsp;&nbsp;&nbsp;if (INVALID_HANDLE_VALUE == fd)\r\n&nbsp;&nbsp;&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...\r\n&nbsp;&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;&nbsp;&nbsp;else\r\n&nbsp;&nbsp;&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DCB dcbSerialParams;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetCommState(fd, &dcbSerialParams);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dcbSerialParams.BaudRate = CBR_115200;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dcbSerialParams.ByteSize = 8;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dcbSerialParams.StopBits = TWOSTOPBITS;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dcbSerialParams.Parity = NOPARITY;\r\n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dcbSerialParams.fDtrControl = DTR_CONTROL_DISABLE;\r\n+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetCommState(fd, &dcbSerialParams);\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COMMTIMEOUTS timeouts;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeouts.ReadIntervalTimeout=50;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeouts.ReadTotalTimeoutConstant=50;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeouts.ReadTotalTimeoutMultiplier=10;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeouts.WriteTotalTimeoutConstant=0;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;timeouts.WriteTotalTimeoutMultiplier=0;\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetCommTimeouts(fd, &timeouts);\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FlushFileBuffers(fd);\r\n&nbsp;&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;&nbsp;&nbsp;return fd;\r\n}\r\n\r\nThe reason of the problem is FT232RL's (or its Windows dirver's) initial value of \r\nfDtrControl and fRtsControl are as following and this makes RL78 reset \r\nafter SetCommState() is called in serial_set_baud().\r\n\r\ndcbSerialParams.fDtrControl = DTR_CONTROL_ENABLE; // 'ENABLE' means DTR CONTROL line is set to 'Low'.\r\ndcbSerialParams.fRtsControl = RTS_CONTROL_ENABLE; // 'ENABLE' means RTS CONTROL line is set to 'Low'.\r\n\r\nint serial_set_baud(port_handle_t fd, int baud)\r\n{\r\n&nbsp;&nbsp;&nbsp;&nbsp;DCB dcbSerialParams;\r\n&nbsp;&nbsp;&nbsp;&nbsp;GetCommState(fd, &dcbSerialParams);\r\n&nbsp;&nbsp;&nbsp;&nbsp;dcbSerialParams.BaudRate = baud;\r\n&nbsp;&nbsp;&nbsp;&nbsp;return SetCommState(fd, &dcbSerialParams) != 0 ? 0 : -1;\r\n}\r\n\r\nOn the other hand, CP2102's (or its Windows dirver's) initial value of \r\nfDtrControl and fRtsControl are as following and this makes no problem.\r\n\r\ndcbSerialParams.fDtrControl = DTR_CONTROL_DISABLE; // 'DISABLE' means DTR CONTROL line is set to 'High'.\r\ndcbSerialParams.fRtsControl = RTS_CONTROL_DISABLE; // 'DISABLE' means RTS CONTROL line is set to 'High'.\r\n\r\nBest Regards,"},"comment":{"url":"https://api.github.com/repos/msalau/rl78flash/issues/comments/254981843","html_url":"https://github.com/msalau/rl78flash/issues/7#issuecomment-254981843","issue_url":"https://api.github.com/repos/msalau/rl78flash/issues/7","id":254981843,"user":{"login":"mon80","id":22886334,"avatar_url":"https://avatars.githubusercontent.com/u/22886334?v=3","gravatar_id":"","url":"https://api.github.com/users/mon80","html_url":"https://github.com/mon80","followers_url":"https://api.github.com/users/mon80/followers","following_url":"https://api.github.com/users/mon80/following{/other_user}","gists_url":"https://api.github.com/users/mon80/gists{/gist_id}","starred_url":"https://api.github.com/users/mon80/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mon80/subscriptions","organizations_url":"https://api.github.com/users/mon80/orgs","repos_url":"https://api.github.com/users/mon80/repos","events_url":"https://api.github.com/users/mon80/events{/privacy}","received_events_url":"https://api.github.com/users/mon80/received_events","type":"User","site_admin":false},"created_at":"2016-10-20T00:54:50Z","updated_at":"2016-10-20T00:54:50Z","body":"Hi,\r\n\r\nAfter confirming various modes, I notice following mistakes.\r\n\r\nFile: rl78g10.c\r\n\r\nstatic void rl78g10_set_reset(port_handle_t fd, int mode, int value)\r\n{\r\n&nbsp;&nbsp;&nbsp;&nbsp;int level = (mode & MODE_INVERT_RESET) ? !value : value;\r\n-&nbsp;&nbsp;if (MODE_RESET_RTS == mode)\r\n+&nbsp;&nbsp;if (MODE_RESET_RTS == (mode & MODE_RESET))\r\n&nbsp;&nbsp;&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serial_set_rts(fd, level);\r\n&nbsp;&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;&nbsp;&nbsp;else\r\n&nbsp;&nbsp;&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serial_set_dtr(fd, level);\r\n&nbsp;&nbsp;&nbsp;&nbsp;}\r\n}\r\n\r\nFile: rl78g10.h\r\n\r\n+#define MODE_RESET&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1\r\n#define MODE_RESET_DTR&nbsp;&nbsp;&nbsp;&nbsp;0\r\n-#define MODE_RESET_RTS&nbsp;&nbsp;&nbsp;&nbsp;1\r\n+#define MODE_RESET_RTS&nbsp;&nbsp;&nbsp;&nbsp;MODE_RESET\r\n#define MODE_MAX_VALUE&nbsp;&nbsp;&nbsp;&nbsp;MODE_RESET_RTS\r\n#define MODE_INVERT_RESET 0x100\r\n\r\nBest regards,\r\nMON-80"}}
{"actor":{"display_login":"mon80"}}