{"id":16162400,"url":"https://github.com/sunsided/stm32f3disco-rust","last_synced_at":"2025-04-07T03:47:55.432Z","repository":{"id":172070328,"uuid":"648773390","full_name":"sunsided/stm32f3disco-rust","owner":"sunsided","description":"Rust embedded on the STM32F3-Discovery / STM32F303VC","archived":false,"fork":false,"pushed_at":"2024-07-06T21:01:36.000Z","size":1664,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-13T08:26:44.308Z","etag":null,"topics":["accelerometer","embedded","gyroscope","l3gd20","lsm303dlhc","magnetometer","rust","stm32f3","stm32f3-discovery","stm32f303vct6","temperature"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"eupl-1.2","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sunsided.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-02T19:24:09.000Z","updated_at":"2024-07-06T21:01:39.000Z","dependencies_parsed_at":"2024-07-05T21:33:30.515Z","dependency_job_id":"80f25724-0765-4b7f-a973-ebbc923f7e20","html_url":"https://github.com/sunsided/stm32f3disco-rust","commit_stats":null,"previous_names":["sunsided/stm32f3disco-led-roulette"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fstm32f3disco-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fstm32f3disco-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fstm32f3disco-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sunsided%2Fstm32f3disco-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sunsided","download_url":"https://codeload.github.com/sunsided/stm32f3disco-rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247589835,"owners_count":20963022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accelerometer","embedded","gyroscope","l3gd20","lsm303dlhc","magnetometer","rust","stm32f3","stm32f3-discovery","stm32f303vct6","temperature"],"created_at":"2024-10-10T02:30:00.010Z","updated_at":"2025-04-07T03:47:55.405Z","avatar_url":"https://github.com/sunsided.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# STM32F3 Discovery 🦀⚡\n\nThe LED Roulette example on the [STM32F3 Discovery](https://www.st.com/en/evaluation-tools/stm32f3discovery.html) board,\non steroids,\nwritten in Rust. An experiment to get started with embedded development in Rust, as well as testing the IDE based\ndevelopment\nand debugging experience in JetBrains ~~CLion while using Rust~~ RustRover.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"docs/led-roulette.webp\" alt=\"Moving LEDs on the STM32F3 Discovery board\"/\u003e\n\u003c/div\u003e\n\nThis project covers:\n\n- `probe-rs` flashing and `defmt` logging.\n- Driving the user LEDs via a Timer interrupt.\n- Querying the LSM303DLHC MEMS IMU via I²C (via [`lsm303dlhc-ng`](https://github.com/sunsided/lsm303dlhc)\n  and [`lsm303dlhc-registers`](https://github.com/sunsided/lsm303dlhc-registers)).\n    - Observing the magnetometer's `DRDY` with an `EXTI2_TSC` interrupt.\n    - Observing the accelerometer's `I1DRDY1` with an `EXTI4` interrupt.\n- Querying the L3GD20 MEMS gyroscope via SPI ([`l3gd20-registers`](https://github.com/sunsided/l3gd20-registers)).\n    - Observing the gyro's `DRDY` with an `EXTI1` interrupt.\n- Temperature readings of the sensors are queried at 1Hz as measured by a 1ms `SysTick` interrupt.\n- Operating a USB CDC serial port for communication.\n    - Uses [serial-sensors-proto](https://github.com/sunsided/serial-sensors-proto) to serialize and byte-stuff\n      the sensor readings and hands them over to [serial-sensors](https://github.com/sunsided/serial-sensors)\n      for further shenanigans.\n\nLed ring shenanigans:\n\n- The accelerometer is used to have the downwards facing LED light up.\n- The magnetometer is used to determine a heading. If the device is pointed away from north,\n  the light wheel will turn in the appropriate direction. If the device faces north,\n  the lights will flash.\n\n## Bin features\n\nThe sensors are set up to provide data at up to 400 Hz, which can make debugging complicated.\nTo slow things down, enter `slowpoke` mode:\n\n```shell\ncargo run --features=slowpoke\n```\n\n## Sensor orientation\n\nThe onboard LSM303DLHC's accelerometer sensor seems to be oriented in a left-handed coordinate system:\n\n- X points forward (towards the USB connectors)\n    - When pointing the USB ports downwards, the sensors reads a positive maximum on the\n      X axis.\n    - When pointing the opposite end downwards, the sensor reads a negative maximum on the X axis.\n- Y points left\n    - When pointing the left side downwards, the sensor reads a positive maximum on the Y axis.\n- Z points down\n    - When pointing the bottom side downwards, the sensor reads a positive maximum on the Z axis.\n\nThe magnetometer on the other hand - pun not intended - appears to use a right-handed coordinate system :\n\n- X points backward (towards the LEDs)\n    - When pointing the USB ports towards the earth's magnetic field vector, the sensors reads a negative maximum on the\n      X axis.\n    - When pointing the opposite end towards the vector, the sensor reads a positive maximum on the X axis.\n- Y points right\n    - When pointing the right side towards the vector, the sensor reads a positive maximum on the Y axis.\n- Z points up\n    - When pointing the top side towards the vector, the sensor reads a positive maximum on the Z axis.\n\n| Accelerometer                                            | Magnetometer                                           | Gyroscope                          |\n|----------------------------------------------------------|--------------------------------------------------------|------------------------------------|\n| ![LSM303DLHC Accelerometer](docs/tikz/accelerometer.png) | ![LSM303DLHC Magnetometer](docs/tikz/magnetometer.png) | ![L3GD20](docs/tikz/gyroscope.png) |\n\n## Flashing \u0026 Running\n\nEasy.\n\n```shell\nDEFMT_LOG=info cargo run\n````\n\n## Requirements\n\n### Target\n\nThis project uses the `thumbv7em-none-eabihf` target. Prepare it using:\n\n```shell\nrustup target add thumbv7em-none-eabihf\n```\n\n### flip-link\n\nSet up [flip-link](https://github.com/knurling-rs/flip-link):\n\n\u003e Adds zero-cost stack overflow protection to your embedded programs.\n\n### probe-rs\n\nSet up [probe-rs](https://probe.rs/), and follow the setup instructions (e.g.\nthe [Linux udev rules](https://probe.rs/docs/getting-started/probe-setup/#linux%3A-udev-rules)).\n\n---\n\n## Troubleshooting\n\n### Outdated firmware\n\nMy STM32F3 Discovery had an outdated version of the ST-Link firmware, and probe-rs refused to work with it:\n\n\u003e probe-rs failed to open the debug probe\n\u003e Error processing command: The firmware on the probe is outdated.\n\nGo\nto [ST-LINK, ST-LINK/V2, ST-LINK/V2-1, STLINK-V3 boards firmware upgrade](https://www.st.com/en/development-tools/stsw-link007.html)\nand download the latest version. Unzip, run the application and follow the instructions.\n\n```shell\njava -jar STLinkUpgrade.jar\n```\n\n## Invalid SRAM size definition\n\n\u003e Error: The flashing procedure failed for 'target/thumbv7em-none-eabihf/debug/stm32f3disco-led-roulette'.\n\u003e\n\u003e Caused by:\n\u003e 0: Failed to erase flash sector at address 0x08000000.\n\u003e 1: Something during the interaction with the core went wrong\n\u003e 2: A timeout occurred.\n\nFrom [this GitHub comment](https://github.com/probe-rs/probe-rs/issues/2496#issuecomment-2154359915):\n\n\u003e The problem is that the chip has 40KB of main SRAM, but the chip definition says 48KB,\n\u003e and we try to place the flash loader's stack at the end of that 48KB region.\n\nI went the hard way and installed `probe-rs` from sources:\n\n```shell\ncargo install probe-rs-tools --git https://github.com/probe-rs/probe-rs --locked\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fstm32f3disco-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunsided%2Fstm32f3disco-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunsided%2Fstm32f3disco-rust/lists"}