lib.rs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //! # HAL for the STM32F1 family of microcontrollers
  2. //!
  3. //! This is an implementation of the [`embedded-hal`] traits for the STM32F1 family of
  4. //! microcontrollers.
  5. //!
  6. //! [`embedded-hal`]: https://crates.io/crates/embedded-hal
  7. //!
  8. //! # Usage
  9. //!
  10. //! ## Building an application (binary crate)
  11. //!
  12. //! A detailed usage guide can be found in the [README]
  13. //!
  14. //! supported microcontrollers are:
  15. //!
  16. //! - stm32f103
  17. //! - stm32f101
  18. //! - stm32f100
  19. //! - stm32f105
  20. //! - stm32f107
  21. //!
  22. //! ## Usage
  23. //!
  24. //! This crate supports multiple microcontrollers in the
  25. //! stm32f1 family. Which specific microcontroller you want to build for has to be
  26. //! specified with a feature, for example `stm32f103`.
  27. //!
  28. //! If no microcontroller is specified, the crate will not compile.
  29. //!
  30. //! The currently supported variants are
  31. //!
  32. //! - `stm32f100`
  33. //! - `stm32f101`
  34. //! - `stm32f103`
  35. //! - `stm32f105`
  36. //! - `stm32f107`
  37. //!
  38. //! You may also need to specify the density of the device with `medium`, `high` or `xl`
  39. //! to enable certain peripherals. Generally the density can be determined by the 2nd character
  40. //! after the number in the device name (i.e. For STM32F103C6U, the 6 indicates a low-density
  41. //! device) but check the datasheet or CubeMX to be sure.
  42. //! * 4, 6 => low density, no feature required
  43. //! * 8, B => `medium` feature
  44. //! * C, D, E => `high` feature
  45. //! * F, G => `xl` feature
  46. //!
  47. //! ## Commonly used setup
  48. //! Almost all peripherals require references to some registers in `RCC` and `AFIO`. The following
  49. //! code shows how to set up those registers
  50. //!
  51. //! ```rust
  52. //! // Get access to the device specific peripherals from the peripheral access crate
  53. //! let dp = pac::Peripherals::take().unwrap();
  54. //!
  55. //! // Take ownership over the raw flash and rcc devices and convert them into the corresponding
  56. //! // HAL structs
  57. //! let mut flash = dp.FLASH.constrain();
  58. //! let mut rcc = dp.RCC.constrain();
  59. //!
  60. //! // Freeze the configuration of all the clocks in the system and store the frozen frequencies in
  61. //! // `clocks`
  62. //! let clocks = rcc.cfgr.freeze(&mut flash.acr);
  63. //!
  64. //! // Prepare the alternate function I/O registers
  65. //! let mut afio = dp.AFIO.constrain(&mut rcc.apb2);
  66. //! ```
  67. //!
  68. //! ## Usage examples
  69. //!
  70. //! See the [examples] folder.
  71. //!
  72. //! Most of the examples require the following additional dependencies
  73. //! ```toml
  74. //! [dependencies]
  75. //! embedded-hal = "0.2.3"
  76. //! nb = "0.1.2"
  77. //! cortex-m = "0.6.2"
  78. //! cortex-m-rt = "0.6.11"
  79. //! # Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives
  80. //! panic-halt = "0.2.0"
  81. //! ```
  82. //!
  83. //! [examples]: https://github.com/stm32-rs/stm32f1xx-hal/tree/v0.7.0/examples
  84. //! [README]: https://github.com/stm32-rs/stm32f1xx-hal/tree/v0.7.0
  85. #![no_std]
  86. #![deny(broken_intra_doc_links)]
  87. // If no target specified, print error message.
  88. #[cfg(not(any(
  89. feature = "stm32f100",
  90. feature = "stm32f101",
  91. feature = "stm32f103",
  92. feature = "stm32f105",
  93. feature = "stm32f107",
  94. )))]
  95. compile_error!("Target not found. A `--features <target-name>` is required.");
  96. // If any two or more targets are specified, print error message.
  97. #[cfg(any(
  98. all(feature = "stm32f100", feature = "stm32f101"),
  99. all(feature = "stm32f100", feature = "stm32f103"),
  100. all(feature = "stm32f100", feature = "stm32f105"),
  101. all(feature = "stm32f100", feature = "stm32f107"),
  102. all(feature = "stm32f101", feature = "stm32f103"),
  103. all(feature = "stm32f101", feature = "stm32f105"),
  104. all(feature = "stm32f101", feature = "stm32f107"),
  105. all(feature = "stm32f103", feature = "stm32f105"),
  106. all(feature = "stm32f103", feature = "stm32f107"),
  107. all(feature = "stm32f105", feature = "stm32f107"),
  108. ))]
  109. compile_error!(
  110. "Multiple targets specified. Only a single `--features <target-name>` can be specified."
  111. );
  112. #[cfg(feature = "device-selected")]
  113. use embedded_hal as hal;
  114. #[cfg(feature = "stm32f100")]
  115. pub use stm32f1::stm32f100 as pac;
  116. #[cfg(feature = "stm32f101")]
  117. pub use stm32f1::stm32f101 as pac;
  118. #[cfg(feature = "stm32f103")]
  119. pub use stm32f1::stm32f103 as pac;
  120. #[cfg(any(feature = "stm32f105", feature = "stm32f107"))]
  121. pub use stm32f1::stm32f107 as pac;
  122. #[cfg(feature = "device-selected")]
  123. #[deprecated(since = "0.6.0", note = "please use `pac` instead")]
  124. #[doc(hidden)]
  125. pub use crate::pac as device;
  126. #[cfg(feature = "device-selected")]
  127. #[deprecated(since = "0.6.0", note = "please use `pac` instead")]
  128. #[doc(hidden)]
  129. pub use crate::pac as stm32;
  130. #[cfg(feature = "device-selected")]
  131. pub mod adc;
  132. #[cfg(feature = "device-selected")]
  133. pub mod afio;
  134. #[cfg(feature = "device-selected")]
  135. pub mod backup_domain;
  136. #[cfg(feature = "device-selected")]
  137. pub mod bb;
  138. #[cfg(all(feature = "device-selected", feature = "has-can"))]
  139. pub mod can;
  140. #[cfg(feature = "device-selected")]
  141. pub mod crc;
  142. #[cfg(feature = "device-selected")]
  143. pub mod delay;
  144. #[cfg(feature = "device-selected")]
  145. pub mod dma;
  146. #[cfg(feature = "device-selected")]
  147. pub mod flash;
  148. #[cfg(feature = "device-selected")]
  149. pub mod gpio;
  150. #[cfg(feature = "device-selected")]
  151. pub mod i2c;
  152. #[cfg(feature = "device-selected")]
  153. pub mod prelude;
  154. #[cfg(feature = "device-selected")]
  155. pub mod pwm;
  156. #[cfg(feature = "device-selected")]
  157. pub mod pwm_input;
  158. #[cfg(feature = "device-selected")]
  159. pub mod qei;
  160. #[cfg(feature = "device-selected")]
  161. pub mod rcc;
  162. #[cfg(feature = "device-selected")]
  163. pub mod rtc;
  164. #[cfg(feature = "device-selected")]
  165. pub mod serial;
  166. #[cfg(feature = "device-selected")]
  167. pub mod spi;
  168. #[cfg(feature = "device-selected")]
  169. pub mod time;
  170. #[cfg(feature = "device-selected")]
  171. pub mod timer;
  172. #[cfg(all(
  173. feature = "stm32-usbd",
  174. any(feature = "stm32f102", feature = "stm32f103")
  175. ))]
  176. pub mod usb;
  177. #[cfg(feature = "device-selected")]
  178. pub mod watchdog;