{"action":"created","issue":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/6077","repository_url":"https://api.github.com/repos/ARMmbed/mbed-os","labels_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/6077/labels{/name}","comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/6077/comments","events_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/6077/events","html_url":"https://github.com/ARMmbed/mbed-os/issues/6077","id":296699365,"node_id":"MDU6SXNzdWUyOTY2OTkzNjU=","number":6077,"title":"FlashIAP does not deal with erasing sectors correctly","user":{"login":"LiyouZhou","id":2660805,"node_id":"MDQ6VXNlcjI2NjA4MDU=","avatar_url":"https://avatars0.githubusercontent.com/u/2660805?v=4","gravatar_id":"","url":"https://api.github.com/users/LiyouZhou","html_url":"https://github.com/LiyouZhou","followers_url":"https://api.github.com/users/LiyouZhou/followers","following_url":"https://api.github.com/users/LiyouZhou/following{/other_user}","gists_url":"https://api.github.com/users/LiyouZhou/gists{/gist_id}","starred_url":"https://api.github.com/users/LiyouZhou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LiyouZhou/subscriptions","organizations_url":"https://api.github.com/users/LiyouZhou/orgs","repos_url":"https://api.github.com/users/LiyouZhou/repos","events_url":"https://api.github.com/users/LiyouZhou/events{/privacy}","received_events_url":"https://api.github.com/users/LiyouZhou/received_events","type":"User","site_admin":false},"labels":[{"id":515346312,"node_id":"MDU6TGFiZWw1MTUzNDYzMTI=","url":"https://api.github.com/repos/ARMmbed/mbed-os/labels/component:%20filesystem","name":"component: filesystem","color":"5319e7","default":false},{"id":427713129,"node_id":"MDU6TGFiZWw0Mjc3MTMxMjk=","url":"https://api.github.com/repos/ARMmbed/mbed-os/labels/mirrored","name":"mirrored","color":"ededed","default":false},{"id":28847979,"node_id":"MDU6TGFiZWwyODg0Nzk3OQ==","url":"https://api.github.com/repos/ARMmbed/mbed-os/labels/type:%20bug","name":"type: bug","color":"b60205","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-02-13T11:11:24Z","updated_at":"2018-06-18T15:34:58Z","closed_at":null,"author_association":"NONE","body":"Note: This is just a template, so feel free to use/remove the unnecessary things\r\n\r\n### Description\r\n- Type: Bug\r\n- Priority: Major\r\n\r\n---------------------------------------------------------------\r\n## Bug\r\n\r\n**Target**\r\nAny STM based targets with Variable internal flash sector size\r\n\r\n**Toolchain:**\r\nAny\r\n\r\n**mbed-os sha:**\r\ncaeaa49d6 Merge pull request #5954 from ARMmbed/release-candidate\r\n\r\n**Expected behavior**\r\nFlashIAP::erase allows the user to erase multiple sectors with one call.\r\n\r\nOn STM F439 (ODIN) sector 12 starting from 0x080e0000 have size 128k, sector 13 starting from 0x08100000 have size 16k. I want to erase these two sectors so I call\r\n\r\nFlashIAP::erase(0x080e0000, (128+16)*1024)\r\n\r\n**Actual behavior**\r\nThe impelmentation cannot deal with variable sector sizes and returns -1 on alignment check.\r\n\r\n**Steps to reproduce**\r\ncompile the following code:\r\n`mbed compile -m UBLOX_EVK_ODIN_W2 -t GCC_ARM` and run.\r\n```\r\n#include \"mbed.h\"\r\n\r\nint main()\r\n{\r\n    FlashIAP flash;\r\n\r\n    flash.init();\r\n\r\n    size_t sec_1_start_addr = flash.get_flash_start() + 0xe0000;\r\n    size_t sec_1_size = flash.get_sector_size(sec_1_start_addr);\r\n    size_t sec_2_start_addr = sec_1_start_addr + sec_1_size;\r\n    size_t sec_2_size = flash.get_sector_size(sec_2_start_addr);\r\n\r\n    int ret = flash.erase(sec_1_start_addr, sec_1_size + sec_2_size);\r\n    printf(\"ret %i\\r\\n\", ret);\r\n\r\n    ret = flash.erase(sec_1_start_addr, sec_1_size);\r\n    printf(\"ret %i\\r\\n\", ret);\r\n\r\n    ret = flash.erase(sec_2_start_addr, sec_2_size);\r\n    printf(\"ret %i\\r\\n\", ret);\r\n\r\n    return 0;\r\n}\r\n```\r\n\r\nThe first call fails while the subsequent calls succeed.\r\n\r\n## RCA\r\n\r\nIn FlashIAP.cpp https://github.com/ARMmbed/mbed-os/blob/master/drivers/FlashIAP.cpp#L118-L144\r\nThe algorithm tries to erase sector by sector but the alignment check is still done on the overall erase size. This will not work on variable sector sizes.\r\n\r\nThe API does not provide a way for user to get the correct erase size. User is forced to doing erasing secotor by sector at the top level thus defeating the purpose of the FlashIAP::erase API.\r\n"},"comment":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/comments/398096658","html_url":"https://github.com/ARMmbed/mbed-os/issues/6077#issuecomment-398096658","issue_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/6077","id":398096658,"node_id":"MDEyOklzc3VlQ29tbWVudDM5ODA5NjY1OA==","user":{"login":"davidsaada","id":30656454,"node_id":"MDQ6VXNlcjMwNjU2NDU0","avatar_url":"https://avatars3.githubusercontent.com/u/30656454?v=4","gravatar_id":"","url":"https://api.github.com/users/davidsaada","html_url":"https://github.com/davidsaada","followers_url":"https://api.github.com/users/davidsaada/followers","following_url":"https://api.github.com/users/davidsaada/following{/other_user}","gists_url":"https://api.github.com/users/davidsaada/gists{/gist_id}","starred_url":"https://api.github.com/users/davidsaada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidsaada/subscriptions","organizations_url":"https://api.github.com/users/davidsaada/orgs","repos_url":"https://api.github.com/users/davidsaada/repos","events_url":"https://api.github.com/users/davidsaada/events{/privacy}","received_events_url":"https://api.github.com/users/davidsaada/received_events","type":"User","site_admin":false},"created_at":"2018-06-18T15:34:58Z","updated_at":"2018-06-18T15:34:58Z","author_association":"CONTRIBUTOR","body":"@0xc0170 - This issue can be closed now. [PR #6140](https://github.com/ARMmbed/mbed-os/pull/6140) fixed it."}}
{"actor":{"display_login":"davidsaada"}}