File tree Expand file tree Collapse file tree 3 files changed +74
-1
lines changed Expand file tree Collapse file tree 3 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ USB_SRCS=hw_config.c stm32_it.c usb_prop.c usb_desc.c usb_istr.c usb_pwr.c \
5454 usb_endp.c usb.c
5555
5656SRCS =main.c system_stm32f10x.c syscalls.c fsmc_nand.c led.c uart.c jtag.c \
57- clock.c cdc.c nand_programmer.c nand_bad_block.c $(USB_SRCS )
57+ clock.c cdc.c nand_programmer.c nand_bad_block.c flash.c $(USB_SRCS )
5858
5959OBJS =$(addprefix $(OBJ_DIR ) ,$(SRCS:.c=.o ) ) \
6060 $(addprefix $(OBJ_DIR ) ,$(STARTUP:.s=.o ) )
Original file line number Diff line number Diff line change 1+ /* Copyright (C) 2017 Bogdan Bogush <[email protected] > 2+ * This program is free software; you can redistribute it and/or modify
3+ * it under the terms of the GNU General Public License version 3.
4+ */
5+
6+ #include <stm32f10x.h>
7+
8+ int flash_page_erase (uint32_t page_addr )
9+ {
10+ FLASH_Status status ;
11+
12+ __disable_irq ();
13+ FLASH_Unlock ();
14+
15+ FLASH_ClearFlag (FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR |
16+ FLASH_FLAG_WRPRTERR );
17+
18+ status = FLASH_ErasePage (page_addr );
19+
20+ FLASH_Lock ();
21+ __enable_irq ();
22+
23+ return status != FLASH_COMPLETE ? -1 : 0 ;
24+ }
25+
26+ int flash_write (uint32_t addr , uint8_t * data , uint32_t data_len )
27+ {
28+ uint32_t word , count , i ;
29+ int ret = -1 ;
30+
31+ __disable_irq ();
32+ FLASH_Unlock ();
33+
34+ FLASH_ClearFlag (FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR |
35+ FLASH_FLAG_WRPRTERR );
36+
37+ count = data_len / 4 ;
38+ if (data_len % 4 )
39+ count ++ ;
40+ for (i = 0 ; i < count ; i ++ )
41+ {
42+ word = * ((uint32_t * )data + i );
43+ if (FLASH_ProgramWord (addr , word ) != FLASH_COMPLETE )
44+ goto Exit ;
45+
46+ addr += 4 ;
47+ }
48+
49+ ret = data_len ;
50+ Exit :
51+ FLASH_Lock ();
52+ __enable_irq ();
53+
54+ return ret ;
55+ }
56+
57+ int flash_read (uint32_t addr , uint8_t * data , uint32_t data_len )
58+ {
59+ uint32_t i ;
60+
61+ for (i = 0 ; i < data_len ; i ++ )
62+ data [i ] = * (uint8_t * ) (addr + i );
63+
64+ return i ;
65+ }
Original file line number Diff line number Diff line change 1+ /* Copyright (C) 2017 Bogdan Bogush <[email protected] > 2+ * This program is free software; you can redistribute it and/or modify
3+ * it under the terms of the GNU General Public License version 3.
4+ */
5+
6+ int flash_page_erase (uint32_t page_addr );
7+ int flash_write (uint32_t addr , uint8_t * data , uint32_t data_len );
8+ int flash_read (uint32_t addr , uint8_t * data , uint32_t data_len );
You can’t perform that action at this time.
0 commit comments