From 2c62e262b2c84b077355d67c6302bd02f6a28552 Mon Sep 17 00:00:00 2001 From: stevie67 Date: Sat, 4 Jan 2014 03:02:32 +0100 Subject: Fix issue #62: Cache loses data Use the storage cache not only for writing but also for reading. This avoids reading stale data and thus data loss. --- stm/storage.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'stm') diff --git a/stm/storage.c b/stm/storage.c index 6878de22e..7342a53ac 100644 --- a/stm/storage.c +++ b/stm/storage.c @@ -49,6 +49,16 @@ static uint8_t *cache_get_addr_for_write(uint32_t flash_addr) { return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start; } +static uint8_t *cache_get_addr_for_read(uint32_t flash_addr) { + uint32_t flash_sector_start; + uint32_t flash_sector_size; + uint32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size); + if (cache_flash_sector_id == flash_sector_id) + return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start; + // not in cache, copy straight from flash + return (uint8_t*)flash_addr; +} + void storage_init(void) { if (!is_initialised) { cache_flash_sector_id = 0; @@ -131,8 +141,8 @@ bool storage_read_block(uint8_t *dest, uint32_t block) { return true; } else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) { - // non-MBR block, just copy straight from flash - uint8_t *src = (uint8_t*)FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE; + uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE; + uint8_t *src = cache_get_addr_for_read(flash_addr); memcpy(dest, src, BLOCK_SIZE); return true; -- cgit v1.2.3 From 2a5e6538b941d1fc9c1c0ef0bb0827b5ed2425d2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 4 Jan 2014 12:34:36 +0000 Subject: stm: Add comments for storage read from cache. --- stm/storage.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'stm') diff --git a/stm/storage.c b/stm/storage.c index 7342a53ac..daee4adb5 100644 --- a/stm/storage.c +++ b/stm/storage.c @@ -53,8 +53,10 @@ static uint8_t *cache_get_addr_for_read(uint32_t flash_addr) { uint32_t flash_sector_start; uint32_t flash_sector_size; uint32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size); - if (cache_flash_sector_id == flash_sector_id) + if (cache_flash_sector_id == flash_sector_id) { + // in cache, copy from there return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start; + } // not in cache, copy straight from flash return (uint8_t*)flash_addr; } @@ -141,6 +143,7 @@ bool storage_read_block(uint8_t *dest, uint32_t block) { return true; } else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) { + // non-MBR block, get data from flash memory, possibly via cache uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE; uint8_t *src = cache_get_addr_for_read(flash_addr); memcpy(dest, src, BLOCK_SIZE); -- cgit v1.2.3 From eb7bfcb28697f6fb2d4d933bc39233aa15423a20 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 4 Jan 2014 15:57:35 +0000 Subject: Split qstr into pools, and put initial pool in ROM. Qstr's are now split into a linked-list of qstr pools. This has 2 benefits: the first pool can be in ROM (huge benefit, since we no longer use RAM for the core qstrs), and subsequent pools use m_new for the next pool instead of m_renew (thus avoiding a huge single table for all the qstrs). Still would be better to use a hash table, but this scheme takes us part of the way (eventually convert the pools to hash tables). Also fixed bug with import. Also improved the way the module code is referenced (not magic number 1 anymore). --- stm/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'stm') diff --git a/stm/main.c b/stm/main.c index e8db2be2c..b7ae8aacc 100644 --- a/stm/main.c +++ b/stm/main.c @@ -15,6 +15,7 @@ #include "misc.h" #include "ff.h" #include "mpconfig.h" +#include "mpqstr.h" #include "nlr.h" #include "misc.h" #include "lexer.h" @@ -621,7 +622,7 @@ mp_obj_t pyb_gpio(int n_args, mp_obj_t *args) { } pin_error: - nlr_jump(mp_obj_new_exception_msg_1_arg(rt_q_ValueError, "pin %s does not exist", pin_name)); + nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_ValueError, "pin %s does not exist", pin_name)); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pyb_gpio_obj, 1, 2, pyb_gpio); -- cgit v1.2.3 From 5830fae26f7dfeb7a263ba5e1b024694930c64ff Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 4 Jan 2014 18:55:44 +0200 Subject: Don't error out if build/ directory already exists. --- stm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stm') diff --git a/stm/Makefile b/stm/Makefile index e84e21eae..729913bae 100644 --- a/stm/Makefile +++ b/stm/Makefile @@ -162,7 +162,7 @@ $(BUILD)/flash.elf: $(OBJ) arm-none-eabi-size $@ $(BUILD): - mkdir $@ + mkdir -p $@ $(BUILD)/%.o: %.s $(AS) -o $@ $< -- cgit v1.2.3 From 71c5181a8dfa69ba9f5ca322a3aba0660be2e166 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 4 Jan 2014 20:21:15 +0000 Subject: Convert Python types to proper Python type hierarchy. Now much more inline with how CPython does types. --- stm/Makefile | 1 + stm/i2c.c | 1 + stm/led.c | 1 + stm/main.c | 1 + stm/servo.c | 1 + 5 files changed, 5 insertions(+) (limited to 'stm') diff --git a/stm/Makefile b/stm/Makefile index 729913bae..d75c945bf 100644 --- a/stm/Makefile +++ b/stm/Makefile @@ -73,6 +73,7 @@ PY_O = \ objfun.o \ objgenerator.o \ objinstance.o \ + objint.o \ objlist.o \ objmodule.o \ objnone.o \ diff --git a/stm/i2c.c b/stm/i2c.c index e00cf4130..3f29f02c0 100644 --- a/stm/i2c.c +++ b/stm/i2c.c @@ -330,6 +330,7 @@ static const mp_obj_type_t i2c_obj_type = { { &mp_const_type }, "I2C", i2c_obj_print, // print + NULL, // make_new NULL, // call_n NULL, // unary_op NULL, // binary_op diff --git a/stm/led.c b/stm/led.c index 08077641a..9305716be 100644 --- a/stm/led.c +++ b/stm/led.c @@ -108,6 +108,7 @@ static const mp_obj_type_t led_obj_type = { { &mp_const_type }, "Led", led_obj_print, // print + NULL, // make_new NULL, // call_n NULL, // unary_op NULL, // binary_op diff --git a/stm/main.c b/stm/main.c index b7ae8aacc..0ab44ca8d 100644 --- a/stm/main.c +++ b/stm/main.c @@ -746,6 +746,7 @@ static const mp_obj_type_t file_obj_type = { { &mp_const_type }, "File", file_obj_print, // print + NULL, // make_new NULL, // call_n NULL, // unary_op NULL, // binary_op diff --git a/stm/servo.c b/stm/servo.c index ae421048b..1e31db514 100644 --- a/stm/servo.c +++ b/stm/servo.c @@ -141,6 +141,7 @@ static const mp_obj_type_t servo_obj_type = { { &mp_const_type }, "Servo", servo_obj_print, // print + NULL, // make_new NULL, // call_n NULL, // unary_op NULL, // binary_op -- cgit v1.2.3 From 1dd657fa87cdfe93ddc30df014a385c801d8dacf Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 5 Jan 2014 11:57:17 +0000 Subject: Add fatfs readme/license. --- stm/fatfs/00readme.txt | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 stm/fatfs/00readme.txt (limited to 'stm') diff --git a/stm/fatfs/00readme.txt b/stm/fatfs/00readme.txt new file mode 100644 index 000000000..bd0939ffa --- /dev/null +++ b/stm/fatfs/00readme.txt @@ -0,0 +1,147 @@ +FatFs Module Source Files R0.10 (C)ChaN, 2013 + + +FILES + + ffconf.h Configuration file for FatFs module. + ff.h Common include file for FatFs and application module. + ff.c FatFs module. + diskio.h Common include file for FatFs and disk I/O module. + diskio.c An example of glue function to attach existing disk I/O module to FatFs. + integer.h Integer type definitions for FatFs. + option Optional external functions. + + Low level disk I/O module is not included in this archive because the FatFs + module is only a generic file system layer and not depend on any specific + storage device. You have to provide a low level disk I/O module that written + to control your storage device. + + + +AGREEMENTS + + FatFs module is an open source software to implement FAT file system to + small embedded systems. This is a free software and is opened for education, + research and commercial developments under license policy of following trems. + + Copyright (C) 2013, ChaN, all right reserved. + + * The FatFs module is a free software and there is NO WARRANTY. + * No restriction on use. You can use, modify and redistribute it for + personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY. + * Redistributions of source code must retain the above copyright notice. + + + +REVISION HISTORY + + Feb 26, 2006 R0.00 Prototype + + Apr 29, 2006 R0.01 First release. + + Jun 01, 2006 R0.02 Added FAT12. + Removed unbuffered mode. + Fixed a problem on small (<32M) patition. + + Jun 10, 2006 R0.02a Added a configuration option _FS_MINIMUM. + + Sep 22, 2006 R0.03 Added f_rename. + Changed option _FS_MINIMUM to _FS_MINIMIZE. + + Dec 11, 2006 R0.03a Improved cluster scan algolithm to write files fast. + Fixed f_mkdir creates incorrect directory on FAT32. + + Feb 04, 2007 R0.04 Supported multiple drive system. (FatFs) + Changed some APIs for multiple drive system. + Added f_mkfs. (FatFs) + Added _USE_FAT32 option. (Tiny-FatFs) + + Apr 01, 2007 R0.04a Supported multiple partitions on a plysical drive. (FatFs) + Fixed an endian sensitive code in f_mkfs. (FatFs) + Added a capability of extending the file size to f_lseek. + Added minimization level 3. + Fixed a problem that can collapse a sector when recreate an + existing file in any sub-directory at non FAT32 cfg. (Tiny-FatFs) + + May 05, 2007 R0.04b Added _USE_NTFLAG option. + Added FSInfo support. + Fixed some problems corresponds to FAT32. (Tiny-FatFs) + Fixed DBCS name can result FR_INVALID_NAME. + Fixed short seek (0 < ofs <= csize) collapses the file object. + + Aug 25, 2007 R0.05 Changed arguments of f_read, f_write. + Changed arguments of f_mkfs. (FatFs) + Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs) + Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs) + + Feb 03, 2008 R0.05a Added f_truncate(). + Added f_utime(). + Fixed off by one error at FAT sub-type determination. + Fixed btr in f_read() can be mistruncated. + Fixed cached sector is not flushed when create and close without write. + + Apr 01, 2008 R0.06 Added f_forward(). (Tiny-FatFs) + Added string functions: fputc(), fputs(), fprintf() and fgets(). + Improved performance of f_lseek() on move to the same or following cluster. + + Apr 01, 2009, R0.07 Merged Tiny-FatFs as a buffer configuration option. + Added long file name support. + Added multiple code page support. + Added re-entrancy for multitask operation. + Added auto cluster size selection to f_mkfs(). + Added rewind option to f_readdir(). + Changed result code of critical errors. + Renamed string functions to avoid name collision. + + Apr 14, 2009, R0.07a Separated out OS dependent code on reentrant cfg. + Added multiple sector size support. + + Jun 21, 2009, R0.07c Fixed f_unlink() may return FR_OK on error. + Fixed wrong cache control in f_lseek(). + Added relative path feature. + Added f_chdir(). + Added f_chdrive(). + Added proper case conversion for extended characters. + + Nov 03, 2009 R0.07e Separated out configuration options from ff.h to ffconf.h. + Added a configuration option, _LFN_UNICODE. + Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH. + Fixed name matching error on the 13 char boundary. + Changed f_readdir() to return the SFN with always upper case on non-LFN cfg. + + May 15, 2010, R0.08 Added a memory configuration option. (_USE_LFN) + Added file lock feature. (_FS_SHARE) + Added fast seek feature. (_USE_FASTSEEK) + Changed some types on the API, XCHAR->TCHAR. + Changed fname member in the FILINFO structure on Unicode cfg. + String functions support UTF-8 encoding files on Unicode cfg. + + Aug 16,'10 R0.08a Added f_getcwd(). (_FS_RPATH = 2) + Added sector erase feature. (_USE_ERASE) + Moved file lock semaphore table from fs object to the bss. + Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'. + Fixed f_mkfs() creates wrong FAT32 volume. + + Jan 15,'11 R0.08b Fast seek feature is also applied to f_read() and f_write(). + f_lseek() reports required table size on creating CLMP. + Extended format syntax of f_printf function. + Ignores duplicated directory separators in given path names. + + Sep 06,'11 R0.09 f_mkfs() supports multiple partition to finish the multiple partition feature. + Added f_fdisk(). (_MULTI_PARTITION = 2) + + Aug 27,'12 R0.09a Fixed assertion failure due to OS/2 EA on FAT12/16. + Changed f_open() and f_opendir() reject null object pointer to avoid crash. + Changed option name _FS_SHARE to _FS_LOCK. + + Jan 23,'13 R0.09b Added f_getlabel() and f_setlabel(). (_USE_LABEL == 1) + + Oct 02,'13 R0.10 Added selection of character encoding on the file. (_STRF_ENCODE) + Added f_closedir(). + Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO) + Added forced mount feature with changes of f_mount(). + Improved behavior of volume auto detection. + Improved write throughput of f_puts() and f_printf(). + Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write(). + Fixed f_write() can be truncated when the file size is close to 4GB. + Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code. -- cgit v1.2.3 From de7fcc0c065c6854e02e0146165be0940fd30510 Mon Sep 17 00:00:00 2001 From: mux Date: Sun, 5 Jan 2014 14:52:37 +0200 Subject: Move user switch code into a separate module * Move user switch code from main.c into a separate module (usrsw) * Add usrsw.c to Makefile --- stm/Makefile | 1 + stm/main.c | 55 +----------------------------------------------- stm/usrsw.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ stm/usrsw.h | 7 ++++++ 4 files changed, 78 insertions(+), 54 deletions(-) create mode 100644 stm/usrsw.c create mode 100644 stm/usrsw.h (limited to 'stm') diff --git a/stm/Makefile b/stm/Makefile index d75c945bf..93e87ec4a 100644 --- a/stm/Makefile +++ b/stm/Makefile @@ -36,6 +36,7 @@ SRC_C = \ sdio.c \ pybwlan.c \ i2c.c \ + usrsw.c \ SRC_S = \ startup_stm32f40xx.s \ diff --git a/stm/main.c b/stm/main.c index 0ab44ca8d..f6aa42abf 100644 --- a/stm/main.c +++ b/stm/main.c @@ -39,6 +39,7 @@ #include "audio.h" #include "pybwlan.h" #include "i2c.h" +#include "usrsw.h" int errno; @@ -73,52 +74,6 @@ static void impl02_c_version(void) { } } -#define PYB_USRSW_PORT (GPIOA) -#define PYB_USRSW_PIN (GPIO_Pin_13) - -void sw_init(void) { - // make it an input with pull-up - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = PYB_USRSW_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; - GPIO_Init(PYB_USRSW_PORT, &GPIO_InitStructure); - - // the rest does the EXTI interrupt - - /* Enable SYSCFG clock */ - RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); - - /* Connect EXTI Line13 to PA13 pin */ - SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource13); - - /* Configure EXTI Line13, rising edge */ - EXTI_InitTypeDef EXTI_InitStructure; - EXTI_InitStructure.EXTI_Line = EXTI_Line13; - EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; - EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; - EXTI_InitStructure.EXTI_LineCmd = ENABLE; - EXTI_Init(&EXTI_InitStructure); - - /* Enable and set EXTI15_10 Interrupt to the lowest priority */ - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); -} - -int sw_get(void) { - if (PYB_USRSW_PORT->IDR & PYB_USRSW_PIN) { - // pulled high, so switch is not pressed - return 0; - } else { - // pulled low, so switch is pressed - return 1; - } -} - void __fatal_error(const char *msg) { lcd_print_strn("\nFATAL ERROR:\n", 14); lcd_print_strn(msg, strlen(msg)); @@ -156,14 +111,6 @@ mp_obj_t pyb_led(mp_obj_t state) { return state; } -mp_obj_t pyb_sw(void) { - if (sw_get()) { - return mp_const_true; - } else { - return mp_const_false; - } -} - /* void g(uint i) { printf("g:%d\n", i); diff --git a/stm/usrsw.c b/stm/usrsw.c new file mode 100644 index 000000000..e2565d0e0 --- /dev/null +++ b/stm/usrsw.c @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include + +#include "misc.h" +#include "mpconfig.h" +#include "obj.h" +#include "usrsw.h" + +#define PYB_USRSW_PORT (GPIOA) +#define PYB_USRSW_PIN (GPIO_Pin_13) + +void sw_init(void) { + // make it an input with pull-up + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Pin = PYB_USRSW_PIN; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; + GPIO_Init(PYB_USRSW_PORT, &GPIO_InitStructure); + + // the rest does the EXTI interrupt + + /* Enable SYSCFG clock */ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); + + /* Connect EXTI Line13 to PA13 pin */ + SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource13); + + /* Configure EXTI Line13, rising edge */ + EXTI_InitTypeDef EXTI_InitStructure; + EXTI_InitStructure.EXTI_Line = EXTI_Line13; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_Init(&EXTI_InitStructure); + + /* Enable and set EXTI15_10 Interrupt to the lowest priority */ + NVIC_InitTypeDef NVIC_InitStructure; + NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); +} + +int sw_get(void) { + if (PYB_USRSW_PORT->IDR & PYB_USRSW_PIN) { + // pulled high, so switch is not pressed + return 0; + } else { + // pulled low, so switch is pressed + return 1; + } +} + +/******************************************************************************/ +/* Micro Python bindings */ + +mp_obj_t pyb_sw(void) { + if (sw_get()) { + return mp_const_true; + } else { + return mp_const_false; + } +} + + diff --git a/stm/usrsw.h b/stm/usrsw.h new file mode 100644 index 000000000..2833baaac --- /dev/null +++ b/stm/usrsw.h @@ -0,0 +1,7 @@ +#ifndef __USRSW_H__ +#define __USRSW_H__ +void sw_init(void); +int sw_get(void); + +mp_obj_t pyb_sw(void); +#endif //__USRSW_H__ -- cgit v1.2.3 From 823877bce03b5d3848a0d1a7302260dc95e7a9cd Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 5 Jan 2014 14:04:55 +0000 Subject: stm: rename sw_xx to switch_xx; change Python bindings to new version. --- stm/main.c | 10 +++++----- stm/usrsw.c | 10 +++++----- stm/usrsw.h | 9 +++------ 3 files changed, 13 insertions(+), 16 deletions(-) (limited to 'stm') diff --git a/stm/main.c b/stm/main.c index f6aa42abf..2121742fd 100644 --- a/stm/main.c +++ b/stm/main.c @@ -773,7 +773,7 @@ int main(void) { led_state(PYB_LED_G1, 1); // more sub-system init - sw_init(); + switch_init(); storage_init(); //usart_init(); disabled while wi-fi is enabled @@ -822,7 +822,7 @@ soft_reset: rt_store_attr(m, qstr_from_str_static("gc"), rt_make_function_0(pyb_gc)); rt_store_attr(m, qstr_from_str_static("delay"), rt_make_function_1(pyb_delay)); rt_store_attr(m, qstr_from_str_static("led"), rt_make_function_1(pyb_led)); - rt_store_attr(m, qstr_from_str_static("switch"), rt_make_function_0(pyb_sw)); + rt_store_attr(m, qstr_from_str_static("switch"), (mp_obj_t)&pyb_switch_obj); rt_store_attr(m, qstr_from_str_static("servo"), rt_make_function_2(pyb_servo_set)); rt_store_attr(m, qstr_from_str_static("pwm"), rt_make_function_2(pyb_pwm_set)); rt_store_attr(m, qstr_from_str_static("accel"), (mp_obj_t)&pyb_mma_read_obj); @@ -848,10 +848,10 @@ soft_reset: // check if user switch held (initiates reset of filesystem) bool reset_filesystem = false; - if (sw_get()) { + if (switch_get()) { reset_filesystem = true; for (int i = 0; i < 50; i++) { - if (!sw_get()) { + if (!switch_get()) { reset_filesystem = false; break; } @@ -1122,7 +1122,7 @@ soft_reset: data[2] = -2; data[3] = 0; for (;;) { - if (sw_get()) { + if (switch_get()) { data[0] = 0x01; // 0x04 is middle, 0x02 is right } else { data[0] = 0x00; diff --git a/stm/usrsw.c b/stm/usrsw.c index e2565d0e0..385547843 100644 --- a/stm/usrsw.c +++ b/stm/usrsw.c @@ -12,7 +12,7 @@ #define PYB_USRSW_PORT (GPIOA) #define PYB_USRSW_PIN (GPIO_Pin_13) -void sw_init(void) { +void switch_init(void) { // make it an input with pull-up GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = PYB_USRSW_PIN; @@ -45,7 +45,7 @@ void sw_init(void) { NVIC_Init(&NVIC_InitStructure); } -int sw_get(void) { +int switch_get(void) { if (PYB_USRSW_PORT->IDR & PYB_USRSW_PIN) { // pulled high, so switch is not pressed return 0; @@ -58,12 +58,12 @@ int sw_get(void) { /******************************************************************************/ /* Micro Python bindings */ -mp_obj_t pyb_sw(void) { - if (sw_get()) { +static mp_obj_t pyb_switch(void) { + if (switch_get()) { return mp_const_true; } else { return mp_const_false; } } - +MP_DEFINE_CONST_FUN_OBJ_0(pyb_switch_obj, pyb_switch); diff --git a/stm/usrsw.h b/stm/usrsw.h index 2833baaac..2da8f069b 100644 --- a/stm/usrsw.h +++ b/stm/usrsw.h @@ -1,7 +1,4 @@ -#ifndef __USRSW_H__ -#define __USRSW_H__ -void sw_init(void); -int sw_get(void); +void switch_init(void); +int switch_get(void); -mp_obj_t pyb_sw(void); -#endif //__USRSW_H__ +MP_DECLARE_CONST_FUN_OBJ(pyb_switch_obj); -- cgit v1.2.3 From 12e2656472bf53e467c066eda6f3e177a97210ca Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 5 Jan 2014 14:34:17 +0000 Subject: stm: allow more flash for the binary. --- stm/stm32f405.ld | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stm') diff --git a/stm/stm32f405.ld b/stm/stm32f405.ld index 5dfa8c145..c19e6a1c1 100644 --- a/stm/stm32f405.ld +++ b/stm/stm32f405.ld @@ -7,7 +7,7 @@ MEMORY { FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 0x100000 /* entire flash, 1 MiB */ FLASH_ISR (rx) : ORIGIN = 0x08000000, LENGTH = 0x004000 /* sector 0, 16 KiB */ - FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x020000 /* sector 5, 128 KiB */ + FLASH_TEXT (rx) : ORIGIN = 0x08020000, LENGTH = 0x080000 /* sectors 5,6,7,8, 4*128KiB = 512 KiB (could increase it more) */ CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 0x010000 /* 64 KiB */ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0x020000 /* 128 KiB */ } -- cgit v1.2.3