ch32f1: Further formatting and layout cleanup
This commit is contained in:
parent
fbc87cc518
commit
0368b76078
|
@ -107,20 +107,23 @@ static void ch32f1_add_flash(target *t, uint32_t addr, size_t length, size_t era
|
||||||
|
|
||||||
#define CLEAR_EOP() target_mem_write32(t, FLASH_SR,FLASH_SR_EOP)
|
#define CLEAR_EOP() target_mem_write32(t, FLASH_SR,FLASH_SR_EOP)
|
||||||
|
|
||||||
#define SET_CR(bit) { ct = target_mem_read32(t, FLASH_CR); \
|
#define SET_CR(bit) do { \
|
||||||
ct |= (bit); \
|
const uint32_t cr = target_mem_read32(t, FLASH_CR) | (bit); \
|
||||||
target_mem_write32(t, FLASH_CR, ct);}
|
target_mem_write32(t, FLASH_CR, cr); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#define CLEAR_CR(bit) do { \
|
||||||
#define CLEAR_CR(bit) {ct = target_mem_read32(t, FLASH_CR); \
|
const uint32_t cr = target_mem_read32(t, FLASH_CR) & (~(bit)); \
|
||||||
ct &= ~(bit); \
|
target_mem_write32(t, FLASH_CR, cr); \
|
||||||
target_mem_write32(t, FLASH_CR, ct);}
|
} while(0)
|
||||||
|
|
||||||
// Which one is the right value ?
|
// Which one is the right value ?
|
||||||
#define MAGIC_WORD 0x100
|
#define MAGIC_WORD 0x100
|
||||||
// #define MAGIC_WORD 0x1000
|
// #define MAGIC_WORD 0x1000
|
||||||
#define MAGIC(adr) { magic = target_mem_read32(t,(adr) ^ MAGIC_WORD); \
|
#define MAGIC(addr) do { \
|
||||||
target_mem_write32(t, FLASH_MAGIC , magic); }
|
magic = target_mem_read32(t, (addr) ^ MAGIC_WORD); \
|
||||||
|
target_mem_write32(t, FLASH_MAGIC , magic); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\fn ch32f1_flash_unlock
|
\fn ch32f1_flash_unlock
|
||||||
|
@ -145,7 +148,6 @@ static int ch32f1_flash_unlock(target *t)
|
||||||
|
|
||||||
static int ch32f1_flash_lock(target *t)
|
static int ch32f1_flash_lock(target *t)
|
||||||
{
|
{
|
||||||
volatile uint32_t ct;
|
|
||||||
DEBUG_INFO("CH32: flash lock \n");
|
DEBUG_INFO("CH32: flash lock \n");
|
||||||
SET_CR(FLASH_CR_LOCK);
|
SET_CR(FLASH_CR_LOCK);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -177,13 +179,14 @@ bool ch32f1_probe(target *t)
|
||||||
t->driver = "CH32F1 medium density (stm32f1 clone)";
|
t->driver = "CH32F1 medium density (stm32f1 clone)";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\fn ch32f1_flash_erase
|
\fn ch32f1_flash_erase
|
||||||
\brief fast erase of CH32
|
\brief fast erase of CH32
|
||||||
*/
|
*/
|
||||||
int ch32f1_flash_erase(struct target_flash *f, target_addr addr, size_t len)
|
int ch32f1_flash_erase(struct target_flash *f, target_addr addr, size_t len)
|
||||||
{
|
{
|
||||||
volatile uint32_t ct, sr, magic;
|
volatile uint32_t sr, magic;
|
||||||
target *t = f->t;
|
target *t = f->t;
|
||||||
DEBUG_INFO("CH32: flash erase \n");
|
DEBUG_INFO("CH32: flash erase \n");
|
||||||
|
|
||||||
|
@ -244,7 +247,7 @@ static bool ch32f1_wait_flash_ready(target *t, uint32_t addr)
|
||||||
|
|
||||||
static int ch32f1_upload(target *t, uint32_t dest, const void *src, uint32_t offset)
|
static int ch32f1_upload(target *t, uint32_t dest, const void *src, uint32_t offset)
|
||||||
{
|
{
|
||||||
volatile uint32_t ct, sr, magic;
|
volatile uint32_t sr, magic;
|
||||||
const uint32_t *ss = (const uint32_t *)(src+offset);
|
const uint32_t *ss = (const uint32_t *)(src+offset);
|
||||||
uint32_t dd = dest + offset;
|
uint32_t dd = dest + offset;
|
||||||
|
|
||||||
|
@ -266,7 +269,7 @@ static int ch32f1_upload(target *t, uint32_t dest, const void *src, uint32_t off
|
||||||
*/
|
*/
|
||||||
int ch32f1_buffer_clear(target *t)
|
int ch32f1_buffer_clear(target *t)
|
||||||
{
|
{
|
||||||
volatile uint32_t ct, sr;
|
volatile uint32_t sr;
|
||||||
SET_CR(FLASH_CR_FTPG_CH32); // Fast page program 4-
|
SET_CR(FLASH_CR_FTPG_CH32); // Fast page program 4-
|
||||||
SET_CR(FLASH_CR_BUF_RESET_CH32); // BUF_RESET 5-
|
SET_CR(FLASH_CR_BUF_RESET_CH32); // BUF_RESET 5-
|
||||||
WAIT_BUSY(); // 6-
|
WAIT_BUSY(); // 6-
|
||||||
|
@ -281,7 +284,7 @@ int ch32f1_buffer_clear(target *t)
|
||||||
static int ch32f1_flash_write(struct target_flash *f,
|
static int ch32f1_flash_write(struct target_flash *f,
|
||||||
target_addr dest, const void *src, size_t len)
|
target_addr dest, const void *src, size_t len)
|
||||||
{
|
{
|
||||||
volatile uint32_t ct, sr, magic;
|
volatile uint32_t sr, magic;
|
||||||
target *t = f->t;
|
target *t = f->t;
|
||||||
size_t length = len;
|
size_t length = len;
|
||||||
#ifdef CH32_VERIFY
|
#ifdef CH32_VERIFY
|
||||||
|
|
Loading…
Reference in New Issue