japaric-archived / photon-hal

Low level Rust bindings to particle's HAL (Hardware Abstraction Layer)
Apache License 2.0
9 stars 8 forks source link

Generate deviceid module #6

Closed dbrgn closed 7 years ago

dbrgn commented 7 years ago

It generates successfully, but I couldn't get it to work. With this in a program:

use hal::deviceid;

let id = deviceid::HAL_Platform_ID();

...it doesn't link properly:

error: linking with `arm-none-eabi-g++` failed: exit code: 1
  |
  = note: "arm-none-eabi-g++" "-g3" "-gdwarf-2" "-Os" "-mcpu=cortex-m3" "-mthumb" "-ffunction-sections" "-fdata-sections" "-fno-builtin-malloc" "-fno-builtin-free" "-fno-builtin-realloc" "build/target/user-part/platform-6-m/src/user_module.o" "build/target/user-part/platform-6-m/src/module_info.o" "build/target/user-part/platform-6-m/src/user_export.o" "build/target/user-part/platform-6-m/src/newlib_stubs.o" "-Wl,--whole-archive" "hal/src/photon/lib/STM32F2xx_Peripheral_Libraries.a" "-Wl,--no-whole-archive" "-nostartfiles" "-Xlinker" "--gc-sections" "-Wl,--whole-archive" "-L" "/home/danilo/.xargo/lib/rustlib/photon/lib" "/mnt/data/Projects/photon-quickstart/target/photon/release/examples/usbserial-21a592d2d61a5529.0.o" "-o" "/mnt/data/Projects/photon-quickstart/target/photon/release/examples/usbserial-21a592d2d61a5529" "-Wl,--gc-sections" "-L" "/mnt/data/Projects/photon-quickstart/target/photon/release/deps" "-L" "/mnt/data/Projects/photon-quickstart/target/release/deps" "-L" "/mnt/data/Projects/photon-quickstart/target/photon/release/build/photon-ec931a572a4ed533/out" "-L" "/mnt/data/Projects/photon-quickstart/target/photon/release/build/photon-ec931a572a4ed533/out/photon/system-part1" "-L" "/home/danilo/.xargo/lib/rustlib/photon/lib" "-lhal-dynalib" "-lservices-dynalib" "-lsystem-dynalib" "-lrt-dynalib" "-lwiring" "-lcommunication-dynalib" "-lplatform" "-lwiring_globals" "-Wl,--no-whole-archive" "-lnosys" "-Tlinker.ld" "--specs=nano.specs" "-Wl,--defsym,USER_FIRMWARE_IMAGE_SIZE=0x20000" "-Wl,--defsym,USER_FIRMWARE_IMAGE_LOCATION=0x80A0000"
  = note: /mnt/data/Projects/photon-quickstart/target/photon/release/examples/usbserial-21a592d2d61a5529.0.o: In function `loop':
          usbserial.cgu-0.rs:(.text.loop+0x40): undefined reference to `HAL_Platform_ID'
          collect2: error: ld returned 1 exit status

(usbserial.rs is the name of the example script.)

@japaric any ideas? I don't know enough about embedded dev to be able to debug this :) Any pointers are appreciated.

homunkulus commented 7 years ago

:umbrella: The latest upstream changes (presumably #5) made this pull request unmergeable. Please resolve the merge conflicts.

japaric commented 7 years ago

@dbrgn this needs a rebase

dbrgn commented 7 years ago

Yep, it's conflicting :) That's easy to solve. But do you know what the problem is with the linking?

japaric commented 7 years ago

Ah, sorry. I totally missed your first comment. I'll take a look.

japaric commented 7 years ago

It seems that that specific symbol is in the libhal.a library, which aren't linking in the photon crate. I'll add that library later today.

japaric commented 7 years ago

Looking at this further. That function seems to be part of the system API and requires to linking to a bunch of libraries: FreeRTOS, WICED, etc. So I'm not sure if this function is supposed to be called from normal user programs. @dbrgn How would you call this function from C/C++? I can't find it in the firmware reference documentation.

dbrgn commented 7 years ago

Hm, deviceId is documented here but I can't find a reference to the platform ID. Maybe that's only meant to be used internally?

The header file is here.

japaric commented 7 years ago

The example links fine if you use deviceId instead of platformId.

dbrgn commented 7 years ago

Ok, I guess I'll update the PR to exclude that function :)

japaric commented 7 years ago

It's fine to land this as it is. It would the task of a highel level abstraction to hide the HAL functions that aren't actually supposed to be exposed / used.

@dbrgn could you add deviceId example to the photon-quickstart template to make sure this works?

dbrgn commented 7 years ago

It would the task of a highel level abstraction to hide the HAL functions that aren't actually supposed to be exposed / used.

Fair enough.

@dbrgn could you add deviceId example to the photon-quickstart template to make sure this works?

Will do!

japaric commented 7 years ago

Thanks!

@homunkulus r+

homunkulus commented 7 years ago

:pushpin: Commit 179f8fb has been approved by japaric

homunkulus commented 7 years ago

:hourglass: Testing commit 179f8fb with merge 179f8fb...

homunkulus commented 7 years ago

:sunny: Test successful - status-travis Approved by: japaric Pushing 179f8fb82e1a3ba959532ae33ad59eb67f165cfc to master...