This is an automated email from Gerrit.

Mathias K?ster (kes...@freenet.de) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/366

-- gerrit

commit b45546d692c9d98efcf9c0e6bc99502e0d3f31f1
Author: Mathias K <kes...@freenet.de>
Date:   Thu Jan 12 11:59:47 2012 +0100

    stlink: add read/write 8bit memory
    
    This patch add layout api funtions and implementation
    to read/write 8bit memory.
    
    Change-Id: I8d145eb07e5afa9ce1830578e57d80a80d21e7dc
    Signed-off-by: Mathias K <kes...@freenet.de>

diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c
index aaf55b0..1e079d5 100644
--- a/src/jtag/drivers/stlink_usb.c
+++ b/src/jtag/drivers/stlink_usb.c
@@ -87,6 +87,7 @@ struct stlink_usb_handle_s {
 #define STLINK_DEBUG_RUNCORE           0x09
 #define STLINK_DEBUG_STEPCORE          0x0a
 #define STLINK_DEBUG_SETFP             0x0b
+#define STLINK_DEBUG_READMEM_8BIT      0x0c
 #define STLINK_DEBUG_WRITEMEM_8BIT     0x0d
 #define STLINK_DEBUG_CLEARFP           0x0e
 #define STLINK_DEBUG_WRITEDEBUGREG     0x0f
@@ -97,7 +98,7 @@ struct stlink_usb_handle_s {
 #define STLINK_SWD_READCOREID          0x32
 
 /** */
-int stlink_usb_recv(void *handle, uint8_t *txbuf, int txsize, uint8_t *rxbuf,
+int stlink_usb_recv(void *handle, const uint8_t *txbuf, int txsize, uint8_t 
*rxbuf,
                    int rxsize)
 {
        struct stlink_usb_handle_s *h;
@@ -524,6 +525,65 @@ int stlink_usb_write_reg(void *handle, int num, uint32_t 
val)
 }
 
 /** */
+int stlink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len,
+                         uint8_t *buffer)
+{
+       int res;
+       struct stlink_usb_handle_s *h;
+
+       assert(handle != NULL);
+
+       h = (struct stlink_usb_handle_s *)handle;
+
+       stlink_usb_init_buffer(handle);
+
+       h->txbuf[0] = STLINK_DEBUG_COMMAND;
+       h->txbuf[1] = STLINK_DEBUG_READMEM_8BIT;
+       h_u32_to_le(h->txbuf + 2, addr);
+       h_u16_to_le(h->txbuf + 2 + 4, len);
+
+       res = stlink_usb_recv(handle, h->txbuf, STLINK_CMD_SIZE, h->rxbuf, len);
+
+       if (res != ERROR_OK)
+               return res;
+
+       memcpy(buffer, h->rxbuf, len);
+
+       return ERROR_OK;
+}
+
+/** */
+int stlink_usb_write_mem8(void *handle, uint32_t addr, uint16_t len,
+                          const uint8_t *buffer)
+{
+       int res;
+       struct stlink_usb_handle_s *h;
+
+       assert(handle != NULL);
+
+       h = (struct stlink_usb_handle_s *)handle;
+
+       stlink_usb_init_buffer(handle);
+
+       h->txbuf[0] = STLINK_DEBUG_COMMAND;
+       h->txbuf[1] = STLINK_DEBUG_WRITEMEM_8BIT;
+       h_u32_to_le(h->txbuf + 2, addr);
+       h_u16_to_le(h->txbuf + 2 + 4, len);
+
+       res = stlink_usb_recv(handle, h->txbuf, STLINK_CMD_SIZE, 0, 0);
+
+       if (res != ERROR_OK)
+               return res;
+
+       res = stlink_usb_recv(handle, (uint8_t *) buffer, len, 0, 0);
+
+       if (res != ERROR_OK)
+               return res;
+
+       return ERROR_OK;
+}
+
+/** */
 int stlink_usb_read_mem32(void *handle, uint32_t addr, uint16_t len,
                          uint32_t *buffer)
 {
@@ -555,7 +615,7 @@ int stlink_usb_read_mem32(void *handle, uint32_t addr, 
uint16_t len,
 
 /** */
 int stlink_usb_write_mem32(void *handle, uint32_t addr, uint16_t len,
-                          uint32_t *buffer)
+                          const uint32_t *buffer)
 {
        int res;
        struct stlink_usb_handle_s *h;
@@ -583,8 +643,6 @@ int stlink_usb_write_mem32(void *handle, uint32_t addr, 
uint16_t len,
        if (res != ERROR_OK)
                return res;
 
-       memcpy(buffer, h->rxbuf, len);
-
        return ERROR_OK;
 }
 
@@ -652,6 +710,10 @@ struct stlink_layout_api_s stlink_layout_api = {
        /** */
        .write_reg = stlink_usb_write_reg,
        /** */
+       .read_mem8 = stlink_usb_read_mem8,
+       /** */
+       .write_mem8 = stlink_usb_write_mem8,
+       /** */
        .read_mem32 = stlink_usb_read_mem32,
        /** */
        .write_mem32 = stlink_usb_write_mem32,
diff --git a/src/jtag/stlink/stlink_layout.h b/src/jtag/stlink/stlink_layout.h
index 46517a7..bf1e2c6 100644
--- a/src/jtag/stlink/stlink_layout.h
+++ b/src/jtag/stlink/stlink_layout.h
@@ -48,11 +48,17 @@ struct stlink_layout_api_s {
        /** */
        int (*write_reg) (void *fd, int num, uint32_t val);
        /** */
+       int (*read_mem8) (void *handle, uint32_t addr, uint16_t len,
+                          uint8_t *buffer);
+       /** */
+       int (*write_mem8) (void *handle, uint32_t addr, uint16_t len,
+                           const uint8_t *buffer);
+       /** */
        int (*read_mem32) (void *handle, uint32_t addr, uint16_t len,
                           uint32_t *buffer);
        /** */
        int (*write_mem32) (void *handle, uint32_t addr, uint16_t len,
-                           uint32_t *buffer);
+                           const uint32_t *buffer);
        /** */
        int (*idcode) (void *fd, uint32_t *idcode);
        /** */

-- 

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to