Skip to content

Commit 7217660

Browse files
Clean up stm32l0_system.c to have proper system events; stm32l0_sfspi.c rework, so that the SFLASH actually goes to DeepPowerDown mode
1 parent bdfc559 commit 7217660

File tree

8 files changed

+275
-345
lines changed

8 files changed

+275
-345
lines changed

system/STM32L0xx/Include/stm32l0_system.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ enum {
8585
#define STM32L0_SYSTEM_LOCK_RUN 0
8686
#define STM32L0_SYSTEM_LOCK_SLEEP 1
8787
#define STM32L0_SYSTEM_LOCK_DEEPSLEEP 2
88-
//#define STM32L0_SYSTEM_LOCK_CLOCKS 0 // ###
89-
//#define STM32L0_SYSTEM_LOCK_STOP 2 // ###
90-
//#define STM32L0_SYSTEM_LOCK_STANDBY 3 // ###
9188
#define STM32L0_SYSTEM_LOCK_RANGE_2_3 3
9289
#define STM32L0_SYSTEM_LOCK_RANGE_3 4
9390
#define STM32L0_SYSTEM_LOCK_REGULATOR 5
@@ -105,6 +102,7 @@ enum {
105102
#define STM32L0_SYSTEM_EVENT_STOP_LEAVE 0x00000008
106103
#define STM32L0_SYSTEM_EVENT_STANDBY 0x00000010
107104
#define STM32L0_SYSTEM_EVENT_RESET 0x00000020
105+
#define STM32L0_SYSTEM_EVENT_DFU 0x00000040
108106

109107
typedef void (*stm32l0_system_callback_t)(void *context, uint32_t events);
110108

@@ -117,12 +115,14 @@ typedef struct _stm32l0_system_notify_t {
117115

118116
#define STM32L0_SYSTEM_RESET_POWERON 0
119117
#define STM32L0_SYSTEM_RESET_EXTERNAL 1
120-
#define STM32L0_SYSTEM_RESET_SOFTWARE 2
121-
#define STM32L0_SYSTEM_RESET_WATCHDOG 3
118+
#define STM32L0_SYSTEM_RESET_INTERNAL 2
119+
#define STM32L0_SYSTEM_RESET_SOFTWARE 3
122120
#define STM32L0_SYSTEM_RESET_FIREWALL 4
123-
#define STM32L0_SYSTEM_RESET_OTHER 5
124-
#define STM32L0_SYSTEM_RESET_STANDBY 6
121+
#define STM32L0_SYSTEM_RESET_WATCHDOG 5
122+
#define STM32L0_SYSTEM_RESET_CRASH 6
123+
#define STM32L0_SYSTEM_RESET_STANDBY 7
125124

125+
#define STM32L0_SYSTEM_WAKEUP_NONE 0x00000000
126126
#define STM32L0_SYSTEM_WAKEUP_PIN 0x00000001
127127
#define STM32L0_SYSTEM_WAKEUP_ALARM 0x00000002
128128
#define STM32L0_SYSTEM_WAKEUP_TIMEOUT 0x00000004
@@ -179,9 +179,9 @@ extern void stm32l0_system_periph_enable(unsigned int periph);
179179
extern void stm32l0_system_periph_disable(unsigned int periph);
180180
extern void stm32l0_system_swd_enable(void);
181181
extern void stm32l0_system_swd_disable(void);
182-
extern uint32_t stm32l0_system_read_backup(unsigned int index);
183-
extern void stm32l0_system_write_backup(unsigned int index, uint32_t data);
184-
extern void stm32l0_system_notify(stm32l0_system_notify_t *notify, stm32l0_system_callback_t callback, void *context, uint32_t events);
182+
extern void stm32l0_system_register(stm32l0_system_notify_t *notify, stm32l0_system_callback_t callback, void *context, uint32_t events);
183+
extern void stm32l0_system_unregister(stm32l0_system_notify_t *notify);
184+
extern void stm32l0_system_notify(uint32_t events);
185185
extern void stm32l0_system_lock(uint32_t lock);
186186
extern void stm32l0_system_unlock(uint32_t lock);
187187
extern void stm32l0_system_reference(uint32_t reference);

system/STM32L0xx/Lib/libstm32l052xx.a

794 Bytes
Binary file not shown.

system/STM32L0xx/Lib/libstm32l072xx.a

784 Bytes
Binary file not shown.

system/STM32L0xx/Lib/libstm32l082xx.a

792 Bytes
Binary file not shown.

system/STM32L0xx/Source/stm32l0_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ bool stm32l0_i2c_create(stm32l0_i2c_t *i2c, const stm32l0_i2c_params_t *params)
10811081

10821082
if (!stm32l0_i2c_device.notify.callback)
10831083
{
1084-
stm32l0_system_notify(&stm32l0_i2c_device.notify, stm32l0_i2c_notify_callback, NULL, (STM32L0_SYSTEM_EVENT_STOP_ENTER | STM32L0_SYSTEM_EVENT_STOP_LEAVE));
1084+
stm32l0_system_register(&stm32l0_i2c_device.notify, stm32l0_i2c_notify_callback, NULL, (STM32L0_SYSTEM_EVENT_STOP_ENTER | STM32L0_SYSTEM_EVENT_STOP_LEAVE));
10851085
}
10861086

10871087
return true;

system/STM32L0xx/Source/stm32l0_sfspi.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,21 +331,21 @@ static void stm32l0_sfspi_callback(void *context, uint32_t events)
331331
{
332332
if (sfspi->ID[0] == SFLASH_MID_MACRONIX)
333333
{
334-
/* lock/unlock will block shared interrupts and USB/MSC.
334+
/* acquire/release will block shared interrupts and USB/MSC.
335335
*/
336336

337-
stm32l0_sfspi_lock(sfspi);
338-
339337
if (sfspi->state == STM32L0_SFSPI_STATE_READY)
340338
{
341-
stm32l0_sfspi_select(sfspi);
339+
stm32l0_spi_acquire(sfspi->spi, 32000000, 0);
340+
341+
stm32l0_sfspi_select(sfspi);
342342
stm32l0_spi_data(sfspi->spi, SFLASH_CMD_DPD);
343343
stm32l0_sfspi_unselect(sfspi);
344344

345-
sfspi->state = STM32L0_SFSPI_STATE_SLEEP;
346-
}
345+
stm32l0_spi_release(sfspi->spi);
347346

348-
stm32l0_sfspi_unlock(sfspi);
347+
sfspi->state = STM32L0_SFSPI_STATE_SLEEP;
348+
}
349349
}
350350
}
351351
}
@@ -409,7 +409,7 @@ bool stm32l0_sfspi_initialize(stm32l0_spi_t *spi, const stm32l0_sfspi_params_t *
409409
{
410410
sfspi->state = STM32L0_SFSPI_STATE_READY;
411411

412-
stm32l0_system_notify(&stm32l0_sfspi.notify, stm32l0_sfspi_callback, (void*)&stm32l0_sfspi, STM32L0_SYSTEM_EVENT_SLEEP);
412+
stm32l0_system_register(&stm32l0_sfspi.notify, stm32l0_sfspi_callback, (void*)&stm32l0_sfspi, STM32L0_SYSTEM_EVENT_SLEEP);
413413
}
414414
}
415415

0 commit comments

Comments
 (0)