tdse-tp4_04-led_ldr

FIUBA - Electrónica - Taller de Sistemas Embebidos - Trabajo Práctico N°: 4 - LED & LDR
Index Commits Files Refs README
commit 90826f3568904adbf9f1a02d39b88fdadc8d0499
parent ef169ef675b81966c8604c522b15eca3459a4550
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sun, 26 Oct 2025 01:27:08 -0300

Update `task_pwm.c`; completely disable semihosting

Diffstat:
MCore/Src/main.c | 4++--
Mapp/inc/logger.h | 2+-
Mapp/src/task_pwm.c | 25++++++++++---------------
3 files changed, 13 insertions(+), 18 deletions(-)
diff --git a/Core/Src/main.c b/Core/Src/main.c
@@ -57,7 +57,7 @@ static void MX_USART2_UART_Init(void);
 static void MX_ADC1_Init(void);
 static void MX_TIM3_Init(void);
 /* USER CODE BEGIN PFP */
-extern void initialise_monitor_handles(void);
+// extern void initialise_monitor_handles(void);
 /* USER CODE END PFP */
 
 /* Private user code ---------------------------------------------------------*/
@@ -73,7 +73,7 @@ int main(void)
 {
 
   /* USER CODE BEGIN 1 */
-  initialise_monitor_handles();
+  // initialise_monitor_handles();
   /* USER CODE END 1 */
 
   /* MCU Configuration--------------------------------------------------------*/
diff --git a/app/inc/logger.h b/app/inc/logger.h
@@ -53,7 +53,7 @@ extern "C" {
 
 #define LOGGER_CONFIG_ENABLE                    (0)
 #define LOGGER_CONFIG_MAXLEN                    (64)
-#define LOGGER_CONFIG_USE_SEMIHOSTING           (1)
+#define LOGGER_CONFIG_USE_SEMIHOSTING           (0)
 
 #if 1 == LOGGER_CONFIG_ENABLE
 #define LOGGER_LOG(...)\
diff --git a/app/src/task_pwm.c b/app/src/task_pwm.c
@@ -55,37 +55,32 @@
 #define PERIOD        (65535)
 #define min(a, b) a < b ? a : b
 
-/********************** internal data declaration ****************************/
-
 /********************** internal functions declaration ***********************/
 void setPWM(TIM_HandleTypeDef timer,
             uint32_t channel,
             uint16_t period,
             uint16_t pulse);
 
-/********************** internal data definition *****************************/
-const char *p_task_pwm         = "Task PWM";
-
 /********************** external data declaration *****************************/
 extern TIM_HandleTypeDef htim3;
 
-
 /********************** external functions definition ************************/
 void task_pwm_init(void *parameters)
 {
-    shared_data_type *shared_data = (shared_data_type *) parameters;
-
-    shared_data->pwm_active = 0;
-    /* Print out: Task Initialized */
-    LOGGER_LOG("  %s is running - %s\r\n", GET_NAME(task_pwm_init), p_task_pwm);
+    shared_data_type *shared_data = (shared_data_type *) parameters;
+    shared_data->pwm_active = 0;
 }
 
 void task_pwm_update(void *parameters)
 {
-    shared_data_type *shared_data = (shared_data_type *) parameters;
-    float x_norm = min(((float)shared_data->adc_value/ADC_MAX_VALUE)*8, 1);
-    shared_data->pwm_active = PERIOD*(1 - pow(x_norm, 1.5));
-    setPWM(htim3, TIM_CHANNEL_1, PERIOD, shared_data->pwm_active);
+    shared_data_type *data = (shared_data_type *) parameters;
+    if (data->adc_end_of_conversion)
+    {
+        data->adc_end_of_conversion = false;
+        float x = ((float)data->adc_value/ADC_MAX_VALUE);
+        data->pwm_active = PERIOD*(1 - 2*pow(x, 2));
+        setPWM(htim3, TIM_CHANNEL_1, PERIOD, data->pwm_active);
+    }
 }
 
 void setPWM(TIM_HandleTypeDef timer, uint32_t channel,