add AT32F425 porting

This commit is contained in:
XIVN1987
2022-12-06 23:20:07 +08:00
parent 8faf69a00c
commit 1ff993dfde
288 changed files with 67638 additions and 44 deletions
+90
View File
@@ -0,0 +1,90 @@
/**
* @file SWD_flash.c
* @brief Program target flash through SWD
*/
#include "swd_host.h"
#include "SWD_flash.h"
extern const program_target_t flash_algo;
error_t target_flash_init(uint32_t flash_start, uint32_t func)
{
if(func == 0)
{
if (0 == swd_set_target_state_hw(RESET_PROGRAM)) {
return ERROR_RESET;
}
// Download flash programming algorithm to target and initialise.
if (0 == swd_write_memory(flash_algo.algo_start, (uint8_t *)flash_algo.algo_blob, flash_algo.algo_size)) {
return ERROR_ALGO_DL;
}
}
else
{
if (0 != swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.init, flash_start, 0, func, 0)) {
return ERROR_INIT;
}
}
return ERROR_SUCCESS;
}
error_t target_flash_uninit(uint32_t func)
{
if (0 != swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.init, func, 0, 0, 0)) {
return ERROR_UNINIT;
}
return ERROR_SUCCESS;
}
error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size)
{
while (size > 0) {
uint32_t write_size = size > flash_algo.program_buffer_size ? flash_algo.program_buffer_size : size;
// Write page to buffer
if (!swd_write_memory(flash_algo.program_buffer, (uint8_t *)buf, write_size)) {
return ERROR_ALGO_DATA_SEQ;
}
// Run flash programming
if (swd_flash_syscall_exec(&flash_algo.sys_call_s,
flash_algo.program_page,
addr,
flash_algo.program_buffer_size,
flash_algo.program_buffer,
0)) {
return ERROR_WRITE;
}
addr += write_size;
buf += write_size;
size -= write_size;
}
return ERROR_SUCCESS;
}
error_t target_flash_erase_sector(uint32_t addr)
{
if (0 != swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_sector, addr, 0, 0, 0)) {
return ERROR_ERASE_SECTOR;
}
return ERROR_SUCCESS;
}
error_t target_flash_erase_chip(void)
{
error_t status = ERROR_SUCCESS;
if (0 != swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.erase_chip, 0, 0, 0, 0)) {
return ERROR_ERASE_ALL;
}
return status;
}
+38
View File
@@ -0,0 +1,38 @@
#ifndef __SWD_FLASH_H__
#define __SWD_FLASH_H__
#include <stdint.h>
typedef enum {
/* Shared errors */
ERROR_SUCCESS = 0,
ERROR_FAILURE,
ERROR_INTERNAL,
/* Target flash errors */
ERROR_RESET,
ERROR_ALGO_DL,
ERROR_ALGO_DATA_SEQ,
ERROR_INIT,
ERROR_UNINIT,
ERROR_SECURITY_BITS,
ERROR_UNLOCK,
ERROR_ERASE_SECTOR,
ERROR_ERASE_ALL,
ERROR_WRITE,
// Add new values here
ERROR_COUNT
} error_t;
error_t target_flash_init(uint32_t flash_start, uint32_t func);
error_t target_flash_uninit(uint32_t func);
error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size);
error_t target_flash_erase_sector(uint32_t addr);
error_t target_flash_erase_chip(void);
#endif // __SWD_FLASH_H__
File diff suppressed because it is too large Load Diff
+39
View File
@@ -0,0 +1,39 @@
#ifndef SWDHOST_CM_H
#define SWDHOST_CM_H
#include <stdint.h>
#include "flash_blob.h"
typedef enum {
RESET_HOLD, // Hold target in reset
RESET_PROGRAM, // Reset target and setup for flash programming.
RESET_RUN, // Reset target and run normally
NO_DEBUG, // Disable debug on running target
DEBUG, // Enable debug on running target
HALT, // Halt the target without resetting it
RUN // Resume the target without resetting it
} TARGET_RESET_STATE;
uint8_t swd_init(void);
uint8_t swd_off(void);
uint8_t swd_init_debug(void);
uint8_t swd_read_dp(uint8_t adr, uint32_t *val);
uint8_t swd_write_dp(uint8_t adr, uint32_t val);
uint8_t swd_read_ap(uint32_t adr, uint32_t *val);
uint8_t swd_write_ap(uint32_t adr, uint32_t val);
uint8_t swd_read_memory(uint32_t address, uint8_t *data, uint32_t size);
uint8_t swd_write_memory(uint32_t address, uint8_t *data, uint32_t size);
uint8_t swd_flash_syscall_exec(const program_syscall_t *sysCallParam, uint32_t entry, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
void swd_set_target_reset(uint8_t asserted);
uint8_t swd_set_target_state_hw(TARGET_RESET_STATE state);
uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state);
uint8_t swd_read_word(uint32_t addr, uint32_t *val);
uint8_t swd_write_word(uint32_t addr, uint32_t val);
#endif
+33
View File
@@ -0,0 +1,33 @@
#ifndef FLASH_BLOB_H
#define FLASH_BLOB_H
#include <stdint.h>
typedef struct {
uint32_t breakpoint;
uint32_t static_base;
uint32_t stack_pointer;
} program_syscall_t;
typedef struct {
const uint32_t init;
const uint32_t uninit;
const uint32_t erase_chip;
const uint32_t erase_sector;
const uint32_t program_page;
const program_syscall_t sys_call_s;
const uint32_t program_buffer;
const uint32_t algo_start;
const uint32_t algo_size;
const uint32_t *algo_blob;
const uint32_t program_buffer_size;
} program_target_t;
typedef struct {
const uint32_t start;
const uint32_t size;
} sector_info_t;
#endif