| 1 |
/** dfu-programmer |
| 2 |
* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License as published by |
| 5 |
* the Free Software Foundation; either version 2 of the License, or |
| 6 |
* (at your option) any later version. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program; if not, write to the Free Software |
| 15 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 16 |
*/ |
| 17 |
|
| 18 |
#ifndef __STM32_H__ |
| 19 |
#define __STM32_H__ |
| 20 |
|
| 21 |
#include <stdio.h> |
| 22 |
#include <stdint.h> |
| 23 |
#include <stdbool.h> |
| 24 |
|
| 25 |
#ifdef __cplusplus |
| 26 |
extern "C" { |
| 27 |
#endif |
| 28 |
|
| 29 |
#include "dfu-device.h" |
| 30 |
#include "intel_hex.h" |
| 31 |
|
| 32 |
#define STM32_FLASH_OFFSET 0x08000000 |
| 33 |
|
| 34 |
typedef enum { |
| 35 |
mem_st_sector0 = 0, |
| 36 |
mem_st_sector1, |
| 37 |
mem_st_sector2, |
| 38 |
mem_st_sector3, |
| 39 |
mem_st_sector4, |
| 40 |
mem_st_sector5, |
| 41 |
mem_st_sector6, |
| 42 |
mem_st_sector7, |
| 43 |
mem_st_sector8, |
| 44 |
mem_st_sector9, |
| 45 |
mem_st_sector10, |
| 46 |
mem_st_sector11, |
| 47 |
mem_st_system, |
| 48 |
mem_st_otp_area, |
| 49 |
mem_st_option_bytes, |
| 50 |
mem_st_all, |
| 51 |
} stm32_mem_sectors; |
| 52 |
|
| 53 |
|
| 54 |
#define STM32_MEM_UNIT_NAMES "Sector 0", "Sector 1", "Sector 2", "Sector 3", \ |
| 55 |
"Sector 4", "Sector 5", "Sector 6", "Sector 7", "Sector 8", "Sector 9", \ |
| 56 |
"Sector 10", "Sector 11", "System Memory", "OTP Area", "Option Bytes", "all" |
| 57 |
|
| 58 |
#define STM32_READ_PROT_ERROR -10 |
| 59 |
|
| 60 |
|
| 61 |
int32_t stm32_erase_flash( dfu_device_t *device, bool quiet ); |
| 62 |
/* mass erase flash |
| 63 |
* device - the usb_dev_handle to communicate with |
| 64 |
* returns status DFU_STATUS_OK if ok, anything else on error |
| 65 |
*/ |
| 66 |
|
| 67 |
int32_t stm32_page_erase( dfu_device_t *device, uint32_t address, |
| 68 |
bool quiet ); |
| 69 |
/* erase a page of memory (provide the page address) */ |
| 70 |
|
| 71 |
int32_t stm32_start_app( dfu_device_t *device, bool quiet ); |
| 72 |
/* Reset the registers to default reset values and start application |
| 73 |
*/ |
| 74 |
|
| 75 |
int32_t stm32_read_flash( dfu_device_t *device, |
| 76 |
intel_buffer_in_t *buin, |
| 77 |
uint8_t mem_segment, |
| 78 |
const bool quiet); |
| 79 |
/* read the flash from buin->info.data_start to data_end and place |
| 80 |
* in buin.data. mem_segment is the segment of memory from the |
| 81 |
* stm32_memory_unit_enum. |
| 82 |
*/ |
| 83 |
|
| 84 |
int32_t stm32_write_flash( dfu_device_t *device, intel_buffer_out_t *bout, |
| 85 |
const bool eeprom, const bool force, const bool hide_progress ); |
| 86 |
/* Flash data from the buffer to the main program memory on the device. |
| 87 |
* buffer contains the data to flash where buffer[0] is aligned with memory |
| 88 |
* address zero (which could be inside the bootloader and unavailable). |
| 89 |
* buffer[start / end] correspond to the start / end of available memory |
| 90 |
* outside the bootloader. |
| 91 |
* flash_page_size is the size of flash pages - used for alignment |
| 92 |
* eeprom bool tells if you want to flash to eeprom or flash memory |
| 93 |
* hide_progress bool sets whether to display progress |
| 94 |
*/ |
| 95 |
|
| 96 |
int32_t stm32_get_commands( dfu_device_t *device ); |
| 97 |
/* @brief get the commands list, should be length 4 |
| 98 |
* @param device pointer |
| 99 |
* @return 0 on success |
| 100 |
*/ |
| 101 |
|
| 102 |
int32_t stm32_get_configuration( dfu_device_t *device ); |
| 103 |
/* @brief get the configuration structure |
| 104 |
* @param device pointer |
| 105 |
* @return 0 on success, negative for error |
| 106 |
*/ |
| 107 |
|
| 108 |
int32_t stm32_read_unprotect( dfu_device_t *device, bool quiet ); |
| 109 |
/* @brief unprotect the device (triggers a mass erase) |
| 110 |
* @param device pointer |
| 111 |
* @return 0 on success |
| 112 |
*/ |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
#if 0 |
| 117 |
int32_t stm32_read_config( dfu_device_t *device, |
| 118 |
stm32_device_info_t *info ); |
| 119 |
|
| 120 |
int32_t stm32_read_fuses( dfu_device_t *device, stm32_avr32_fuses_t * info ); |
| 121 |
|
| 122 |
int32_t stm32_set_fuse( dfu_device_t *device, const uint8_t property, |
| 123 |
const uint32_t value ); |
| 124 |
|
| 125 |
int32_t stm32_set_config( dfu_device_t *device, const uint8_t property, |
| 126 |
const uint8_t value ); |
| 127 |
|
| 128 |
int32_t stm32_blank_check( dfu_device_t *device, const uint32_t start, |
| 129 |
const uint32_t end, bool quiet ); |
| 130 |
|
| 131 |
int32_t stm32_secure( dfu_device_t *device ); |
| 132 |
|
| 133 |
int32_t stm32_getsecure( dfu_device_t *device ); |
| 134 |
|
| 135 |
int32_t stm32_user( dfu_device_t *device, intel_buffer_out_t *bout ); |
| 136 |
|
| 137 |
void stm32_print_device_info( FILE *stream, stm32_device_info_t *info ); |
| 138 |
#endif |
| 139 |
|
| 140 |
#ifdef __cplusplus |
| 141 |
} |
| 142 |
#endif |
| 143 |
|
| 144 |
#endif /* __STM32_H__ */ |
| 145 |
|
| 146 |
// cSpell:ignore shiftwidth |
| 147 |
// vim: shiftwidth=2 |