esp.rst 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. :mod:`esp` --- functions related to the ESP8266
  2. ===============================================
  3. .. module:: esp
  4. :synopsis: functions related to the ESP8266
  5. The ``esp`` module contains specific functions related to the ESP8266 module.
  6. Functions
  7. ---------
  8. .. function:: sleep_type([sleep_type])
  9. Get or set the sleep type.
  10. If the *sleep_type* parameter is provided, sets the sleep type to its
  11. value. If the function is called without parameters, returns the current
  12. sleep type.
  13. The possible sleep types are defined as constants:
  14. * ``SLEEP_NONE`` -- all functions enabled,
  15. * ``SLEEP_MODEM`` -- modem sleep, shuts down the WiFi Modem circuit.
  16. * ``SLEEP_LIGHT`` -- light sleep, shuts down the WiFi Modem circuit
  17. and suspends the processor periodically.
  18. The system enters the set sleep mode automatically when possible.
  19. .. function:: deepsleep(time=0)
  20. Enter deep sleep.
  21. The whole module powers down, except for the RTC clock circuit, which can
  22. be used to restart the module after the specified time if the pin 16 is
  23. connected to the reset pin. Otherwise the module will sleep until manually
  24. reset.
  25. .. function:: flash_id()
  26. Read the device ID of the flash memory.
  27. .. function:: flash_read(byte_offset, length_or_buffer)
  28. .. function:: flash_write(byte_offset, bytes)
  29. .. function:: flash_erase(sector_no)
  30. .. function:: set_native_code_location(start, length)
  31. Set the location that native code will be placed for execution after it is
  32. compiled. Native code is emitted when the ``@micropython.native``,
  33. ``@micropython.viper`` and ``@micropython.asm_xtensa`` decorators are applied
  34. to a function. The ESP8266 must execute code from either iRAM or the lower
  35. 1MByte of flash (which is memory mapped), and this function controls the
  36. location.
  37. If *start* and *length* are both ``None`` then the native code location is
  38. set to the unused portion of memory at the end of the iRAM1 region. The
  39. size of this unused portion depends on the firmware and is typically quite
  40. small (around 500 bytes), and is enough to store a few very small
  41. functions. The advantage of using this iRAM1 region is that it does not
  42. get worn out by writing to it.
  43. If neither *start* nor *length* are ``None`` then they should be integers.
  44. *start* should specify the byte offset from the beginning of the flash at
  45. which native code should be stored. *length* specifies how many bytes of
  46. flash from *start* can be used to store native code. *start* and *length*
  47. should be multiples of the sector size (being 4096 bytes). The flash will
  48. be automatically erased before writing to it so be sure to use a region of
  49. flash that is not otherwise used, for example by the firmware or the
  50. filesystem.
  51. When using the flash to store native code *start+length* must be less
  52. than or equal to 1MByte. Note that the flash can be worn out if repeated
  53. erasures (and writes) are made so use this feature sparingly.
  54. In particular, native code needs to be recompiled and rewritten to flash
  55. on each boot (including wake from deepsleep).
  56. In both cases above, using iRAM1 or flash, if there is no more room left
  57. in the specified region then the use of a native decorator on a function
  58. will lead to `MemoryError` exception being raised during compilation of
  59. that function.