summaryrefslogtreecommitdiffstatshomepage
path: root/stmhal/modpyb.c
diff options
context:
space:
mode:
Diffstat (limited to 'stmhal/modpyb.c')
-rw-r--r--stmhal/modpyb.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/stmhal/modpyb.c b/stmhal/modpyb.c
index 18507f9ef8..7bd7d5f994 100644
--- a/stmhal/modpyb.c
+++ b/stmhal/modpyb.c
@@ -14,6 +14,7 @@
#include "pyexec.h"
#include "led.h"
#include "pin.h"
+#include "timer.h"
#include "extint.h"
#include "usrsw.h"
#include "rng.h"
@@ -31,14 +32,7 @@
#include "modpyb.h"
#include "ff.h"
-STATIC mp_obj_t pyb_unique_id(void) {
- // get unique id; 96 bits
- byte *id = (byte*)0x1fff7a10;
- return mp_obj_new_bytes(id, 12);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_unique_id_obj, pyb_unique_id);
-
-// get lots of info about the board
+// print lots of info about the board
STATIC mp_obj_t pyb_info(uint n_args, const mp_obj_t *args) {
// get and print unique id; 96 bits
{
@@ -103,28 +97,44 @@ STATIC mp_obj_t pyb_info(uint n_args, const mp_obj_t *args) {
return mp_const_none;
}
-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_info_obj, 0, 1, pyb_info);
+// get unique MCU id; 96 bits = 12 bytes
+STATIC mp_obj_t pyb_unique_id(void) {
+ byte *id = (byte*)0x1fff7a10;
+ return mp_obj_new_bytes(id, 12);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_unique_id_obj, pyb_unique_id);
+
+// get clock frequencies
+// TODO should also be able to set frequency via this function
+STATIC mp_obj_t pyb_freq(void) {
+ mp_obj_t tuple[4] = {
+ mp_obj_new_int(HAL_RCC_GetSysClockFreq()),
+ mp_obj_new_int(HAL_RCC_GetHCLKFreq()),
+ mp_obj_new_int(HAL_RCC_GetPCLK1Freq()),
+ mp_obj_new_int(HAL_RCC_GetPCLK2Freq()),
+ };
+ return mp_obj_new_tuple(4, tuple);
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_freq_obj, pyb_freq);
+
// sync all file systems
STATIC mp_obj_t pyb_sync(void) {
storage_flush();
return mp_const_none;
}
-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_sync_obj, pyb_sync);
STATIC mp_obj_t pyb_millis(void) {
return mp_obj_new_int(HAL_GetTick());
}
-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_millis_obj, pyb_millis);
STATIC mp_obj_t pyb_delay(mp_obj_t count) {
HAL_Delay(mp_obj_get_int(count));
return mp_const_none;
}
-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_delay_obj, pyb_delay);
STATIC mp_obj_t pyb_udelay(mp_obj_t usec) {
@@ -241,8 +251,9 @@ MP_DECLARE_CONST_FUN_OBJ(pyb_usb_mode_obj); // defined in main.c
STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_pyb) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&pyb_unique_id_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_info), (mp_obj_t)&pyb_info_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_unique_id), (mp_obj_t)&pyb_unique_id_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_freq), (mp_obj_t)&pyb_freq_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_gc), (mp_obj_t)&pyb_gc_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_repl_info), (mp_obj_t)&pyb_set_repl_info_obj },
@@ -264,6 +275,8 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_udelay), (mp_obj_t)&pyb_udelay_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&pyb_sync_obj },
+ { MP_OBJ_NEW_QSTR(MP_QSTR_Timer), (mp_obj_t)&pyb_timer_type },
+
#if MICROPY_HW_ENABLE_RNG
{ MP_OBJ_NEW_QSTR(MP_QSTR_rng), (mp_obj_t)&pyb_rng_get_obj },
#endif