diff --git a/cores/arduino/stm32/analog.c b/cores/arduino/stm32/analog.c index 9028ab4bb7..d4c66e5adf 100644 --- a/cores/arduino/stm32/analog.c +++ b/cores/arduino/stm32/analog.c @@ -191,6 +191,31 @@ static uint32_t get_adc_channel(PinName pin) return channel; } +static uint32_t get_pwm_channel(PinName pin) +{ + uint32_t function = pinmap_function(pin, PinMap_PWM); + uint32_t channel = 0; + switch(STM_PIN_CHANNEL(function)) { + case 1: + channel = TIM_CHANNEL_1; + break; + case 2: + channel = TIM_CHANNEL_2; + break; + case 3: + channel = TIM_CHANNEL_3; + break; + case 4: + channel = TIM_CHANNEL_4; + break; + default: + channel = 0; + break; + } + return channel; +} + +#ifdef HAL_DAC_MODULE_ENABLED static uint32_t get_dac_channel(PinName pin) { uint32_t function = pinmap_function(pin, PinMap_DAC); @@ -216,29 +241,6 @@ static uint32_t get_dac_channel(PinName pin) return channel; } -static uint32_t get_pwm_channel(PinName pin) -{ - uint32_t function = pinmap_function(pin, PinMap_PWM); - uint32_t channel = 0; - switch(STM_PIN_CHANNEL(function)) { - case 1: - channel = TIM_CHANNEL_1; - break; - case 2: - channel = TIM_CHANNEL_2; - break; - case 3: - channel = TIM_CHANNEL_3; - break; - case 4: - channel = TIM_CHANNEL_4; - break; - default: - channel = 0; - break; - } - return channel; -} ////////////////////////// DAC INTERFACE FUNCTIONS ///////////////////////////// /** @@ -369,6 +371,7 @@ void dac_stop(PinName pin) return; } } +#endif //HAL_DAC_MODULE_ENABLED ////////////////////////// ADC INTERFACE FUNCTIONS ///////////////////////////// diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index cbe3604e0a..ec4436a92e 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -73,6 +73,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) { uint8_t do_init = 0; PinName p = analogToPinName(ulPin); if(p != NC) { +#ifdef HAL_DAC_MODULE_ENABLED if(pin_in_pinmap(p, PinMap_DAC)) { if(is_pin_configured(p, g_anOutputPinConfigured) == false) { do_init = 1; @@ -80,13 +81,15 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) { } ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION); dac_write_value(p, ulValue, do_init); - } else if(pin_in_pinmap(p, PinMap_PWM)) { - if(is_pin_configured(p, g_anOutputPinConfigured) == false) { - do_init = 1; - set_pin_configured(p, g_anOutputPinConfigured); - } - ulValue = mapResolution(ulValue, _writeResolution, PWM_RESOLUTION); - pwm_start(p, PWM_FREQUENCY*PWM_MAX_DUTY_CYCLE, + } else +#endif //HAL_DAC_MODULE_ENABLED + if(pin_in_pinmap(p, PinMap_PWM)) { + if(is_pin_configured(p, g_anOutputPinConfigured) == false) { + do_init = 1; + set_pin_configured(p, g_anOutputPinConfigured); + } + ulValue = mapResolution(ulValue, _writeResolution, PWM_RESOLUTION); + pwm_start(p, PWM_FREQUENCY*PWM_MAX_DUTY_CYCLE, PWM_MAX_DUTY_CYCLE, ulValue, do_init); } else { //DIGITAL PIN ONLY @@ -98,7 +101,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) { } else { digitalWrite(ulPin, HIGH); - } + } } } } diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 24fc7218ee..57e49cfcff 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -35,9 +35,12 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) if(p != NC) { // If the pin that support PWM or DAC output, we need to turn it off if(is_pin_configured(p, g_anOutputPinConfigured)) { +#ifdef HAL_DAC_MODULE_ENABLED if(pin_in_pinmap(p, PinMap_DAC)) { dac_stop(p); - } else if(pin_in_pinmap(p, PinMap_PWM)) { + } else +#endif //HAL_DAC_MODULE_ENABLED + if(pin_in_pinmap(p, PinMap_PWM)) { pwm_stop(p); } reset_pin_configured(p, g_anOutputPinConfigured);