How can I erase whole phone securely? How can I erase my phone completely and securely before selling it for someone else? I have read that secure deletion procedures used on regular hard disks are ineffective on flash drives connected through USB, due to inability to tell the embedded controller to effectively erase all of the data, or something like that.

Not sure about internal storage though (both phone storage and internal SD card), however both of this and the SD card should be erased securely, so that I can be absolutely sure that none of my private data will be available to the next user.
For a real safe delete of all data on the device, a simple factory-reset won't do: data might still be recoverable if one takes the efforts required for such a data-recovery. So I'd recommend taking a look at e.g. Nuke My Phone:

Following National Institute of Standards and Technology (NIST) guidelines, Nuke My Phone sanitizes your internal SD card, where Android phones typically save pictures, downloads, documents, and other such personal data. Then, we eliminate the guesswork by prompting you to initiate the factory reset.
Nuke My Phone doesn’t eradicate data from your external SD card, but that’s okay because reusing your SD card in your new device will save you money! If your device has an external SD card, make sure to remove it before recycling or trade-in.

So this app should really wipe your internal-storage: it not only deletes content, but overwrites it with random data. This way, nothing is recoverable anymore afterwards -- and you can savely give away/sell your device.