Skip to content

Commit

Permalink
import nrf52832
Browse files Browse the repository at this point in the history
  • Loading branch information
juju2013 committed Sep 12, 2018
1 parent 501d747 commit 3cc48be
Show file tree
Hide file tree
Showing 7 changed files with 699 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mecrisp-stellaris-source/nrf52832/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@

ARMGNU?=arm-none-eabi

COPS = -Wall -O0 -nostdlib -nostartfiles -ffreestanding -save-temps
AOPS = --warn --fatal-warnings -g

all : mecrisp-stellaris-nrf52832.bin

mecrisp-stellaris-nrf52832.o : mecrisp-stellaris-nrf52832.s
$(ARMGNU)-as ${AOPS} mecrisp-stellaris-nrf52832.s -o mecrisp-stellaris-nrf52832.o

mecrisp-stellaris-nrf52832.bin : memmap mecrisp-stellaris-nrf52832.o
$(ARMGNU)-ld -o mecrisp-stellaris-nrf52832.elf -T memmap mecrisp-stellaris-nrf52832.o
$(ARMGNU)-objdump -D mecrisp-stellaris-nrf52832.elf > mecrisp-stellaris-nrf52832.list
$(ARMGNU)-objcopy mecrisp-stellaris-nrf52832.elf mecrisp-stellaris-nrf52832.bin -O binary
$(ARMGNU)-objcopy mecrisp-stellaris-nrf52832.elf mecrisp-stellaris-nrf52832.hex -O ihex

clean:
rm -f *.bin
rm -f *.o
rm -f *.elf
rm -f *.list
rm -f *.hex
218 changes: 218 additions & 0 deletions mecrisp-stellaris-source/nrf52832/flash.s
Original file line number Diff line number Diff line change
@@ -0,0 1,218 @@
@
@ Mecrisp-Stellaris - A native code Forth implementation for ARM-Cortex M microcontrollers
@ Copyright (C) 2013 Matthias Koch
@
@ 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 3 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, see <http://www.gnu.org/licenses/>.
@

@ Schreiben und Löschen des Flash-Speichers im STM32F051.

@ In diesem Chip gibt es Flashschreibzugriffe mit wählbarer Breite -
@ so ist es diesmal ganz komfortabel. Leider gibt es nur weniger große
@ Sektoren, die getrennt gelöscht werden können.

@ Write and Erase Flash in STM32F051.
@ Porting: Rewrite this ! You need hflash! and - as far as possible - cflash!


.equ NVMC, 0x4001E000

.equ NVM_READY, NVMC 0x400 @ Ready Flag
.equ NVM_CONFIG, NVMC 0x504 @ Configuration register
.equ NVM_ERASEPAGE, NVMC 0x508 @ Register for erasing a page in code region 1

@.equ FLASH_ACR, FLASH_Base 0x00 @ Flash Access Control Register
@.equ FLASH_KEYR, FLASH_Base 0x04 @ Flash Key Register
@.equ FLASH_SR, FLASH_Base 0x0C @ Flash Status Register
@.equ FLASH_CR, FLASH_Base 0x10 @ Flash Control Register
@.equ FLASH_AR, FLASH_Base 0x14 @ Flash Address Register
@.equ FLASH_OBR, FLASH_Base 0x1C @ Flash Option Byte Register

@ -----------------------------------------------------------------------------
Wortbirne Flag_visible, "hflash!" @ ( x Addr -- )
@ Schreibt an die auf 2 gerade Adresse in den Flash.
h_flashkomma:
@ -----------------------------------------------------------------------------
popda r0 @ Adresse
popda r1 @ Inhalt.

@ Ist die gewünschte Stelle im Flash-Dictionary ? Außerhalb des Forth-Kerns ?
ldr r3, =Kernschutzadresse
cmp r0, r3
blo 3f

ldr r3, =FlashDictionaryEnde
cmp r0, r3
bhs 3f


@ Prüfe Inhalt. Schreibe nur, wenn es NICHT -1 ist.
ldr r3, =0xFFFF
ands r1, r3 @ High-Halfword der Daten wegmaskieren
cmp r1, r3
beq 2f @ Fertig ohne zu Schreiben

@ Prüfe die Adresse: Sie muss auf 2 gerade sein:
movs r2, #1
ands r2, r0
cmp r2, #0
bne 3f

@ Ist an der gewünschten Stelle -1 im Speicher ?
ldrh r2, [r0]
cmp r2, r3
bne 3f

@ Okay, alle Proben bestanden.

@ Im STM32F051 ist der Flash-Speicher gespiegelt, die wirkliche Adresse liegt weiter hinten !
@ Flash memory is mirrored, use true address later for write
@ldr r2, =0x08000000
@adds r0, r2

@ Bereit zum Schreiben !

@ Unlock Flash Control
@ldr r2, =FLASH_KEYR
@ldr r3, =0x45670123
@str r3, [r2]
@ldr r3, =0xCDEF89AB
@str r3, [r2]

@ Enable write
@ldr r2, =FLASH_CR
ldr r2, =NVM_CONFIG
movs r3, #1 @ Select Flash programming
str r3, [r2]

@ Write to Flash !
@ NRF requires 32-bit write
@ If low halfword assume high halfword =0xFFFF
@ if high halfword reflash low halfword as well

