Skip to content

Commit acc0be3

Browse files
authored
Merge pull request #46 from fpistm/issue_44_fix_warnings
Issue 44 fix warnings
2 parents ed710fe + b37099d commit acc0be3

File tree

29 files changed

+291
-303
lines changed

29 files changed

+291
-303
lines changed

cores/arduino/WInterrupts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode)
2727
uint32_t it_mode;
2828
PinName p = digitalPinToPinName(pin);
2929
GPIO_TypeDef* port = set_GPIO_Port_Clock(STM_PORT(p));
30-
if (port == NC)
30+
if (!port)
3131
return;
3232

3333
switch(mode) {
@@ -53,7 +53,7 @@ void detachInterrupt(uint32_t pin)
5353
{
5454
PinName p = digitalPinToPinName(pin);
5555
GPIO_TypeDef* port = get_GPIO_Port(STM_PORT(p));
56-
if (port == NC)
56+
if (!port)
5757
return;
5858
stm32_interrupt_disable(port, STM_GPIO_PIN(p));
5959
}

cores/arduino/avr/dtostrf.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020

2121
#include <stdio.h>
22+
#include <stdlib.h>
23+
#include <string.h>
2224

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

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

64+
// Handle minimum field width of the output string
65+
// width is signed value, negative for left adjustment.
66+
// Range -128,127
67+
char fmt[129] = "";
68+
unsigned int w = width;
69+
if (width < 0) {
70+
negative = 1;
71+
w = -width;
72+
} else {
73+
negative = 0;
74+
}
75+
76+
if(strlen(sout) < w) {
77+
memset(fmt, ' ', 128);
78+
fmt[w-strlen(sout)] = '\0';
79+
if(negative == 0) {
80+
char *tmp = strdup(sout);
81+
strcpy(sout,fmt);
82+
strcat(sout, tmp);
83+
free(tmp);
84+
} else {
85+
// left adjustment
86+
strcat(sout, fmt);
87+
}
88+
}
89+
6290
return sout;
6391
}

