stm32.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Copyright (c) 2021 Project CHIP Authors
  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. import os
  15. from enum import Enum, auto
  16. from .gn import GnBuilder
  17. class stm32App(Enum):
  18. LIGHT = auto()
  19. def ExampleName(self):
  20. if self == stm32App.LIGHT:
  21. return 'lighting-app'
  22. else:
  23. raise Exception('Unknown app type: %r' % self)
  24. def AppNamePrefix(self):
  25. if self == stm32App.LIGHT:
  26. return 'chip-stm32-lighting-example'
  27. else:
  28. raise Exception('Unknown app type: %r' % self)
  29. def FlashBundleName(self):
  30. if self == stm32App.LIGHT:
  31. return 'lighting_app.out.flashbundle.txt'
  32. else:
  33. raise Exception('Unknown app type: %r' % self)
  34. def BuildRoot(self, root):
  35. return os.path.join(root, 'examples', self.ExampleName(), 'stm32')
  36. class stm32Board(Enum):
  37. STM32WB55XX = auto()
  38. def GetIC(self):
  39. if self == stm32Board.STM32WB55XX:
  40. return 'STM32WB5MM-DK'
  41. else:
  42. raise Exception('Unknown board #: %r' % self)
  43. class stm32Builder(GnBuilder):
  44. def __init__(self,
  45. root,
  46. runner,
  47. app: stm32App = stm32App.LIGHT,
  48. board: stm32Board = stm32Board.STM32WB55XX):
  49. super(stm32Builder, self).__init__(
  50. root=app.BuildRoot(root),
  51. runner=runner)
  52. self.board = board
  53. self.app = app
  54. stm32_chip = self.board.GetIC()
  55. self.extra_gn_options = ['stm32_ic_family="%s"' % stm32_chip]
  56. self.extra_gn_options.append('chip_config_network_layer_ble=true')
  57. self.extra_gn_options.append('treat_warnings_as_errors=false')
  58. def GnBuildArgs(self):
  59. return self.extra_gn_options
  60. def build_outputs(self):
  61. items = {}
  62. for extension in ["out", "out.map", "out.hex"]:
  63. name = '%s.%s' % (self.app.AppNamePrefix(), extension)
  64. items[name] = os.path.join(self.output_dir, name)
  65. # Figure out flash bundle files and build accordingly
  66. with open(os.path.join(self.output_dir, self.app.FlashBundleName())) as f:
  67. for line in f.readlines():
  68. name = line.strip()
  69. items['flashbundle/%s' %
  70. name] = os.path.join(self.output_dir, name)
  71. return items