Narasimma DLN
/
NUCLEO_F091RC_IAP_UART
Sample IAP test code for Nucleo_F091RC
stm_iap.h@0:de2687a62a94, 2017-06-17 (annotated)
- Committer:
- narasimma23
- Date:
- Sat Jun 17 07:00:41 2017 +0000
- Revision:
- 0:de2687a62a94
Sample IAP test code for Nucleo_F091RC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
narasimma23 | 0:de2687a62a94 | 1 | /** |
narasimma23 | 0:de2687a62a94 | 2 | * Author: Narasimma DLN |
narasimma23 | 0:de2687a62a94 | 3 | * Email: narasimma23@gmail.com |
narasimma23 | 0:de2687a62a94 | 4 | */ |
narasimma23 | 0:de2687a62a94 | 5 | |
narasimma23 | 0:de2687a62a94 | 6 | #include "mbed.h" |
narasimma23 | 0:de2687a62a94 | 7 | |
narasimma23 | 0:de2687a62a94 | 8 | #define FLASH_START_ADDR 0x08000000 |
narasimma23 | 0:de2687a62a94 | 9 | #define FLASH_SIZE_ADDR 0x1FFFF7CC |
narasimma23 | 0:de2687a62a94 | 10 | #define FLASH_SIZE (256 * 1024) |
narasimma23 | 0:de2687a62a94 | 11 | #define FLASH_SECTOR_SIZE (2 * FLASH_PAGE_SIZE) |
narasimma23 | 0:de2687a62a94 | 12 | #define FLASH_SECTORS 64 |
narasimma23 | 0:de2687a62a94 | 13 | |
narasimma23 | 0:de2687a62a94 | 14 | /* |
narasimma23 | 0:de2687a62a94 | 15 | #define FLASH_SECTOR_0 0x08000000 |
narasimma23 | 0:de2687a62a94 | 16 | #define FLASH_SECTOR_1 0x08001000 |
narasimma23 | 0:de2687a62a94 | 17 | #define FLASH_SECTOR_2 0x08002000 |
narasimma23 | 0:de2687a62a94 | 18 | #define FLASH_SECTOR_3 0x08003000 |
narasimma23 | 0:de2687a62a94 | 19 | #define FLASH_SECTOR_4 0x08004000 |
narasimma23 | 0:de2687a62a94 | 20 | #define FLASH_SECTOR_5 0x08005000 |
narasimma23 | 0:de2687a62a94 | 21 | #define FLASH_SECTOR_6 0x08006000 |
narasimma23 | 0:de2687a62a94 | 22 | #define FLASH_SECTOR_7 0x08007000 |
narasimma23 | 0:de2687a62a94 | 23 | #define FLASH_SECTOR_8 0x08008000 |
narasimma23 | 0:de2687a62a94 | 24 | #define FLASH_SECTOR_9 0x08009000 |
narasimma23 | 0:de2687a62a94 | 25 | #define FLASH_SECTOR_10 0x0800A000 |
narasimma23 | 0:de2687a62a94 | 26 | #define FLASH_SECTOR_11 0x0800B000 |
narasimma23 | 0:de2687a62a94 | 27 | #define FLASH_SECTOR_12 0x0800C000 |
narasimma23 | 0:de2687a62a94 | 28 | #define FLASH_SECTOR_13 0x0800D000 |
narasimma23 | 0:de2687a62a94 | 29 | #define FLASH_SECTOR_14 0x0800E000 |
narasimma23 | 0:de2687a62a94 | 30 | #define FLASH_SECTOR_15 0x0800F000 |
narasimma23 | 0:de2687a62a94 | 31 | #define FLASH_SECTOR_16 0x08010000 |
narasimma23 | 0:de2687a62a94 | 32 | #define FLASH_SECTOR_17 0x08011000 |
narasimma23 | 0:de2687a62a94 | 33 | #define FLASH_SECTOR_18 0x08012000 |
narasimma23 | 0:de2687a62a94 | 34 | #define FLASH_SECTOR_19 0x08013000 |
narasimma23 | 0:de2687a62a94 | 35 | #define FLASH_SECTOR_20 0x08014000 |
narasimma23 | 0:de2687a62a94 | 36 | #define FLASH_SECTOR_21 0x08015000 |
narasimma23 | 0:de2687a62a94 | 37 | #define FLASH_SECTOR_22 0x08016000 |
narasimma23 | 0:de2687a62a94 | 38 | #define FLASH_SECTOR_23 0x08017000 |
narasimma23 | 0:de2687a62a94 | 39 | #define FLASH_SECTOR_24 0x08018000 |
narasimma23 | 0:de2687a62a94 | 40 | #define FLASH_SECTOR_25 0x08019000 |
narasimma23 | 0:de2687a62a94 | 41 | #define FLASH_SECTOR_26 0x0801A000 |
narasimma23 | 0:de2687a62a94 | 42 | #define FLASH_SECTOR_27 0x0801B000 |
narasimma23 | 0:de2687a62a94 | 43 | #define FLASH_SECTOR_28 0x0801C000 |
narasimma23 | 0:de2687a62a94 | 44 | #define FLASH_SECTOR_29 0x0801D000 |
narasimma23 | 0:de2687a62a94 | 45 | #define FLASH_SECTOR_30 0x0801E000 |
narasimma23 | 0:de2687a62a94 | 46 | #define FLASH_SECTOR_31 0x0801F000 |
narasimma23 | 0:de2687a62a94 | 47 | #define FLASH_SECTOR_32 0x08020000 |
narasimma23 | 0:de2687a62a94 | 48 | #define FLASH_SECTOR_33 0x08021000 |
narasimma23 | 0:de2687a62a94 | 49 | #define FLASH_SECTOR_34 0x08022000 |
narasimma23 | 0:de2687a62a94 | 50 | #define FLASH_SECTOR_35 0x08023000 |
narasimma23 | 0:de2687a62a94 | 51 | #define FLASH_SECTOR_36 0x08024000 |
narasimma23 | 0:de2687a62a94 | 52 | #define FLASH_SECTOR_37 0x08025000 |
narasimma23 | 0:de2687a62a94 | 53 | #define FLASH_SECTOR_38 0x08026000 |
narasimma23 | 0:de2687a62a94 | 54 | #define FLASH_SECTOR_39 0x08027000 |
narasimma23 | 0:de2687a62a94 | 55 | #define FLASH_SECTOR_40 0x08028000 |
narasimma23 | 0:de2687a62a94 | 56 | #define FLASH_SECTOR_41 0x08029000 |
narasimma23 | 0:de2687a62a94 | 57 | #define FLASH_SECTOR_42 0x0802A000 |
narasimma23 | 0:de2687a62a94 | 58 | #define FLASH_SECTOR_43 0x0802B000 |
narasimma23 | 0:de2687a62a94 | 59 | #define FLASH_SECTOR_44 0x0802C000 |
narasimma23 | 0:de2687a62a94 | 60 | #define FLASH_SECTOR_45 0x0802D000 |
narasimma23 | 0:de2687a62a94 | 61 | #define FLASH_SECTOR_46 0x0802E000 |
narasimma23 | 0:de2687a62a94 | 62 | #define FLASH_SECTOR_47 0x0802F000 |
narasimma23 | 0:de2687a62a94 | 63 | #define FLASH_SECTOR_48 0x08030000 |
narasimma23 | 0:de2687a62a94 | 64 | #define FLASH_SECTOR_49 0x08031000 |
narasimma23 | 0:de2687a62a94 | 65 | #define FLASH_SECTOR_50 0x08032000 |
narasimma23 | 0:de2687a62a94 | 66 | #define FLASH_SECTOR_51 0x08033000 |
narasimma23 | 0:de2687a62a94 | 67 | #define FLASH_SECTOR_52 0x08034000 |
narasimma23 | 0:de2687a62a94 | 68 | #define FLASH_SECTOR_53 0x08035000 |
narasimma23 | 0:de2687a62a94 | 69 | #define FLASH_SECTOR_54 0x08036000 |
narasimma23 | 0:de2687a62a94 | 70 | #define FLASH_SECTOR_55 0x08037000 |
narasimma23 | 0:de2687a62a94 | 71 | #define FLASH_SECTOR_56 0x08038000 |
narasimma23 | 0:de2687a62a94 | 72 | #define FLASH_SECTOR_57 0x08039000 |
narasimma23 | 0:de2687a62a94 | 73 | #define FLASH_SECTOR_58 0x0803A000 |
narasimma23 | 0:de2687a62a94 | 74 | #define FLASH_SECTOR_59 0x0803B000 |
narasimma23 | 0:de2687a62a94 | 75 | #define FLASH_SECTOR_60 0x0803C000 |
narasimma23 | 0:de2687a62a94 | 76 | #define FLASH_SECTOR_61 0x0803D000 |
narasimma23 | 0:de2687a62a94 | 77 | #define FLASH_SECTOR_62 0x0803E000 |
narasimma23 | 0:de2687a62a94 | 78 | #define FLASH_SECTOR_63 0x0803F000 |
narasimma23 | 0:de2687a62a94 | 79 | */ |
narasimma23 | 0:de2687a62a94 | 80 | |
narasimma23 | 0:de2687a62a94 | 81 | /* Return Code */ |
narasimma23 | 0:de2687a62a94 | 82 | typedef enum { |
narasimma23 | 0:de2687a62a94 | 83 | Success = 0, |
narasimma23 | 0:de2687a62a94 | 84 | WriteProtError, |
narasimma23 | 0:de2687a62a94 | 85 | ProgrammingError, |
narasimma23 | 0:de2687a62a94 | 86 | }IAPCode; |
narasimma23 | 0:de2687a62a94 | 87 | |
narasimma23 | 0:de2687a62a94 | 88 | // Get the flash sectors |
narasimma23 | 0:de2687a62a94 | 89 | void get_flash_sectors(void); |
narasimma23 | 0:de2687a62a94 | 90 | |
narasimma23 | 0:de2687a62a94 | 91 | // Get Flash Size |
narasimma23 | 0:de2687a62a94 | 92 | uint32_t get_flash_size(void); |
narasimma23 | 0:de2687a62a94 | 93 | |
narasimma23 | 0:de2687a62a94 | 94 | // Get Sector Number |
narasimma23 | 0:de2687a62a94 | 95 | uint8_t get_sector_number(uint32_t _addr); |
narasimma23 | 0:de2687a62a94 | 96 | |
narasimma23 | 0:de2687a62a94 | 97 | // Get Sector Size |
narasimma23 | 0:de2687a62a94 | 98 | uint32_t get_sector_size(uint32_t addr); |
narasimma23 | 0:de2687a62a94 | 99 | |
narasimma23 | 0:de2687a62a94 | 100 | // Erase a Flash Sector |
narasimma23 | 0:de2687a62a94 | 101 | IAPCode erase_sector(int address); |
narasimma23 | 0:de2687a62a94 | 102 | |
narasimma23 | 0:de2687a62a94 | 103 | // Programming Flash Memory |
narasimma23 | 0:de2687a62a94 | 104 | IAPCode program_flash(uint32_t address, uint16_t *data, unsigned int length); |