diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-05 22:27:11 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-05 22:27:11 +0000 |
commit | d52a0318ce266e1d9ce0d877f64a8fe097cef080 (patch) | |
tree | 9c57f2bd169754c56679b25dd41c003a046c1137 /stm | |
parent | 49fb6e53b35f991d79caadbb6320a39452944b4d (diff) | |
parent | 12e2656472bf53e467c066eda6f3e177a97210ca (diff) | |
download | micropython-d52a0318ce266e1d9ce0d877f64a8fe097cef080.tar.gz micropython-d52a0318ce266e1d9ce0d877f64a8fe097cef080.zip |
Merge remote-tracking branch 'upstream/master' into list_remove
Diffstat (limited to 'stm')
-rw-r--r-- | stm/Makefile | 4 | ||||
-rw-r--r-- | stm/fatfs/00readme.txt | 147 | ||||
-rw-r--r-- | stm/i2c.c | 1 | ||||
-rw-r--r-- | stm/led.c | 1 | ||||
-rw-r--r-- | stm/main.c | 69 | ||||
-rw-r--r-- | stm/servo.c | 1 | ||||
-rw-r--r-- | stm/stm32f405.ld | 2 | ||||
-rw-r--r-- | stm/storage.c | 17 | ||||
-rw-r--r-- | stm/usrsw.c | 69 | ||||
-rw-r--r-- | stm/usrsw.h | 4 |
10 files changed, 251 insertions, 64 deletions
diff --git a/stm/Makefile b/stm/Makefile index e84e21eae2..93e87ec4af 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 \ @@ -73,6 +74,7 @@ PY_O = \ objfun.o \ objgenerator.o \ objinstance.o \ + objint.o \ objlist.o \ objmodule.o \ objnone.o \ @@ -162,7 +164,7 @@ $(BUILD)/flash.elf: $(OBJ) arm-none-eabi-size $@ $(BUILD): - mkdir $@ + mkdir -p $@ $(BUILD)/%.o: %.s $(AS) -o $@ $< diff --git a/stm/fatfs/00readme.txt b/stm/fatfs/00readme.txt new file mode 100644 index 0000000000..bd0939ffab --- /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.
@@ -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 @@ -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 e8db2be2ca..2121742fd8 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" @@ -38,6 +39,7 @@ #include "audio.h" #include "pybwlan.h" #include "i2c.h" +#include "usrsw.h" int errno; @@ -72,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)); @@ -155,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); @@ -621,7 +569,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); @@ -745,6 +693,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 @@ -824,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 @@ -873,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); @@ -899,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; } @@ -1173,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/servo.c b/stm/servo.c index ae421048b9..1e31db5140 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 diff --git a/stm/stm32f405.ld b/stm/stm32f405.ld index 5dfa8c145d..c19e6a1c19 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 */ } diff --git a/stm/storage.c b/stm/storage.c index 6878de22e6..daee4adb5e 100644 --- a/stm/storage.c +++ b/stm/storage.c @@ -49,6 +49,18 @@ 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) { + // 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; +} + void storage_init(void) { if (!is_initialised) { cache_flash_sector_id = 0; @@ -131,8 +143,9 @@ 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; + // 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); return true; diff --git a/stm/usrsw.c b/stm/usrsw.c new file mode 100644 index 0000000000..385547843f --- /dev/null +++ b/stm/usrsw.c @@ -0,0 +1,69 @@ +#include <stm_misc.h> +#include <stm32f4xx_gpio.h> +#include <stm32f4xx_exti.h> +#include <stm32f4xx_syscfg.h> +#include <stm32f4xx_rcc.h> + +#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 switch_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 switch_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 */ + +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 new file mode 100644 index 0000000000..2da8f069ba --- /dev/null +++ b/stm/usrsw.h @@ -0,0 +1,4 @@ +void switch_init(void); +int switch_get(void); + +MP_DECLARE_CONST_FUN_OBJ(pyb_switch_obj); |