lib.rs 806 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #![no_std]
  2. #[cfg(target_arch = "arm")]
  3. use flipper_f1_sys::hal::{huart1, HAL_UART_Transmit_IT};
  4. #[no_mangle]
  5. pub extern "C" fn add(a: u32, b: u32) -> u32 {
  6. a + b
  7. }
  8. #[no_mangle]
  9. pub extern "C" fn rust_uart_write() {
  10. let string = "Rust test string\n";
  11. let bytes = string.as_bytes();
  12. #[cfg(target_arch = "arm")]
  13. unsafe {
  14. HAL_UART_Transmit_IT(&mut huart1, bytes.as_ptr() as *mut _, bytes.len() as u16);
  15. }
  16. #[cfg(not(target_arch = "arm"))]
  17. unsafe {
  18. extern "C" {
  19. fn write(handle: i32, ptr: *const u8, size: usize) -> isize;
  20. }
  21. write(1, bytes.as_ptr(), bytes.len());
  22. }
  23. }
  24. mod aux {
  25. use core::panic::PanicInfo;
  26. #[panic_handler]
  27. fn panic(_info: &PanicInfo) -> ! {
  28. loop {
  29. continue;
  30. }
  31. }
  32. }