added licensing
parent
5c5c93db40
commit
603d04992c
@ -1,11 +1,49 @@
|
||||
/**
|
||||
* @file flash.h
|
||||
* Provides functionality for using an external SPI flash
|
||||
*
|
||||
* Copyright (C) 2018 Clyne Sullivan
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FLASH_H_
|
||||
#define FLASH_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Initializes GPIO ports and variables for flash IO. Must be called before
|
||||
* any reads or writes.
|
||||
*/
|
||||
void flash_init(void);
|
||||
|
||||
/**
|
||||
* Does a blocking read of the flash chip into a pre-allocated buffer.
|
||||
* @param buf the buffer to read in to
|
||||
* @param addr the address to read from in the flash chip
|
||||
* @param count the number of bytes to read from the chip
|
||||
*/
|
||||
void flash_read(char *buf, uint32_t addr, unsigned int count);
|
||||
|
||||
/**
|
||||
* Does a blocking write to the flash chip using data from a pre-allocated
|
||||
* buffer.
|
||||
* @param buf the buffer to read data from
|
||||
* @param addr the address to write to in the flash chip
|
||||
* @param count the number of bytes to write to the chip
|
||||
*/
|
||||
void flash_write(const char *buf, uint32_t addr, unsigned int count);
|
||||
|
||||
#endif // FLASH_H_
|
||||
|
@ -1,8 +1,51 @@
|
||||
/**
|
||||
* @file stdlib.h
|
||||
* Provides missing C standard library functions
|
||||
* The newlib versions of these calls are not being used due to dependence on
|
||||
* unsupported system calls.
|
||||
*
|
||||
* Copyright (C) 2018 Clyne Sullivan
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef STDLIB_H_
|
||||
#define STDLIB_H_
|
||||
|
||||
/**
|
||||
* Parses a formatted string, storing the result in the given buffer.
|
||||
* @param buf the buffer to print the parsed string to
|
||||
* @param max the maximum number of bytes to write to the buffer
|
||||
* @param format the format string
|
||||
* @return a pointer to the buffer
|
||||
*/
|
||||
char *snprintf(char *buf, unsigned int max, const char *format, ...);
|
||||
|
||||
/**
|
||||
* Attempts to convert the given string to a float.
|
||||
* @param s the string to convert
|
||||
* @param endptr if not-null, set to the address of the character after the
|
||||
* number
|
||||
* @return the resulting float, or zero if an error occurred
|
||||
*/
|
||||
float strtof(const char *s, char **endptr);
|
||||
|
||||
/**
|
||||
* Attempts to convert the given string to an integer.
|
||||
* @param s the string to convert
|
||||
* @return the resulting integer, or zero if an error occurred
|
||||
*/
|
||||
int atoi(const char *s);
|
||||
|
||||
#endif // STDLIB_H_
|
||||
|
@ -1 +0,0 @@
|
||||
print "Hello, world!"
|
@ -0,0 +1,29 @@
|
||||
print("Hello.\n")
|
||||
|
||||
fg = 32767
|
||||
|
||||
# draw bg, lines
|
||||
rect(50, 50, 380, 220, 6375)
|
||||
line(50, 160, 430, 160, fg)
|
||||
line(240, 50, 240, 270, fg)
|
||||
|
||||
x = 50
|
||||
while (x <= 430) {
|
||||
line(x, 170, x, 150, fg)
|
||||
x = x + 20
|
||||
}
|
||||
|
||||
y = 50
|
||||
while (y <= 270) {
|
||||
line(230, y, 250, y, fg)
|
||||
y = y + 20
|
||||
}
|
||||
|
||||
while (1) {
|
||||
x = rand(379) + 50
|
||||
y = rand(219) + 50
|
||||
i = 50 + rand(379)
|
||||
j = 50 + rand(219)
|
||||
|
||||
line(x, y, i, j, 511)
|
||||
}
|
Binary file not shown.
@ -1,162 +1,82 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
**
|
||||
|
||||
** File : LinkerScript.ld
|
||||
**
|
||||
** Abstract : Linker script for STM32L476RGTx Device with
|
||||
** 1024KByte FLASH, 96KByte RAM
|
||||
**
|
||||
** Set heap size, stack size and stack location according
|
||||
** to application requirements.
|
||||
**
|
||||
** Set memory bank area and size if external memory is used.
|
||||
**
|
||||
** Target : STMicroelectronics STM32
|
||||
**
|
||||
**
|
||||
** Distribution: The file is distributed as is, without any warranty
|
||||
** of any kind.
|
||||
**
|
||||
** (c)Copyright Ac6.
|
||||
** You may use this file as-is or modify it according to the needs of your
|
||||
** project. Distribution of this file (unmodified or modified) is not
|
||||
** permitted. Ac6 permit registered System Workbench for MCU users the
|
||||
** rights to distribute the assembled, compiled & linked contents of this
|
||||
** file as part of an application binary file, provided that it is built
|
||||
** using the System Workbench for MCU toolchain.
|
||||
**
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
/* Entry Point */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* Highest address of the user mode stack */
|
||||
_estack = 0x20018000; /* end of RAM */
|
||||
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 1024K
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
|
||||
}
|
||||
|
||||
/* Define output sections */
|
||||
SECTIONS
|
||||
{
|
||||
/* The startup code goes first into FLASH */
|
||||
.isr_vector :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
KEEP(*(.isr_vector)) /* Startup code */
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
|
||||
/* The program code and other data goes into FLASH */
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
*(.text) /* .text sections (code) */
|
||||
*(.text*) /* .text* sections (code) */
|
||||
*(.glue_7) /* glue arm to thumb code */
|
||||
*(.glue_7t) /* glue thumb to arm code */
|
||||
*(.eh_frame)
|
||||
|
||||
KEEP (*(.init))
|
||||
KEEP (*(.fini))
|
||||
|
||||
. = ALIGN(8);
|
||||
_etext = .; /* define a global symbols at end of code */
|
||||
} >FLASH
|
||||
|
||||
/* Constant data goes into FLASH */
|
||||
.rodata :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
*(.rodata) /* .rodata sections (constants, strings, etc.) */
|
||||
*(.rodata*) /* .rodata* sections (constants, strings, etc.) */
|
||||
. = ALIGN(8);
|
||||
} >FLASH
|
||||
|
||||
.ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH
|
||||
.ARM : {
|
||||
__exidx_start = .;
|
||||
*(.ARM.exidx*)
|
||||
__exidx_end = .;
|
||||
} >FLASH
|
||||
|
||||
.preinit_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__preinit_array_start = .);
|
||||
KEEP (*(.preinit_array*))
|
||||
PROVIDE_HIDDEN (__preinit_array_end = .);
|
||||
} >FLASH
|
||||
.init_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__init_array_start = .);
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array*))
|
||||
PROVIDE_HIDDEN (__init_array_end = .);
|
||||
} >FLASH
|
||||
.fini_array :
|
||||
{
|
||||
PROVIDE_HIDDEN (__fini_array_start = .);
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
KEEP (*(.fini_array*))
|
||||
PROVIDE_HIDDEN (__fini_array_end = .);
|
||||
} >FLASH
|
||||
|
||||
/* used by the startup to initialize data */
|
||||
_sidata = LOADADDR(.data);
|
||||
|
||||
/* Initialized data sections goes into RAM, load LMA copy after code */
|
||||
.data :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
_sdata = .; /* create a global symbol at data start */
|
||||
*(.data) /* .data sections */
|
||||
*(.data*) /* .data* sections */
|
||||
|
||||
. = ALIGN(8);
|
||||
_edata = .; /* define a global symbol at data end */
|
||||
} >RAM AT> FLASH
|
||||
|
||||
|
||||
/* Uninitialized data section */
|
||||
. = ALIGN(4);
|
||||
.bss :
|
||||
{
|
||||
/* This is used by the startup in order to initialize the .bss secion */
|
||||
_sbss = .; /* define a global symbol at bss start */
|
||||
__bss_start__ = _sbss;
|
||||
*(.bss)
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
|
||||
. = ALIGN(4);
|
||||
_ebss = .; /* define a global symbol at bss end */
|
||||
__bss_end__ = _ebss;
|
||||
} >RAM
|
||||
|
||||
/* User_heap_stack section, used to check that there is enough RAM left */
|
||||
._user_heap_stack :
|
||||
{
|
||||
. = ALIGN(8);
|
||||
*(._user_heap_stack)
|
||||
. = ALIGN(8);
|
||||
} >RAM
|
||||
|
||||
|
||||
|
||||
/* Remove information from the standard libraries */
|
||||
/DISCARD/ :
|
||||
{
|
||||
libc.a ( * )
|
||||
libm.a ( * )
|
||||
libgcc.a ( * )
|
||||
}
|
||||
|
||||
.ARM.attributes 0 : { *(.ARM.attributes) }
|
||||
}
|
||||
|
||||
/**
|
||||
* @file linker.ld
|
||||
*
|
||||
* Copyright (C) 2018 Clyne Sullivan
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* enter at the reset handler */
|
||||
ENTRY(Reset_Handler)
|
||||
|
||||
/* description of memory regions */
|
||||
MEMORY {
|
||||
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
|
||||
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 96K
|
||||
}
|
||||
|
||||
/* description of ELF sections */
|
||||
SECTIONS {
|
||||
/* keep startup code at beginning */
|
||||
.isr_vector : {
|
||||
. = ALIGN(8);
|
||||
KEEP(*(.isr_vector))
|
||||
. = ALIGN(8);
|
||||
} > FLASH
|
||||
|
||||
/* code sections */
|
||||
.text : {
|
||||
. = ALIGN(8);
|
||||
*(.text)
|
||||
. = ALIGN(8);
|
||||
} > FLASH
|
||||
|
||||
/* readonly data */
|
||||
.rodata : {
|
||||
. = ALIGN(8);
|
||||
*(.rodata)
|
||||
. = ALIGN(8);
|
||||
} > FLASH
|
||||
|
||||
/* init_array/fini_array (TODO understand this) */
|
||||
.init_array : {
|
||||
PROVIDE_HIDDEN(__init_array_start = .);
|
||||
KEEP(*(.init_array))
|
||||
PROVIDE_HIDDEN(__init_array_end = .);
|
||||
} > FLASH
|
||||
|
||||
.fini_array : {
|
||||
PROVIDE_HIDDEN(__fini_array_start = .);
|
||||
KEEP(*(.fini_array))
|
||||
PROVIDE_HIDDEN(__fini_array_end = .);
|
||||
} > FLASH
|
||||
|
||||
/* initialized data */
|
||||
_sidata = LOADADDR(.data);
|
||||
.data : {
|
||||
. = ALIGN(8);
|
||||
_sdata = .;
|
||||
*(.data)
|
||||
. = ALIGN(8);
|
||||
_edata = .;
|
||||
} > RAM AT > FLASH
|
||||
|
||||
/* uninitialized data */
|
||||
.bss : {
|
||||
. = ALIGN(8);
|
||||
__bss_start__ = .;
|
||||
*(.bss)
|
||||
__bss_end__ = .;
|
||||
} > RAM
|
||||
}
|
||||
|
@ -1,4 +1,23 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# @file run.sh
|
||||
# Starts openocd and connects gdb to the target, for programming/debugging
|
||||
#
|
||||
# Copyright (C) 2018 Clyne Sullivan
|
||||
#
|
||||
# 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 <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
openocd -f /usr/share/openocd/scripts/board/st_nucleo_l476rg.cfg > /dev/null &
|
||||
gdb-multiarch -iex "target remote localhost:3333" out/main.elf
|
||||
|
@ -0,0 +1,110 @@
|
||||
#include <stm32l476xx.h>
|
||||
#include <gpio.h>
|
||||
#include <clock.h>
|
||||
|
||||
#define READ 0x03
|
||||
#define WRITE 0x02
|
||||
#define WREN 0x06
|
||||
#define WRDS 0x04
|
||||
|
||||
#define SCK GPIO_PORT(C, 9)
|
||||
#define SI GPIO_PORT(B, 8)
|
||||
#define SO GPIO_PORT(B, 9)
|
||||
#define CS GPIO_PORT(C, 4)
|
||||
|
||||
void flash_out(uint8_t);
|
||||
uint8_t flash_in(void);
|
||||
|
||||
void flash_init(void)
|
||||
{
|
||||
gpio_mode(SCK, OUTPUT);
|
||||
gpio_mode(SI, OUTPUT);
|
||||
gpio_mode(CS, OUTPUT);
|
||||
gpio_mode(SO, OUTPUT);
|
||||
gpio_dout(SO, 0);
|
||||
gpio_mode(SO, INPUT);
|
||||
gpio_dout(CS, 1);
|
||||
gpio_dout(SCK, 0);
|
||||
gpio_dout(SI, 0);
|
||||
|
||||
//RCC->AHB3ENR |= RCC_AHB3ENR_QSPIEN;
|
||||
|
||||
//// 10MHz operation, per datasheet
|
||||
//QUADSPI->CR &= ~(0xFF << QUADSPI_CR_PRESCALER_Pos);
|
||||
//QUADSPI->CR |= 7 << QUADSPI_CR_PRESCALER_Pos;
|
||||
|
||||
//// pick FSEL! 0=1, 1=2
|
||||
|
||||
//// FSIZE = 16, 2^17 bits = 1Mb
|
||||
//QUADSPI->DCR = (16 << QUADSPI_DCR_FSIZE_Pos);
|
||||
|
||||
//// Memmap mode, single-spi
|
||||
//QUADSPI->CCR = (3 << QUADSPI_CCR_FMODE_Pos) | (1 << QUADSPI_CCR_DMODE_Pos)
|
||||
// | (2 << QUADSPI_CCR_ADSIZE_Pos) | (1 << QUADSPI_CCR_ADMODE_Pos)
|
||||
// | (1 << QUADSPI_CCR_IMODE_Pos);
|
||||
//// TODO CCR also takes instruction byte
|
||||
//QUADSPI->CCR |= (READ << QUADSPI_CCR_INSTRUCTION_Pos);
|
||||
|
||||
//QUADSPI->CR |= QUADSPI_CR_EN;
|
||||
}
|
||||
|
||||
void flash_out(uint8_t byte)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
gpio_dout(SI, (byte & (1 << (7 - i))));
|
||||
gpio_dout(SCK, 1);
|
||||
gpio_dout(SCK, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void flash_addr(uint32_t addr)
|
||||
{
|
||||
for (uint8_t i = 0; i < 24; i++) {
|
||||
gpio_dout(SI, (addr & (1 << (23 - i))));
|
||||
gpio_dout(SCK, 1);
|
||||
gpio_dout(SCK, 0);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t flash_in(void)
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
gpio_dout(SCK, 1);
|
||||
gpio_dout(SCK, 0);
|
||||
if (gpio_din(SO))
|
||||
byte |= (1 << (7 - i));
|
||||
}
|
||||
return byte;
|
||||
}
|
||||
|
||||
void flash_read(char *buf, uint32_t addr, unsigned int count)
|
||||
{
|
||||
if (buf == 0)
|
||||
return;
|
||||
gpio_dout(CS, 0);
|
||||
flash_out(READ);
|
||||
flash_addr(addr);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
buf[i] = flash_in();
|
||||
gpio_dout(CS, 1);
|
||||
}
|
||||
|
||||
void flash_write(const char *buf, uint32_t addr, unsigned int count)
|
||||
{
|
||||
if (buf == 0)
|
||||
return;
|
||||
gpio_dout(CS, 0);
|
||||
flash_out(WREN);
|
||||
gpio_dout(CS, 1);
|
||||
gpio_dout(CS, 0);
|
||||
flash_out(WRITE);
|
||||
flash_addr(addr);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
flash_out(buf[i]);
|
||||
gpio_dout(CS, 1);
|
||||
delay(100);
|
||||
//gpio_dout(CS, 0);
|
||||
//flash_out(WRDS);
|
||||
//gpio_dout(CS, 1);
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
print "Hello."
|
||||
|
||||
set fg 32767
|
||||
|
||||
# draw bg, lines
|
||||
rect 50 50 380 220 6375
|
||||
line 50 160 430 160 fg
|
||||
line 240 50 240 270 fg
|
||||
|
||||
set x 50
|
||||
do
|
||||
line x 170 x 150 fg
|
||||
set x (x + 20)
|
||||
while (x < 431)
|
||||
|
||||
set y 50
|
||||
do
|
||||
line 230 y 250 y fg
|
||||
set y (y + 20)
|
||||
while (y < 271)
|
||||
|
||||
do
|
||||
rand 379 > x
|
||||
rand 219 > y
|
||||
rand 379 > i
|
||||
rand 219 > j
|
||||
set x (x + 50)
|
||||
set y (y + 50)
|
||||
set i (i + 50)
|
||||
set j (j + 50)
|
||||
|
||||
line x y i j 511
|
||||
while (1)
|
@ -1,21 +0,0 @@
|
||||
do
|
||||
getkey > input
|
||||
print input
|
||||
delay 1000
|
||||
while (1)
|
||||
|
||||
#do
|
||||
# getkey > input
|
||||
# if (input & 4)
|
||||
# rand 479 > x
|
||||
# rand 319 > y
|
||||
# rand 479 > i
|
||||
# rand 319 > j
|
||||
# rand 32767 > purple
|
||||
#
|
||||
# line x y i j purple
|
||||
# end
|
||||
#while (1)
|
||||
#
|
||||
#print "done"
|
||||
|
Loading…
Reference in New Issue