Skip to content

Commit 4e5a890

Browse files
author
Daniel Jäckle
committed
Update drivers for the boards.
1 parent 55b0da3 commit 4e5a890

29 files changed

+1127
-921
lines changed

src/boards/LoRaMote/board.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,37 @@ static void BoardUnusedIoInit( void );
7676
*/
7777
static void SystemClockConfig( void );
7878

79+
/*!
80+
* Timer calibration
81+
*/
82+
static void CalibrateTimer( void );
83+
7984
/*!
8085
* System Clock Re-Configuration when waking up from STOP mode
8186
*/
8287
static void SystemClockReConfig( void );
8388

89+
/*!
90+
* Timer used at first boot to calibrate the Timer
91+
*/
92+
static TimerEvent_t TimerCalibrationTimer;
93+
8494
/*!
8595
* Flag to indicate if the MCU is Initialized
8696
*/
8797
static bool McuInitialized = false;
8898

99+
/*!
100+
* Flag to indicate if the Timer is Calibrated
101+
*/
102+
static bool TimerCalibrated = false;
103+
104+
105+
static void OnTimerCalibrationTimerEvent( void )
106+
{
107+
TimerCalibrated = true;
108+
}
109+
89110
void BoardInitPeriph( void )
90111
{
91112
/* Init the GPIO extender pins */
@@ -144,13 +165,12 @@ void BoardInitMcu( void )
144165

145166
DelayMs( 1000 ); // 1000 ms for Usb initialization
146167
#endif
168+
147169
RtcInit( );
148170

149171
BoardUnusedIoInit( );
150172

151173
I2cInit( &I2c, I2C_SCL, I2C_SDA );
152-
153-
McuInitialized = true;
154174
}
155175
else
156176
{
@@ -161,6 +181,12 @@ void BoardInitMcu( void )
161181

162182
SpiInit( &SX1272.Spi, RADIO_MOSI, RADIO_MISO, RADIO_SCLK, NC );
163183
SX1272IoInit( );
184+
185+
if( McuInitialized == false )
186+
{
187+
McuInitialized = true;
188+
CalibrateTimer( );
189+
}
164190
}
165191

166192
void BoardDeInitMcu( void )
@@ -261,9 +287,9 @@ void SystemClockConfig( void )
261287
RCC_ClkInitTypeDef RCC_ClkInitStruct;
262288
RCC_PeriphCLKInitTypeDef PeriphClkInit;
263289

264-
__HAL_RCC_PWR_CLK_ENABLE();
290+
__HAL_RCC_PWR_CLK_ENABLE( );
265291

266-
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
292+
__HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE1 );
267293

268294
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
269295
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
@@ -285,7 +311,7 @@ void SystemClockConfig( void )
285311
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
286312
HAL_RCCEx_PeriphCLKConfig( &PeriphClkInit );
287313

288-
HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq( )/1000 );
314+
HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq( ) / 1000 );
289315

290316
HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK );
291317

@@ -296,6 +322,20 @@ void SystemClockConfig( void )
296322
HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 );
297323
}
298324

