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_
|
#ifndef FLASH_H_
|
||||||
#define FLASH_H_
|
#define FLASH_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes GPIO ports and variables for flash IO. Must be called before
|
||||||
|
* any reads or writes.
|
||||||
|
*/
|
||||||
void flash_init(void);
|
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);
|
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);
|
void flash_write(const char *buf, uint32_t addr, unsigned int count);
|
||||||
|
|
||||||
#endif // FLASH_H_
|
#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_
|
#ifndef STDLIB_H_
|
||||||
#define 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, ...);
|
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);
|
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);
|
int atoi(const char *s);
|
||||||
|
|
||||||
#endif // STDLIB_H_
|
#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,4 +1,23 @@
|
|||||||
#!/bin/bash
|
#!/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 &
|
openocd -f /usr/share/openocd/scripts/board/st_nucleo_l476rg.cfg > /dev/null &
|
||||||
gdb-multiarch -iex "target remote localhost:3333" out/main.elf
|
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