flipperzero-firmware_official_dev 844 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. commit 0ec8fc4c55178e9ad7daa014a9268dcfbb8da573
  2. Author: あく <alleteam@gmail.com>
  3. Date: Wed Apr 26 05:11:42 2023 +0900
  4. FuriHal: use proper divider for core2 when transition to sleep, remove extra stop mode transition checks, cleanup code. Furi: proper assert and check messages. (#2615)
  5. diff --git a/firmware/targets/f7/ble_glue/ble_app.c b/firmware/targets/f7/ble_glue/ble_app.c
  6. index a325830cf..37d8f7cd0 100644
  7. --- a/firmware/targets/f7/ble_glue/ble_app.c
  8. +++ b/firmware/targets/f7/ble_glue/ble_app.c
  9. @@ -88,7 +88,7 @@ bool ble_app_init() {
  10. .min_tx_power = 0,
  11. .max_tx_power = 0,
  12. .rx_model_config = 1,
  13. - /* New stack (13.3->16.0)*/
  14. + /* New stack (13.3->15.0) */
  15. .max_adv_set_nbr = 1, // Only used if SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV is set
  16. .max_adv_data_len = 31, // Only used if SHCI_C2_BLE_INIT_OPTIONS_EXT_ADV is set
  17. .tx_path_compens = 0, // RF TX Path Compensation, * 0.1 dB
  18. diff --git a/firmware/targets/f7/furi_hal/furi_hal_bt.c b/firmware/targets/f7/furi_hal/furi_hal_bt.c
  19. index 0857fe4ee..b08c9ea27 100644
  20. --- a/firmware/targets/f7/furi_hal/furi_hal_bt.c
  21. +++ b/firmware/targets/f7/furi_hal/furi_hal_bt.c
  22. @@ -84,9 +84,7 @@ void furi_hal_bt_init() {
  23. }
  24. // Explicitly tell that we are in charge of CLK48 domain
  25. - if(!LL_HSEM_IsSemaphoreLocked(HSEM, CFG_HW_CLK48_CONFIG_SEMID)) {
  26. - furi_check(LL_HSEM_1StepLock(HSEM, CFG_HW_CLK48_CONFIG_SEMID) == 0);
  27. - }
  28. + furi_check(LL_HSEM_1StepLock(HSEM, CFG_HW_CLK48_CONFIG_SEMID) == 0);
  29. // Start Core2
  30. ble_glue_init();
  31. @@ -129,9 +127,7 @@ bool furi_hal_bt_start_radio_stack() {
  32. furi_mutex_acquire(furi_hal_bt_core2_mtx, FuriWaitForever);
  33. // Explicitly tell that we are in charge of CLK48 domain
  34. - if(!LL_HSEM_IsSemaphoreLocked(HSEM, CFG_HW_CLK48_CONFIG_SEMID)) {
  35. - furi_check(LL_HSEM_1StepLock(HSEM, CFG_HW_CLK48_CONFIG_SEMID) == 0);
  36. - }
  37. + furi_check(LL_HSEM_1StepLock(HSEM, CFG_HW_CLK48_CONFIG_SEMID) == 0);
  38. do {
  39. // Wait until C2 is started or timeout
  40. diff --git a/firmware/targets/f7/furi_hal/furi_hal_clock.c b/firmware/targets/f7/furi_hal/furi_hal_clock.c
  41. index d85524ce4..a4df4877e 100644
  42. --- a/firmware/targets/f7/furi_hal/furi_hal_clock.c
  43. +++ b/firmware/targets/f7/furi_hal/furi_hal_clock.c
  44. @@ -213,7 +213,11 @@ void furi_hal_clock_switch_to_hsi() {
  45. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
  46. ;
  47. - LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
  48. + LL_C2_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  49. +
  50. + LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
  51. + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_0)
  52. + ;
  53. }
  54. void furi_hal_clock_switch_to_pll() {
  55. @@ -228,7 +232,11 @@ void furi_hal_clock_switch_to_pll() {
  56. while(!LL_RCC_PLLSAI1_IsReady())
  57. ;
  58. + LL_C2_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_2);
  59. +
  60. LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
  61. + while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3)
  62. + ;
  63. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  64. LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSE);
  65. diff --git a/firmware/targets/f7/furi_hal/furi_hal_power.c b/firmware/targets/f7/furi_hal/furi_hal_power.c
  66. index 3e4e3f48b..7d9334c2c 100644
  67. --- a/firmware/targets/f7/furi_hal/furi_hal_power.c
  68. +++ b/firmware/targets/f7/furi_hal/furi_hal_power.c
  69. @@ -29,10 +29,6 @@
  70. #define FURI_HAL_POWER_DEBUG_STOP_GPIO (&gpio_ext_pc3)
  71. #endif
  72. -#ifndef FURI_HAL_POWER_DEBUG_ABNORMAL_GPIO
  73. -#define FURI_HAL_POWER_DEBUG_ABNORMAL_GPIO (&gpio_ext_pb3)
  74. -#endif
  75. -
  76. #ifndef FURI_HAL_POWER_STOP_MODE
  77. #define FURI_HAL_POWER_STOP_MODE (LL_PWR_MODE_STOP2)
  78. #endif
  79. @@ -92,10 +88,8 @@ void furi_hal_power_init() {
  80. #ifdef FURI_HAL_POWER_DEBUG
  81. furi_hal_gpio_init_simple(FURI_HAL_POWER_DEBUG_WFI_GPIO, GpioModeOutputPushPull);
  82. furi_hal_gpio_init_simple(FURI_HAL_POWER_DEBUG_STOP_GPIO, GpioModeOutputPushPull);
  83. - furi_hal_gpio_init_simple(FURI_HAL_POWER_DEBUG_ABNORMAL_GPIO, GpioModeOutputPushPull);
  84. furi_hal_gpio_write(FURI_HAL_POWER_DEBUG_WFI_GPIO, 0);
  85. furi_hal_gpio_write(FURI_HAL_POWER_DEBUG_STOP_GPIO, 0);
  86. - furi_hal_gpio_write(FURI_HAL_POWER_DEBUG_ABNORMAL_GPIO, 0);
  87. #endif
  88. LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
  89. @@ -158,9 +152,7 @@ bool furi_hal_power_sleep_available() {
  90. static inline bool furi_hal_power_deep_sleep_available() {
  91. return furi_hal_bt_is_alive() && !furi_hal_rtc_is_flag_set(FuriHalRtcFlagLegacySleep) &&
  92. - !furi_hal_debug_is_gdb_session_active() && !LL_PWR_IsActiveFlag_CRPE() &&
  93. - !LL_PWR_IsActiveFlag_CRP() && !LL_PWR_IsActiveFlag_BLEA() &&
  94. - !LL_PWR_IsActiveFlag_BLEWU();
  95. + !furi_hal_debug_is_gdb_session_active();
  96. }
  97. static inline void furi_hal_power_light_sleep() {
  98. @@ -211,16 +203,7 @@ static inline void furi_hal_power_deep_sleep() {
  99. __force_stores();
  100. #endif
  101. - bool should_abort_sleep = LL_PWR_IsActiveFlag_CRPE() || LL_PWR_IsActiveFlag_CRP() ||
  102. - LL_PWR_IsActiveFlag_BLEA() || LL_PWR_IsActiveFlag_BLEWU();
  103. -
  104. - if(should_abort_sleep) {
  105. -#ifdef FURI_HAL_POWER_DEBUG
  106. - furi_hal_gpio_write(FURI_HAL_POWER_DEBUG_ABNORMAL_GPIO, 1);
  107. -#endif
  108. - } else {
  109. - __WFI();
  110. - }
  111. + __WFI();
  112. LL_LPM_EnableSleep();
  113. diff --git a/furi/core/check.h b/furi/core/check.h
  114. index a507fc1ea..ea83f2219 100644
  115. --- a/furi/core/check.h
  116. +++ b/furi/core/check.h
  117. @@ -48,21 +48,21 @@ FURI_NORETURN void __furi_halt();
  118. } while(0)
  119. /** Check condition and crash if check failed */
  120. -#define furi_check(__e) \
  121. - do { \
  122. - if(!(__e)) { \
  123. - furi_crash(__FURI_ASSERT_MESSAGE_FLAG); \
  124. - } \
  125. - } while(0)
  126. -
  127. -/** Only in debug build: Assert condition and crash if assert failed */
  128. -#ifdef FURI_DEBUG
  129. -#define furi_assert(__e) \
  130. +#define furi_check(__e) \
  131. do { \
  132. if(!(__e)) { \
  133. furi_crash(__FURI_CHECK_MESSAGE_FLAG); \
  134. } \
  135. } while(0)
  136. +
  137. +/** Only in debug build: Assert condition and crash if assert failed */
  138. +#ifdef FURI_DEBUG
  139. +#define furi_assert(__e) \
  140. + do { \
  141. + if(!(__e)) { \
  142. + furi_crash(__FURI_ASSERT_MESSAGE_FLAG); \
  143. + } \
  144. + } while(0)
  145. #else
  146. #define furi_assert(__e) \
  147. do { \