Skip to content

Issue 44 fix warnings #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cores/arduino/WInterrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
uint32_t it_mode;
PinName p = digitalPinToPinName(pin);
GPIO_TypeDef* port = set_GPIO_Port_Clock(STM_PORT(p));
if (port == NC)
if (!port)
return;

switch(mode) {
Expand All @@ -53,7 +53,7 @@ void detachInterrupt(uint32_t pin)
{
PinName p = digitalPinToPinName(pin);
GPIO_TypeDef* port = get_GPIO_Port(STM_PORT(p));
if (port == NC)
if (!port)
return;
stm32_interrupt_disable(port, STM_GPIO_PIN(p));
}
28 changes: 28 additions & 0 deletions cores/arduino/avr/dtostrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
//Commented code is the original version
Expand Down Expand Up @@ -59,5 +61,31 @@ char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {

sprintf(sout, "%ld.%ld", int_part, dec_part);

// Handle minimum field width of the output string
// width is signed value, negative for left adjustment.
// Range -128,127
char fmt[129] = "";
unsigned int w = width;
if (width < 0) {
negative = 1;
w = -width;
} else {
negative = 0;
}

if(strlen(sout) < w) {
memset(fmt, ' ', 128);
fmt[w-strlen(sout)] = '\0';
if(negative == 0) {
char *tmp = strdup(sout);
strcpy(sout,fmt);
strcat(sout, tmp);
free(tmp);
} else {
// left adjustment
strcat(sout, fmt);
}
}

return sout;
}
5 changes: 4 additions & 1 deletion cores/arduino/stm32/PinNamesTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ typedef enum {
#define STM_PORT(X) (((uint32_t)(X) >> 4) & 0xF)
#define STM_PIN(X) ((uint32_t)(X) & 0xF)
// Check PinName is valid: FirstPort <= PortName <= LastPort
#define STM_VALID_PINNAME(X) ((STM_PORT(X) >= FirstPort) && (STM_PORT(X) <= LastPort))
// As FirstPort is equal to 0 and STM_PORT cast as an unsigned
// (STM_PORT(X) >= FirstPort) is always true
//#define STM_VALID_PINNAME(X) ((STM_PORT(X) >= FirstPort) && (STM_PORT(X) <= LastPort))
#define STM_VALID_PINNAME(X) (STM_PORT(X) <= LastPort)

#define STM_GPIO_PIN(X) ((uint16_t)(1<<STM_PIN(X)))
/* Defines to be used by application */
Expand Down
44 changes: 22 additions & 22 deletions cores/arduino/stm32/PortNames.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,54 @@ GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx) {
GPIO_TypeDef* gpioPort = 0;
switch (port_idx) {
case PortA:
gpioPort = GPIOA_BASE;
gpioPort = (GPIO_TypeDef *)GPIOA_BASE;
break;
case PortB:
gpioPort = GPIOB_BASE;
gpioPort = (GPIO_TypeDef *)GPIOB_BASE;
break;
#if defined GPIOC_BASE
case PortC:
gpioPort = GPIOC_BASE;
gpioPort = (GPIO_TypeDef *)GPIOC_BASE;
break;
#endif
#if defined GPIOD_BASE
case PortD:
gpioPort = GPIOD_BASE;
gpioPort = (GPIO_TypeDef *)GPIOD_BASE;
break;
#endif
#if defined GPIOE_BASE
case PortE:
gpioPort = GPIOE_BASE;
gpioPort = (GPIO_TypeDef *)GPIOE_BASE;
break;
#endif
#if defined GPIOF_BASE
case PortF:
gpioPort = GPIOF_BASE;
gpioPort = (GPIO_TypeDef *)GPIOF_BASE;
break;
#endif
#if defined GPIOG_BASE
case PortG:
gpioPort = GPIOG_BASE;
gpioPort = (GPIO_TypeDef *)GPIOG_BASE;
break;
#endif
#if defined GPIOH_BASE
case PortH:
gpioPort = GPIOH_BASE;
gpioPort = (GPIO_TypeDef *)GPIOH_BASE;
break;
#endif
#if defined GPIOI_BASE
case PortI:
gpioPort = GPIOI_BASE;
gpioPort = (GPIO_TypeDef *)GPIOI_BASE;
break;
#endif
#if defined GPIOJ_BASE
case PortJ:
gpioPort = GPIOJ_BASE;
gpioPort = (GPIO_TypeDef *)GPIOJ_BASE;
break;
#endif
#if defined GPIOK_BASE
case PortK:
gpioPort = GPIOK_BASE;
gpioPort = (GPIO_TypeDef *)GPIOK_BASE;
break;
#endif
default:
Expand All @@ -99,64 +99,64 @@ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) {
GPIO_TypeDef* gpioPort = 0;
switch (port_idx) {
case PortA:
gpioPort = GPIOA_BASE;
gpioPort = (GPIO_TypeDef *)GPIOA_BASE;
__HAL_RCC_GPIOA_CLK_ENABLE();
break;
case PortB:
gpioPort = GPIOB_BASE;
gpioPort = (GPIO_TypeDef *)GPIOB_BASE;
__HAL_RCC_GPIOB_CLK_ENABLE();
break;
#if defined GPIOC_BASE
case PortC:
gpioPort = GPIOC_BASE;
gpioPort = (GPIO_TypeDef *)GPIOC_BASE;
__HAL_RCC_GPIOC_CLK_ENABLE();
break;
#endif
#if defined GPIOD_BASE
case PortD:
gpioPort = GPIOD_BASE;
gpioPort = (GPIO_TypeDef *)GPIOD_BASE;
__HAL_RCC_GPIOD_CLK_ENABLE();
break;
#endif
#if defined GPIOE_BASE
case PortE:
gpioPort = GPIOE_BASE;
gpioPort = (GPIO_TypeDef *)GPIOE_BASE;
__HAL_RCC_GPIOE_CLK_ENABLE();
break;
#endif
#if defined GPIOF_BASE
case PortF:
gpioPort = GPIOF_BASE;
gpioPort = (GPIO_TypeDef *)GPIOF_BASE;
__HAL_RCC_GPIOF_CLK_ENABLE();
break;
#endif
#if defined GPIOG_BASE
case PortG:
gpioPort = GPIOG_BASE;
gpioPort = (GPIO_TypeDef *)GPIOG_BASE;
__HAL_RCC_GPIOG_CLK_ENABLE();
break;
#endif
#if defined GPIOH_BASE
case PortH:
gpioPort = GPIOH_BASE;
gpioPort = (GPIO_TypeDef *)GPIOH_BASE;
__HAL_RCC_GPIOH_CLK_ENABLE();
break;
#endif
#if defined GPIOI_BASE
case PortI:
gpioPort = GPIOI_BASE;
gpioPort = (GPIO_TypeDef *)GPIOI_BASE;
__HAL_RCC_GPIOI_CLK_ENABLE();
break;
#endif
#if defined GPIOJ_BASE
case PortJ:
gpioPort = GPIOJ_BASE;
gpioPort = (GPIO_TypeDef *)GPIOJ_BASE;
__HAL_RCC_GPIOJ_CLK_ENABLE();
break;
#endif
#if defined GPIOK_BASE
case PortK:
gpioPort = GPIOK_BASE;
gpioPort = (GPIO_TypeDef *)GPIOK_BASE;
__HAL_RCC_GPIOK_CLK_ENABLE();
break;
#endif
Expand Down
17 changes: 11 additions & 6 deletions cores/arduino/stm32/analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
#error "ADC_CLOCK_DIV could not be defined"
#endif

#ifndef ADC_REGULAR_RANK_1
#define ADC_REGULAR_RANK_1 1
#endif
/**
* @}
*/
Expand Down Expand Up @@ -255,6 +257,8 @@ void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_TypeDef *port;
UNUSED(hdac);

/*##-1- Enable peripherals and GPIO Clocks #################################*/
/* Enable GPIO clock ****************************************/
port = set_GPIO_Port_Clock(STM_PORT(g_current_pin));
Expand Down Expand Up @@ -290,7 +294,7 @@ void dac_write_value(PinName pin, uint32_t value, uint8_t do_init)
uint32_t dacChannel;

DacHandle.Instance = pinmap_peripheral(pin, PinMap_DAC);
if (DacHandle.Instance == NC) return;
if (DacHandle.Instance == NP) return;
dacChannel = get_dac_channel(pin);
if (!IS_DAC_CHANNEL(dacChannel)) return;
if(do_init == 1) {
Expand Down Expand Up @@ -338,6 +342,7 @@ void dac_write_value(PinName pin, uint32_t value, uint8_t do_init)
*/
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
{
UNUSED(hdac);
/* DAC Periph clock disable */
#ifdef __HAL_RCC_DAC1_CLK_DISABLE
__HAL_RCC_DAC1_CLK_DISABLE();
Expand All @@ -359,7 +364,7 @@ void dac_stop(PinName pin)
uint32_t dacChannel;

DacHandle.Instance = pinmap_peripheral(pin, PinMap_DAC);
if (DacHandle.Instance == NC) return;
if (DacHandle.Instance == NP) return;
dacChannel = get_dac_channel(pin);
if (!IS_DAC_CHANNEL(dacChannel)) return;

Expand Down Expand Up @@ -550,7 +555,7 @@ uint16_t adc_read_value(PinName pin)

AdcHandle.Instance = pinmap_peripheral(pin, PinMap_ADC);

if (AdcHandle.Instance == NC) return 0;
if (AdcHandle.Instance == NP) return 0;

AdcHandle.Init.ClockPrescaler = ADC_CLOCK_DIV; /* Asynchronous clock mode, input ADC clock divided */
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; /* 12-bit resolution for converted data */
Expand Down Expand Up @@ -717,7 +722,7 @@ void pwm_start(PinName pin, uint32_t clock_freq,

/* Compute the prescaler value to have TIM counter clock equal to clock_freq Hz */
timHandle.Instance = pinmap_peripheral(pin, PinMap_PWM);
if (timHandle.Instance == NC) return 0;
if (timHandle.Instance == NP) return;
timHandle.Init.Prescaler = (uint32_t)(getTimerClkFreq(timHandle.Instance) / clock_freq) - 1;
timHandle.Init.Period = period -1;
timHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
Expand Down Expand Up @@ -778,9 +783,9 @@ void pwm_stop(PinName pin)
uint32_t timChannel;

timHandle.Instance = pinmap_peripheral(pin, PinMap_PWM);
if (timHandle.Instance == NC) return 0;
if (timHandle.Instance == NP) return;
timChannel = get_pwm_channel(pin);
if (!IS_TIM_CHANNELS(timChannel)) return 0;
if (!IS_TIM_CHANNELS(timChannel)) return;

#ifndef STM32L0xx
if (STM_PIN_INVERTED(pinmap_function(pin, PinMap_PWM))) {
Expand Down
67 changes: 1 addition & 66 deletions cores/arduino/stm32/digital_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,67 +35,13 @@
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/

/** @addtogroup stm32f4xx_system
* @{
*/

/** @addtogroup STM32F4xx_System_Private_Includes
* @{
*/
#include "digital_io.h"
#include "stm32_def.h"
#include "hw_config.h"

#ifdef __cplusplus
extern "C" {
#endif
/**
* @}
*/

/** @addtogroup STM32F4xx_System_Private_TypesDefinitions
* @{
*/

/**
* @}
*/

/** @addtogroup STM32F4xx_System_Private_Defines
* @{
*/
/**
* @}
*/

/** @addtogroup STM32F4xx_System_Private_Macros
* @{
*/

/**
* @}
*/

/** @addtogroup STM32F4xx_System_Private_Variables
* @{
*/

/**
* @}
*/

/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
* @{
*/

/**
* @}
*/


/**
* @brief This function initialize the IO
Expand All @@ -108,7 +54,7 @@
void digital_io_init(PinName pin, uint32_t mode, uint32_t pull)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(pin));;
GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(pin));
GPIO_InitStructure.Pin = STM_GPIO_PIN(pin);
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStructure.Mode = mode;
Expand Down Expand Up @@ -144,17 +90,6 @@ uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin)
return (uint32_t)HAL_GPIO_ReadPin(port, pin);
}

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/
#ifdef __cplusplus
}
#endif
Expand Down
Loading