stm32_util.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * This file is free software: you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This file is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #pragma once
  16. #include "hal.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. void stm32_timer_set_input_filter(stm32_tim_t *tim, uint8_t channel, uint8_t filter_mode);
  21. void stm32_timer_set_channel_input(stm32_tim_t *tim, uint8_t channel, uint8_t input_source);
  22. #if CH_DBG_ENABLE_STACK_CHECK == TRUE
  23. // print stack usage
  24. void show_stack_usage(void);
  25. #endif
  26. // allocation functions in malloc.c
  27. size_t mem_available(void);
  28. void *malloc_dma(size_t size);
  29. void *malloc_sdcard_dma(size_t size);
  30. void *malloc_fastmem(size_t size);
  31. thread_t *thread_create_alloc(size_t size, const char *name, tprio_t prio, tfunc_t pf, void *arg);
  32. // flush all dcache
  33. void memory_flush_all(void);
  34. // UTC system clock handling
  35. void stm32_set_utc_usec(uint64_t time_utc_usec);
  36. uint64_t stm32_get_utc_usec(void);
  37. // hook for FAT timestamps
  38. uint32_t get_fattime(void);
  39. // one-time programmable area
  40. #if defined(STM32F4)
  41. #define OTP_BASE 0x1fff7800
  42. #define OTP_SIZE 512
  43. #elif defined(STM32F7)
  44. #define OTP_BASE 0x1ff0f000
  45. #define OTP_SIZE 1024
  46. #endif
  47. enum rtc_boot_magic {
  48. RTC_BOOT_OFF = 0,
  49. RTC_BOOT_HOLD = 0xb0070001,
  50. RTC_BOOT_FAST = 0xb0070002,
  51. RTC_BOOT_CANBL = 0xb0080000 // ORd with 8 bit local node ID
  52. };
  53. // see if RTC registers is setup for a fast reboot
  54. enum rtc_boot_magic check_fast_reboot(void);
  55. // set RTC register for a fast reboot
  56. void set_fast_reboot(enum rtc_boot_magic v);
  57. // enable peripheral power if needed
  58. void peripheral_power_enable(void);
  59. // initialise allocation subsystem
  60. void malloc_init(void);
  61. /*
  62. read mode of a pin. This allows a pin config to be read, changed and
  63. then written back
  64. */
  65. #if defined(STM32F7) || defined(STM32H7) || defined(STM32F4)
  66. iomode_t palReadLineMode(ioline_t line);
  67. #endif
  68. // set n RTC backup registers starting at given idx
  69. void set_rtc_backup(uint8_t idx, const uint32_t *v, uint8_t n);
  70. // get RTC backup registers starting at given idx
  71. void get_rtc_backup(uint8_t idx, uint32_t *v, uint8_t n);
  72. void stm32_cacheBufferInvalidate(const void *p, size_t size);
  73. void stm32_cacheBufferFlush(const void *p, size_t size);
  74. #ifdef __cplusplus
  75. }
  76. #endif