I have a lot of boards and usually need to re-use code even for different projects.

boot.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ## FILE OBTAINED FROM: https://github.com/RetiredWizard/PyDOS/blob/main/cpython/boot.py
  2. ## BECAUSE ! I cannot find anyone else who explains boot.py clearly enough to work for the Cardputer and Circuitpython
  3. ## *specifically* for writing to the SD card!
  4. ## Minor edits made to comments and print statements for relevance to Cardputer generally
  5. """CircuitPython Essentials Storage logging boot.py file"""
  6. from sys import implementation
  7. import board
  8. import digitalio
  9. import storage
  10. # The file system will be set to Read/Write status for next
  11. # power cycle unless a control GPIO is grounded (GP2,5 or 6 depending on the Microcontroller)
  12. # in which case the host computer will have Read/Write access and PyDOS will have readonly access.
  13. if board.board_id == 'arduino_nano_rp2040_connect':
  14. swpin = board.D2
  15. elif board.board_id in ['raspberry_pi_pico','cytron_maker_pi_rp2040']:
  16. swpin = board.GP6
  17. elif board.board_id == 'adafruit_qtpy_esp32c3':
  18. swpin = board.A1
  19. elif board.board_id == 'adafruit_itsybitsy_rp2040':
  20. swpin = board.D7
  21. else:
  22. if "D5" in dir(board):
  23. swpin = board.D5
  24. elif "GP5" in dir(board):
  25. swpin = board.GP5
  26. elif "IO5" in dir(board):
  27. swpin = board.IO5
  28. elif "D6" in dir(board):
  29. swpin = board.D6
  30. elif "GP6" in dir(board):
  31. swpin = board.GP6
  32. elif "IO6" in dir(board):
  33. swpin = board.IO6
  34. elif "D2" in dir(board):
  35. swpin = board.D2
  36. elif "GP2" in dir(board):
  37. swpin = board.GP2
  38. elif "IO2" in dir(board):
  39. swpin = board.IO2
  40. else:
  41. swpin = None
  42. if swpin:
  43. switch = digitalio.DigitalInOut(swpin)
  44. switch.direction = digitalio.Direction.INPUT
  45. switch.pull = digitalio.Pull.UP
  46. # If the switch pin is connected to ground (switch.value == False) allow host to write to the drive
  47. if switch.value == False:
  48. # Mounts so Host computer can write to micro-flash
  49. storage.remount("/", True)
  50. print("Switch False (pin grounded), FS is ReadOnly")
  51. else:
  52. storage.remount("/", False)
  53. print("Switch True (not grounded), FS is ReadWrite")
  54. switch.deinit()
  55. else:
  56. storage.remount("/", False )