You could try any of the following:
The Android pendant (port) of GParted for Linux, AParted. It currently does not support the
exFAT file system, but supports most common Linux file systems and
FAT32, and it can detect unmounted partitions and format by block device id. It can auto-repair drives too. Here is it's online manual.
What @Firelord suggested:
Get the block device id of the flash drive by using the
blkid command from TWRP's "terminal emulator" option under the "Advanced" button.
You could try
mkdosfs -v [-n Label] BLOCKDEV KBYTES, where all the options have been explained above. This will format the block device to FAT32, if the binary is available (I think it is present in
busybox and CyanogenMod), otherwise:
Do what @Izzy suggested in @Firelord's linked question:
(The working directory should be
/system/bin/, whichever has the
busybox binaries installed to it. Also, all commands must be run as root (
su -c before anything else))
mkfs.vfat [-v] [-n LABEL] BLOCKDEV [KBYTES]
What do those options stand for?
-v: Generate verbose output (reporting)
-n Label: Give the file system a name
BLOCKDEV: the file system (block device) you want to format
KBYTES: probably the block size in KB(I'm not 100% sure with this)
So the minimal thing to do would be:
mkfs.vfat -v /dev/block/uba1
(provided your drive to format is available as
/dev/block/uba1 on your system). One more example, giving the file system a name:
mkfs.vfat -v -n MyNewDisk /dev/block/uba1
It should report success then -- or an error if it failed.