cores/arduino/stm32/PinNamesTypes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ typedef enum {
129129
#define STM_PORT(X) (((uint32_t)(X) >> 4) & 0xF)
130130
#define STM_PIN(X) ((uint32_t)(X) & 0xF)
131131
// Check PinName is valid: FirstPort <= PortName <= LastPort
132-
#define STM_VALID_PINNAME(X) ((STM_PORT(X) >= FirstPort) && (STM_PORT(X) <= LastPort))
132+
// As FirstPort is equal to 0 and STM_PORT cast as an unsigned
133+
// (STM_PORT(X) >= FirstPort) is always true
134+
//#define STM_VALID_PINNAME(X) ((STM_PORT(X) >= FirstPort) && (STM_PORT(X) <= LastPort))
135+
#define STM_VALID_PINNAME(X) (STM_PORT(X) <= LastPort)
133136

134137
#define STM_GPIO_PIN(X) ((uint16_t)(1<<STM_PIN(X)))
135138
/* Defines to be used by application */

cores/arduino/stm32/PortNames.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,54 +35,54 @@ GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx) {
3535
GPIO_TypeDef* gpioPort = 0;
3636
switch (port_idx) {
3737
case PortA:
38-
gpioPort = GPIOA_BASE;
38+
gpioPort = (GPIO_TypeDef *)GPIOA_BASE;
3939
break;
4040
case PortB:
41-
gpioPort = GPIOB_BASE;
41+
gpioPort = (GPIO_TypeDef *)GPIOB_BASE;
4242
break;
4343
#if defined GPIOC_BASE
4444
case PortC:
45-
gpioPort = GPIOC_BASE;
45+
gpioPort = (GPIO_TypeDef *)GPIOC_BASE;
4646
break;
4747
#endif
4848
#if defined GPIOD_BASE
4949
case PortD:
50-
gpioPort = GPIOD_BASE;
50+
gpioPort = (GPIO_TypeDef *)GPIOD_BASE;
5151
break;
5252
#endif
5353
#if defined GPIOE_BASE
5454
case PortE:
55-
gpioPort = GPIOE_BASE;
55+
gpioPort = (GPIO_TypeDef *)GPIOE_BASE;
5656
break;
5757
#endif
5858
#if defined GPIOF_BASE
5959
case PortF:
60-
gpioPort = GPIOF_BASE;
60+
gpioPort = (GPIO_TypeDef *)GPIOF_BASE;
6161
break;
6262
#endif
6363
#if defined GPIOG_BASE
6464
case PortG:
65-
gpioPort = GPIOG_BASE;
65+
gpioPort = (GPIO_TypeDef *)GPIOG_BASE;
6666
break;
6767
#endif
6868
#if defined GPIOH_BASE
6969
case PortH:
70-
gpioPort = GPIOH_BASE;
70+
gpioPort = (GPIO_TypeDef *)GPIOH_BASE;
7171
break;
7272
#endif
7373
#if defined GPIOI_BASE
7474
case PortI:
75-
gpioPort = GPIOI_BASE;
75+
gpioPort = (GPIO_TypeDef *)GPIOI_BASE;
7676
break;
7777
#endif
7878
#if defined GPIOJ_BASE
7979
case PortJ:
80-
gpioPort = GPIOJ_BASE;
80+
gpioPort = (GPIO_TypeDef *)GPIOJ_BASE;
8181
break;
8282
#endif
8383
#if defined GPIOK_BASE
8484
case PortK:
85-
gpioPort = GPIOK_BASE;
85+
gpioPort = (GPIO_TypeDef *)GPIOK_BASE;
8686
break;
8787
#endif
8888
default:
@@ -99,64 +99,64 @@ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) {
9999
GPIO_TypeDef* gpioPort = 0;
100100
switch (port_idx) {
101101
case PortA:
102-
gpioPort = GPIOA_BASE;
102+
gpioPort = (GPIO_TypeDef *)GPIOA_BASE;
103103
__HAL_RCC_GPIOA_CLK_ENABLE();
104104
break;
105105
case PortB:
106-
gpioPort = GPIOB_BASE;
106+
gpioPort = (GPIO_TypeDef *)GPIOB_BASE;
107107
__HAL_RCC_GPIOB_CLK_ENABLE();
108108
break;
109109
#if defined GPIOC_BASE
110110
case PortC:
111-
gpioPort = GPIOC_BASE;
111+
gpioPort = (GPIO_TypeDef *)GPIOC_BASE;
112112
__HAL_RCC_GPIOC_CLK_ENABLE();
113113
break;
114114
#endif
115115
#if defined GPIOD_BASE
116116
case PortD:
117-
gpioPort = GPIOD_BASE;
117+
gpioPort = (GPIO_TypeDef *)GPIOD_BASE;
118118
__HAL_RCC_GPIOD_CLK_ENABLE();
119119
break;
120120
#endif
121121
#if defined GPIOE_BASE
122122
case PortE:
123-
gpioPort = GPIOE_BASE;
123+
gpioPort = (GPIO_TypeDef *)GPIOE_BASE;
124124
__HAL_RCC_GPIOE_CLK_ENABLE();
125125
break;
126126
#endif
127127
#if defined GPIOF_BASE
128128
case PortF:
129-
gpioPort = GPIOF_BASE;
129+
gpioPort = (GPIO_TypeDef *)GPIOF_BASE;
130130
__HAL_RCC_GPIOF_CLK_ENABLE();
131131
break;
132132
#endif
133133
#if defined GPIOG_BASE
134134
case PortG:
135-
gpioPort = GPIOG_BASE;
135+
gpioPort = (GPIO_TypeDef *)GPIOG_BASE;
136136
__HAL_RCC_GPIOG_CLK_ENABLE();
137137
break;
138138
#endif
139139
#if defined GPIOH_BASE
140140
case PortH:
141-
gpioPort = GPIOH_BASE;
141+
gpioPort = (GPIO_TypeDef *)GPIOH_BASE;
142142
__HAL_RCC_GPIOH_CLK_ENABLE();
143143
break;
144144
#endif
145145
#if defined GPIOI_BASE
146146
case PortI:
147-
gpioPort = GPIOI_BASE;
147+
gpioPort = (GPIO_TypeDef *)GPIOI_BASE;
148148
__HAL_RCC_GPIOI_CLK_ENABLE();
149149
break;
150150
#endif
151151
#if defined GPIOJ_BASE
152152
case PortJ:
153-
gpioPort = GPIOJ_BASE;
153+
gpioPort = (GPIO_TypeDef *)GPIOJ_BASE;
154154
__HAL_RCC_GPIOJ_CLK_ENABLE();
155155
break;
156156
#endif
157157
#if defined GPIOK_BASE
158158
case PortK:
159-
gpioPort = GPIOK_BASE;
159+
gpioPort = (GPIO_TypeDef *)GPIOK_BASE;
160160
__HAL_RCC_GPIOK_CLK_ENABLE();
161161
break;
162162
#endif

cores/arduino/stm32/analog.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@
9393
#error "ADC_CLOCK_DIV could not be defined"
9494
#endif
9595

96+
#ifndef ADC_REGULAR_RANK_1
9697
#define ADC_REGULAR_RANK_1 1
98+
#endif
9799
/**
98100
* @}
99101
*/
@@ -255,6 +257,8 @@ void HAL_DAC_MspInit(DAC_HandleTypeDef *hdac)
255257
{
256258
GPIO_InitTypeDef GPIO_InitStruct;
257259
GPIO_TypeDef *port;
260+
UNUSED(hdac);
261+
258262
/*##-1- Enable peripherals and GPIO Clocks #################################*/
259263
/* Enable GPIO clock ****************************************/
260264
port = set_GPIO_Port_Clock(STM_PORT(g_current_pin));
@@ -290,7 +294,7 @@ void dac_write_value(PinName pin, uint32_t value, uint8_t do_init)
290294
uint32_t dacChannel;
291295

292296
DacHandle.Instance = pinmap_peripheral(pin, PinMap_DAC);
293-
if (DacHandle.Instance == NC) return;
297+
if (DacHandle.Instance == NP) return;
294298
dacChannel = get_dac_channel(pin);
295299
if (!IS_DAC_CHANNEL(dacChannel)) return;
296300
if(do_init == 1) {
@@ -338,6 +342,7 @@ void dac_write_value(PinName pin, uint32_t value, uint8_t do_init)
338342
*/
339343
void HAL_DAC_MspDeInit(DAC_HandleTypeDef* hdac)
340344
{
345+
UNUSED(hdac);
341346
/* DAC Periph clock disable */
342347
#ifdef __HAL_RCC_DAC1_CLK_DISABLE
343348
__HAL_RCC_DAC1_CLK_DISABLE();
@@ -359,7 +364,7 @@ void dac_stop(PinName pin)
359364
uint32_t dacChannel;
360365

361366
DacHandle.Instance = pinmap_peripheral(pin, PinMap_DAC);
362-
if (DacHandle.Instance == NC) return;
367+
if (DacHandle.Instance == NP) return;
363368
dacChannel = get_dac_channel(pin);
364369
if (!IS_DAC_CHANNEL(dacChannel)) return;
365370

@@ -550,7 +555,7 @@ uint16_t adc_read_value(PinName pin)
550555

551556
AdcHandle.Instance = pinmap_peripheral(pin, PinMap_ADC);
552557

553-
if (AdcHandle.Instance == NC) return 0;
558+
if (AdcHandle.Instance == NP) return 0;
554559

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

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

780785
timHandle.Instance = pinmap_peripheral(pin, PinMap_PWM);
781-
if (timHandle.Instance == NC) return 0;
786+
if (timHandle.Instance == NP) return;
782787
timChannel = get_pwm_channel(pin);
783-
if (!IS_TIM_CHANNELS(timChannel)) return 0;
788+
if (!IS_TIM_CHANNELS(timChannel)) return;
784789

785790
#ifndef STM32L0xx
786791
if (STM_PIN_INVERTED(pinmap_function(pin, PinMap_PWM))) {

cores/arduino/stm32/digital_io.c

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -35,67 +35,13 @@
3535
*
3636
******************************************************************************
3737
*/
38-
/** @addtogroup CMSIS
39-
* @{
40-
*/
41-
42-
/** @addtogroup stm32f4xx_system
43-
* @{
44-
*/
45-
46-
/** @addtogroup STM32F4xx_System_Private_Includes
47-
* @{
48-
*/
4938
#include "digital_io.h"
5039
#include "stm32_def.h"
5140
#include "hw_config.h"
5241

5342
#ifdef __cplusplus
5443
extern "C" {
5544
#endif
56-
/**
57-
* @}
58-
*/
59-
60-
/** @addtogroup STM32F4xx_System_Private_TypesDefinitions
61-
* @{
62-
*/
63-
64-
/**
65-
* @}
66-
*/
67-
68-
/** @addtogroup STM32F4xx_System_Private_Defines
69-
* @{
70-
*/
71-
/**
72-
* @}
73-
*/
74-
75-
/** @addtogroup STM32F4xx_System_Private_Macros
76-
* @{
77-
*/
78-
79-
/**
80-
* @}
81-
*/
82-
83-
/** @addtogroup STM32F4xx_System_Private_Variables
84-
* @{
85-
*/
86-
87-
/**
88-
* @}
89-
*/
90-
91-
/** @addtogroup STM32F4xx_System_Private_FunctionPrototypes
92-
* @{
93-
*/
94-
95-
/**
96-
* @}
97-
*/
98-
9945

10046
/**
10147
* @brief This function initialize the IO
@@ -108,7 +54,7 @@
10854
void digital_io_init(PinName pin, uint32_t mode, uint32_t pull)
10955
{
11056
GPIO_InitTypeDef GPIO_InitStructure;
111-
GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(pin));;
57+
GPIO_TypeDef *port = set_GPIO_Port_Clock(STM_PORT(pin));
11258
GPIO_InitStructure.Pin = STM_GPIO_PIN(pin);
11359
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
11460
GPIO_InitStructure.Mode = mode;
@@ -144,17 +90,6 @@ uint32_t digital_io_read(GPIO_TypeDef *port, uint32_t pin)
14490
return (uint32_t)HAL_GPIO_ReadPin(port, pin);
14591
}
14692

147-
/**
148-
* @}
149-
*/
150-
151-
/**
152-
* @}
153-
*/
154-
155-
/**
156-
* @}
157-
*/
15893
#ifdef __cplusplus
15994
}
16095
#endif

0 commit comments

Comments
 (0)