11#if defined(PLATFORM_STM32 )
2- /*************
3- I hope this software works LOL
4- ***************/
52
63#include "lf_STM32f4_support.h"
74#include "platform.h"
1512static volatile bool _lf_sleep_interrupted = false;
1613static volatile bool _lf_async_event = false;
1714
18- #define LF_MAX_SLEEP_NS USEC(UINT32_MAX)
19- #define LF_MIN_SLEEP_NS USEC(5)
20-
2115// nested critical section counter
2216static uint32_t _lf_num_nested_crit_sec = 0 ;
2317
@@ -56,31 +50,28 @@ void _lf_initialize_clock(void) {
5650
5751 /* This is to make the Prescaler actually work
5852 * For some reason, the Prescaler only kicks in once the timer has reset once.
59- * Thus, the current solution is to manually ret the value to a really large
53+ * Thus, the current solution is to manually set the value to a really large
6054 * and force it to reset once. Its really jank but its the only way I could
6155 * find to make it work
6256 */
6357 TIM5 -> CNT = 0xFFFFFFFE ;
6458}
6559
66- /**
67- * ISR for handling timer overflow -> We increment the upper timer
68- */
60+
61+ // ISR for handling timer overflow -> We increment the upper timer
6962void TIM5_IRQHandler (void ) {
7063 if (TIM5 -> SR & (1 << 1 )) {
7164 TIM5 -> SR &= ~(1 << 1 );
7265 _lf_time_us_high += 1 ;
7366 }
7467}
7568
76- /**
77- * Write the time since boot into time variable
78- */
69+ // Write the time since boot into time variable
7970int _lf_clock_now (instant_t * t )
8071{
8172 // Timer is cooked
8273 if (!t ) {
83- return - 1 ;
74+ return 1 ;
8475 }
8576 // Get the current microseconds from TIM5
8677 uint32_t _lf_time_us_low = TIM5 -> CNT ;
@@ -92,25 +83,20 @@ int _lf_clock_now(instant_t *t)
9283}
9384
9485/**
95- * Make the STM32 go honk shoo mimimi for set nanoseconds
96- * I essentially stole this from the lf_nrf52 support
86+ * Blocks the STM32 for set nanoseconds
9787 */
98- int lf_sleep (interval_t sleep_duration ) {
88+ void lf_sleep (interval_t sleep_duration ) {
9989 instant_t target_time ;
10090 instant_t current_time ;
10191
10292 _lf_clock_now (& current_time );
10393 target_time = current_time + sleep_duration ;
10494 while (current_time <= target_time )
10595 _lf_clock_now (& current_time );
106-
107- return 0 ;
10896}
10997
11098/**
111- * Make the STM32 go honk shoo honk shoo for set nanoseconds
112- * This one uses a do-while loop. :)
113- * I essentially stole this from the lf_nrf52 support
99+ * Blocks the STM32 for set nanoseconds
114100 */
115101static void lf_busy_wait_until (instant_t wakeup_time ) {
116102 instant_t now ;
@@ -119,11 +105,9 @@ static void lf_busy_wait_until(instant_t wakeup_time) {
119105 } while (now < wakeup_time );
120106}
121107
122- // I am pretty sure this function doesnt work
123- // Ill try to fix it once i know what the fuck its supposed to do, LOL
108+
124109/* sleep until wakeup time
125110 But, wake up if there is an async event
126-
127111*/
128112int _lf_interruptable_sleep_until_locked (environment_t * env , instant_t wakeup_time ) {
129113 // Get the current time and sleep time
@@ -155,8 +139,7 @@ int _lf_interruptable_sleep_until_locked(environment_t *env, instant_t wakeup_ti
155139 if (!_lf_async_event ) {
156140 return 0 ;
157141 } else {
158- LF_PRINT_DEBUG (" *The STM32 rises from sleep* \n" );
159- return -1 ;
142+ return 1 ;
160143 }
161144
162145}
@@ -199,25 +182,19 @@ int _lf_single_threaded_notify_of_event() {
199182 return 0 ;
200183}
201184
202- int test_func (void ) {
203- return 5 ;
204- }
205-
206185// + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
207- // | Other functions I found -> taken from the generated main.c
186+ // | Other functions -> taken from the generated main.c
208187// + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +
209188void lf_SystemClock_Config (void ) {
210189 RCC_OscInitTypeDef RCC_OscInitStruct = {0 };
211190 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0 };
212191
213- /** Configure the main internal regulator output voltage
214- */
192+ // Configure the main internal regulator output voltage
215193 __HAL_RCC_PWR_CLK_ENABLE ();
216194 __HAL_PWR_VOLTAGESCALING_CONFIG (PWR_REGULATOR_VOLTAGE_SCALE3 );
217195
218- /** Initializes the RCC Oscillators according to the specified parameters
219- * in the RCC_OscInitTypeDef structure.
220- */
196+ // Initializes the RCC Oscillators according to the specified parameters
197+ // in the RCC_OscInitTypeDef structure.
221198 RCC_OscInitStruct .OscillatorType = RCC_OSCILLATORTYPE_HSI ;
222199 RCC_OscInitStruct .HSIState = RCC_HSI_ON ;
223200 RCC_OscInitStruct .HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT ;
@@ -226,8 +203,7 @@ void lf_SystemClock_Config(void) {
226203 Error_Handler ();
227204 }
228205
229- /** Initializes the CPU, AHB and APB buses clocks
230- */
206+ // Initializes the CPU, AHB and APB buses clocks
231207 RCC_ClkInitStruct .ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 ;
232208 RCC_ClkInitStruct .SYSCLKSource = RCC_SYSCLKSOURCE_HSI ;
233209 RCC_ClkInitStruct .AHBCLKDivider = RCC_SYSCLK_DIV1 ;
@@ -240,12 +216,12 @@ void lf_SystemClock_Config(void) {
240216}
241217
242218void Error_Handler (void ) {
243- /* USER CODE BEGIN Error_Handler_Debug */
244- /* User can add his own implementation to report the HAL error return state */
219+ // USER CODE BEGIN Error_Handler_Debug
220+ // User can add his own implementation to report the HAL error return state
245221 __disable_irq ();
246222 while (1 ) {
247223 }
248- /* USER CODE END Error_Handler_Debug */
224+ // USER CODE END Error_Handler_Debug
249225}
250226
251227#endif
0 commit comments