Skip to content

Commit c4901db

Browse files
committed
Merge pull request #701 from bcostm/master
Targets: NUCLEOs - Align hal files
2 parents 1cc251f + ac6b5cb commit c4901db

File tree

26 files changed

+110
-86
lines changed

26 files changed

+110
-86
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/PinNames.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@
3636
extern "C" {
3737
#endif
3838

39+
// See stm32f0xx_hal_gpio.h and stm32f0xx_hal_gpio_ex.h for values of MODE, PUPD and AFNUM
3940
#define STM_PIN_DATA(MODE, PUPD, AFNUM) ((int)(((AFNUM) << 7) | ((PUPD) << 4) | ((MODE) << 0)))
40-
4141
#define STM_PIN_MODE(X) (((X) >> 0) & 0x0F)
4242
#define STM_PIN_PUPD(X) (((X) >> 4) & 0x07)
4343
#define STM_PIN_AFNUM(X) (((X) >> 7) & 0x0F)
44-
4544
#define STM_MODE_INPUT (0)
4645
#define STM_MODE_OUTPUT_PP (1)
4746
#define STM_MODE_OUTPUT_OD (2)

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
#define DEVICE_STDIO_MESSAGES 1
6565

66-
//#define DEVICE_ERROR_RED 0
66+
#define DEVICE_ERROR_RED 0
6767

6868
#include "objects.h"
6969

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/i2c_api.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
8080
pin_mode(sda, OpenDrain);
8181
pin_mode(scl, OpenDrain);
8282
}
83+
8384
// Enable I2C2 clock and pinout if not done
8485
if ((obj->i2c == I2C_2) && !i2c2_inited) {
8586
i2c2_inited = 1;
@@ -176,7 +177,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
176177
int count;
177178
int value;
178179

179-
/* update CR2 register */
180+
// Update CR2 register
180181
i2c->CR2 = (i2c->CR2 & (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP)))
181182
| (uint32_t)(((uint32_t)address & I2C_CR2_SADD) | (((uint32_t)length << 16) & I2C_CR2_NBYTES) | (uint32_t)I2C_SOFTEND_MODE | (uint32_t)I2C_GENERATE_START_READ);
182183

@@ -199,15 +200,15 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
199200
// If not repeated start, send stop.
200201
if (stop) {
201202
i2c_stop(obj);
202-
/* Wait until STOPF flag is set */
203+
// Wait until STOPF flag is set
203204
timeout = FLAG_TIMEOUT;
204205
while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_STOPF) == RESET) {
205206
timeout--;
206207
if (timeout == 0) {
207208
return -1;
208209
}
209210
}
210-
/* Clear STOP Flag */
211+
// Clear STOP Flag
211212
__HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_STOPF);
212213
}
213214

@@ -221,12 +222,10 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
221222
int timeout;
222223
int count;
223224

224-
/* update CR2 register */
225+
// Update CR2 register
225226
i2c->CR2 = (i2c->CR2 & (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP)))
226227
| (uint32_t)(((uint32_t)address & I2C_CR2_SADD) | (((uint32_t)length << 16) & I2C_CR2_NBYTES) | (uint32_t)I2C_SOFTEND_MODE | (uint32_t)I2C_GENERATE_START_WRITE);
227228

228-
229-
230229
for (count = 0; count < length; count++) {
231230
i2c_byte_write(obj, data[count]);
232231
}
@@ -241,18 +240,18 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
241240
}
242241
__HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_TC);
243242

244-
// If not repeated start, send stop.
243+
// If not repeated start, send stop
245244
if (stop) {
246245
i2c_stop(obj);
247-
/* Wait until STOPF flag is set */
246+
// Wait until STOPF flag is set
248247
timeout = FLAG_TIMEOUT;
249248
while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_STOPF) == RESET) {
250249
timeout--;
251250
if (timeout == 0) {
252251
return -1;
253252
}
254253
}
255-
/* Clear STOP Flag */
254+
// Clear STOP Flag
256255
__HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_STOPF);
257256
}
258257

