In-system programming tool for LPC microcontrollers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chips.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Copyright 2017 Clayton G. Hobbs
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Chips supported by Alpaca ISP"""
  15. from collections import namedtuple
  16. from alpaca_isp.lpc import LPC8xx
  17. class Chip(namedtuple("Chip", [
  18. # Name of the chip
  19. "name",
  20. # Class that represents this chip
  21. "family",
  22. # Size of flash in KiB
  23. "flash",
  24. # Size of RAM in KiB
  25. "ram",
  26. # Address of the start of RAM
  27. "ram_start",
  28. # RAM location to which we can safely write
  29. "ram_base",
  30. # Maximum number of bytes we can copy
  31. "max_copy",
  32. # Sector table
  33. "sectors"])):
  34. """Flashing-related properties of an LPC microcontroller"""
  35. __slots__ = ()
  36. @property
  37. def sector_segments(self):
  38. """Returns a list of (start, end) tuples for each flash sector"""
  39. sector_segments = []
  40. for i in range(len(self.sectors)):
  41. sector_segments.append((sum(self.sectors[:i]),
  42. sum(self.sectors[:i+1])))
  43. return sector_segments
  44. def sectors_used(self, segments):
  45. """Returns a list of sectors used by the given memory segments
  46. segments: a list of (start, end) tuples representing segments of used
  47. memory
  48. """
  49. sector_segments = self.sector_segments
  50. s = set()
  51. for dseg in segments:
  52. for i, sseg in enumerate(sector_segments):
  53. if ((dseg[0] >= sseg[0] and dseg[1] <= sseg[1])
  54. or (dseg[0] < sseg[0] and dseg[1] > sseg[1])
  55. or (sseg[0] <= dseg[0] < sseg[1])
  56. or (sseg[0] < dseg[1] <= sseg[1])):
  57. s.add(i)
  58. return sorted(s)
  59. chips = {
  60. 0x00008221: Chip(
  61. name="LPC822M101JHI33",
  62. family=LPC8xx,
  63. flash=16,
  64. ram=4,
  65. ram_start=0x10000000,
  66. ram_base=0x10000300,
  67. max_copy=1024,
  68. sectors=(1024,)*16),
  69. 0x00008222: Chip(
  70. name="LPC822M101JDH20",
  71. family=LPC8xx,
  72. flash=16,
  73. ram=4,
  74. ram_start=0x10000000,
  75. ram_base=0x10000300,
  76. max_copy=1024,
  77. sectors=(1024,)*16),
  78. 0x00008241: Chip(
  79. name="LPC824M201JHI33",
  80. family=LPC8xx,
  81. flash=32,
  82. ram=8,
  83. ram_start=0x10000000,
  84. ram_base=0x10000300,
  85. max_copy=1024,
  86. sectors=(1024,)*32),
  87. 0x00008242: Chip(
  88. name="LPC824M201JDH20",
  89. family=LPC8xx,
  90. flash=32,
  91. ram=8,
  92. ram_start=0x10000000,
  93. ram_base=0x10000300,
  94. max_copy=1024,
  95. sectors=(1024,)*32)
  96. }