You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2016/06/15 22:04:29 UTC
[46/51] [partial] incubator-mynewt-site git commit: Fixed broken
Quick Start link and added OpenOCD option for Arduino Primo debugging
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/lpcspifi_write.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/lpcspifi_write.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/lpcspifi_write.S
new file mode 100755
index 0000000..8435a20
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/lpcspifi_write.S
@@ -0,0 +1,222 @@
+/***************************************************************************
+ * Copyright (C) 2012 by George Harris *
+ * george@luminairecoffee.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .syntax unified
+ .cpu cortex-m3
+ .thumb
+ .thumb_func
+
+/*
+ * Params :
+ * r0 = workarea start, status (out)
+ * r1 = workarea end
+ * r2 = target address (offset from flash base)
+ * r3 = count (bytes)
+ * r4 = page size
+ * Clobbered:
+ * r7 - rp
+ * r8 - wp, tmp
+ * r9 - send/receive data
+ * r10 - temp
+ * r11 - current page end address
+ */
+
+/*
+ * This code is embedded within: src/flash/nor/lpcspifi.c as a "C" array.
+ *
+ * To rebuild:
+ * arm-none-eabi-gcc -c lpcspifi_write.S
+ * arm-none-eabi-objcopy -O binary lpcspifi_write.o lpcspifi_write.bin
+ * xxd -c 8 -i lpcspifi_write.bin > lpcspifi_write.txt
+ *
+ * Then read and edit this result into the "C" source.
+ */
+
+#define SSP_BASE_HIGH 0x4008
+#define SSP_BASE_LOW 0x3000
+#define SSP_CR0_OFFSET 0x00
+#define SSP_CR1_OFFSET 0x04
+#define SSP_DATA_OFFSET 0x08
+#define SSP_CPSR_OFFSET 0x10
+#define SSP_SR_OFFSET 0x0c
+
+#define SSP_CLOCK_BASE_HIGH 0x4005
+#define SSP_CLOCK_BASE_LOW 0x0000
+#define SSP_BRANCH_CLOCK_BASE_HIGH 0x4005
+#define SSP_BRANCH_CLOCK_BASE_LOW 0x2000
+#define SSP_BASE_CLOCK_OFFSET 0x94
+#define SSP_BRANCH_CLOCK_OFFSET 0x700
+
+#define IOCONFIG_BASE_HIGH 0x4008
+#define IOCONFIG_BASE_LOW 0x6000
+#define IOCONFIG_SCK_OFFSET 0x18c
+#define IOCONFIG_HOLD_OFFSET 0x190
+#define IOCONFIG_WP_OFFSET 0x194
+#define IOCONFIG_MISO_OFFSET 0x198
+#define IOCONFIG_MOSI_OFFSET 0x19c
+#define IOCONFIG_CS_OFFSET 0x1a0
+
+#define IO_BASE_HIGH 0x400f
+#define IO_BASE_LOW 0x4000
+#define IO_CS_OFFSET 0xab
+#define IODIR_BASE_HIGH 0x400f
+#define IODIR_BASE_LOW 0x6000
+#define IO_CS_DIR_OFFSET 0x14
+
+
+setup: /* Initialize SSP pins and module */
+ mov.w r10, #IOCONFIG_BASE_LOW
+ movt r10, #IOCONFIG_BASE_HIGH
+ mov.w r8, #0xea
+ str.w r8, [r10, #IOCONFIG_SCK_OFFSET] /* Configure SCK pin function */
+ mov.w r8, #0x40
+ str.w r8, [r10, #IOCONFIG_HOLD_OFFSET] /* Configure /HOLD pin function */
+ mov.w r8, #0x40
+ str.w r8, [r10, #IOCONFIG_WP_OFFSET] /* Configure /WP pin function */
+ mov.w r8, #0xed
+ str.w r8, [r10, #IOCONFIG_MISO_OFFSET] /* Configure MISO pin function */
+ mov.w r8, #0xed
+ str.w r8, [r10, #IOCONFIG_MOSI_OFFSET] /* Configure MOSI pin function */
+ mov.w r8, #0x44
+ str.w r8, [r10, #IOCONFIG_CS_OFFSET] /* Configure CS pin function */
+
+ mov.w r10, #IODIR_BASE_LOW
+ movt r10, #IODIR_BASE_HIGH
+ mov.w r8, #0x800
+ str r8, [r10, #IO_CS_DIR_OFFSET] /* Set CS as output */
+ mov.w r10, #IO_BASE_LOW
+ movt r10, #IO_BASE_HIGH
+ mov.w r8, #0xff
+ str.w r8, [r10, #IO_CS_OFFSET] /* Set CS high */
+
+ mov.w r10, #SSP_CLOCK_BASE_LOW
+ movt r10, #SSP_CLOCK_BASE_HIGH
+ mov.w r8, #0x0000
+ movt r8, #0x0100
+ str.w r8, [r10, #SSP_BASE_CLOCK_OFFSET] /* Configure SSP0 base clock (use 12 MHz IRC) */
+
+ mov.w r10, #SSP_BRANCH_CLOCK_BASE_LOW
+ movt r10, #SSP_BRANCH_CLOCK_BASE_HIGH
+ mov.w r8, #0x01
+ str.w r8, [r10, #SSP_BRANCH_CLOCK_OFFSET] /* Configure (enable) SSP0 branch clock */
+
+ mov.w r10, #SSP_BASE_LOW
+ movt r10, #SSP_BASE_HIGH
+ mov.w r8, #0x07
+ str.w r8, [r10, #SSP_CR0_OFFSET] /* Set clock postscale */
+ mov.w r8, #0x02
+ str.w r8, [r10, #SSP_CPSR_OFFSET] /* Set clock prescale */
+ str.w r8, [r10, #SSP_CR1_OFFSET] /* Enable SSP in SPI mode */
+
+ mov.w r11, #0x00
+find_next_page_boundary:
+ add r11, r4 /* Increment to the next page */
+ cmp r11, r2
+ /* If we have not reached the next page boundary after the target address, keep going */
+ bls find_next_page_boundary
+write_enable:
+ bl cs_down
+ mov.w r9, #0x06 /* Send the write enable command */
+ bl write_data
+ bl cs_up
+
+ bl cs_down
+ mov.w r9, #0x05 /* Get status register */
+ bl write_data
+ mov.w r9, #0x00 /* Dummy data to clock in status */
+ bl write_data
+ bl cs_up
+
+ tst r9, #0x02 /* If the WE bit isn't set, we have a problem. */
+ beq error
+page_program:
+ bl cs_down
+ mov.w r9, #0x02 /* Send the page program command */
+ bl write_data
+write_address:
+ lsr r9, r2, #16 /* Send the current 24-bit write address, MSB first */
+ bl write_data
+ lsr r9, r2, #8
+ bl write_data
+ mov.w r9, r2
+ bl write_data
+wait_fifo:
+ ldr r8, [r0] /* read the write pointer */
+ cmp r8, #0 /* if it's zero, we're gonzo */
+ beq exit
+ ldr r7, [r0, #4] /* read the read pointer */
+ cmp r7, r8 /* wait until they are not equal */
+ beq wait_fifo
+write:
+ ldrb r9, [r7], #0x01 /* Load one byte from the FIFO, increment the read pointer by 1 */
+ bl write_data /* send the byte to the flash chip */
+
+ cmp r7, r1 /* wrap the read pointer if it is at the end */
+ it cs
+ addcs r7, r0, #8 /* skip loader args */
+ str r7, [r0, #4] /* store the new read pointer */
+ subs r3, r3, #1 /* decrement count */
+ cbz r3, exit /* Exit if we have written everything */
+
+ add r2, #1 /* Increment flash address by 1 */
+ cmp r11, r2 /* See if we have reached the end of a page */
+ bne wait_fifo /* If not, keep writing bytes */
+ bl cs_up /* Otherwise, end the command and keep going w/ the next page */
+ add r11, r4 /* Move up the end-of-page address by the page size*/
+wait_flash_busy: /* Wait for the flash to finish the previous page write */
+ bl cs_down
+ mov.w r9, #0x05 /* Get status register */
+ bl write_data
+ mov.w r9, #0x00 /* Dummy data to clock in status */
+ bl write_data
+ bl cs_up
+ tst r9, #0x01 /* If it isn't done, keep waiting */
+ bne wait_flash_busy
+ b write_enable /* If it is done, start a new page write */
+write_data: /* Send/receive 1 byte of data over SSP */
+ mov.w r10, #SSP_BASE_LOW
+ movt r10, #SSP_BASE_HIGH
+ str.w r9, [r10, #SSP_DATA_OFFSET] /* Write supplied data to the SSP data reg */
+wait_transmit:
+ ldr r9, [r10, #SSP_SR_OFFSET] /* Check SSP status */
+ tst r9, #0x0010 /* Check if BSY bit is set */
+ bne wait_transmit /* If still transmitting, keep waiting */
+ ldr r9, [r10, #SSP_DATA_OFFSET] /* Load received data */
+ bx lr /* Exit subroutine */
+cs_up:
+ mov.w r8, #0xff
+ b cs_write
+cs_down:
+ mov.w r8, #0x0000
+cs_write:
+ mov.w r10, #IO_BASE_LOW
+ movt r10, #IO_BASE_HIGH
+ str.w r8, [r10, #IO_CS_OFFSET]
+ bx lr
+error:
+ movs r0, #0
+ str r0, [r2, #4] /* set rp = 0 on error */
+exit:
+ bl cs_up /* end the command before returning */
+ mov r0, r6
+ bkpt #0x00
+
+ .end
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/mdr32fx.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/mdr32fx.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/mdr32fx.S
new file mode 100755
index 0000000..73f4b6f
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/mdr32fx.S
@@ -0,0 +1,125 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Andreas Fritiofson *
+ * andreas.fritiofson@gmail.com *
+ * *
+ * Copyright (C) 2013 by Paul Fertser *
+ * fercerpav@gmail.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .syntax unified
+ .cpu cortex-m0
+ .thumb
+ .thumb_func
+ .global write
+
+ /* Params:
+ * r0 - flash base (in), status (out)
+ * r1 - count (32bit)
+ * r2 - workarea start
+ * r3 - workarea end
+ * r4 - target address
+ * Clobbered:
+ * r5 - rp
+ * r6 - wp, tmp
+ * r7 - current FLASH_CMD
+ */
+
+#define FLASH_CMD 0x00
+#define FLASH_ADR 0x04
+#define FLASH_DI 0x08
+
+#define FLASH_NVSTR (1 << 13)
+#define FLASH_PROG (1 << 12)
+#define FLASH_MAS1 (1 << 11)
+#define FLASH_ERASE (1 << 10)
+#define FLASH_SE (1 << 8)
+#define FLASH_YE (1 << 7)
+#define FLASH_XE (1 << 6)
+
+ ldr r7, [r0, #FLASH_CMD]
+wait_fifo:
+ ldr r6, [r2, #0] /* read wp */
+ cmp r6, #0 /* abort if wp == 0 */
+ beq exit
+ ldr r5, [r2, #4] /* read rp */
+ cmp r5, r6 /* wait until rp != wp */
+ beq wait_fifo
+
+ ldr r6, [r5] /* "*target_address++ = *rp++" */
+ str r4, [r0, #FLASH_ADR]
+ str r6, [r0, #FLASH_DI]
+
+ ldr r6, =(FLASH_XE | FLASH_PROG)
+ orrs r7, r7, r6
+ str r7, [r0, #FLASH_CMD]
+ # wait 5us
+ movs r6, #5
+ bl delay
+ ldr r6, =#FLASH_NVSTR
+ orrs r7, r7, r6
+ str r7, [r0, #FLASH_CMD]
+ # wait 10us
+ movs r6, #13
+ bl delay
+ movs r6, #FLASH_YE
+ orrs r7, r7, r6
+ str r7, [r0, #FLASH_CMD]
+ # wait 40us
+ movs r6, #61
+ bl delay
+ movs r6, #FLASH_YE
+ bics r7, r7, r6
+ str r7, [r0, #FLASH_CMD]
+ ldr r6, =#FLASH_PROG
+ bics r7, r7, r6
+ str r7, [r0, #FLASH_CMD]
+ # wait 5us
+ movs r6, #5
+ bl delay
+ ldr r6, =#(FLASH_XE | FLASH_NVSTR)
+ bics r7, r7, r6
+ str r7, [r0, #FLASH_CMD]
+
+ adds r5, #4
+ adds r4, #4
+
+ cmp r5, r3 /* wrap rp at end of buffer */
+ bcc no_wrap
+ mov r5, r2
+ adds r5, #8
+no_wrap:
+ str r5, [r2, #4] /* store rp */
+ subs r1, r1, #1 /* decrement word count */
+ cmp r1, #0
+ beq exit /* loop if not done */
+ b wait_fifo
+exit:
+ mov r0, r6 /* return status in r0 */
+ bkpt #0
+
+ /* r6 - in
+ * for r6 == 1 it'll take:
+ * 1 (prepare operand) + 4 (bl) + 2 (subs+cmp) + 1 (bne) + 3 (b) ->
+ * 11 tacts == 1.4us with 8MHz
+ * every extra iteration will take 5 tacts == 0.6us */
+delay:
+ subs r6, r6, #1
+ cmp r6, #0
+ bne delay
+ bx lr
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/mrvlqspi_write.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/mrvlqspi_write.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/mrvlqspi_write.S
new file mode 100755
index 0000000..064192c
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/mrvlqspi_write.S
@@ -0,0 +1,232 @@
+/***************************************************************************
+ * Copyright (C) 2014 by Mahavir Jain <mj...@marvell.com> *
+ * *
+ * Adapted from (contrib/loaders/flash/lpcspifi_write.S): *
+ * Copyright (C) 2012 by George Harris *
+ * george@luminairecoffee.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .syntax unified
+ .cpu cortex-m3
+ .thumb
+ .thumb_func
+
+/*
+ * For compilation:
+ * arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -c contrib/loaders/flash/mrvlqspi_write.S
+ * arm-none-eabi-objcopy -O binary mrvlqspi_write.o code.bin
+ * Copy code.bin into mrvlqspi flash driver
+ */
+
+/*
+ * Params :
+ * r0 = workarea start, status (out)
+ * r1 = workarea end
+ * r2 = target address (offset from flash base)
+ * r3 = count (bytes)
+ * r4 = page size
+ * r5 = qspi base address
+ * Clobbered:
+ * r7 - rp
+ * r8 - wp, tmp
+ * r9 - send/receive data
+ * r10 - current page end address
+ */
+
+#define CNTL 0x0
+#define CONF 0x4
+#define DOUT 0x8
+#define DIN 0xc
+#define INSTR 0x10
+#define ADDR 0x14
+#define RDMODE 0x18
+#define HDRCNT 0x1c
+#define DINCNT 0x20
+
+#define SS_EN (1 << 0)
+#define XFER_RDY (1 << 1)
+#define RFIFO_EMPTY (1 << 4)
+#define WFIFO_EMPTY (1 << 6)
+#define WFIFO_FULL (1 << 7)
+#define FIFO_FLUSH (1 << 9)
+#define RW_EN (1 << 13)
+#define XFER_STOP (1 << 14)
+#define XFER_START (1 << 15)
+
+#define INS_WRITE_ENABLE 0x06
+#define INS_READ_STATUS 0x05
+#define INS_PAGE_PROGRAM 0x02
+
+init:
+ mov.w r10, #0x00
+find_next_page_boundary:
+ add r10, r4 /* Increment to the next page */
+ cmp r10, r2
+ /* If we have not reached the next page boundary after the target address, keep going */
+ bls find_next_page_boundary
+write_enable:
+ /* Flush read/write fifo's */
+ bl flush_fifo
+
+ /* Instruction byte 1 */
+ movs r8, #0x1
+ str r8, [r5, #HDRCNT]
+
+ /* Set write enable instruction */
+ movs r8, #INS_WRITE_ENABLE
+ str r8, [r5, #INSTR]
+
+ movs r9, #0x1
+ bl start_tx
+ bl stop_tx
+page_program:
+ /* Instruction byte 1, Addr byte 3 */
+ movs r8, #0x31
+ str r8, [r5, #HDRCNT]
+ /* Todo: set addr and data pin to single */
+write_address:
+ mov r8, r2
+ str r8, [r5, #ADDR]
+ /* Set page program instruction */
+ movs r8, #INS_PAGE_PROGRAM
+ str r8, [r5, #INSTR]
+ /* Start write transfer */
+ movs r9, #0x1
+ bl start_tx
+wait_fifo:
+ ldr r8, [r0] /* read the write pointer */
+ cmp r8, #0 /* if it's zero, we're gonzo */
+ beq exit
+ ldr r7, [r0, #4] /* read the read pointer */
+ cmp r7, r8 /* wait until they are not equal */
+ beq wait_fifo
+write:
+ ldrb r9, [r7], #0x01 /* Load one byte from the FIFO, increment the read pointer by 1 */
+ bl write_data /* send the byte to the flash chip */
+
+ cmp r7, r1 /* wrap the read pointer if it is at the end */
+ it cs
+ addcs r7, r0, #8 /* skip loader args */
+ str r7, [r0, #4] /* store the new read pointer */
+ subs r3, r3, #1 /* decrement count */
+ cmp r3, #0 /* Exit if we have written everything */
+ beq write_wait
+ add r2, #1 /* Increment flash address by 1 */
+ cmp r10, r2 /* See if we have reached the end of a page */
+ bne wait_fifo /* If not, keep writing bytes */
+write_wait:
+ bl stop_tx /* Otherwise, end the command and keep going w/ the next page */
+ add r10, r4 /* Move up the end-of-page address by the page size*/
+check_flash_busy: /* Wait for the flash to finish the previous page write */
+ /* Flush read/write fifo's */
+ bl flush_fifo
+ /* Instruction byte 1 */
+ movs r8, #0x1
+ str r8, [r5, #HDRCNT]
+ /* Continuous data in of status register */
+ movs r8, #0x0
+ str r8, [r5, #DINCNT]
+ /* Set write enable instruction */
+ movs r8, #INS_READ_STATUS
+ str r8, [r5, #INSTR]
+ /* Start read transfer */
+ movs r9, #0x0
+ bl start_tx
+wait_flash_busy:
+ bl read_data
+ and.w r9, r9, #0x1
+ cmp r9, #0x0
+ bne.n wait_flash_busy
+ bl stop_tx
+ cmp r3, #0
+ bne.n write_enable /* If it is done, start a new page write */
+ b exit /* All data written, exit */
+
+write_data: /* Send/receive 1 byte of data over QSPI */
+ ldr r8, [r5, #CNTL]
+ lsls r8, r8, #24
+ bmi.n write_data
+ str r9, [r5, #DOUT]
+ bx lr
+
+read_data: /* Read 1 byte of data over QSPI */
+ ldr r8, [r5, #CNTL]
+ lsls r8, r8, #27
+ bmi.n read_data
+ ldr r9, [r5, #DIN]
+ bx lr
+
+flush_fifo: /* Flush read write fifos */
+ ldr r8, [r5, #CONF]
+ orr.w r8, r8, #FIFO_FLUSH
+ str r8, [r5, #CONF]
+flush_reset:
+ ldr r8, [r5, #CONF]
+ lsls r8, r8, #22
+ bmi.n flush_reset
+ bx lr
+
+start_tx:
+ ldr r8, [r5, #CNTL]
+ orr.w r8, r8, #SS_EN
+ str r8, [r5, #CNTL]
+xfer_rdy:
+ ldr r8, [r5, #CNTL]
+ lsls r8, r8, #30
+ bpl.n xfer_rdy
+ ldr r8, [r5, #CONF]
+ bfi r8, r9, #13, #1
+ orr.w r8, r8, #XFER_START
+ str r8, [r5, #CONF]
+ bx lr
+
+stop_tx:
+ ldr r8, [r5, #CNTL]
+ lsls r8, r8, #30
+ bpl.n stop_tx
+wfifo_wait:
+ ldr r8, [r5, #CNTL]
+ lsls r8, r8, #25
+ bpl.n wfifo_wait
+ ldr r8, [r5, #CONF]
+ orr.w r8, r8, #XFER_STOP
+ str r8, [r5, #CONF]
+xfer_start:
+ ldr r8, [r5, #CONF]
+ lsls r8, r8, #16
+ bmi.n xfer_start
+ss_disable:
+ # Disable SS_EN
+ ldr r8, [r5, #CNTL]
+ bic.w r8, r8, #SS_EN
+ str r8, [r5, #CNTL]
+wait:
+ ldr r8, [r5, #CNTL]
+ lsls r8, r8, #30
+ bpl.n wait
+ bx lr
+
+error:
+ movs r0, #0
+ str r0, [r2, #4] /* set rp = 0 on error */
+exit:
+ mov r0, r6
+ bkpt #0x00
+
+ .end
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/pic32mx.s
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/pic32mx.s b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/pic32mx.s
new file mode 100755
index 0000000..9f41965
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/pic32mx.s
@@ -0,0 +1,132 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .arch m4k
+ .set noreorder
+ .set noat
+
+/* params:
+ * $a0 src adr - ram + result
+ * $a1 dest adr - flash
+ * $a2 count (32bit words)
+ * vars
+ *
+ * temps:
+ * $t0, $t1, $t2, $t3, $t4, $t5
+ * $s0, $s1, $s3, $s4, $s5
+ */
+
+ .type main, @function
+ .global main
+
+.ent main
+main:
+ /* setup constants */
+ lui $t0, 0xaa99
+ ori $t0, 0x6655 /* NVMKEY1 */
+ lui $t1, 0x5566
+ ori $t1, 0x99AA /* NVMKEY2 */
+ lui $t2, 0xBF80
+ ori $t2, 0xF400 /* NVMCON */
+ ori $t3, $zero, 0x4003 /* NVMCON row write cmd */
+ ori $t4, $zero, 0x8000 /* NVMCON start cmd */
+
+write_row:
+ /* can we perform a row write: 128 32bit words */
+ sltiu $s3, $a2, 128
+ bne $s3, $zero, write_word
+ ori $t5, $zero, 0x4000 /* NVMCON clear cmd */
+
+ /* perform row write 512 bytes */
+ sw $a1, 32($t2) /* set NVMADDR with dest addr - real addr */
+ sw $a0, 64($t2) /* set NVMSRCADDR with src addr - real addr */
+
+ bal progflash
+ addiu $a0, $a0, 512
+ addiu $a1, $a1, 512
+ beq $zero, $zero, write_row
+ addiu $a2, $a2, -128
+
+write_word:
+ /* write 32bit words */
+ lui $s5, 0xa000
+ ori $s5, 0x0000
+ or $a0, $a0, $s5 /* convert to virtual addr */
+
+ beq $zero, $zero, next_word
+ ori $t3, $zero, 0x4001 /* NVMCON word write cmd */
+
+prog_word:
+ lw $s4, 0($a0) /* load data - from virtual addr */
+ sw $s4, 48($t2) /* set NVMDATA with data */
+ sw $a1, 32($t2) /* set NVMADDR with dest addr - real addr */
+
+ bal progflash
+ addiu $a0, $a0, 4
+ addiu $a1, $a1, 4
+ addiu $a2, $a2, -1
+next_word:
+ bne $a2, $zero, prog_word
+ nop
+
+done:
+ beq $zero, $zero, exit
+ addiu $a0, $zero, 0
+
+error:
+ /* save result to $a0 */
+ addiu $a0, $s1, 0
+
+exit:
+ sdbbp
+.end main
+
+ .type progflash, @function
+ .global progflash
+
+.ent progflash
+progflash:
+ sw $t3, 0($t2) /* set NVMWREN */
+ sw $t0, 16($t2) /* write NVMKEY1 */
+ sw $t1, 16($t2) /* write NVMKEY2 */
+ sw $t4, 8($t2) /* start operation */
+
+waitflash:
+ lw $s0, 0($t2)
+ and $s0, $s0, $t4
+ bne $s0, $zero, waitflash
+ nop
+
+ /* following is to comply with errata #34
+ * 500ns delay required */
+ nop
+ nop
+ nop
+ nop
+ /* check for errors */
+ lw $s1, 0($t2)
+ andi $s1, $zero, 0x3000
+ bne $s1, $zero, error
+ sw $t5, 4($t2) /* clear NVMWREN */
+ jr $ra
+ nop
+
+.end progflash
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/sim3x.s
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/sim3x.s b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/sim3x.s
new file mode 100755
index 0000000..cdb3ef6
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/sim3x.s
@@ -0,0 +1,81 @@
+/***************************************************************************
+ * Copyright (C) 2014 by Ladislav B�bel *
+ * ladababel@seznam.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ ***************************************************************************/
+
+#define INITIAL_UNLOCK 0x5A
+#define MULTIPLE_UNLOCK 0xF2
+
+#define FLASHCTRL_KEY 0x4002E0C0
+#define FLASHCTRL_CONFIG 0x4002E000
+#define FLASHCTRL_WRADDR 0x4002E0A0
+#define FLASHCTRL_WRDATA 0x4002E0B0
+#define BUSYF 0x00100000
+
+
+ /* Write the initial unlock value to KEY (0xA5) */
+ movs r6, #INITIAL_UNLOCK
+ str r6, [r0, #FLASHCTRL_KEY]
+
+ /* Write the multiple unlock value to KEY (0xF2) */
+ movs r6, #MULTIPLE_UNLOCK
+ str r6, [r0, #FLASHCTRL_KEY]
+
+wait_fifo:
+ ldr r6, [r2, #0]
+ cmp r6, #0
+ beq exit
+ ldr r5, [r2, #4]
+ cmp r5, r6
+ beq wait_fifo
+
+ /* wait for BUSYF flag */
+wait_busy1:
+ ldr r6, [r0, #FLASHCTRL_CONFIG]
+ tst r6, #BUSYF
+ bne wait_busy1
+
+ /* Write the destination address to WRADDR */
+ str r4, [r0, #FLASHCTRL_WRADDR]
+
+ /* Write the data half-word to WRDATA in right-justified format */
+ ldrh r6, [r5]
+ str r6, [r0, #FLASHCTRL_WRDATA]
+
+ adds r5, #2
+ adds r4, #2
+
+ /* wrap rp at end of buffer */
+ cmp r5, r3
+ bcc no_wrap
+ mov r5, r2
+ adds r5, #8
+
+no_wrap:
+ str r5, [r2, #4]
+ subs r1, r1, #1
+ cmp r1, #0
+ beq exit
+ b wait_fifo
+
+exit:
+ movs r6, #MULTIPLE_LOCK
+ str r6, [r0, #FLASHCTRL_KEY]
+
+ /* wait for BUSYF flag */
+wait_busy2:
+ ldr r6, [r0, #FLASHCTRL_CONFIG]
+ tst r6, #BUSYF
+ bne wait_busy2
+
+ bkpt #0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stellaris.s
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stellaris.s b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stellaris.s
new file mode 100755
index 0000000..6e1ed69
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stellaris.s
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Magnus Lundin *
+ * lundin@mlu.mine.nu *
+ * *
+ * Copyright (C) 2008 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .syntax unified
+ .cpu cortex-m3
+ .thumb
+ .thumb_func
+
+/*
+ * Params :
+ * r0 = workarea start
+ * r1 = workarea end
+ * r2 = target address
+ * r3 = count (32bit words)
+ *
+ * Clobbered:
+ * r4 = pFLASH_CTRL_BASE
+ * r5 = FLASHWRITECMD
+ * r7 - rp
+ * r8 - wp, tmp
+ */
+
+write:
+ ldr r4, pFLASH_CTRL_BASE
+ ldr r5, FLASHWRITECMD
+
+wait_fifo:
+ ldr r8, [r0, #0] /* read wp */
+ cmp r8, #0 /* abort if wp == 0 */
+ beq exit
+ ldr r7, [r0, #4] /* read rp */
+ cmp r7, r8 /* wait until rp != wp */
+ beq wait_fifo
+
+mainloop:
+ str r2, [r4, #0] /* FMA - write address */
+ add r2, r2, #4 /* increment target address */
+ ldr r8, [r7], #4
+ str r8, [r4, #4] /* FMD - write data */
+ str r5, [r4, #8] /* FMC - enable write */
+busy:
+ ldr r8, [r4, #8]
+ tst r8, #1
+ bne busy
+
+ cmp r7, r1 /* wrap rp at end of buffer */
+ it cs
+ addcs r7, r0, #8 /* skip loader args */
+ str r7, [r0, #4] /* store rp */
+ subs r3, r3, #1 /* decrement word count */
+ cbz r3, exit /* loop if not done */
+ b wait_fifo
+exit:
+ bkpt #0
+
+pFLASH_CTRL_BASE: .word 0x400FD000
+FLASHWRITECMD: .word 0xA4420001
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32f1x.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32f1x.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32f1x.S
new file mode 100755
index 0000000..5ce463d
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32f1x.S
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Andreas Fritiofson *
+ * andreas.fritiofson@gmail.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .syntax unified
+ .cpu cortex-m0
+ .thumb
+ .thumb_func
+ .global write
+
+ /* Params:
+ * r0 - flash base (in), status (out)
+ * r1 - count (halfword-16bit)
+ * r2 - workarea start
+ * r3 - workarea end
+ * r4 - target address
+ * Clobbered:
+ * r5 - rp
+ * r6 - wp, tmp
+ * r7 - tmp
+ */
+
+#define STM32_FLASH_SR_OFFSET 0x0c /* offset of SR register from flash reg base */
+
+wait_fifo:
+ ldr r6, [r2, #0] /* read wp */
+ cmp r6, #0 /* abort if wp == 0 */
+ beq exit
+ ldr r5, [r2, #4] /* read rp */
+ cmp r5, r6 /* wait until rp != wp */
+ beq wait_fifo
+ ldrh r6, [r5] /* "*target_address++ = *rp++" */
+ strh r6, [r4]
+ adds r5, #2
+ adds r4, #2
+busy:
+ ldr r6, [r0, #STM32_FLASH_SR_OFFSET] /* wait until BSY flag is reset */
+ movs r7, #1
+ tst r6, r7
+ bne busy
+ movs r7, #0x14 /* check the error bits */
+ tst r6, r7
+ bne error
+ cmp r5, r3 /* wrap rp at end of buffer */
+ bcc no_wrap
+ mov r5, r2
+ adds r5, #8
+no_wrap:
+ str r5, [r2, #4] /* store rp */
+ subs r1, r1, #1 /* decrement halfword count */
+ cmp r1, #0
+ beq exit /* loop if not done */
+ b wait_fifo
+error:
+ movs r0, #0
+ str r0, [r2, #4] /* set rp = 0 on error */
+exit:
+ mov r0, r6 /* return status in r0 */
+ bkpt #0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32f2x.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32f2x.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32f2x.S
new file mode 100755
index 0000000..0dd1223
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32f2x.S
@@ -0,0 +1,81 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * Copyright (C) 2011 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .syntax unified
+ .cpu cortex-m3
+ .thumb
+ .thumb_func
+
+/*
+ * Params :
+ * r0 = workarea start, status (out)
+ * r1 = workarea end
+ * r2 = target address
+ * r3 = count (16bit words)
+ * r4 = flash base
+ *
+ * Clobbered:
+ * r6 - temp
+ * r7 - rp
+ * r8 - wp, tmp
+ */
+
+#define STM32_FLASH_CR_OFFSET 0x10 /* offset of CR register in FLASH struct */
+#define STM32_FLASH_SR_OFFSET 0x0c /* offset of SR register in FLASH struct */
+
+wait_fifo:
+ ldr r8, [r0, #0] /* read wp */
+ cmp r8, #0 /* abort if wp == 0 */
+ beq exit
+ ldr r7, [r0, #4] /* read rp */
+ cmp r7, r8 /* wait until rp != wp */
+ beq wait_fifo
+
+ ldr r6, STM32_PROG16
+ str r6, [r4, #STM32_FLASH_CR_OFFSET]
+ ldrh r6, [r7], #0x02 /* read one half-word from src, increment ptr */
+ strh r6, [r2], #0x02 /* write one half-word from src, increment ptr */
+ dsb
+busy:
+ ldr r6, [r4, #STM32_FLASH_SR_OFFSET]
+ tst r6, #0x10000 /* BSY (bit16) == 1 => operation in progress */
+ bne busy /* wait more... */
+ tst r6, #0xf0 /* PGSERR | PGPERR | PGAERR | WRPERR */
+ bne error /* fail... */
+
+ cmp r7, r1 /* wrap rp at end of buffer */
+ it cs
+ addcs r7, r0, #8 /* skip loader args */
+ str r7, [r0, #4] /* store rp */
+ subs r3, r3, #1 /* decrement halfword count */
+ cbz r3, exit /* loop if not done */
+ b wait_fifo
+error:
+ movs r1, #0
+ str r1, [r0, #4] /* set rp = 0 on error */
+exit:
+ mov r0, r6 /* return status in r0 */
+ bkpt #0x00
+
+STM32_PROG16: .word 0x101 /* PG | PSIZE_16*/
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32l4x.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32l4x.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32l4x.S
new file mode 100755
index 0000000..799dec5
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32l4x.S
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * Copyright (C) 2011 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2015 Uwe Bonnes *
+ * bon@elektron.ikp.physik.tu-darmstadt.de *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc. *
+ ***************************************************************************/
+
+ .text
+ .syntax unified
+ .cpu cortex-m4
+ .thumb
+ .thumb_func
+
+/* To assemble:
+ * arm-none-eabi-gcc -c stm32l4x.S
+ *
+ * To disassemble:
+ * arm-none-eabi-objdump -o stm32l4x.o
+ *
+ * To generate binary file:
+ * arm-none-eabi-objcopy -O binary stm32l4x.o stm32l4_flash_write_code.bin
+ *
+ * To generate include file:
+ * xxd -i stm32l4_flash_write_code.bin
+ */
+
+/*
+ * Params :
+ * r0 = workarea start, status (out)
+ * r1 = workarea end
+ * r2 = target address
+ * r3 = count (64bit words)
+ * r4 = flash base
+ *
+ * Clobbered:
+ * r5 - rp
+ * r6/7 - temp (64-bit)
+ * r8 - wp, tmp
+ */
+
+#define STM32_FLASH_CR_OFFSET 0x14 /* offset of CR register in FLASH struct */
+#define STM32_FLASH_SR_OFFSET 0x10 /* offset of SR register in FLASH struct */
+
+wait_fifo:
+ ldr r8, [r0, #0] /* read wp */
+ cmp r8, #0 /* abort if wp == 0 */
+ beq exit
+ ldr r5, [r0, #4] /* read rp */
+ subs r6, r8, r5 /* number of bytes available for read in r6*/
+ itt mi /* if wrapped around*/
+ addmi r6, r1 /* add size of buffer */
+ submi r6, r0
+ cmp r6, #8 /* wait until 8 bytes are available */
+ bcc wait_fifo
+
+ ldr r6, STM32_PROG
+ str r6, [r4, #STM32_FLASH_CR_OFFSET]
+ ldrd r6, [r5], #0x08 /* read one word from src, increment ptr */
+ strd r6, [r2], #0x08 /* write one word to dst, increment ptr */
+ dsb
+busy:
+ ldr r6, [r4, #STM32_FLASH_SR_OFFSET]
+ tst r6, #0x10000 /* BSY (bit16) == 1 => operation in progress */
+ bne busy /* wait more... */
+ tst r6, #0xfa /* PGSERR | PGPERR | PGAERR | WRPERR | PROGERR*/
+ bne error /* fail... */
+
+ cmp r5, r1 /* wrap rp at end of buffer */
+ it cs
+ addcs r5, r0, #8 /* skip loader args */
+ str r5, [r0, #4] /* store rp */
+ subs r3, r3, #1 /* decrement dword count */
+ cbz r3, exit /* loop if not done */
+ b wait_fifo
+error:
+ movs r1, #0
+ str r1, [r0, #4] /* set rp = 0 on error */
+exit:
+ mov r0, r6 /* return status in r0 */
+ bkpt #0x00
+
+STM32_PROG: .word 0x1 /* PG */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32lx.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32lx.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32lx.S
new file mode 100755
index 0000000..88deed3
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/stm32lx.S
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * Copyright (C) 2011 �yvind Harboe *
+ * oyvind.harboe@zylin.com *
+ * *
+ * Copyright (C) 2011 Clement Burin des Roziers *
+ * clement.burin-des-roziers@hikob.com *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+
+// Build : arm-eabi-gcc -c stm32lx.S
+ .text
+ .syntax unified
+ .cpu cortex-m3
+ .thumb
+ .thumb_func
+ .global write
+
+/*
+ r0 - destination address
+ r1 - source address
+ r2 - count
+*/
+
+ // Set 0 to r3
+ movs r3, #0
+ // Go to compare
+ b.n test_done
+
+write_word:
+ // Load one word from address in r0, increment by 4
+ ldr.w ip, [r1], #4
+ // Store the word to address in r1, increment by 4
+ str.w ip, [r0], #4
+ // Increment r3
+ adds r3, #1
+
+test_done:
+ // Compare r3 and r2
+ cmp r3, r2
+ // Loop if not zero
+ bcc.n write_word
+
+ // Set breakpoint to exit
+ bkpt #0x00
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/str7x.s
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/str7x.s b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/str7x.s
new file mode 100755
index 0000000..a163ee6
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/str7x.s
@@ -0,0 +1,59 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .arm
+ .arch armv4t
+
+ .section .init
+/*
+ r0 source address
+ r1 address
+ r2 FLASH_CR0
+ r3 dword count
+ r4 result
+ r5 busy mask
+*/
+
+write:
+ mov r4, #0x10000000 /* set DWPG bit */
+ str r4, [r2, #0x0] /* FLASH_CR0 */
+ str r1, [r2, #0x10] /* FLASH_AR */
+ ldr r4, [r0], #4 /* load data */
+ str r4, [r2, #0x8] /* FLASH_DR0 */
+ ldr r4, [r0], #4 /* load data */
+ str r4, [r2, #0xc] /* FLASH_DR1 */
+ mov r4, #0x90000000 /* set DWPG and WMS bits */
+ str r4, [r2, #0x0] /* FLASH_CR0 */
+busy:
+ ldr r4, [r2, #0x0] /* FLASH_CR0 */
+ tst r4, r5
+ bne busy
+ ldr r4, [r2, #0x14] /* FLASH_ER */
+ tst r4, #0xff /* do we have errors */
+ tsteq r4, #0x100 /* write protection set */
+ bne exit
+ add r1, r1, #0x8 /* next 8 bytes */
+ subs r3, r3, #1 /* decremment dword count */
+ bne write
+exit:
+ b exit
+
+ .end
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/str9x.s
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/str9x.s b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/str9x.s
new file mode 100755
index 0000000..4daac77
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/str9x.s
@@ -0,0 +1,56 @@
+/***************************************************************************
+ * Copyright (C) 2010 by Spencer Oliver *
+ * spen@spen-soft.co.uk *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+ .text
+ .arm
+ .arch armv5t
+
+ .section .init
+/*
+ r0 source address (in)
+ r1 target address (in)
+ r2 word count (in)
+ r3 result (out)
+*/
+
+write:
+ bic r4, r1, #3 /* word address */
+ mov r3, #0x40 /* write command */
+ strh r3, [r4, #0]
+ ldrh r3, [r0], #2 /* read data */
+ strh r3, [r1], #2 /* write data */
+ mov r3, #0x70 /* status command */
+ strh r3, [r4, #0]
+busy:
+ ldrb r3, [r4, #0] /* status */
+ tst r3, #0x80
+ beq busy
+ mov r5, #0x50 /* clear status command */
+ strh r5, [r4, #0]
+ mov r5, #0xFF /* read array */
+ strh r5, [r4, #0]
+ tst r3, #0x12
+ bne exit
+ subs r2, r2, #1 /* decremment word count */
+ bne write
+exit:
+ bkpt #0
+
+ .end
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase.S
new file mode 100755
index 0000000..e5a4808
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase.S
@@ -0,0 +1,53 @@
+/*
+ * Infineon XMC1000 flash sectors erase
+ *
+ * Copyright (c) 2016 Andreas F�rber
+ *
+ * Based on XMC1100 AA-Step Reference Manual
+ *
+ * License: GPL-2.0+
+ */
+
+#include "xmc1xxx.S"
+
+#define DUMMY_VALUE 0x42
+
+ .macro erase_page, nvmbase, addr, tmp, tmp2
+
+ movs \tmp, #DUMMY_VALUE
+ str \tmp, [\addr]
+
+ busy_wait \nvmbase, \tmp, \tmp2
+
+ .endm
+
+
+ .macro erase, nvmbase, addr, end, tmp, tmp2
+
+ movs \tmp, #NVMPROG_ACTION_PAGE_ERASE_CONTINUOUS
+ strh \tmp, [\nvmbase, #NVMPROG]
+2001:
+ erase_page \nvmbase, \addr, \tmp, \tmp2
+
+ movs \tmp, #(NVM_PAGE_SIZE - 1)
+ adds \tmp, \tmp, #1
+ add \addr, \addr, \tmp
+ cmp \addr, \end
+ blt 2001b
+
+ movs \tmp, #NVMPROG_ACTION_IDLE
+ strh \tmp, [\nvmbase, #NVMPROG]
+
+ .endm
+
+
+ /*
+ * r0 = 0x40050000
+ * r1 = e.g. 0x10001000
+ * r2 = e.g. 0x10011000
+ * NVMPROG.ACTION = 0x00
+ */
+erase:
+ erase r0, r1, r2, r3, r4
+
+ bkpt #0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase.inc
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase.inc b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase.inc
new file mode 100755
index 0000000..b33e57d
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase.inc
@@ -0,0 +1,4 @@
+/* Autogenerated with ../../../../src/helper/bin2char.sh */
+0xa2,0x23,0x83,0x80,0x42,0x23,0x0b,0x60,0x03,0x88,0x01,0x24,0x23,0x40,0xa3,0x42,
+0xfa,0xd0,0xff,0x23,0x01,0x33,0x19,0x44,0x91,0x42,0xf3,0xdb,0x00,0x23,0x83,0x80,
+0x00,0xbe,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase_check.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase_check.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase_check.S
new file mode 100755
index 0000000..6c99344
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase_check.S
@@ -0,0 +1,67 @@
+/*
+ * Infineon XMC1000 flash sector erase check
+ *
+ * Copyright (c) 2016 Andreas F�rber
+ *
+ * Based on XMC1100 AA-Step Reference Manual
+ *
+ * License: GPL-2.0+
+ */
+
+#include "xmc1xxx.S"
+
+ .macro verify_block, nvmbase, addr, tmp, tmp2
+
+ movs \tmp, #0x00
+ mvns \tmp, \tmp
+ str \tmp, [\addr, #0x0]
+ str \tmp, [\addr, #0x4]
+ str \tmp, [\addr, #0x8]
+ str \tmp, [\addr, #0xC]
+
+ busy_wait \nvmbase, \tmp, \tmp2
+
+ .endm
+
+
+ .macro erase_check, nvmbase, addr, end, tmp, tmp2
+
+ ldrh \tmp, [\nvmbase, #NVMCONF]
+ movs \tmp2, #NVMCONF_HRLEV_MASK
+ mvns \tmp2, \tmp2
+ ands \tmp, \tmp, \tmp2
+ movs \tmp2, #NVMCONF_HRLEV_HRE
+ orrs \tmp, \tmp, \tmp2
+ strh \tmp, [\nvmbase, #NVMCONF]
+
+ movs \tmp, #NVMPROG_ACTION_VERIFY_CONTINUOUS
+ strh \tmp, [\nvmbase, #NVMPROG]
+2001:
+ verify_block \nvmbase, \addr, \tmp, \tmp2
+
+ ldrh \tmp, [\nvmbase, #NVMSTATUS]
+ movs \tmp2, #NVMSTATUS_VERR_MASK
+ ands \tmp, \tmp, \tmp2
+ cmp \tmp, #NVMSTATUS_VERR_NOFAIL
+ bne 2010f
+
+ adds \addr, \addr, #NVM_BLOCK_SIZE
+ cmp \addr, \end
+ blt 2001b
+2010:
+ movs \tmp, #NVMPROG_ACTION_IDLE
+ strh \tmp, [\nvmbase, #NVMPROG]
+
+ .endm
+
+
+ /*
+ * r0 = 0x40050000
+ * r1 = e.g. 0x10001000
+ * r2 = e.g. 0x10002000
+ * NVMPROG.ACTION = 0x00
+ */
+erase_check:
+ erase_check r0, r1, r2, r3, r4
+
+ bkpt #0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase_check.inc
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase_check.inc b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase_check.inc
new file mode 100755
index 0000000..8fc8e0b
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/erase_check.inc
@@ -0,0 +1,5 @@
+/* Autogenerated with ../../../../src/helper/bin2char.sh */
+0x03,0x89,0x06,0x24,0xe4,0x43,0x23,0x40,0x04,0x24,0x23,0x43,0x03,0x81,0xe0,0x23,
+0x83,0x80,0x00,0x23,0xdb,0x43,0x0b,0x60,0x4b,0x60,0x8b,0x60,0xcb,0x60,0x03,0x88,
+0x01,0x24,0x23,0x40,0xa3,0x42,0xfa,0xd0,0x03,0x88,0x0c,0x24,0x23,0x40,0x00,0x2b,
+0x02,0xd1,0x10,0x31,0x91,0x42,0xec,0xdb,0x00,0x23,0x83,0x80,0x00,0xbe,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/write.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/write.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/write.S
new file mode 100755
index 0000000..640f6ca
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/write.S
@@ -0,0 +1,58 @@
+/*
+ * Infineon XMC1000 flash write
+ *
+ * Copyright (c) 2016 Andreas F�rber
+ *
+ * Based on XMC1100 AA-Step Reference Manual
+ *
+ * License: GPL-2.0+
+ */
+
+#include "xmc1xxx.S"
+
+ .macro write_block, nvmbase, dest, src, tmp, tmp2
+
+ ldr \tmp, [\src, #0x0]
+ str \tmp, [\dest, #0x0]
+ ldr \tmp, [\src, #0x4]
+ str \tmp, [\dest, #0x4]
+ ldr \tmp, [\src, #0x8]
+ str \tmp, [\dest, #0x8]
+ ldr \tmp, [\src, #0xc]
+ str \tmp, [\dest, #0xc]
+
+ busy_wait \nvmbase, \tmp, \tmp2
+
+ .endm
+
+
+ .macro write, nvmbase, dest, src, count, tmp, tmp2
+
+ movs \tmp, #NVMPROG_ACTION_WRITE_CONTINUOUS
+ strh \tmp, [\nvmbase, #NVMPROG]
+1001:
+ write_block \nvmbase, \dest, \src, \tmp, \tmp2
+
+ adds \dest, \dest, #NVM_BLOCK_SIZE
+ adds \src, \src, #NVM_BLOCK_SIZE
+ subs \count, \count, #1
+ cmp \count, #0
+ bgt 1001b
+
+ movs \tmp, #NVMPROG_ACTION_IDLE
+ strh \tmp, [\nvmbase, #NVMPROG]
+
+ .endm
+
+
+ /*
+ * r0 = 0x40050000
+ * r1 = e.g. 0x10001000
+ * r2 = e.g. 0x20000000
+ * r3 = e.g. 1
+ * NVMPROG.ACTION = 0x00
+ */
+write:
+ write r0, r1, r2, r3, r4, r5
+
+ bkpt #0
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/write.inc
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/write.inc b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/write.inc
new file mode 100755
index 0000000..8272bb7
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/write.inc
@@ -0,0 +1,4 @@
+/* Autogenerated with ../../../../src/helper/bin2char.sh */
+0xa1,0x24,0x84,0x80,0x14,0x68,0x0c,0x60,0x54,0x68,0x4c,0x60,0x94,0x68,0x8c,0x60,
+0xd4,0x68,0xcc,0x60,0x04,0x88,0x01,0x25,0x2c,0x40,0xac,0x42,0xfa,0xd0,0x10,0x31,
+0x10,0x32,0x01,0x3b,0x00,0x2b,0xed,0xdc,0x00,0x24,0x84,0x80,0x00,0xbe,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/xmc1xxx.S
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/xmc1xxx.S b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/xmc1xxx.S
new file mode 100755
index 0000000..dfe7d3f
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/flash/xmc1xxx/xmc1xxx.S
@@ -0,0 +1,46 @@
+/*
+ * Infineon XMC1000 flash
+ *
+ * Copyright (c) 2016 Andreas F�rber
+ *
+ * Based on XMC1100 AA-Step Reference Manual
+ *
+ * License: GPL-2.0+
+ */
+
+ .text
+ .syntax unified
+ .cpu cortex-m0
+ .thumb
+ .thumb_func
+
+#define NVMSTATUS 0x00
+#define NVMPROG 0x04
+#define NVMCONF 0x08
+
+#define NVMSTATUS_BUSY (1 << 0)
+#define NVMSTATUS_VERR_NOFAIL (0x0 << 2)
+#define NVMSTATUS_VERR_MASK (0x3 << 2)
+
+#define NVMPROG_ACTION_IDLE 0x00
+#define NVMPROG_ACTION_WRITE_CONTINUOUS 0xA1
+#define NVMPROG_ACTION_PAGE_ERASE_CONTINUOUS 0xA2
+#define NVMPROG_ACTION_VERIFY_CONTINUOUS 0xE0
+
+#define NVMCONF_HRLEV_NR (0x0 << 1)
+#define NVMCONF_HRLEV_HRE (0x2 << 1)
+#define NVMCONF_HRLEV_MASK (0x3 << 1)
+
+#define NVM_WORD_SIZE 4
+#define NVM_BLOCK_SIZE (4 * NVM_WORD_SIZE)
+#define NVM_PAGE_SIZE (16 * NVM_BLOCK_SIZE)
+
+ .macro busy_wait, nvmbase, tmp, tmp2
+1:
+ ldrh \tmp, [\nvmbase, #NVMSTATUS]
+ movs \tmp2, #NVMSTATUS_BUSY
+ ands \tmp, \tmp, \tmp2
+ cmp \tmp, \tmp2
+ beq 1b
+
+ .endm
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/watchdog/armv7m_kinetis_wdog.inc
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/watchdog/armv7m_kinetis_wdog.inc b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/watchdog/armv7m_kinetis_wdog.inc
new file mode 100755
index 0000000..4b6579e
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/watchdog/armv7m_kinetis_wdog.inc
@@ -0,0 +1,4 @@
+/* Autogenerated with ../../../src/helper/bin2char.sh */
+0x04,0x4b,0x05,0x4a,0xda,0x81,0x05,0x4a,0xda,0x81,0x01,0x24,0x1a,0x88,0xa2,0x43,
+0x1a,0x80,0x06,0xe0,0x00,0x20,0x05,0x40,0x20,0xc5,0x00,0x00,0x28,0xd9,0x00,0x00,
+0x00,0x00,0x00,0xbe,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/watchdog/armv7m_kinetis_wdog.s
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/watchdog/armv7m_kinetis_wdog.s b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/watchdog/armv7m_kinetis_wdog.s
new file mode 100755
index 0000000..bac924a
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/loaders/watchdog/armv7m_kinetis_wdog.s
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * Copyright (C) 2015 Tomas Vanek *
+ * vanekt@fbl.cz *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc. *
+ ***************************************************************************/
+
+/*
+ Disable watchdog for Kinetis Kx and KVx
+ Parameters: none
+ Used instruction set should work on both Cortex-M4 and M0+
+*/
+
+ .text
+ .syntax unified
+ .cpu cortex-m0
+ .thumb
+
+WDOG_ADDR = 0x40052000
+/* WDOG registers offsets */
+WDOG_STCTRLH = 0
+WDOG_UNLOCK = 0x0e
+
+WDOG_KEY1 = 0xc520
+WDOG_KEY2 = 0xd928
+
+ .thumb_func
+start:
+/* WDOG_UNLOCK = 0xC520 */
+ ldr r3, =WDOG_ADDR
+ ldr r2, =WDOG_KEY1
+ strh r2, [r3, WDOG_UNLOCK]
+/* WDOG_UNLOCK = 0xD928 */
+ ldr r2, =WDOG_KEY2
+ strh r2, [r3, WDOG_UNLOCK]
+/* WDOG_STCTRLH clear bit 0 */
+ movs r4, #1
+ ldrh r2, [r3, WDOG_STCTRLH]
+ bics r2, r4
+ strh r2, [r3, WDOG_STCTRLH]
+/* OpenOCD checks exit point address. Jump to the very end. */
+ b done
+
+ .pool
+
+/* Avoid padding at .text segment end. Otherwise exit point check fails. */
+ .skip ( . - start + 2) & 2, 0
+done:
+ bkpt #0
+
+ .end
+
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/remote_bitbang/remote_bitbang_sysfsgpio.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/remote_bitbang/remote_bitbang_sysfsgpio.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/remote_bitbang/remote_bitbang_sysfsgpio.c
new file mode 100755
index 0000000..e59a1bd
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/remote_bitbang/remote_bitbang_sysfsgpio.c
@@ -0,0 +1,408 @@
+/***************************************************************************
+ * Copyright (C) 2013 Paul Fertser <fe...@gmail.com> *
+ * Copyright (C) 2012 by Creative Product Design, marc @ cpdesign.com.au *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
+ ***************************************************************************/
+
+/*
+ This is a test application to be used as a remote bitbang server for
+ the OpenOCD remote_bitbang interface driver.
+
+ To compile run:
+ gcc -Wall -ansi -pedantic -std=c99 -o remote_bitbang_sysfsgpio remote_bitbang_sysfsgpio.c
+
+
+ Usage example:
+
+ On Raspberry Pi run:
+ socat TCP6-LISTEN:7777,fork EXEC:"sudo ./remote_bitbang_sysfsgpio tck 11 tms 25 tdo 9 tdi 10"
+
+ On host run:
+ openocd -c "interface remote_bitbang; remote_bitbang_host raspberrypi; remote_bitbang_port 7777" \
+ -f target/stm32f1x.cfg
+
+ Or if you want to test UNIX sockets, run both on Raspberry Pi:
+ socat UNIX-LISTEN:/tmp/remotebitbang-socket,fork EXEC:"sudo ./remote_bitbang_sysfsgpio tck 11 tms 25 tdo 9 tdi 10"
+ openocd -c "interface remote_bitbang; remote_bitbang_host /tmp/remotebitbang-socket" -f target/stm32f1x.cfg
+*/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#define LOG_ERROR(...) do { \
+ fprintf(stderr, __VA_ARGS__); \
+ fputc('\n', stderr); \
+ } while (0)
+#define LOG_WARNING(...) LOG_ERROR(__VA_ARGS__)
+
+#define ERROR_OK (-1)
+#define ERROR_FAIL (-2)
+#define ERROR_JTAG_INIT_FAILED ERROR_FAIL
+
+/*
+ * Helper func to determine if gpio number valid
+ *
+ * Assume here that there will be less than 1000 gpios on a system
+ */
+static int is_gpio_valid(int gpio)
+{
+ return gpio >= 0 && gpio < 1000;
+}
+
+/*
+ * Helper func to open, write to and close a file
+ * name and valstr must be null terminated.
+ *
+ * Returns negative on failure.
+ */
+static int open_write_close(const char *name, const char *valstr)
+{
+ int ret;
+ int fd = open(name, O_WRONLY);
+ if (fd < 0)
+ return fd;
+
+ ret = write(fd, valstr, strlen(valstr));
+ close(fd);
+
+ return ret;
+}
+
+/*
+ * Helper func to unexport gpio from sysfs
+ */
+static void unexport_sysfs_gpio(int gpio)
+{
+ char gpiostr[4];
+
+ if (!is_gpio_valid(gpio))
+ return;
+
+ snprintf(gpiostr, sizeof(gpiostr), "%d", gpio);
+ if (open_write_close("/sys/class/gpio/unexport", gpiostr) < 0)
+ LOG_ERROR("Couldn't unexport gpio %d", gpio);
+
+ return;
+}
+
+/*
+ * Exports and sets up direction for gpio.
+ * If the gpio is an output, it is initialized according to init_high,
+ * otherwise it is ignored.
+ *
+ * If the gpio is already exported we just show a warning and continue; if
+ * openocd happened to crash (or was killed by user) then the gpios will not
+ * have been cleaned up.
+ */
+static int setup_sysfs_gpio(int gpio, int is_output, int init_high)
+{
+ char buf[40];
+ char gpiostr[4];
+ int ret;
+
+ if (!is_gpio_valid(gpio))
+ return ERROR_OK;
+
+ snprintf(gpiostr, sizeof(gpiostr), "%d", gpio);
+ ret = open_write_close("/sys/class/gpio/export", gpiostr);
+ if (ret < 0) {
+ if (errno == EBUSY) {
+ LOG_WARNING("gpio %d is already exported", gpio);
+ } else {
+ LOG_ERROR("Couldn't export gpio %d", gpio);
+ perror("sysfsgpio: ");
+ return ERROR_FAIL;
+ }
+ }
+
+ snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction", gpio);
+ ret = open_write_close(buf, is_output ? (init_high ? "high" : "low") : "in");
+ if (ret < 0) {
+ LOG_ERROR("Couldn't set direction for gpio %d", gpio);
+ perror("sysfsgpio: ");
+ unexport_sysfs_gpio(gpio);
+ return ERROR_FAIL;
+ }
+
+ snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/value", gpio);
+ if (is_output)
+ ret = open(buf, O_WRONLY | O_NONBLOCK | O_SYNC);
+ else
+ ret = open(buf, O_RDONLY | O_NONBLOCK | O_SYNC);
+
+ if (ret < 0)
+ unexport_sysfs_gpio(gpio);
+
+ return ret;
+}
+
+/*
+ * file descriptors for /sys/class/gpio/gpioXX/value
+ * Set up during init.
+ */
+static int tck_fd = -1;
+static int tms_fd = -1;
+static int tdi_fd = -1;
+static int tdo_fd = -1;
+static int trst_fd = -1;
+static int srst_fd = -1;
+
+/*
+ * Bitbang interface read of TDO
+ *
+ * The sysfs value will read back either '0' or '1'. The trick here is to call
+ * lseek to bypass buffering in the sysfs kernel driver.
+ */
+static int sysfsgpio_read(void)
+{
+ char buf[1];
+
+ /* important to seek to signal sysfs of new read */
+ lseek(tdo_fd, 0, SEEK_SET);
+ int ret = read(tdo_fd, &buf, sizeof(buf));
+
+ if (ret < 0) {
+ LOG_WARNING("reading tdo failed");
+ return 0;
+ }
+
+ return buf[0];
+}
+
+/*
+ * Bitbang interface write of TCK, TMS, TDI
+ *
+ * Seeing as this is the only function where the outputs are changed,
+ * we can cache the old value to avoid needlessly writing it.
+ */
+static void sysfsgpio_write(int tck, int tms, int tdi)
+{
+ const char one[] = "1";
+ const char zero[] = "0";
+
+ static int last_tck;
+ static int last_tms;
+ static int last_tdi;
+
+ static int first_time;
+ size_t bytes_written;
+
+ if (!first_time) {
+ last_tck = !tck;
+ last_tms = !tms;
+ last_tdi = !tdi;
+ first_time = 1;
+ }
+
+ if (tdi != last_tdi) {
+ bytes_written = write(tdi_fd, tdi ? &one : &zero, 1);
+ if (bytes_written != 1)
+ LOG_WARNING("writing tdi failed");
+ }
+
+ if (tms != last_tms) {
+ bytes_written = write(tms_fd, tms ? &one : &zero, 1);
+ if (bytes_written != 1)
+ LOG_WARNING("writing tms failed");
+ }
+
+ /* write clk last */
+ if (tck != last_tck) {
+ bytes_written = write(tck_fd, tck ? &one : &zero, 1);
+ if (bytes_written != 1)
+ LOG_WARNING("writing tck failed");
+ }
+
+ last_tdi = tdi;
+ last_tms = tms;
+ last_tck = tck;
+}
+
+/*
+ * Bitbang interface to manipulate reset lines SRST and TRST
+ *
+ * (1) assert or (0) deassert reset lines
+ */
+static void sysfsgpio_reset(int trst, int srst)
+{
+ const char one[] = "1";
+ const char zero[] = "0";
+ size_t bytes_written;
+
+ /* assume active low */
+ if (srst_fd >= 0) {
+ bytes_written = write(srst_fd, srst ? &zero : &one, 1);
+ if (bytes_written != 1)
+ LOG_WARNING("writing srst failed");
+ }
+
+ /* assume active low */
+ if (trst_fd >= 0) {
+ bytes_written = write(trst_fd, trst ? &zero : &one, 1);
+ if (bytes_written != 1)
+ LOG_WARNING("writing trst failed");
+ }
+}
+
+/* gpio numbers for each gpio. Negative values are invalid */
+static int tck_gpio = -1;
+static int tms_gpio = -1;
+static int tdi_gpio = -1;
+static int tdo_gpio = -1;
+static int trst_gpio = -1;
+static int srst_gpio = -1;
+
+/* helper func to close and cleanup files only if they were valid/ used */
+static void cleanup_fd(int fd, int gpio)
+{
+ if (gpio >= 0) {
+ if (fd >= 0)
+ close(fd);
+
+ unexport_sysfs_gpio(gpio);
+ }
+}
+
+static void cleanup_all_fds(void)
+{
+ cleanup_fd(tck_fd, tck_gpio);
+ cleanup_fd(tms_fd, tms_gpio);
+ cleanup_fd(tdi_fd, tdi_gpio);
+ cleanup_fd(tdo_fd, tdo_gpio);
+ cleanup_fd(trst_fd, trst_gpio);
+ cleanup_fd(srst_fd, srst_gpio);
+}
+
+static void process_remote_protocol(void)
+{
+ int c;
+ while (1) {
+ c = getchar();
+ if (c == EOF || c == 'Q') /* Quit */
+ break;
+ else if (c == 'b' || c == 'B') /* Blink */
+ continue;
+ else if (c >= 'r' && c <= 'r' + 2) { /* Reset */
+ char d = c - 'r';
+ sysfsgpio_reset(!!(d & 2),
+ (d & 1));
+ } else if (c >= '0' && c <= '0' + 7) {/* Write */
+ char d = c - '0';
+ sysfsgpio_write(!!(d & 4),
+ !!(d & 2),
+ (d & 1));
+ } else if (c == 'R')
+ putchar(sysfsgpio_read());
+ else
+ LOG_ERROR("Unknown command '%c' received", c);
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ LOG_WARNING("SysfsGPIO remote_bitbang JTAG driver\n");
+
+ for (int i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "tck"))
+ tck_gpio = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "tms"))
+ tms_gpio = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "tdo"))
+ tdo_gpio = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "tdi"))
+ tdi_gpio = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "trst"))
+ trst_gpio = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "srst"))
+ srst_gpio = atoi(argv[++i]);
+ else {
+ LOG_ERROR("Usage:\n%s ((tck|tms|tdo|tdi|trst|srst) num)*", argv[0]);
+ return -1;
+ }
+ }
+
+ if (!(is_gpio_valid(tck_gpio)
+ && is_gpio_valid(tms_gpio)
+ && is_gpio_valid(tdi_gpio)
+ && is_gpio_valid(tdo_gpio))) {
+ if (!is_gpio_valid(tck_gpio))
+ LOG_ERROR("gpio num for tck is invalid");
+ if (!is_gpio_valid(tms_gpio))
+ LOG_ERROR("gpio num for tms is invalid");
+ if (!is_gpio_valid(tdo_gpio))
+ LOG_ERROR("gpio num for tdo is invalid");
+ if (!is_gpio_valid(tdi_gpio))
+ LOG_ERROR("gpio num for tdi is invalid");
+
+ LOG_ERROR("Require tck, tms, tdi and tdo gpios to all be specified");
+ return ERROR_JTAG_INIT_FAILED;
+ }
+
+ /*
+ * Configure TDO as an input, and TDI, TCK, TMS, TRST, SRST
+ * as outputs. Drive TDI and TCK low, and TMS/TRST/SRST high.
+ */
+ tck_fd = setup_sysfs_gpio(tck_gpio, 1, 0);
+ if (tck_fd < 0)
+ goto out_error;
+
+ tms_fd = setup_sysfs_gpio(tms_gpio, 1, 1);
+ if (tms_fd < 0)
+ goto out_error;
+
+ tdi_fd = setup_sysfs_gpio(tdi_gpio, 1, 0);
+ if (tdi_fd < 0)
+ goto out_error;
+
+ tdo_fd = setup_sysfs_gpio(tdo_gpio, 0, 0);
+ if (tdo_fd < 0)
+ goto out_error;
+
+ /* assume active low */
+ if (trst_gpio > 0) {
+ trst_fd = setup_sysfs_gpio(trst_gpio, 1, 1);
+ if (trst_fd < 0)
+ goto out_error;
+ }
+
+ /* assume active low */
+ if (srst_gpio > 0) {
+ srst_fd = setup_sysfs_gpio(srst_gpio, 1, 1);
+ if (srst_fd < 0)
+ goto out_error;
+ }
+
+ LOG_WARNING("SysfsGPIO nums: tck = %d, tms = %d, tdi = %d, tdo = %d",
+ tck_gpio, tms_gpio, tdi_gpio, tdo_gpio);
+ LOG_WARNING("SysfsGPIO num: srst = %d", srst_gpio);
+ LOG_WARNING("SysfsGPIO num: trst = %d", trst_gpio);
+
+ setvbuf(stdout, NULL, _IONBF, 0);
+ process_remote_protocol();
+
+ cleanup_all_fds();
+ return 0;
+out_error:
+ cleanup_all_fds();
+ return ERROR_JTAG_INIT_FAILED;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rpc_examples/ocd_rpc_example.py
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rpc_examples/ocd_rpc_example.py b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rpc_examples/ocd_rpc_example.py
new file mode 100755
index 0000000..6c8529c
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rpc_examples/ocd_rpc_example.py
@@ -0,0 +1,145 @@
+#!/usr/bin/env python3
+"""
+OpenOCD RPC example, covered by GNU GPLv3 or later
+Copyright (C) 2014 Andreas Ortmann (ortmann@finf.uni-hannover.de)
+
+
+Example output:
+./ocd_rpc_example.py
+echo says hi!
+
+target state: halted
+target halted due to debug-request, current mode: Thread
+xPSR: 0x01000000 pc: 0x00000188 msp: 0x10000fd8
+
+variable @ 0x10000000: 0x01c9c380
+
+variable @ 0x10000000: 0xdeadc0de
+
+memory (before): ['0xdeadc0de', '0x00000011', '0xaaaaaaaa', '0x00000023',
+'0x00000042', '0x0000ffff']
+
+memory (after): ['0x00000001', '0x00000000', '0xaaaaaaaa', '0x00000023',
+'0x00000042', '0x0000ffff']
+"""
+
+import socket
+import itertools
+
+def strToHex(data):
+ return map(strToHex, data) if isinstance(data, list) else int(data, 16)
+
+def hexify(data):
+ return "<None>" if data is None else ("0x%08x" % data)
+
+def compareData(a, b):
+ for i, j, num in zip(a, b, itertools.count(0)):
+ if i != j:
+ print("difference at %d: %s != %s" % (num, hexify(i), hexify(j)))
+
+
+class OpenOcd:
+ COMMAND_TOKEN = '\x1a'
+ def __init__(self, verbose=False):
+ self.verbose = verbose
+ self.tclRpcIp = "127.0.0.1"
+ self.tclRpcPort = 6666
+ self.bufferSize = 4096
+
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ def __enter__(self):
+ self.sock.connect((self.tclRpcIp, self.tclRpcPort))
+ return self
+
+ def __exit__(self, type, value, traceback):
+ try:
+ self.send("exit")
+ finally:
+ self.sock.close()
+
+ def send(self, cmd):
+ """Send a command string to TCL RPC. Return the result that was read."""
+ data = (cmd + OpenOcd.COMMAND_TOKEN).encode("utf-8")
+ if self.verbose:
+ print("<- ", data)
+
+ self.sock.send(data)
+ return self._recv()
+
+ def _recv(self):
+ """Read from the stream until the token (\x1a) was received."""
+ data = bytes()
+ while True:
+ chunk = self.sock.recv(self.bufferSize)
+ data += chunk
+ if bytes(OpenOcd.COMMAND_TOKEN, encoding="utf-8") in chunk:
+ break
+
+ if self.verbose:
+ print("-> ", data)
+
+ data = data.decode("utf-8").strip()
+ data = data[:-1] # strip trailing \x1a
+
+ return data
+
+ def readVariable(self, address):
+ raw = self.send("ocd_mdw 0x%x" % address).split(": ")
+ return None if (len(raw) < 2) else strToHex(raw[1])
+
+ def readMemory(self, wordLen, address, n):
+ self.send("array unset output") # better to clear the array before
+ self.send("mem2array output %d 0x%x %d" % (wordLen, address, n))
+
+ output = self.send("ocd_echo $output").split(" ")
+
+ return [int(output[2*i+1]) for i in range(len(output)//2)]
+
+ def writeVariable(self, address, value):
+ assert value is not None
+ self.send("mww 0x%x 0x%x" % (address, value))
+
+ def writeMemory(self, wordLen, address, n, data):
+ array = " ".join(["%d 0x%x" % (a, b) for a, b in enumerate(data)])
+
+ self.send("array unset 1986\u0432\u04351\u0442") # better to clear the array before
+ self.send("array set 1986\u0432\u04351\u0442 { %s }" % array)
+ self.send("array2mem 1986\u0432\u04351\u0442 0x%x %s %d" % (wordLen, address, n))
+
+if __name__ == "__main__":
+
+ def show(*args):
+ print(*args, end="\n\n")
+
+ with OpenOcd() as ocd:
+ ocd.send("reset")
+
+ show(ocd.send("ocd_echo \"echo says hi!\"")[:-1])
+ show(ocd.send("capture \"ocd_halt\"")[:-1])
+
+ # Read the first few words at the RAM region (put starting adress of RAM
+ # region into 'addr')
+ addr = 0x10000000
+
+ value = ocd.readVariable(addr)
+ show("variable @ %s: %s" % (hexify(addr), hexify(value)))
+
+ ocd.writeVariable(addr, 0xdeadc0de)
+ show("variable @ %s: %s" % (hexify(addr), hexify(ocd.readVariable(addr))))
+
+ data = [1, 0, 0xaaaaaaaa, 0x23, 0x42, 0xffff]
+ wordlen = 32
+ n = len(data)
+
+ read = ocd.readMemory(wordlen, addr, n)
+ show("memory (before):", list(map(hexify, read)))
+
+ ocd.writeMemory(wordlen, addr, n, data)
+
+ read = ocd.readMemory(wordlen, addr, n)
+ show("memory (after):", list(map(hexify, read)))
+
+ compareData(read, data)
+
+ ocd.send("resume")
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rpc_examples/ocdrpc.hs
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rpc_examples/ocdrpc.hs b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rpc_examples/ocdrpc.hs
new file mode 100755
index 0000000..27fb1ae
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rpc_examples/ocdrpc.hs
@@ -0,0 +1,56 @@
+-- OpenOCD RPC example, covered by GNU GPLv3 or later
+-- Copyright (C) 2014 Paul Fertser
+--
+-- Example output:
+-- $ ./ocdrpc
+-- Halting the target, full log output captured:
+-- target state: halted
+-- target halted due to debug-request, current mode: Thread
+-- xPSR: 0x21000000 pc: 0x00003352 msp: 0x20000fe8
+--
+-- Read memory, parse the result and show as a list of strings:
+-- ["0x20001000","0x0000334d","0x00002abb","0x0000118f","0x00002707","0x00002707","0x00002707","0x00000000","0x00000000","0x00000000","0x00000000","0x00002707","0x00002707","0x00000000","0x00002707","0x00002781"]
+-- Resuming
+
+{-# LANGUAGE OverloadedStrings #-}
+module Main where
+
+import Prelude
+import Control.Applicative
+import Network.Socket
+import System.IO.Streams.Core hiding (connect)
+import System.IO.Streams.Network
+import System.IO.Streams.Attoparsec
+import Data.Attoparsec.ByteString.Char8
+import Data.Attoparsec.Combinator
+import Data.ByteString.Char8 hiding (putStrLn, concat, map)
+import Text.Printf
+
+ocdReply = manyTill anyChar (char '\x1a')
+
+ocdExec (oistream, oostream) command = do
+ write (Just $ pack $ command ++ "\x1a") oostream
+ parseFromStream ocdReply oistream
+
+-- For each line: dispose of address, then match hex values
+mdwParser = (manyTill anyChar (string ": ") *>
+ hexadecimal `sepBy` char ' ')
+ `sepBy` string " \n"
+
+ocdMdw :: (InputStream ByteString, OutputStream ByteString) -> Integer -> Integer -> IO [Integer]
+ocdMdw s start count = do
+ s <- ocdExec s $ "ocd_mdw " ++ show start ++ " " ++ show count
+ case parseOnly mdwParser (pack s) of
+ Right r -> return $ concat r
+
+main = do
+ osock <- socket AF_INET Stream defaultProtocol
+ haddr <- inet_addr "127.0.0.1"
+ connect osock (SockAddrInet 6666 haddr)
+ ostreams <- socketToStreams osock
+ putStrLn "Halting the target, full log output captured:"
+ ocdExec ostreams "capture \"halt\"" >>= putStrLn
+ putStrLn "Read memory, parse the result and show as a list of strings:"
+ ocdMdw ostreams 0 16 >>= putStrLn . (show :: [String] -> String) . map (printf "0x%08x")
+ putStrLn "Resuming"
+ ocdExec ostreams "resume"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/e302582d/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rtos-helpers/FreeRTOS-openocd.c
----------------------------------------------------------------------
diff --git a/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rtos-helpers/FreeRTOS-openocd.c b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rtos-helpers/FreeRTOS-openocd.c
new file mode 100755
index 0000000..81a3ab7
--- /dev/null
+++ b/docs/os/tutorials/downloads/openocd-code-89bf96ffe6ac66c80407af8383b9d5adc0dc35f4/contrib/rtos-helpers/FreeRTOS-openocd.c
@@ -0,0 +1,20 @@
+/*
+ * Since at least FreeRTOS V7.5.3 uxTopUsedPriority is no longer
+ * present in the kernel, so it has to be supplied by other means for
+ * OpenOCD's threads awareness.
+ *
+ * Add this file to your project, and, if you're using --gc-sections,
+ * ``--undefined=uxTopUsedPriority'' (or
+ * ``-Wl,--undefined=uxTopUsedPriority'' when using gcc for final
+ * linking) to your LDFLAGS; same with all the other symbols you need.
+ */
+
+#include "FreeRTOS.h"
+
+#ifdef __GNUC__
+#define USED __attribute__((used))
+#else
+#define USED
+#endif
+
+const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1;