Calling stop() should close the serial port
To upload designs, you'll need to enable LFS and have an admin enable hashed storage.
More information