325+
void CalibrateTimer( void )
326+
{
327+
if( TimerCalibrated == false )
328+
{
329+
TimerInit( &TimerCalibrationTimer, OnTimerCalibrationTimerEvent );
330+
TimerSetValue( &TimerCalibrationTimer, 1000 );
331+
TimerStart( &TimerCalibrationTimer );
332+
while( TimerCalibrated == false )
333+
{
334+
TimerLowPowerHandler( );
335+
}
336+
}
337+
}
338+
299339
void SystemClockReConfig( void )
300340
{
301341
__HAL_RCC_PWR_CLK_ENABLE( );

src/boards/LoRaMote/board.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Maintainer: Miguel Luis and Gregory Cristian
5959
#endif
6060

6161
#ifndef FAIL
62-
#define FAIL 0
62+
#define FAIL 0
6363
#endif
6464

6565
/*!
@@ -121,15 +121,15 @@ Maintainer: Miguel Luis and Gregory Cristian
121121
#define I2C_SCL PB_8
122122
#define I2C_SDA PB_9
123123

124-
#define CON_EXT_1 PB_13
125-
#define CON_EXT_3 PB_15
126-
#define CON_EXT_7 PB_12
124+
#define CON_EXT_1 PB_13
125+
#define CON_EXT_3 PB_15
126+
#define CON_EXT_7 PB_12
127127
#define CON_EXT_8 PB_14
128-
#define CON_EXT_9 PA_1
128+
#define CON_EXT_9 PA_1
129129
#define BAT_LEVEL PA_3
130130

131131
#define BOOT_1 PB_2
132-
132+
133133
#define GPS_PPS PA_8
134134
#define UART_TX PA_9
135135
#define UART_RX PA_10
@@ -219,7 +219,7 @@ uint8_t BoardGetBatteryLevel( void );
219219
uint32_t BoardGetRandomSeed( void );
220220

221221
/*!
222-
* \brief Gets the board 64 bits unique ID
222+
* \brief Gets the board 64 bits unique ID
223223
*
224224
* \param [IN] id Pointer to an array that will contain the Unique ID
225225
*/
@@ -232,5 +232,4 @@ void BoardGetUniqueId( uint8_t *id );
232232
*/
233233
uint8_t GetBoardPowerSource( void );
234234

235-
236235
#endif // __BOARD_H__

src/boards/LoRaMote/gpio-board.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void GpioMcuInit( Gpio_t *obj, PinNames pin, PinModes mode, PinConfigs config, P
2828
obj->pin = pin;
2929
obj->pinIndex = ( 0x01 << ( obj->pin & 0x0F ) );
3030

31-
3231
if( ( obj->pin & 0xF0 ) == 0x00 )
3332
{
3433
obj->port = GPIOA;
@@ -116,15 +115,15 @@ void GpioMcuSetInterrupt( Gpio_t *obj, IrqModes irqMode, IrqPriorities irqPriori
116115

117116
if( irqMode == IRQ_RISING_EDGE )
118117
{
119-
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
118+
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
120119
}
121120
else if( irqMode == IRQ_FALLING_EDGE )
122121
{
123-
GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
122+
GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
124123
}
125124
else
126125
{
127-
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING_FALLING;
126+
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING_FALLING;
128127
}
129128

130129
GPIO_InitStructure.Pull = GPIO_NOPULL;
@@ -215,6 +214,21 @@ void GpioMcuWrite( Gpio_t *obj, uint32_t value )
215214
HAL_GPIO_WritePin( obj->port, obj->pinIndex , ( GPIO_PinState )value );
216215
}
217216

217+
void GpioMcuToggle( Gpio_t *obj )
218+
{
219+
if( ( obj == NULL ) || ( obj->port == NULL ) )
220+
{
221+
assert_param( FAIL );
222+
}
223+
224+
// Check if pin is not connected
225+
if( obj->pin == NC )
226+
{
227+
return;
228+
}
229+
HAL_GPIO_TogglePin( obj->port, obj->pinIndex );
230+
}
231+
218232
uint32_t GpioMcuRead( Gpio_t *obj )
219233
{
220234
if( obj == NULL )
@@ -226,43 +240,54 @@ uint32_t GpioMcuRead( Gpio_t *obj )
226240
{
227241
return 0;
228242
}
229-
return HAL_GPIO_ReadPin( obj->port, obj->pinIndex);
243+
return HAL_GPIO_ReadPin( obj->port, obj->pinIndex );
230244
}
231245

232-
233246
void EXTI0_IRQHandler( void )
234247
{
248+
#if !defined( USE_NO_TIMER )
235249
RtcRecoverMcuStatus( );
250+
#endif
236251
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_0 );
237252
}
238253

239254
void EXTI1_IRQHandler( void )
240255
{
256+
#if !defined( USE_NO_TIMER )
241257
RtcRecoverMcuStatus( );
258+
#endif
242259
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_1 );
243260
}
244261

245262
void EXTI2_IRQHandler( void )
246263
{
264+
#if !defined( USE_NO_TIMER )
247265
RtcRecoverMcuStatus( );
266+
#endif
248267
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_2 );
249268
}
250269

251270
void EXTI3_IRQHandler( void )
252271
{
272+
#if !defined( USE_NO_TIMER )
253273
RtcRecoverMcuStatus( );
274+
#endif
254275
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_3 );
255276
}
256277

257278
void EXTI4_IRQHandler( void )
258279
{
280+
#if !defined( USE_NO_TIMER )
259281
RtcRecoverMcuStatus( );
282+
#endif
260283
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_4 );
261284
}
262285

263286
void EXTI9_5_IRQHandler( void )
264287
{
288+
#if !defined( USE_NO_TIMER )
265289
RtcRecoverMcuStatus( );
290+
#endif
266291
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_5 );
267292
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_6 );
268293
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_7 );
@@ -272,7 +297,9 @@ void EXTI9_5_IRQHandler( void )
272297

273298
void EXTI15_10_IRQHandler( void )
274299
{
300+
#if !defined( USE_NO_TIMER )
275301
RtcRecoverMcuStatus( );
302+
#endif
276303
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_10 );
277304
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_11 );
278305
HAL_GPIO_EXTI_IRQHandler( GPIO_PIN_12 );

src/boards/LoRaMote/gpio-board.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ void GpioMcuRemoveInterrupt( Gpio_t *obj );
5656
*/
5757
void GpioMcuWrite( Gpio_t *obj, uint32_t value );
5858

59+
/*!
60+
* \brief Toggle the value to the GPIO output
61+
*
62+
* \param [IN] obj Pointer to the GPIO object
63+
*/
64+
void GpioMcuToggle( Gpio_t *obj );
65+
5966
/*!
6067
* \brief Reads the current GPIO input value
6168
*

src/boards/LoRaMote/i2c-board.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ typedef enum {
3232

3333
void I2cMcuInit( I2c_t *obj, PinNames scl, PinNames sda )
3434
{
35-
__HAL_RCC_I2C1_FORCE_RESET();
36-
__HAL_RCC_I2C1_RELEASE_RESET();
35+
__HAL_RCC_I2C1_FORCE_RESET( );
36+
__HAL_RCC_I2C1_RELEASE_RESET( );
3737

38-
obj->I2c.Instance = (I2C_TypeDef *) I2C1_BASE;
38+
obj->I2c.Instance = ( I2C_TypeDef * )I2C1_BASE;
3939

4040
GpioInit( &obj->Scl, scl, PIN_ALTERNATE_FCT, PIN_OPEN_DRAIN, PIN_NO_PULL, GPIO_AF4_I2C1 );
4141
GpioInit( &obj->Sda, sda, PIN_ALTERNATE_FCT, PIN_OPEN_DRAIN, PIN_NO_PULL, GPIO_AF4_I2C1 );

0 commit comments

Comments
 (0)