pico.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. # WizIO 2022 Georgi Angelov
  2. # http://www.wizio.eu/
  3. # https://github.com/Wiz-IO/wizio-pico
  4. from os.path import join
  5. from SCons.Script import DefaultEnvironment, Builder
  6. from platformio.builder.tools.piolib import PlatformIOLibBuilder
  7. def add_ops(env):
  8. if "PICO_STDIO_UART" in env.get("CPPDEFINES"):
  9. env.Append( CPPDEFINES = [ "LIB_PICO_STDIO_UART"] )
  10. if "LIB_PICO_STDIO_UART" in env.get("CPPDEFINES"):
  11. env.Append( CPPDEFINES = [ "PICO_STDIO_UART"] )
  12. if "PICO_STDIO_USB" in env.get("CPPDEFINES"):
  13. env.Append( CPPDEFINES = [ "LIB_PICO_STDIO_USB"] )
  14. if "LIB_PICO_STDIO_USB" in env.get("CPPDEFINES"):
  15. env.Append( CPPDEFINES = [ "PICO_STDIO_USB"] )
  16. if "PICO_STDIO_SEMIHOSTING" in env.get("CPPDEFINES"):
  17. env.Append( CPPDEFINES = [ "LIB_PICO_STDIO_SEMIHOSTING"] )
  18. if "LIB_PICO_STDIO_SEMIHOSTING" in env.get("CPPDEFINES"):
  19. env.Append( CPPDEFINES = [ "PICO_STDIO_SEMIHOSTING"] )
  20. tab = ' *'
  21. OBJ_DIR = join( "$BUILD_DIR", env.platform, env.sdk, "pico" )
  22. LIB_DIR = join( env.framework_dir, env.sdk, "pico" )
  23. if "PICO_DOUBLE_SUPPORT_ROM_V1" in env.get("CPPDEFINES"):
  24. print(tab, 'PICO_DOUBLE_SUPPORT_ROM_V1')
  25. env.BuildSources( join(OBJ_DIR, "pico_double"), join(LIB_DIR, "pico_double") )
  26. env.Append( LINKFLAGS = [
  27. "-Wl,-wrap,__aeabi_dadd",
  28. "-Wl,-wrap,__aeabi_ddiv",
  29. "-Wl,-wrap,__aeabi_dmul",
  30. "-Wl,-wrap,__aeabi_drsub",
  31. "-Wl,-wrap,__aeabi_dsub",
  32. "-Wl,-wrap,__aeabi_cdcmpeq",
  33. "-Wl,-wrap,__aeabi_cdrcmple",
  34. "-Wl,-wrap,__aeabi_cdcmple",
  35. "-Wl,-wrap,__aeabi_dcmpeq",
  36. "-Wl,-wrap,__aeabi_dcmplt",
  37. "-Wl,-wrap,__aeabi_dcmple",
  38. "-Wl,-wrap,__aeabi_dcmpge",
  39. "-Wl,-wrap,__aeabi_dcmpgt",
  40. "-Wl,-wrap,__aeabi_dcmpun",
  41. "-Wl,-wrap,__aeabi_i2d",
  42. "-Wl,-wrap,__aeabi_l2d",
  43. "-Wl,-wrap,__aeabi_ui2d",
  44. "-Wl,-wrap,__aeabi_ul2d",
  45. "-Wl,-wrap,__aeabi_d2iz",
  46. "-Wl,-wrap,__aeabi_d2lz",
  47. "-Wl,-wrap,__aeabi_d2uiz",
  48. "-Wl,-wrap,__aeabi_d2ulz",
  49. "-Wl,-wrap,__aeabi_d2f",
  50. "-Wl,-wrap,sqrt",
  51. "-Wl,-wrap,cos",
  52. "-Wl,-wrap,sin",
  53. "-Wl,-wrap,tan",
  54. "-Wl,-wrap,atan2",
  55. "-Wl,-wrap,exp",
  56. "-Wl,-wrap,log",
  57. "-Wl,-wrap,ldexp",
  58. "-Wl,-wrap,copysign",
  59. "-Wl,-wrap,trunc",
  60. "-Wl,-wrap,floor",
  61. "-Wl,-wrap,ceil",
  62. "-Wl,-wrap,round",
  63. "-Wl,-wrap,sincos",
  64. "-Wl,-wrap,asin",
  65. "-Wl,-wrap,acos",
  66. "-Wl,-wrap,atan",
  67. "-Wl,-wrap,sinh",
  68. "-Wl,-wrap,cosh",
  69. "-Wl,-wrap,tanh",
  70. "-Wl,-wrap,asinh",
  71. "-Wl,-wrap,acosh",
  72. "-Wl,-wrap,atanh",
  73. "-Wl,-wrap,exp2",
  74. "-Wl,-wrap,log2",
  75. "-Wl,-wrap,exp10",
  76. "-Wl,-wrap,log10",
  77. "-Wl,-wrap,pow",
  78. "-Wl,-wrap,powint",
  79. "-Wl,-wrap,hypot",
  80. "-Wl,-wrap,cbrt",
  81. "-Wl,-wrap,fmod",
  82. "-Wl,-wrap,drem",
  83. "-Wl,-wrap,remainder",
  84. "-Wl,-wrap,remquo",
  85. "-Wl,-wrap,expm1",
  86. "-Wl,-wrap,log1p",
  87. "-Wl,-wrap,fma",
  88. ])
  89. if "PICO_FLOAT_SUPPORT_ROM_V1" in env.get("CPPDEFINES"):
  90. print(tab, 'PICO_FLOAT_SUPPORT_ROM_V1')
  91. env.BuildSources( join(OBJ_DIR, "pico_float"), join(LIB_DIR, "pico_float") )
  92. env.Append( LINKFLAGS = [
  93. "-Wl,-wrap,__aeabi_fadd",
  94. "-Wl,-wrap,__aeabi_fdiv",
  95. "-Wl,-wrap,__aeabi_fmul",
  96. "-Wl,-wrap,__aeabi_frsub",
  97. "-Wl,-wrap,__aeabi_fsub",
  98. "-Wl,-wrap,__aeabi_cfcmpeq",
  99. "-Wl,-wrap,__aeabi_cfrcmple",
  100. "-Wl,-wrap,__aeabi_cfcmple",
  101. "-Wl,-wrap,__aeabi_fcmpeq",
  102. "-Wl,-wrap,__aeabi_fcmplt",
  103. "-Wl,-wrap,__aeabi_fcmple",
  104. "-Wl,-wrap,__aeabi_fcmpge",
  105. "-Wl,-wrap,__aeabi_fcmpgt",
  106. "-Wl,-wrap,__aeabi_fcmpun",
  107. "-Wl,-wrap,__aeabi_i2f",
  108. "-Wl,-wrap,__aeabi_l2f",
  109. "-Wl,-wrap,__aeabi_ui2f",
  110. "-Wl,-wrap,__aeabi_ul2f",
  111. "-Wl,-wrap,__aeabi_f2iz",
  112. "-Wl,-wrap,__aeabi_f2lz",
  113. "-Wl,-wrap,__aeabi_f2uiz",
  114. "-Wl,-wrap,__aeabi_f2ulz",
  115. "-Wl,-wrap,__aeabi_f2d",
  116. "-Wl,-wrap,sqrtf",
  117. "-Wl,-wrap,cosf",
  118. "-Wl,-wrap,sinf",
  119. "-Wl,-wrap,tanf",
  120. "-Wl,-wrap,atan2f",
  121. "-Wl,-wrap,expf",
  122. "-Wl,-wrap,logf",
  123. "-Wl,-wrap,ldexpf",
  124. "-Wl,-wrap,copysignf",
  125. "-Wl,-wrap,truncf",
  126. "-Wl,-wrap,floorf",
  127. "-Wl,-wrap,ceilf",
  128. "-Wl,-wrap,roundf",
  129. "-Wl,-wrap,sincosf",
  130. "-Wl,-wrap,asinf",
  131. "-Wl,-wrap,acosf",
  132. "-Wl,-wrap,atanf",
  133. "-Wl,-wrap,sinhf",
  134. "-Wl,-wrap,coshf",
  135. "-Wl,-wrap,tanhf",
  136. "-Wl,-wrap,asinhf",
  137. "-Wl,-wrap,acoshf",
  138. "-Wl,-wrap,atanhf",
  139. "-Wl,-wrap,exp2f",
  140. "-Wl,-wrap,log2f",
  141. "-Wl,-wrap,exp10f",
  142. "-Wl,-wrap,log10f",
  143. "-Wl,-wrap,powf",
  144. "-Wl,-wrap,powintf",
  145. "-Wl,-wrap,hypotf",
  146. "-Wl,-wrap,cbrtf",
  147. "-Wl,-wrap,fmodf",
  148. "-Wl,-wrap,dremf",
  149. "-Wl,-wrap,remainderf",
  150. "-Wl,-wrap,remquof",
  151. "-Wl,-wrap,expm1f",
  152. "-Wl,-wrap,log1pf",
  153. "-Wl,-wrap,fmaf",
  154. ])
  155. if "PICO_DIVIDER_HARDWARE" in env.get("CPPDEFINES"):
  156. print(tab, 'PICO_DIVIDER_HARDWARE')
  157. env.BuildSources( join(OBJ_DIR, "pico_divider"), join(LIB_DIR, "pico_divider") )
  158. env.Append( LINKFLAGS = [
  159. "-Wl,-wrap,__aeabi_idiv",
  160. "-Wl,-wrap,__aeabi_idivmod",
  161. "-Wl,-wrap,__aeabi_ldivmod",
  162. "-Wl,-wrap,__aeabi_uidiv",
  163. "-Wl,-wrap,__aeabi_uidivmod",
  164. "-Wl,-wrap,__aeabi_uldivmod",
  165. ])
  166. if "PICO_INT64_OPS_PICO" in env.get("CPPDEFINES"):
  167. print(tab, 'PICO_INT64_OPS_PICO')
  168. env.BuildSources( join(OBJ_DIR, "pico_int64_ops"), join(LIB_DIR, "pico_int64_ops") )
  169. env.Append( LINKFLAGS = [
  170. "-Wl,-wrap,wrapper_func __aeabi_lmul",
  171. ])
  172. if "PICO_BIT_OPS_PICO" in env.get("CPPDEFINES"):
  173. print(tab, 'PICO_BIT_OPS_PICO')
  174. env.BuildSources( join(OBJ_DIR, "pico_bit_ops"), join(LIB_DIR, "pico_bit_ops") )
  175. env.Append( LINKFLAGS = [
  176. "-Wl,-wrap,__clzsi2",
  177. "-Wl,-wrap,__clzsi2",
  178. "-Wl,-wrap,__clzdi2",
  179. "-Wl,-wrap,__ctzsi2",
  180. "-Wl,-wrap,__ctzdi2",
  181. "-Wl,-wrap,__popcountsi2",
  182. "-Wl,-wrap,__popcountdi2",
  183. #"-Wl,-wrap,__clz",
  184. #"-Wl,-wrap,__clzl",
  185. #"-Wl,-wrap,__clzsi2",
  186. #"-Wl,-wrap,__clzll",
  187. ])
  188. if "PICO_MEM_OPS_PICO" in env.get("CPPDEFINES"):
  189. print(tab, 'PICO_MEM_OPS_PICO')
  190. env.BuildSources( join(OBJ_DIR, "pico_mem_ops"), join(LIB_DIR, "pico_mem_ops") )
  191. env.Append( LINKFLAGS = [
  192. "-Wl,-wrap,memcpy",
  193. "-Wl,-wrap,memset",
  194. "-Wl,-wrap,__aeabi_memcpy",
  195. "-Wl,-wrap,__aeabi_memset",
  196. "-Wl,-wrap,__aeabi_memcpy4",
  197. "-Wl,-wrap,__aeabi_memset4",
  198. "-Wl,-wrap,__aeabi_memcpy8",
  199. "-Wl,-wrap,__aeabi_memset8",
  200. ])
  201. if 'ARDUINO' == env.get("PROGNAME"):
  202. return ########################################################################################
  203. if "PICO_PRINTF_PICO" in env.get("CPPDEFINES"):
  204. print(tab, 'PICO_PRINTF_PICO')
  205. env.BuildSources( join(OBJ_DIR, "pico_printf"), join(LIB_DIR, "pico_printf") )
  206. env.Append( LINKFLAGS = [
  207. "-Wl,-wrap,sprintf",
  208. "-Wl,-wrap,snprintf",
  209. "-Wl,-wrap,vsnprintf",
  210. "-Wl,-wrap,printf",
  211. "-Wl,-wrap,vprintf",
  212. "-Wl,-wrap,puts",
  213. "-Wl,-wrap,putchar",
  214. ])
  215. if "PICO_STDIO_USB" in env.get("CPPDEFINES") or "PICO_STDIO_UART" in env.get("CPPDEFINES") or "PICO_STDIO_SEMIHOSTING" in env.get("CPPDEFINES"):
  216. env.BuildSources( join(OBJ_DIR, "pico_stdio"), join(LIB_DIR, "pico_stdio") )
  217. if "PICO_STDIO_USB" in env.get("CPPDEFINES"):
  218. print(tab, 'STDIO : USB')
  219. env.BuildSources( join(OBJ_DIR, "pico_stdio_usb"), join(LIB_DIR, "pico_stdio_usb") )
  220. if "PICO_STDIO_UART" in env.get("CPPDEFINES"):
  221. print(tab, 'STDIO : UART')
  222. env.BuildSources( join(OBJ_DIR, "pico_stdio_uart"), join(LIB_DIR, "pico_stdio_uart") )
  223. if "PICO_STDIO_SEMIHOSTING" in env.get("CPPDEFINES"):
  224. print(tab, 'STDIO : SEMIHOSTING')
  225. env.BuildSources( join(OBJ_DIR, "pico_stdio_semihosting"), join(LIB_DIR, "pico_stdio_semihosting") )
  226. env.Append( LINKFLAGS = [
  227. "-Wl,-wrap,malloc",
  228. "-Wl,-wrap,calloc",
  229. "-Wl,-wrap,free",
  230. ])
  231. def add_tinyusb(env):
  232. OBJ_DIR = join( "$BUILD_DIR", env.platform, env.sdk, "pico", "usb" )
  233. USB_DIR = join( env.framework_dir, env.sdk, "lib", "tinyusb", "src" )
  234. for define in env.get("CPPDEFINES"):
  235. if "USB" in define:
  236. env.Append( CPPDEFINES = [ "CFG_TUSB_MCU=OPT_MCU_RP2040", "CFG_TUSB_OS=OPT_OS_PICO" ], CPPPATH = [ USB_DIR ] )
  237. if "PICO_USB_HOST" in define:
  238. #[ini] build_flags = -D PICO_USB_HOST ... load lib as host
  239. print(' * TINYUSB : HOST')
  240. env.BuildSources( OBJ_DIR, USB_DIR, src_filter = [ "+<*>", "-<device>", "+<class>" ] )
  241. else:
  242. #[ini] build_flags = -D PICO_USB_DEVICE / PICO_STDIO_USB ... load lib as device
  243. print(' * TINYUSB : DEVICE')
  244. env.BuildSources( OBJ_DIR, USB_DIR, src_filter = [ "+<*>", "-<host>", "+<class>" ] )
  245. break
  246. def add_sdk(env):
  247. add_ops(env)
  248. add_tinyusb(env)
  249. if 'ARDUINO' != env.get("PROGNAME"):
  250. new_delete = "+"
  251. pico_malloc = '+'
  252. else:
  253. new_delete = "-"
  254. pico_malloc = '-'
  255. filter = [ "+<*>",
  256. "-<lib>",
  257. "-<boot_stage2>",
  258. "-<pico/pico_cyw43_arch>",
  259. "-<pico/pico_lwip>",
  260. "-<pico/pico_bit_ops>",
  261. "-<pico/pico_divider>",
  262. "-<pico/pico_int64_ops>",
  263. "-<pico/pico_printf>",
  264. "-<pico/pico_float>",
  265. "-<pico/pico_double>",
  266. "-<pico/pico_stdio>",
  267. "-<pico/pico_stdio_usb>",
  268. "-<pico/pico_stdio_uart>",
  269. "-<pico/pico_stdio_semihosting>",
  270. "-<pico/pico_mem_ops>",
  271. "-<pico/pico_standard_link/crt0.S>",
  272. new_delete + "<pico/pico_standard_link/new_delete.cpp>",
  273. pico_malloc + "<pico/pico_malloc>"
  274. ]
  275. env.BuildSources( join("$BUILD_DIR", env.platform, env.sdk), join(env.framework_dir, env.sdk), src_filter = filter )