Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

try! Swift Embedded with Raspberry Pi Pico

try! Swift Embedded with Raspberry Pi Pico

swift expands #2

yochidros

May 13, 2024
Tweet

More Decks by yochidros

Other Decks in Programming

Transcript

  1. Who am I? Name => yochidros Job => So!ware Engineer

    Company => bitkey (2024/01 ~ ) X => Github => https://x.com/yochidros https://github.com/yochidros
  2. 1. ϥεύΠ picoΛങ͏ (792ԁ) • 2. swi! snapshot൛ΛΠϯετʔϧ 3. GCC

    ARM ToolchainͷΠϯετʔϧ • 4. pico-sdkͷμ΢ϯϩʔυ • 5. swi!-embeded-examplesͷμ΢ϯϩʔυ • https://www.switch-science.com/products/6900 https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads https://github.com/raspberrypi/pico-sdk https://github.com/apple/swi!-embedded-examples ※ɹswi! snapshot version: org.swi!.59202404131a (4/13)
  3. • -function-sections : ηΫγϣϯ͝ͱʹؔ਺Λग़ྗ • -enable-experimental-feature Embedded:ɹswi! embedded mode •

    -wmo: ࠷దԽ • -parse-as-library: ϥΠϒϥϦͱͯ͠ղੳ -Xfrontend -function-sections -enable-experimental-feature Embedded -wmo -parse-as-library
  4. `$\( echo '$`<TARGET_PROPERTY:swift-blinky,INCLUDE_DIRECTORIES>' | tr '\;' '\\n' `$\( echo '$`{CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}'

    | tr ' ' '\\n' -import-bridging-header ${CMAKE_CURRENT_LIST_DIR}/BridgingHeader.h ${CMAKE_CURRENT_LIST_DIR}/Main.swift -c -o ${CMAKE_CURRENT_BINARY_DIR}/_swiftcode.o
  5. @main struct Main { static func main() { // PICO_DEFAULT_LED_PIN

    = GP25 let led = UInt32(PICO_DEFAULT_LED_PIN) gpio_init(led) // gpio番号を初期化 gpio_set_dir(led, /*out*/true) // 出力に設定 while true { gpio_put(led, true) // high sleep_ms(250) gpio_put(led, false) // low sleep_ms(250) } } }
  6. ੍໿͕͋Δ • printؔ਺͕StaticStringͱIntegerͷΈαϙʔτ • String (։ൃத) • Existential • Weak/

    unowned reference • VarArgs • Swi! Concurrency (Single thread modeͷΈactor,task͕ར༻Մ ೳ) • heap allocation͕ར༻Ͱ͖ͳ͍৔߹ ▪ Class, Array, Dictionary ▪ function capture https://github.com/apple/swi!/blob/main/docs/EmbeddedSwi!/EmbeddedSwi!Status.md
  7. pico, pico-w atomicؔ਺͕llvmͱgccͰҰக͠ͳ͍ error: ld returned 1 exit status ...

    arm-none-eabi/bin/ld: _swiftcode.o: in function `$ss10swi...` undefined reference to `__atomic_load_4' undefined reference to `__atomic_fetch_add_4' undefined reference to `__atomic_fetch_sub_4' undefined reference to `__atomic_compare_exchange_4' undefined reference to `__atomic_store_4'
  8. FIN