movs r3, #2
ands r3, r0
beq 4f @ low halfword
eors r0, r3
ldrh r3, [r0]
lsls r1, #16
orrs r1, r3
b 5f
4: ldr r3, =0xFFFF0000
orrs r1, r3
5: str r1, [r0]

@ Wait for Flash BUSY Flag to be cleared
@ldr r2, =FLASH_SR
ldr r2, =NVM_READY

1: ldr r3, [r2]
movs r0, #1
ands r0, r3
beq 1b

@ Lock Flash after finishing this
@ldr r2, =FLASH_CR
ldr r2, =NVM_CONFIG
@movs r3, #0x80
movs r3, #0x00
str r3, [r2]

2:bx lr
3:Fehler_Quit "Wrong address or data for writing flash !"


@ -----------------------------------------------------------------------------
Wortbirne Flag_visible, "flashpageerase" @ ( Addr -- )
@ Löscht einen 1kb großen Flashblock Deletes one 1kb Flash page
flashpageerase:
@ -----------------------------------------------------------------------------
push {r0, r1, r2, r3, lr}
popda r0 @ Adresse zum Löschen holen Fetch address to erase.

@ Ist die gewünschte Stelle im Flash-Dictionary ? Außerhalb des Forth-Kerns ? Don't erase Forth core.
ldr r3, =Kernschutzadresse
cmp r0, r3
blo 2f

@ldr r2, =FLASH_KEYR
@ldr r3, =0x45670123
@str r3, [r2]
@ldr r3, =0xCDEF89AB
@str r3, [r2]

@ Enable erase
@ldr r2, =FLASH_CR
ldr r2, =NVM_CONFIG
movs r3, #2 @ Set Erase bit
str r3, [r2]

@ Set page to erase
@ldr r2, =FLASH_AR
ldr r2, =NVM_ERASEPAGE
str r0, [r2]

@ Start erasing
@ldr r2, =FLASH_CR
@movs r3, #0x42 @ Start Erase
@str r3, [r2]

@ Wait for Flash BUSY Flag to be cleared
@ldr r2, =FLASH_SR
ldr r2, =NVM_READY
1: ldr r3, [r2]
movs r0, #1
ands r0, r3
beq 1b

@ Lock Flash after finishing this
@ldr r2, =FLASH_CR
ldr r2, =NVM_CONFIG
@movs r3, #0x80
movs r3, #0x00
str r3, [r2]

2:pop {r0, r1, r2, r3, pc}

@ -----------------------------------------------------------------------------
Wortbirne Flag_visible, "eraseflash" @ ( -- )
@ Löscht den gesamten Inhalt des Flashdictionaries.
@ -----------------------------------------------------------------------------
ldr r0, =FlashDictionaryAnfang
eraseflash_intern:
cpsid i
ldr r1, =FlashDictionaryEnde
ldr r2, =0xFFFF

1: ldrh r3, [r0]
cmp r3, r2
beq 2f
pushda r0
dup
write "Erase block at "
bl hexdot
writeln " from Flash"
bl flashpageerase
2: adds r0, #2
cmp r0, r1
bne 1b
writeln "Finished. Reset !"
bl Restart

@ -----------------------------------------------------------------------------
Wortbirne Flag_visible, "eraseflashfrom" @ ( Addr -- )
@ Beginnt an der angegebenen Adresse mit dem Löschen des Dictionaries.
@ -----------------------------------------------------------------------------
popda r0
b.n eraseflash_intern
70 changes: 70 additions & 0 deletions mecrisp-stellaris-source/nrf52832/interrupts.s
Original file line number Diff line number Diff line change
@@ -0,0 1,70 @@
@
@ Mecrisp-Stellaris - A native code Forth implementation for ARM-Cortex M microcontrollers
@ Copyright (C) 2013 Matthias Koch
@ Copyright (C) 2018 juju2013@github
@
@ 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 3 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, see <http://www.gnu.org/licenses/>.
@

@ Routinen für die Interrupthandler, die zur Laufzeit neu gesetzt werden können.
@ Code for interrupt handlers that are exchangeable on the fly

@------------------------------------------------------------------------------
@ nRF52 has 1 interrupt by peripheric, which may share a same ID
@ and the ID is connected to NVIC
@ All interrupt handlers work the same way and are generated with a macro:
@------------------------------------------------------------------------------

interrupt NVIC0
interrupt NVIC1
interrupt NVIC2
interrupt NVIC3
interrupt NVIC4
interrupt NVIC5
interrupt NVIC6
interrupt NVIC7
interrupt NVIC8
interrupt NVIC9
interrupt NVIC10
interrupt NVIC11
interrupt NVIC12
interrupt NVIC13
interrupt NVIC14
interrupt NVIC15
interrupt NVIC16
interrupt NVIC17
interrupt NVIC18
interrupt NVIC19
interrupt NVIC20
interrupt NVIC21
interrupt NVIC22
interrupt NVIC23
interrupt NVIC24
interrupt NVIC25
interrupt NVIC26
interrupt NVIC27
interrupt NVIC28
interrupt NVIC29
interrupt NVIC30
interrupt NVIC31
interrupt NVIC32
interrupt NVIC33
interrupt NVIC34
interrupt NVIC35
interrupt NVIC36
interrupt NVIC37
interrupt NVIC38

.ltorg
@------------------------------------------------------------------------------
Loading

0 comments on commit 3cc48be

Please sign in to comment.