Merge branch 'master' of github.com:iabdalkader/micropython into iabdalkader-master
Conflicts: stm/main.c
This commit is contained in:
commit
b080c7946b
|
@ -64,6 +64,7 @@ SRC_C = \
|
||||||
i2c.c \
|
i2c.c \
|
||||||
usrsw.c \
|
usrsw.c \
|
||||||
adc.c \
|
adc.c \
|
||||||
|
rtc.c \
|
||||||
# pybwlan.c \
|
# pybwlan.c \
|
||||||
|
|
||||||
SRC_S = \
|
SRC_S = \
|
||||||
|
|
|
@ -1961,7 +1961,7 @@ void USB_OTG_ActiveRemoteWakeup(USB_OTG_CORE_HANDLE *pdev)
|
||||||
if(pdev->cfg.low_power)
|
if(pdev->cfg.low_power)
|
||||||
{
|
{
|
||||||
/* un-gate USB Core clock */
|
/* un-gate USB Core clock */
|
||||||
power.d32 = USB_OTG_READ_REG32(&pdev->regs.PCGCCTL); // dpgeorge: taking the address here might be wrong...
|
power.d32 = USB_OTG_READ_REG32(pdev->regs.PCGCCTL);
|
||||||
power.b.gatehclk = 0;
|
power.b.gatehclk = 0;
|
||||||
power.b.stoppclk = 0;
|
power.b.stoppclk = 0;
|
||||||
USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
|
USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
|
||||||
|
@ -1995,7 +1995,7 @@ void USB_OTG_UngateClock(USB_OTG_CORE_HANDLE *pdev)
|
||||||
if(dsts.b.suspsts == 1)
|
if(dsts.b.suspsts == 1)
|
||||||
{
|
{
|
||||||
/* un-gate USB Core clock */
|
/* un-gate USB Core clock */
|
||||||
power.d32 = USB_OTG_READ_REG32(&pdev->regs.PCGCCTL); // dpgeorge: taking the address here might be wrong...
|
power.d32 = USB_OTG_READ_REG32(pdev->regs.PCGCCTL);
|
||||||
power.b.gatehclk = 0;
|
power.b.gatehclk = 0;
|
||||||
power.b.stoppclk = 0;
|
power.b.stoppclk = 0;
|
||||||
USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
|
USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
|
||||||
|
|
|
@ -352,7 +352,7 @@ static uint32_t DCD_HandleResume_ISR(USB_OTG_CORE_HANDLE *pdev)
|
||||||
if(pdev->cfg.low_power)
|
if(pdev->cfg.low_power)
|
||||||
{
|
{
|
||||||
/* un-gate USB Core clock */
|
/* un-gate USB Core clock */
|
||||||
power.d32 = USB_OTG_READ_REG32(&pdev->regs.PCGCCTL); // dpgeorge: taking the address here might be wrong...
|
power.d32 = USB_OTG_READ_REG32(pdev->regs.PCGCCTL);
|
||||||
power.b.gatehclk = 0;
|
power.b.gatehclk = 0;
|
||||||
power.b.stoppclk = 0;
|
power.b.stoppclk = 0;
|
||||||
USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
|
USB_OTG_WRITE_REG32(pdev->regs.PCGCCTL, power.d32);
|
||||||
|
|
135
stm/main.c
135
stm/main.c
|
@ -42,6 +42,7 @@
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "usrsw.h"
|
#include "usrsw.h"
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "rtc.h"
|
||||||
|
|
||||||
int errno;
|
int errno;
|
||||||
|
|
||||||
|
@ -62,8 +63,10 @@ void flash_error(int n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void __fatal_error(const char *msg) {
|
void __fatal_error(const char *msg) {
|
||||||
|
#if MICROPY_HW_HAS_LCD
|
||||||
lcd_print_strn("\nFATAL ERROR:\n", 14);
|
lcd_print_strn("\nFATAL ERROR:\n", 14);
|
||||||
lcd_print_strn(msg, strlen(msg));
|
lcd_print_strn(msg, strlen(msg));
|
||||||
|
#endif
|
||||||
for (;;) {
|
for (;;) {
|
||||||
flash_error(1);
|
flash_error(1);
|
||||||
}
|
}
|
||||||
|
@ -541,87 +544,6 @@ mp_obj_t pyb_hid_send_report(mp_obj_t arg) {
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rtc_init(void) {
|
|
||||||
uint32_t rtc_clksrc;
|
|
||||||
uint32_t timeout = 1000000;
|
|
||||||
|
|
||||||
/* Enable the PWR clock */
|
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
|
||||||
|
|
||||||
/* Allow access to RTC */
|
|
||||||
PWR_BackupAccessCmd(ENABLE);
|
|
||||||
|
|
||||||
/* Enable the LSE OSC */
|
|
||||||
RCC_LSEConfig(RCC_LSE_ON);
|
|
||||||
|
|
||||||
/* Wait till LSE is ready */
|
|
||||||
while((RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (--timeout > 0)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If LSE timed out, use LSI instead */
|
|
||||||
if (timeout == 0) {
|
|
||||||
/* Enable the LSI OSC */
|
|
||||||
RCC_LSICmd(ENABLE);
|
|
||||||
|
|
||||||
/* Wait till LSI is ready */
|
|
||||||
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Use LSI as the RTC Clock Source */
|
|
||||||
rtc_clksrc = RCC_RTCCLKSource_LSI;
|
|
||||||
} else {
|
|
||||||
/* Use LSE as the RTC Clock Source */
|
|
||||||
rtc_clksrc = RCC_RTCCLKSource_LSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Select the RTC Clock Source */
|
|
||||||
RCC_RTCCLKConfig(rtc_clksrc);
|
|
||||||
|
|
||||||
/* Note: LSI is around (32KHz), these dividers should work either way */
|
|
||||||
/* ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
|
|
||||||
uint32_t uwSynchPrediv = 0xFF;
|
|
||||||
uint32_t uwAsynchPrediv = 0x7F;
|
|
||||||
|
|
||||||
/* Enable the RTC Clock */
|
|
||||||
RCC_RTCCLKCmd(ENABLE);
|
|
||||||
|
|
||||||
/* Wait for RTC APB registers synchronisation */
|
|
||||||
RTC_WaitForSynchro();
|
|
||||||
|
|
||||||
/* Configure the RTC data register and RTC prescaler */
|
|
||||||
RTC_InitTypeDef RTC_InitStructure;
|
|
||||||
RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv;
|
|
||||||
RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv;
|
|
||||||
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
|
|
||||||
RTC_Init(&RTC_InitStructure);
|
|
||||||
|
|
||||||
// Set the date (BCD)
|
|
||||||
RTC_DateTypeDef RTC_DateStructure;
|
|
||||||
RTC_DateStructure.RTC_Year = 0x13;
|
|
||||||
RTC_DateStructure.RTC_Month = RTC_Month_October;
|
|
||||||
RTC_DateStructure.RTC_Date = 0x26;
|
|
||||||
RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Saturday;
|
|
||||||
RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);
|
|
||||||
|
|
||||||
// Set the time (BCD)
|
|
||||||
RTC_TimeTypeDef RTC_TimeStructure;
|
|
||||||
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
|
|
||||||
RTC_TimeStructure.RTC_Hours = 0x01;
|
|
||||||
RTC_TimeStructure.RTC_Minutes = 0x53;
|
|
||||||
RTC_TimeStructure.RTC_Seconds = 0x00;
|
|
||||||
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
|
|
||||||
|
|
||||||
// Indicator for the RTC configuration
|
|
||||||
//RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
|
|
||||||
}
|
|
||||||
|
|
||||||
mp_obj_t pyb_rtc_read(void) {
|
|
||||||
RTC_TimeTypeDef RTC_TimeStructure;
|
|
||||||
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
|
|
||||||
printf("%02d:%02d:%02d\n", RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
|
|
||||||
return mp_const_none;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct _pyb_file_obj_t {
|
typedef struct _pyb_file_obj_t {
|
||||||
mp_obj_base_t base;
|
mp_obj_base_t base;
|
||||||
FIL fp;
|
FIL fp;
|
||||||
|
@ -726,8 +648,10 @@ int main(void) {
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
// configure SDIO pins to be high to start with (apparently makes it more robust)
|
#if MICROPY_HW_HAS_SDCARD
|
||||||
{
|
{
|
||||||
|
// configure SDIO pins to be high to start with (apparently makes it more robust)
|
||||||
|
// FIXME this is not making them high, it just makes them outputs...
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
|
||||||
|
@ -740,17 +664,23 @@ int main(void) {
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// basic sub-system init
|
// basic sub-system init
|
||||||
sys_tick_init();
|
sys_tick_init();
|
||||||
led_init();
|
led_init();
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_RTC
|
||||||
rtc_init();
|
rtc_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
// turn on LED to indicate bootup
|
// turn on LED to indicate bootup
|
||||||
led_state(PYB_LED_G1, 1);
|
led_state(PYB_LED_G1, 1);
|
||||||
|
|
||||||
// more sub-system init
|
// more sub-system init
|
||||||
|
#if MICROPY_HW_HAS_SWITCH
|
||||||
switch_init();
|
switch_init();
|
||||||
|
#endif
|
||||||
storage_init();
|
storage_init();
|
||||||
|
|
||||||
// uncomment these 2 lines if you want REPL on USART_6 (or another usart) as well as on USB VCP
|
// uncomment these 2 lines if you want REPL on USART_6 (or another usart) as well as on USB VCP
|
||||||
|
@ -768,23 +698,31 @@ soft_reset:
|
||||||
qstr_init();
|
qstr_init();
|
||||||
rt_init();
|
rt_init();
|
||||||
|
|
||||||
|
#if MICROPY_HW_HAS_LCD
|
||||||
// LCD init (create in with LCD())
|
// LCD init (create in with LCD())
|
||||||
lcd_init();
|
lcd_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_SERVO
|
||||||
// servo
|
// servo
|
||||||
servo_init();
|
servo_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_AUDIO
|
||||||
// audio
|
// audio
|
||||||
//audio_init();
|
audio_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_TIMER
|
||||||
// timer
|
// timer
|
||||||
timer_init();
|
timer_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_RNG
|
||||||
// RNG
|
// RNG
|
||||||
if (1) {
|
|
||||||
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
|
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
|
||||||
RNG_Cmd(ENABLE);
|
RNG_Cmd(ENABLE);
|
||||||
}
|
#endif
|
||||||
|
|
||||||
// add some functions to the python namespace
|
// add some functions to the python namespace
|
||||||
{
|
{
|
||||||
|
@ -792,7 +730,9 @@ soft_reset:
|
||||||
|
|
||||||
mp_obj_t m = mp_obj_new_module(MP_QSTR_pyb);
|
mp_obj_t m = mp_obj_new_module(MP_QSTR_pyb);
|
||||||
rt_store_attr(m, MP_QSTR_info, rt_make_function_n(0, pyb_info));
|
rt_store_attr(m, MP_QSTR_info, rt_make_function_n(0, pyb_info));
|
||||||
|
#if MICROPY_HW_HAS_SDCARD
|
||||||
rt_store_attr(m, MP_QSTR_sd_test, rt_make_function_n(0, pyb_sd_test));
|
rt_store_attr(m, MP_QSTR_sd_test, rt_make_function_n(0, pyb_sd_test));
|
||||||
|
#endif
|
||||||
rt_store_attr(m, MP_QSTR_stop, rt_make_function_n(0, pyb_stop));
|
rt_store_attr(m, MP_QSTR_stop, rt_make_function_n(0, pyb_stop));
|
||||||
rt_store_attr(m, MP_QSTR_standby, rt_make_function_n(0, pyb_standby));
|
rt_store_attr(m, MP_QSTR_standby, rt_make_function_n(0, pyb_standby));
|
||||||
rt_store_attr(m, MP_QSTR_source_dir, rt_make_function_n(1, pyb_source_dir));
|
rt_store_attr(m, MP_QSTR_source_dir, rt_make_function_n(1, pyb_source_dir));
|
||||||
|
@ -800,8 +740,12 @@ soft_reset:
|
||||||
rt_store_attr(m, MP_QSTR_sync, rt_make_function_n(0, pyb_sync));
|
rt_store_attr(m, MP_QSTR_sync, rt_make_function_n(0, pyb_sync));
|
||||||
rt_store_attr(m, MP_QSTR_gc, rt_make_function_n(0, pyb_gc));
|
rt_store_attr(m, MP_QSTR_gc, rt_make_function_n(0, pyb_gc));
|
||||||
rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay));
|
rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay));
|
||||||
|
#if MICROPY_HW_HAS_SWITCH
|
||||||
rt_store_attr(m, MP_QSTR_switch, (mp_obj_t)&pyb_switch_obj);
|
rt_store_attr(m, MP_QSTR_switch, (mp_obj_t)&pyb_switch_obj);
|
||||||
|
#endif
|
||||||
|
#if MICROPY_HW_ENABLE_SERVO
|
||||||
rt_store_attr(m, MP_QSTR_servo, rt_make_function_n(2, pyb_servo_set));
|
rt_store_attr(m, MP_QSTR_servo, rt_make_function_n(2, pyb_servo_set));
|
||||||
|
#endif
|
||||||
rt_store_attr(m, MP_QSTR_pwm, rt_make_function_n(2, pyb_pwm_set));
|
rt_store_attr(m, MP_QSTR_pwm, rt_make_function_n(2, pyb_pwm_set));
|
||||||
#if MICROPY_HW_HAS_MMA7660
|
#if MICROPY_HW_HAS_MMA7660
|
||||||
rt_store_attr(m, MP_QSTR_accel, (mp_obj_t)&pyb_mma_read_obj);
|
rt_store_attr(m, MP_QSTR_accel, (mp_obj_t)&pyb_mma_read_obj);
|
||||||
|
@ -809,10 +753,16 @@ soft_reset:
|
||||||
rt_store_attr(m, MP_QSTR_mma_mode, (mp_obj_t)&pyb_mma_write_mode_obj);
|
rt_store_attr(m, MP_QSTR_mma_mode, (mp_obj_t)&pyb_mma_write_mode_obj);
|
||||||
#endif
|
#endif
|
||||||
rt_store_attr(m, MP_QSTR_hid, rt_make_function_n(1, pyb_hid_send_report));
|
rt_store_attr(m, MP_QSTR_hid, rt_make_function_n(1, pyb_hid_send_report));
|
||||||
|
#if MICROPY_HW_HAS_RTC
|
||||||
rt_store_attr(m, MP_QSTR_time, rt_make_function_n(0, pyb_rtc_read));
|
rt_store_attr(m, MP_QSTR_time, rt_make_function_n(0, pyb_rtc_read));
|
||||||
|
#endif
|
||||||
|
#if MICROPY_HW_ENABLE_RNG
|
||||||
rt_store_attr(m, MP_QSTR_rand, rt_make_function_n(0, pyb_rng_get));
|
rt_store_attr(m, MP_QSTR_rand, rt_make_function_n(0, pyb_rng_get));
|
||||||
|
#endif
|
||||||
rt_store_attr(m, MP_QSTR_Led, (mp_obj_t)&pyb_Led_obj);
|
rt_store_attr(m, MP_QSTR_Led, (mp_obj_t)&pyb_Led_obj);
|
||||||
|
#if MICROPY_HW_ENABLE_SERVO
|
||||||
rt_store_attr(m, MP_QSTR_Servo, rt_make_function_n(1, pyb_Servo));
|
rt_store_attr(m, MP_QSTR_Servo, rt_make_function_n(1, pyb_Servo));
|
||||||
|
#endif
|
||||||
rt_store_attr(m, MP_QSTR_I2C, rt_make_function_n(2, pyb_I2C));
|
rt_store_attr(m, MP_QSTR_I2C, rt_make_function_n(2, pyb_I2C));
|
||||||
rt_store_attr(m, MP_QSTR_gpio, (mp_obj_t)&pyb_gpio_obj);
|
rt_store_attr(m, MP_QSTR_gpio, (mp_obj_t)&pyb_gpio_obj);
|
||||||
rt_store_attr(m, MP_QSTR_Usart, rt_make_function_n(2, pyb_Usart));
|
rt_store_attr(m, MP_QSTR_Usart, rt_make_function_n(2, pyb_Usart));
|
||||||
|
@ -822,11 +772,14 @@ soft_reset:
|
||||||
rt_store_name(MP_QSTR_open, rt_make_function_n(2, pyb_io_open));
|
rt_store_name(MP_QSTR_open, rt_make_function_n(2, pyb_io_open));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MICROPY_HW_HAS_LCD
|
||||||
// print a message to the LCD
|
// print a message to the LCD
|
||||||
lcd_print_str(" micro py board\n");
|
lcd_print_str(" micro py board\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
// check if user switch held (initiates reset of filesystem)
|
// check if user switch held (initiates reset of filesystem)
|
||||||
bool reset_filesystem = false;
|
bool reset_filesystem = false;
|
||||||
|
#if MICROPY_HW_HAS_SWITCH
|
||||||
if (switch_get()) {
|
if (switch_get()) {
|
||||||
reset_filesystem = true;
|
reset_filesystem = true;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
|
@ -837,7 +790,7 @@ soft_reset:
|
||||||
sys_tick_delay_ms(10);
|
sys_tick_delay_ms(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
// local filesystem init
|
// local filesystem init
|
||||||
{
|
{
|
||||||
// try to mount the flash
|
// try to mount the flash
|
||||||
|
@ -965,11 +918,15 @@ soft_reset:
|
||||||
data[2] = -2;
|
data[2] = -2;
|
||||||
data[3] = 0;
|
data[3] = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
#if MICROPY_HW_HAS_SWITCH
|
||||||
if (switch_get()) {
|
if (switch_get()) {
|
||||||
data[0] = 0x01; // 0x04 is middle, 0x02 is right
|
data[0] = 0x01; // 0x04 is middle, 0x02 is right
|
||||||
} else {
|
} else {
|
||||||
data[0] = 0x00;
|
data[0] = 0x00;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
data[0] = 0x00;
|
||||||
|
#endif
|
||||||
mma_start(0x4c /* MMA_ADDR */, 1);
|
mma_start(0x4c /* MMA_ADDR */, 1);
|
||||||
mma_send_byte(0);
|
mma_send_byte(0);
|
||||||
mma_restart(0x4c /* MMA_ADDR */, 0);
|
mma_restart(0x4c /* MMA_ADDR */, 0);
|
||||||
|
@ -987,9 +944,11 @@ soft_reset:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_HAS_WLAN
|
||||||
// wifi
|
// wifi
|
||||||
//pyb_wlan_init();
|
pyb_wlan_init();
|
||||||
//pyb_wlan_start();
|
pyb_wlan_start();
|
||||||
|
#endif
|
||||||
|
|
||||||
do_repl();
|
do_repl();
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ machine_float_t machine_sqrt(machine_float_t x);
|
||||||
#define MICROPY_HW_HAS_SDCARD (1)
|
#define MICROPY_HW_HAS_SDCARD (1)
|
||||||
#define MICROPY_HW_HAS_MMA7660 (1)
|
#define MICROPY_HW_HAS_MMA7660 (1)
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (0)
|
#define MICROPY_HW_HAS_LIS3DSH (0)
|
||||||
|
#define MICROPY_HW_HAS_LCD (0)
|
||||||
|
#define MICROPY_HW_HAS_WLAN (0)
|
||||||
#define MICROPY_HW_ENABLE_RNG (1)
|
#define MICROPY_HW_ENABLE_RNG (1)
|
||||||
#define MICROPY_HW_ENABLE_RTC (1)
|
#define MICROPY_HW_ENABLE_RTC (1)
|
||||||
#define MICROPY_HW_ENABLE_TIMER (1)
|
#define MICROPY_HW_ENABLE_TIMER (1)
|
||||||
|
@ -51,6 +53,8 @@ machine_float_t machine_sqrt(machine_float_t x);
|
||||||
#define MICROPY_HW_HAS_SDCARD (1)
|
#define MICROPY_HW_HAS_SDCARD (1)
|
||||||
#define MICROPY_HW_HAS_MMA7660 (1)
|
#define MICROPY_HW_HAS_MMA7660 (1)
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (0)
|
#define MICROPY_HW_HAS_LIS3DSH (0)
|
||||||
|
#define MICROPY_HW_HAS_LCD (0)
|
||||||
|
#define MICROPY_HW_HAS_WLAN (0)
|
||||||
#define MICROPY_HW_ENABLE_RNG (1)
|
#define MICROPY_HW_ENABLE_RNG (1)
|
||||||
#define MICROPY_HW_ENABLE_RTC (1)
|
#define MICROPY_HW_ENABLE_RTC (1)
|
||||||
#define MICROPY_HW_ENABLE_TIMER (1)
|
#define MICROPY_HW_ENABLE_TIMER (1)
|
||||||
|
@ -70,6 +74,8 @@ machine_float_t machine_sqrt(machine_float_t x);
|
||||||
#define MICROPY_HW_HAS_SDCARD (0)
|
#define MICROPY_HW_HAS_SDCARD (0)
|
||||||
#define MICROPY_HW_HAS_MMA7660 (0)
|
#define MICROPY_HW_HAS_MMA7660 (0)
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (1)
|
#define MICROPY_HW_HAS_LIS3DSH (1)
|
||||||
|
#define MICROPY_HW_HAS_LCD (0)
|
||||||
|
#define MICROPY_HW_HAS_WLAN (0)
|
||||||
#define MICROPY_HW_ENABLE_RNG (1)
|
#define MICROPY_HW_ENABLE_RNG (1)
|
||||||
#define MICROPY_HW_ENABLE_RTC (1)
|
#define MICROPY_HW_ENABLE_RTC (1)
|
||||||
#define MICROPY_HW_ENABLE_TIMER (1)
|
#define MICROPY_HW_ENABLE_TIMER (1)
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stm32f4xx.h>
|
||||||
|
|
||||||
|
#include "misc.h"
|
||||||
|
#include "mpconfig.h"
|
||||||
|
#include "mpconfigport.h"
|
||||||
|
#include "qstr.h"
|
||||||
|
#include "obj.h"
|
||||||
|
#include "rtc.h"
|
||||||
|
|
||||||
|
void rtc_init(void) {
|
||||||
|
uint32_t rtc_clksrc;
|
||||||
|
uint32_t timeout = 1000000;
|
||||||
|
|
||||||
|
/* Enable the PWR clock */
|
||||||
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
|
||||||
|
|
||||||
|
/* Allow access to RTC */
|
||||||
|
PWR_BackupAccessCmd(ENABLE);
|
||||||
|
|
||||||
|
/* Enable the LSE OSC */
|
||||||
|
RCC_LSEConfig(RCC_LSE_ON);
|
||||||
|
|
||||||
|
/* Wait till LSE is ready */
|
||||||
|
while((RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) && (--timeout > 0)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If LSE timed out, use LSI instead */
|
||||||
|
if (timeout == 0) {
|
||||||
|
/* Enable the LSI OSC */
|
||||||
|
RCC_LSICmd(ENABLE);
|
||||||
|
|
||||||
|
/* Wait till LSI is ready */
|
||||||
|
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use LSI as the RTC Clock Source */
|
||||||
|
rtc_clksrc = RCC_RTCCLKSource_LSI;
|
||||||
|
} else {
|
||||||
|
/* Use LSE as the RTC Clock Source */
|
||||||
|
rtc_clksrc = RCC_RTCCLKSource_LSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Select the RTC Clock Source */
|
||||||
|
RCC_RTCCLKConfig(rtc_clksrc);
|
||||||
|
|
||||||
|
/* Note: LSI is around (32KHz), these dividers should work either way */
|
||||||
|
/* ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
|
||||||
|
uint32_t uwSynchPrediv = 0xFF;
|
||||||
|
uint32_t uwAsynchPrediv = 0x7F;
|
||||||
|
|
||||||
|
/* Enable the RTC Clock */
|
||||||
|
RCC_RTCCLKCmd(ENABLE);
|
||||||
|
|
||||||
|
/* Wait for RTC APB registers synchronisation */
|
||||||
|
RTC_WaitForSynchro();
|
||||||
|
|
||||||
|
/* Configure the RTC data register and RTC prescaler */
|
||||||
|
RTC_InitTypeDef RTC_InitStructure;
|
||||||
|
RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv;
|
||||||
|
RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv;
|
||||||
|
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
|
||||||
|
RTC_Init(&RTC_InitStructure);
|
||||||
|
|
||||||
|
// Set the date (BCD)
|
||||||
|
RTC_DateTypeDef RTC_DateStructure;
|
||||||
|
RTC_DateStructure.RTC_Year = 0x13;
|
||||||
|
RTC_DateStructure.RTC_Month = RTC_Month_October;
|
||||||
|
RTC_DateStructure.RTC_Date = 0x26;
|
||||||
|
RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Saturday;
|
||||||
|
RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);
|
||||||
|
|
||||||
|
// Set the time (BCD)
|
||||||
|
RTC_TimeTypeDef RTC_TimeStructure;
|
||||||
|
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
|
||||||
|
RTC_TimeStructure.RTC_Hours = 0x01;
|
||||||
|
RTC_TimeStructure.RTC_Minutes = 0x53;
|
||||||
|
RTC_TimeStructure.RTC_Seconds = 0x00;
|
||||||
|
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
|
||||||
|
|
||||||
|
// Indicator for the RTC configuration
|
||||||
|
//RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/* Micro Python bindings */
|
||||||
|
|
||||||
|
mp_obj_t pyb_rtc_read(void) {
|
||||||
|
RTC_TimeTypeDef RTC_TimeStructure;
|
||||||
|
RTC_GetTime(RTC_Format_BIN, &RTC_TimeStructure);
|
||||||
|
printf("%02d:%02d:%02d\n", RTC_TimeStructure.RTC_Hours, RTC_TimeStructure.RTC_Minutes, RTC_TimeStructure.RTC_Seconds);
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
Loading…
Reference in New Issue