@@ -297,7 +296,7 @@ void i2c_reset(i2c_t *obj)
297296
{
298297
int timeout;
299298

300-
// wait before reset
299+
// Wait before reset
301300
timeout = LONG_TIMEOUT;
302301
while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
303302

@@ -334,7 +333,6 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
334333

335334
void i2c_slave_mode(i2c_t *obj, int enable_slave)
336335
{
337-
338336
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
339337
uint16_t tmpreg;
340338

@@ -350,7 +348,6 @@ void i2c_slave_mode(i2c_t *obj, int enable_slave)
350348

351349
// Set new mode
352350
i2c->OAR1 = tmpreg;
353-
354351
}
355352

356353
// See I2CSlave.h

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/pwmout_api.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
#include "mbed_error.h"
3737

3838
// TIM1 cannot be used because already used by the us_ticker
39-
// Uncomment/comment line above to use an alternate timer,
40-
// If the channel is not the same,
41-
// Please don't forget to uncomment/comment in the pwmout_write() function also
4239
static const PinMap PinMap_PWM[] = {
4340
{PA_4, PWM_14, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF4_TIM14)}, // TIM14_CH1
4441
{PA_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF1_TIM3)}, // TIM3_CH1
@@ -128,7 +125,6 @@ void pwmout_write(pwmout_t* obj, float value)
128125
// Channels 1
129126
case PA_4:
130127
case PA_6:
131-
// case PA_7:
132128
case PB_1:
133129
case PB_4:
134130
case PB_8:
@@ -140,7 +136,6 @@ void pwmout_write(pwmout_t* obj, float value)
140136
// Channels 1N
141137
case PB_6:
142138
case PB_7:
143-
// case PB_15:
144139
channel = TIM_CHANNEL_1;
145140
complementary_channel = 1;
146141
break;
@@ -157,7 +152,6 @@ void pwmout_write(pwmout_t* obj, float value)
157152
channel = TIM_CHANNEL_3;
158153
break;
159154
// Channels 4
160-
// case PB_1:
161155
case PC_9:
162156
channel = TIM_CHANNEL_4;
163157
break;

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/rtc_api.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ void rtc_init(void)
5959

6060
// Enable LSE Oscillator
6161
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
62-
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; /* Mandatory, otherwise the PLL is reconfigured! */
63-
RCC_OscInitStruct.LSEState = RCC_LSE_ON; /* External 32.768 kHz clock on OSC_IN/OSC_OUT */
62+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
63+
RCC_OscInitStruct.LSEState = RCC_LSE_ON; // External 32.768 kHz clock on OSC_IN/OSC_OUT
6464
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
6565
// Connect LSE to RTC
6666
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
@@ -76,8 +76,8 @@ void rtc_init(void)
7676
}
7777
// Connect LSI to RTC
7878
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
79-
// [TODO] This value is LSI typical value. To be measured precisely using a timer input capture.
80-
rtc_freq = 32000;
79+
// This value is LSI typical value. To be measured precisely using a timer input capture for example.
80+
rtc_freq = LSI_VALUE;
8181
}
8282

8383
// Enable RTC

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/serial_api.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
102102
__USART1_CLK_ENABLE();
103103
obj->index = 0;
104104
}
105+
105106
if (obj->uart == UART_2) {
106107
__USART2_CLK_ENABLE();
107108
obj->index = 1;
@@ -110,8 +111,12 @@ void serial_init(serial_t *obj, PinName tx, PinName rx)
110111
// Configure the UART pins
111112
pinmap_pinout(tx, PinMap_UART_TX);
112113
pinmap_pinout(rx, PinMap_UART_RX);
113-
pin_mode(tx, PullUp);
114-
pin_mode(rx, PullUp);
114+
if (tx != NC) {
115+
pin_mode(tx, PullUp);
116+
}
117+
if (rx != NC) {
118+
pin_mode(rx, PullUp);
119+
}
115120

116121
// Configure UART
117122
obj->baudrate = 9600;
@@ -139,6 +144,7 @@ void serial_free(serial_t *obj)
139144
__USART1_RELEASE_RESET();
140145
__USART1_CLK_DISABLE();
141146
}
147+
142148
if (obj->uart == UART_2) {
143149
__USART2_FORCE_RESET();
144150
__USART2_RELEASE_RESET();

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/spi_api.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void spi_free(spi_t *obj)
154154
__SPI2_CLK_DISABLE();
155155
}
156156

