int stlink2_write_word(programmer_t *pgm, unsigned int word, unsigned int start) { unsigned char buf[4], start2[2]; pack_int16(start, start2); stlink2_cmd(pgm, 0xf40a, 8, 0x00, 0x02, 0x00, 0x00, HI(start), LO(start), HI(word), LO(word)); usleep(2000); return(stlink2_get_status(pgm)); // Should be '1' }
int stlink2_write_byte(programmer_t *pgm, unsigned char byte, unsigned int start) { unsigned char buf[4], start2[2]; pack_int16(start, start2); stlink2_cmd(pgm, 0xf40a, 7, 0x00, 0x01, 0x00, 0x00, HI(start), LO(start), byte); usleep(2000); return(stlink2_get_status(pgm)); // Should be '1' }
void stlink2_init_session(programmer_t *pgm) { int i; char f4_cmd_arg1[] = { 0x07, 0x07, 0x08, 0x07, 0x04, 0x03, 0x05, }; for(i = 0; i < sizeof(f4_cmd_arg1); i++) { stlink2_cmd(pgm, 0xf400 | f4_cmd_arg1[i], 0); TRY(8, stlink2_get_status(pgm) == 0); } stlink2_write_byte(pgm, 0xa0, 0x7f80); // mov 0x0a, SWIM_CSR2 ;; Init SWIM stlink2_cmd(pgm, 0xf408, 0); TRY(8, stlink2_get_status(pgm) == 0); stlink2_write_and_read_byte(pgm, 0xa0, 0x7f99); stlink2_cmd(pgm, 0xf40c, 0); msg_recv_int8(pgm); // 0x08 (or 0x0a if used stlink2_write_byte() instead) }
void stlink2_srst(programmer_t *pgm) { stlink2_cmd(pgm, 0xf407, 2, 0x00, 0x01); stlink2_get_status(pgm); stlink2_cmd(pgm, 0xf408, 2, 0x00, 0x01); stlink2_get_status(pgm); }
unsigned int stlink2_get_status(programmer_t *pgm) { stlink2_cmd(pgm, 0xf409, 0); return msg_recv_int32(pgm); }