Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
6e44381c
Commit
6e44381c
authored
Apr 19, 2014
by
Damien George
Browse files
stmhal: Improve RTC class; make fatfs use RTC for time stamping files.
parent
ed5117f6
Changes
5
Hide whitespace changes
Inline
Side-by-side
stmhal/diskio.c
View file @
6e44381c
...
...
@@ -9,11 +9,19 @@
#include
<stdint.h>
#include
<stdio.h>
#include
"ff.h"
/* FatFs lower layer API */
#include
"diskio.h"
/* FatFs lower layer API */
#include
"stm32f4xx_hal.h"
#include
"misc.h"
#include
"mpconfig.h"
#include
"qstr.h"
#include
"obj.h"
#include
"systick.h"
#include
"rtc.h"
#include
"storage.h"
#include
"sdcard.h"
#include
"ff.h"
/* FatFs lower layer API */
#include
"diskio.h"
/* FatFs lower layer API */
const
PARTITION
VolToPart
[]
=
{
{
0
,
1
},
// Logical drive 0 ==> Physical drive 0, 1st partition
...
...
@@ -190,12 +198,9 @@ DWORD get_fattime (
void
)
{
// TODO replace with call to RTC
int
year
=
2013
;
int
month
=
10
;
int
day
=
12
;
int
hour
=
21
;
int
minute
=
42
;
int
second
=
13
;
return
((
year
-
1980
)
<<
25
)
|
((
month
)
<<
21
)
|
((
day
)
<<
16
)
|
((
hour
)
<<
11
)
|
((
minute
)
<<
5
)
|
(
second
/
2
);
RTC_TimeTypeDef
time
;
RTC_DateTypeDef
date
;
HAL_RTC_GetTime
(
&
RTCHandle
,
&
time
,
FORMAT_BIN
);
HAL_RTC_GetDate
(
&
RTCHandle
,
&
date
,
FORMAT_BIN
);
return
((
2000
+
date
.
Year
-
1980
)
<<
25
)
|
((
date
.
Month
)
<<
21
)
|
((
date
.
Date
)
<<
16
)
|
((
time
.
Hours
)
<<
11
)
|
((
time
.
Minutes
)
<<
5
)
|
(
time
.
Seconds
/
2
);
}
stmhal/modpyb.c
View file @
6e44381c
...
...
@@ -268,8 +268,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
#endif
#if MICROPY_HW_ENABLE_RTC
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_time
),
(
mp_obj_t
)
&
pyb_rtc_read_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_rtc_info
),
(
mp_obj_t
)
&
pyb_rtc_info_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_RTC
),
(
mp_obj_t
)
&
pyb_rtc_type
},
#endif
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_Pin
),
(
mp_obj_t
)
&
pin_type
},
...
...
stmhal/qstrdefsport.h
View file @
6e44381c
...
...
@@ -39,9 +39,13 @@ Q(FileIO)
// Entries for sys.path
Q
(
0
:/
)
Q
(
0
:/
lib
)
Q
(
rtc_info
)
Q
(
millis
)
// for RTC class
Q
(
RTC
)
Q
(
info
)
Q
(
datetime
)
// for Pin class
Q
(
Pin
)
Q
(
PinAF
)
...
...
stmhal/rtc.c
View file @
6e44381c
#include
<stdio.h>
#include
"stm32f4xx_hal.h"
#include
"stm32f4xx_hal_rtc.h"
#include
"misc.h"
#include
"mpconfig.h"
#include
"qstr.h"
#include
"obj.h"
#include
"systick.h"
#include
"runtime.h"
//#include "systick.h"
#include
"rtc.h"
static
RTC_HandleTypeDef
R
tc
Handle
;
RTC_HandleTypeDef
R
TC
Handle
;
static
machine_uint_t
rtc_info
;
#define RTC_INFO_USE_EXISTING (0)
...
...
@@ -125,7 +125,7 @@ static void RTC_CalendarConfig(void);
void
rtc_init
(
void
)
{
/*##-1- Configure the RTC peripheral #######################################*/
R
tc
Handle
.
Instance
=
RTC
;
R
TC
Handle
.
Instance
=
RTC
;
/* Configure RTC prescaler and RTC data registers */
/* RTC configured as follow:
...
...
@@ -135,16 +135,16 @@ void rtc_init(void) {
- OutPut = Output Disable
- OutPutPolarity = High Polarity
- OutPutType = Open Drain */
R
tc
Handle
.
Init
.
HourFormat
=
RTC_HOURFORMAT_24
;
R
tc
Handle
.
Init
.
AsynchPrediv
=
RTC_ASYNCH_PREDIV
;
R
tc
Handle
.
Init
.
SynchPrediv
=
RTC_SYNCH_PREDIV
;
R
tc
Handle
.
Init
.
OutPut
=
RTC_OUTPUT_DISABLE
;
R
tc
Handle
.
Init
.
OutPutPolarity
=
RTC_OUTPUT_POLARITY_HIGH
;
R
tc
Handle
.
Init
.
OutPutType
=
RTC_OUTPUT_TYPE_OPENDRAIN
;
R
TC
Handle
.
Init
.
HourFormat
=
RTC_HOURFORMAT_24
;
R
TC
Handle
.
Init
.
AsynchPrediv
=
RTC_ASYNCH_PREDIV
;
R
TC
Handle
.
Init
.
SynchPrediv
=
RTC_SYNCH_PREDIV
;
R
TC
Handle
.
Init
.
OutPut
=
RTC_OUTPUT_DISABLE
;
R
TC
Handle
.
Init
.
OutPutPolarity
=
RTC_OUTPUT_POLARITY_HIGH
;
R
TC
Handle
.
Init
.
OutPutType
=
RTC_OUTPUT_TYPE_OPENDRAIN
;
machine_uint_t
tick
=
HAL_GetTick
();
if
(
HAL_RTC_Init
(
&
R
tc
Handle
)
!=
HAL_OK
)
if
(
HAL_RTC_Init
(
&
R
TC
Handle
)
!=
HAL_OK
)
{
/* Initialization Error */
//Error_Handler();
...
...
@@ -156,7 +156,7 @@ void rtc_init(void) {
/*##-2- Check if Data stored in BackUp register0: No Need to reconfigure RTC#*/
/* Read the Back Up Register 0 Data */
if
(
HAL_RTCEx_BKUPRead
(
&
R
tc
Handle
,
RTC_BKP_DR0
)
!=
0x32F2
)
if
(
HAL_RTCEx_BKUPRead
(
&
R
TC
Handle
,
RTC_BKP_DR0
)
!=
0x32F2
)
{
/* Configure RTC Calendar */
RTC_CalendarConfig
();
...
...
@@ -193,7 +193,7 @@ static void RTC_CalendarConfig(void)
sdatestructure
.
Date
=
0x18
;
sdatestructure
.
WeekDay
=
RTC_WEEKDAY_TUESDAY
;
if
(
HAL_RTC_SetDate
(
&
R
tc
Handle
,
&
sdatestructure
,
FORMAT_BCD
)
!=
HAL_OK
)
if
(
HAL_RTC_SetDate
(
&
R
TC
Handle
,
&
sdatestructure
,
FORMAT_BCD
)
!=
HAL_OK
)
{
/* Initialization Error */
//Error_Handler();
...
...
@@ -209,7 +209,7 @@ static void RTC_CalendarConfig(void)
stimestructure
.
DayLightSaving
=
RTC_DAYLIGHTSAVING_NONE
;
stimestructure
.
StoreOperation
=
RTC_STOREOPERATION_RESET
;
if
(
HAL_RTC_SetTime
(
&
R
tc
Handle
,
&
stimestructure
,
FORMAT_BCD
)
!=
HAL_OK
)
if
(
HAL_RTC_SetTime
(
&
R
TC
Handle
,
&
stimestructure
,
FORMAT_BCD
)
!=
HAL_OK
)
{
/* Initialization Error */
//Error_Handler();
...
...
@@ -217,25 +217,86 @@ static void RTC_CalendarConfig(void)
}
/*##-3- Writes a data in a RTC Backup data Register0 #######################*/
HAL_RTCEx_BKUPWrite
(
&
R
tc
Handle
,
RTC_BKP_DR0
,
0x32F2
);
HAL_RTCEx_BKUPWrite
(
&
R
TC
Handle
,
RTC_BKP_DR0
,
0x32F2
);
}
/******************************************************************************/
// Micro Python bindings
mp_obj_
t
pyb_rtc_
info
(
void
)
{
return
mp_obj_new_int
(
rtc_info
)
;
}
typedef
struc
t
_
pyb_rtc_
obj_t
{
mp_obj_base_t
base
;
}
pyb_rtc_obj_t
;
MP_DEFINE_CONST_FUN_OBJ_0
(
pyb_rtc_info_obj
,
pyb_rtc_
info
)
;
STATIC
const
pyb_rtc_obj_t
pyb_rtc_obj
=
{{
&
pyb_rtc_
type
}}
;
mp_obj_t
pyb_rtc_read
(
void
)
{
RTC_TimeTypeDef
time
;
RTC_DateTypeDef
date
;
HAL_RTC_GetTime
(
&
RtcHandle
,
&
time
,
FORMAT_BIN
);
HAL_RTC_GetDate
(
&
RtcHandle
,
&
date
,
FORMAT_BIN
);
printf
(
"%02d-%02d-%04d %02d:%02d:%02d
\n
"
,
date
.
Date
,
date
.
Month
,
2000
+
date
.
Year
,
time
.
Hours
,
time
.
Minutes
,
time
.
Seconds
);
return
mp_const_none
;
STATIC
mp_obj_t
pyb_rtc_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
// check arguments
mp_check_nargs
(
n_args
,
0
,
0
,
n_kw
,
false
);
// return constant object
return
(
mp_obj_t
)
&
pyb_rtc_obj
;
}
MP_DEFINE_CONST_FUN_OBJ_0
(
pyb_rtc_read_obj
,
pyb_rtc_read
);
mp_obj_t
pyb_rtc_info
(
mp_obj_t
self_in
)
{
return
mp_obj_new_int
(
rtc_info
);
}
MP_DEFINE_CONST_FUN_OBJ_1
(
pyb_rtc_info_obj
,
pyb_rtc_info
);
mp_obj_t
pyb_rtc_datetime
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
if
(
n_args
==
1
)
{
// get date and time
// note: need to call get time then get date to correctly access the registers
RTC_DateTypeDef
date
;
RTC_TimeTypeDef
time
;
HAL_RTC_GetTime
(
&
RTCHandle
,
&
time
,
FORMAT_BIN
);
HAL_RTC_GetDate
(
&
RTCHandle
,
&
date
,
FORMAT_BIN
);
mp_obj_t
tuple
[
8
]
=
{
mp_obj_new_int
(
2000
+
date
.
Year
),
mp_obj_new_int
(
date
.
Month
),
mp_obj_new_int
(
date
.
Date
),
mp_obj_new_int
(
date
.
WeekDay
),
mp_obj_new_int
(
time
.
Hours
),
mp_obj_new_int
(
time
.
Minutes
),
mp_obj_new_int
(
time
.
Seconds
),
mp_obj_new_int
(
time
.
SubSeconds
),
};
return
mp_obj_new_tuple
(
8
,
tuple
);
}
else
{
// set date and time
mp_obj_t
*
items
;
mp_obj_get_array_fixed_n
(
args
[
1
],
8
,
&
items
);
RTC_DateTypeDef
date
;
date
.
Year
=
mp_obj_get_int
(
items
[
0
])
-
2000
;
date
.
Month
=
mp_obj_get_int
(
items
[
1
]);
date
.
Date
=
mp_obj_get_int
(
items
[
2
]);
date
.
WeekDay
=
mp_obj_get_int
(
items
[
3
]);
HAL_RTC_SetDate
(
&
RTCHandle
,
&
date
,
FORMAT_BCD
);
RTC_TimeTypeDef
time
;
time
.
Hours
=
mp_obj_get_int
(
items
[
4
]);
time
.
Minutes
=
mp_obj_get_int
(
items
[
5
]);
time
.
Seconds
=
mp_obj_get_int
(
items
[
6
]);
time
.
SubSeconds
=
mp_obj_get_int
(
items
[
7
]);
time
.
TimeFormat
=
RTC_HOURFORMAT12_AM
;
time
.
DayLightSaving
=
RTC_DAYLIGHTSAVING_NONE
;
time
.
StoreOperation
=
RTC_STOREOPERATION_SET
;
HAL_RTC_SetTime
(
&
RTCHandle
,
&
time
,
FORMAT_BCD
);
return
mp_const_none
;
}
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
pyb_rtc_datetime_obj
,
1
,
2
,
pyb_rtc_datetime
);
STATIC
const
mp_map_elem_t
pyb_rtc_locals_dict_table
[]
=
{
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_info
),
(
mp_obj_t
)
&
pyb_rtc_info_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_datetime
),
(
mp_obj_t
)
&
pyb_rtc_datetime_obj
},
};
STATIC
MP_DEFINE_CONST_DICT
(
pyb_rtc_locals_dict
,
pyb_rtc_locals_dict_table
);
const
mp_obj_type_t
pyb_rtc_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_RTC
,
.
make_new
=
pyb_rtc_make_new
,
.
locals_dict
=
(
mp_obj_t
)
&
pyb_rtc_locals_dict
,
};
stmhal/rtc.h
View file @
6e44381c
void
rtc_init
(
void
);
extern
RTC_HandleTypeDef
RTCHandle
;
extern
const
mp_obj_type_t
pyb_rtc_type
;
MP_DECLARE_CONST_FUN_OBJ
(
pyb_rtc_info_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_rtc_read_obj
);
void
rtc_init
(
void
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment