-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: updated stlink library to develop
- Loading branch information
Showing
29 changed files
with
1,069 additions
and
1,048 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
#ifndef STLINK_BACKEND_H_ | ||
#define STLINK_BACKEND_H_ | ||
#ifndef BACKEND_H | ||
#define BACKEND_H | ||
|
||
#include <stdint.h> | ||
|
||
typedef struct _stlink_backend { | ||
void (*close) (stlink_t * sl); | ||
int (*exit_debug_mode) (stlink_t * sl); | ||
int (*enter_swd_mode) (stlink_t * sl); | ||
int (*enter_jtag_mode) (stlink_t * stl); | ||
int (*exit_dfu_mode) (stlink_t * stl); | ||
int (*core_id) (stlink_t * stl); | ||
int (*reset) (stlink_t * stl); | ||
int (*jtag_reset) (stlink_t * stl, int value); | ||
int (*run) (stlink_t * stl, enum run_type type); | ||
int (*status) (stlink_t * stl); | ||
int (*version) (stlink_t *sl); | ||
int (*read_debug32) (stlink_t *sl, uint32_t addr, uint32_t *data); | ||
int (*read_mem32) (stlink_t *sl, uint32_t addr, uint16_t len); | ||
int (*write_debug32) (stlink_t *sl, uint32_t addr, uint32_t data); | ||
int (*write_mem32) (stlink_t *sl, uint32_t addr, uint16_t len); | ||
int (*write_mem8) (stlink_t *sl, uint32_t addr, uint16_t len); | ||
int (*read_all_regs) (stlink_t *sl, struct stlink_reg * regp); | ||
int (*read_reg) (stlink_t *sl, int r_idx, struct stlink_reg * regp); | ||
int (*read_all_unsupported_regs) (stlink_t *sl, struct stlink_reg *regp); | ||
int (*read_unsupported_reg) (stlink_t *sl, int r_idx, struct stlink_reg *regp); | ||
int (*write_unsupported_reg) (stlink_t *sl, uint32_t value, int idx, struct stlink_reg *regp); | ||
int (*write_reg) (stlink_t *sl, uint32_t reg, int idx); | ||
int (*step) (stlink_t * stl); | ||
int (*current_mode) (stlink_t * stl); | ||
int (*force_debug) (stlink_t *sl); | ||
int32_t (*exit_debug_mode) (stlink_t * sl); | ||
int32_t (*enter_swd_mode) (stlink_t * sl); | ||
int32_t (*enter_jtag_mode) (stlink_t * stl); | ||
int32_t (*exit_dfu_mode) (stlink_t * stl); | ||
int32_t (*core_id) (stlink_t * stl); | ||
int32_t (*reset) (stlink_t * stl); | ||
int32_t (*jtag_reset) (stlink_t * stl, int32_t value); | ||
int32_t (*run) (stlink_t * stl, enum run_type type); | ||
int32_t (*status) (stlink_t * stl); | ||
int32_t (*version) (stlink_t *sl); | ||
int32_t (*read_debug32) (stlink_t *sl, uint32_t addr, uint32_t *data); | ||
int32_t (*read_mem32) (stlink_t *sl, uint32_t addr, uint16_t len); | ||
int32_t (*write_debug32) (stlink_t *sl, uint32_t addr, uint32_t data); | ||
int32_t (*write_mem32) (stlink_t *sl, uint32_t addr, uint16_t len); | ||
int32_t (*write_mem8) (stlink_t *sl, uint32_t addr, uint16_t len); | ||
int32_t (*read_all_regs) (stlink_t *sl, struct stlink_reg * regp); | ||
int32_t (*read_reg) (stlink_t *sl, int32_t r_idx, struct stlink_reg * regp); | ||
int32_t (*read_all_unsupported_regs) (stlink_t *sl, struct stlink_reg *regp); | ||
int32_t (*read_unsupported_reg) (stlink_t *sl, int32_t r_idx, struct stlink_reg *regp); | ||
int32_t (*write_unsupported_reg) (stlink_t *sl, uint32_t value, int32_t idx, struct stlink_reg *regp); | ||
int32_t (*write_reg) (stlink_t *sl, uint32_t reg, int32_t idx); | ||
int32_t (*step) (stlink_t * stl); | ||
int32_t (*current_mode) (stlink_t * stl); | ||
int32_t (*force_debug) (stlink_t *sl); | ||
int32_t (*target_voltage) (stlink_t *sl); | ||
int (*set_swdclk) (stlink_t * stl, int freq_khz); | ||
int (*trace_enable) (stlink_t * sl, uint32_t frequency); | ||
int (*trace_disable) (stlink_t * sl); | ||
int (*trace_read) (stlink_t * sl, uint8_t* buf, size_t size); | ||
int32_t (*set_swdclk) (stlink_t * stl, int32_t freq_khz); | ||
int32_t (*trace_enable) (stlink_t * sl, uint32_t frequency); | ||
int32_t (*trace_disable) (stlink_t * sl); | ||
int32_t (*trace_read) (stlink_t * sl, uint8_t* buf, uint32_t size); | ||
} stlink_backend_t; | ||
|
||
#endif // STLINK_BACKEND_H_ | ||
#endif // BACKEND_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* File: calculate.h | ||
* | ||
* Calculation of sector numbers and pages | ||
*/ | ||
|
||
#ifndef CALCULATE_H | ||
#define CALCULATE_H | ||
|
||
uint32_t calculate_F4_sectornum(uint32_t); | ||
uint32_t calculate_F7_sectornum(uint32_t); | ||
uint32_t calculate_H7_sectornum(stlink_t *, uint32_t, uint32_t); | ||
uint32_t calculate_L4_page(stlink_t *, uint32_t); | ||
|
||
#endif // CALCULATE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* File: common_flash.h | ||
* | ||
* Flash operations | ||
*/ | ||
|
||
#ifndef COMMON_FLASH_H | ||
#define COMMON_FLASH_H | ||
|
||
#define BANK_1 0 | ||
#define BANK_2 1 | ||
|
||
uint32_t get_stm32l0_flash_base(stlink_t *); | ||
uint32_t read_flash_cr(stlink_t *, uint32_t); | ||
void lock_flash(stlink_t *); | ||
// static inline int32_t write_flash_sr(stlink_t *sl, uint32_t bank, uint32_t val); | ||
void clear_flash_error(stlink_t *); | ||
uint32_t read_flash_sr(stlink_t *sl, uint32_t bank); | ||
uint32_t is_flash_busy(stlink_t *sl); | ||
void wait_flash_busy(stlink_t *); | ||
int32_t check_flash_error(stlink_t *); | ||
// static inline uint32_t is_flash_locked(stlink_t *sl); | ||
// static void unlock_flash(stlink_t *sl); | ||
int32_t unlock_flash_if(stlink_t *); | ||
int32_t lock_flash_option(stlink_t *); | ||
// static bool is_flash_option_locked(stlink_t *sl); | ||
// static int32_t unlock_flash_option(stlink_t *sl); | ||
int32_t unlock_flash_option_if(stlink_t *); | ||
void write_flash_cr_psiz(stlink_t *, uint32_t, uint32_t); | ||
void clear_flash_cr_pg(stlink_t *, uint32_t); | ||
// static void wait_flash_busy_progress(stlink_t *sl); | ||
// static inline void write_flash_ar(stlink_t *sl, uint32_t n, uint32_t bank); | ||
// static inline void write_flash_cr_snb(stlink_t *sl, uint32_t n, uint32_t bank); | ||
// static void set_flash_cr_per(stlink_t *sl, uint32_t bank); | ||
// static void clear_flash_cr_per(stlink_t *sl, uint32_t bank); | ||
// static inline void write_flash_cr_bker_pnb(stlink_t *sl, uint32_t n); | ||
// static void set_flash_cr_strt(stlink_t *sl, uint32_t bank); | ||
// static void set_flash_cr_mer(stlink_t *sl, bool v, uint32_t bank); | ||
int32_t stlink_erase_flash_page(stlink_t *sl, stm32_addr_t flashaddr); | ||
int32_t stlink_erase_flash_section(stlink_t *sl, stm32_addr_t base_addr, uint32_t size, bool align_size); | ||
int32_t stlink_erase_flash_mass(stlink_t *sl); | ||
int32_t stlink_mwrite_flash(stlink_t *sl, uint8_t *data, uint32_t length, stm32_addr_t addr); | ||
int32_t stlink_fwrite_flash(stlink_t *sl, const char *path, stm32_addr_t addr); | ||
int32_t stlink_fcheck_flash(stlink_t *sl, const char *path, stm32_addr_t addr); | ||
int32_t stlink_verify_write_flash(stlink_t *sl, stm32_addr_t address, uint8_t *data, uint32_t length); | ||
int32_t stlink_check_address_range_validity(stlink_t *sl, stm32_addr_t addr, uint32_t size); | ||
int32_t stlink_check_address_alignment(stlink_t *sl, stm32_addr_t addr); | ||
int32_t stlink_write_flash(stlink_t *sl, stm32_addr_t addr, uint8_t *base, uint32_t len, uint8_t eraseonly); | ||
void stlink_fwrite_finalize(stlink_t *, stm32_addr_t); | ||
|
||
#endif // COMMON_FLASH_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
/* | ||
* File: stlink.h | ||
* File: flash_loader.h | ||
* | ||
* This should contain all the common top level stlink interfaces, | ||
* regardless of how the backend does the work.... | ||
* Flash loaders | ||
*/ | ||
|
||
#ifndef STLINK_FLASH_LOADER_H_ | ||
#define STLINK_FLASH_LOADER_H_ | ||
#ifndef FLASH_LOADER_H | ||
#define FLASH_LOADER_H | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
int32_t stlink_flash_loader_init(stlink_t *sl, flash_loader_t* fl); | ||
// static int32_t loader_v_dependent_assignment(stlink_t *sl, | ||
// const uint8_t **loader_code, uint32_t *loader_size, | ||
// const uint8_t *high_v_loader, uint32_t high_v_loader_size, | ||
// const uint8_t *low_v_loader, uint32_t low_v_loader_size); | ||
int32_t stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, uint32_t* size); | ||
int32_t stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, const uint8_t* buf, uint32_t size); | ||
|
||
#include <stlink.h> | ||
|
||
int stlink_flash_loader_init(stlink_t *sl, flash_loader_t* fl); | ||
int stlink_flash_loader_write_to_sram(stlink_t *sl, stm32_addr_t* addr, size_t* size); | ||
int stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t target, const uint8_t* buf, size_t size); | ||
/* === Functions from old header file flashloader.h === */ | ||
|
||
#endif // STLINK_FLASH_LOADER_H_ | ||
int32_t stm32l1_write_half_pages(stlink_t *sl, stm32_addr_t addr, uint8_t *base, uint32_t len, uint32_t pagesize); | ||
// static void set_flash_cr_pg(stlink_t *sl, uint32_t bank); | ||
// static void set_dma_state(stlink_t *sl, flash_loader_t *fl, int32_t bckpRstr); | ||
int32_t stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl); | ||
int32_t stlink_flashloader_write(stlink_t *sl, flash_loader_t *fl, stm32_addr_t addr, uint8_t *base, uint32_t len); | ||
int32_t stlink_flashloader_stop(stlink_t *sl, flash_loader_t *fl); | ||
|
||
#endif // FLASH_LOADER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
#ifndef SYS_HELPER_H | ||
#define SYS_HELPER_H | ||
/* | ||
* File: helper.h | ||
* | ||
* General helper functions | ||
*/ | ||
|
||
unsigned time_ms(); | ||
#ifndef HELPER_H | ||
#define HELPER_H | ||
|
||
int arg_parse_freq(const char *str); | ||
uint32_t time_ms(); | ||
int32_t arg_parse_freq(const char *str); | ||
|
||
#endif /* SYS_HELPER_H */ | ||
#endif // HELPER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* WjCryptLib_Md5 (https://github.com/WaterJuice/WjCryptLib) | ||
* Implementation of MD5 hash function. Originally written by Alexander Peslyak. | ||
* Modified by WaterJuice retaining Public Domain license. | ||
* This is free and unencumbered software released into the public domain - June 2013 - waterjuice.org | ||
*/ | ||
|
||
#ifndef LIB_MD5_H | ||
#define LIB_MD5_H | ||
|
||
#pragma once | ||
|
||
/* TYPES */ | ||
|
||
/* Md5Context | ||
* This must be initialised using Md5Initialised. | ||
* Do not modify the contents of this structure directly. | ||
*/ | ||
typedef struct { | ||
uint32_t lo; | ||
uint32_t hi; | ||
uint32_t a; | ||
uint32_t b; | ||
uint32_t c; | ||
uint32_t d; | ||
uint8_t buffer[64]; | ||
uint32_t block[16]; | ||
} Md5Context; | ||
|
||
#define MD5_HASH_SIZE (128 / 8) | ||
|
||
typedef struct { | ||
uint8_t bytes [MD5_HASH_SIZE]; | ||
} MD5_HASH; | ||
|
||
/* PUBLIC FUNCTIONS */ | ||
|
||
/* Md5Initialise | ||
* Initialises an MD5 Context. | ||
* Use this to initialise/reset a context. | ||
*/ | ||
void Md5Initialise(Md5Context* Context /* [out] */); | ||
|
||
/* Md5Update | ||
* Adds data to the MD5 context. | ||
* This will process the data and update the internal state of the context. | ||
* Keep on calling this function until all the data has been added. | ||
* Then call Md5Finalise to calculate the hash. | ||
*/ | ||
void Md5Update(Md5Context* Context /* [in out] */, void const* Buffer /* [in] */, uint32_t BufferSize /* [in] */); | ||
|
||
/* Md5Finalise | ||
* Performs the final calculation of the hash and returns the digest | ||
* (16 byte buffer containing 128bit hash). | ||
* After calling this, Md5Initialised must be used to reuse the context. | ||
*/ | ||
void Md5Finalise(Md5Context* Context /* [in out] */, MD5_HASH* Digest /* [in] */); | ||
|
||
/* Md5Calculate | ||
* Combines Md5Initialise, Md5Update, and Md5Finalise into one function. | ||
* Calculates the MD5 hash of the buffer. | ||
*/ | ||
void Md5Calculate(void const* Buffer /* [in] */, uint32_t BufferSize /* [in] */, MD5_HASH* Digest /* [in] */); | ||
|
||
#endif // LIB_MD5_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.