157-
// Configure GPIO
157+
// Configure GPIOs
158158
pin_function(obj->pin_miso, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
159159
pin_function(obj->pin_mosi, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
160160
pin_function(obj->pin_sclk, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
@@ -220,6 +220,7 @@ void spi_frequency(spi_t *obj, int hz)
220220
} else { // >= 24000000
221221
obj->br_presc = SPI_BAUDRATEPRESCALER_2; // 24 MHz
222222
}
223+
223224
init_spi(obj);
224225
}
225226

@@ -245,13 +246,12 @@ static inline void ssp_write(spi_t *obj, int value)
245246
{
246247
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
247248
while (!ssp_writeable(obj));
248-
249-
if (obj->bits <= SPI_DATASIZE_8BIT) {
250-
// force 8-bit access the data register due to SPI data buffer in this device
249+
if (obj->bits == SPI_DATASIZE_8BIT) {
250+
// Force 8-bit access to the data register
251251
uint8_t *p_spi_dr = 0;
252252
p_spi_dr = (uint8_t *) & (spi->DR);
253253
*p_spi_dr = (uint8_t)value;
254-
} else {
254+
} else { // SPI_DATASIZE_16BIT
255255
spi->DR = (uint16_t)value;
256256
}
257257
}
@@ -260,9 +260,8 @@ static inline int ssp_read(spi_t *obj)
260260
{
261261
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
262262
while (!ssp_readable(obj));
263-
264-
if (obj->bits <= SPI_DATASIZE_8BIT) {
265-
// force 8-bit access the data register due to SPI data buffer in this device
263+
if (obj->bits == SPI_DATASIZE_8BIT) {
264+
// Force 8-bit access to the data register
266265
uint8_t *p_spi_dr = 0;
267266
p_spi_dr = (uint8_t *) & (spi->DR);
268267
return (int)(*p_spi_dr);
@@ -294,14 +293,28 @@ int spi_slave_read(spi_t *obj)
294293
{
295294
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
296295
while (!ssp_readable(obj));
297-
return (int)spi->DR;
296+
if (obj->bits == SPI_DATASIZE_8BIT) {
297+
// Force 8-bit access to the data register
298+
uint8_t *p_spi_dr = 0;
299+
p_spi_dr = (uint8_t *) & (spi->DR);
300+
return (int)(*p_spi_dr);
301+
} else {
302+
return (int)spi->DR;
303+
}
298304
}
299305

300306
void spi_slave_write(spi_t *obj, int value)
301307
{
302308
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
303309
while (!ssp_writeable(obj));
304-
spi->DR = (uint16_t)value;
310+
if (obj->bits == SPI_DATASIZE_8BIT) {
311+
// Force 8-bit access to the data register
312+
uint8_t *p_spi_dr = 0;
313+
p_spi_dr = (uint8_t *) & (spi->DR);
314+
*p_spi_dr = (uint8_t)value;
315+
} else { // SPI_DATASIZE_16BIT
316+
spi->DR = (uint16_t)value;
317+
}
305318
}
306319

307320
int spi_busy(spi_t *obj)

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F072RB/i2c_api.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
8282
pin_mode(sda, OpenDrain);
8383
pin_mode(scl, OpenDrain);
8484
}
85+
8586
// Enable I2C2 clock and pinout if not done
8687
if ((obj->i2c == I2C_2) && !i2c2_inited) {
8788
i2c2_inited = 1;
@@ -178,7 +179,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
178179
int count;
179180
int value;
180181

181-
/* update CR2 register */
182+
// Update CR2 register
182183
i2c->CR2 = (i2c->CR2 & (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP)))
183184
| (uint32_t)(((uint32_t)address & I2C_CR2_SADD) | (((uint32_t)length << 16) & I2C_CR2_NBYTES) | (uint32_t)I2C_SOFTEND_MODE | (uint32_t)I2C_GENERATE_START_READ);
184185

@@ -201,15 +202,15 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
201202
// If not repeated start, send stop.
202203
if (stop) {
203204
i2c_stop(obj);
204-
/* Wait until STOPF flag is set */
205+
// Wait until STOPF flag is set
205206
timeout = FLAG_TIMEOUT;
206207
while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_STOPF) == RESET) {
207208
timeout--;
208209
if (timeout == 0) {
209210
return -1;
210211
}
211212
}
212-
/* Clear STOP Flag */
213+
// Clear STOP Flag
213214
__HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_STOPF);
214215
}
215216

@@ -223,12 +224,10 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
223224
int timeout;
224225
int count;
225226

226-
/* update CR2 register */
227+
// Update CR2 register
227228
i2c->CR2 = (i2c->CR2 & (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | I2C_CR2_RD_WRN | I2C_CR2_START | I2C_CR2_STOP)))
228229
| (uint32_t)(((uint32_t)address & I2C_CR2_SADD) | (((uint32_t)length << 16) & I2C_CR2_NBYTES) | (uint32_t)I2C_SOFTEND_MODE | (uint32_t)I2C_GENERATE_START_WRITE);
229230

230-
231-
232231
for (count = 0; count < length; count++) {
233232
i2c_byte_write(obj, data[count]);
234233
}
@@ -243,18 +242,18 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
243242
}
244243
__HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_TC);
245244

246-
// If not repeated start, send stop.
245+
// If not repeated start, send stop
247246
if (stop) {
248247
i2c_stop(obj);
249-
/* Wait until STOPF flag is set */
248+
// Wait until STOPF flag is set
250249
timeout = FLAG_TIMEOUT;
251250
while (__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_STOPF) == RESET) {
252251
timeout--;
253252
if (timeout == 0) {
254253
return -1;
255254
}
256255
}
257-
/* Clear STOP Flag */
256+
// Clear STOP Flag
258257
__HAL_I2C_CLEAR_FLAG(&I2cHandle, I2C_FLAG_STOPF);
259258
}
260259

@@ -299,7 +298,7 @@ void i2c_reset(i2c_t *obj)
299298
{
300299
int timeout;
301300

302-
// wait before reset
301+
// Wait before reset
303302
timeout = LONG_TIMEOUT;
304303
while ((__HAL_I2C_GET_FLAG(&I2cHandle, I2C_FLAG_BUSY)) && (timeout-- != 0));
305304

@@ -336,7 +335,6 @@ void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
336335

337336
void i2c_slave_mode(i2c_t *obj, int enable_slave)
338337
{
339-
340338
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
341339
uint16_t tmpreg;
342340

@@ -352,7 +350,6 @@ void i2c_slave_mode(i2c_t *obj, int enable_slave)
352350

353351
// Set new mode
354352
i2c->OAR1 = tmpreg;
355-
356353
}
357354

358355
// See I2CSlave.h

0 commit comments

Comments
 (0)