Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jake Read
ucbus-stepper
Commits
e61c79df
Commit
e61c79df
authored
Oct 14, 2020
by
Jake Read
Browse files
ll op write
parent
63cbf13b
Changes
3
Hide whitespace changes
Inline
Side-by-side
firmware/cl-step-controller/src/drivers/step_cl.cpp
View file @
e61c79df
...
@@ -50,117 +50,54 @@ void Step_CL::init(void){
...
@@ -50,117 +50,54 @@ void Step_CL::init(void){
// #define BYTES_PER_PAGE 512
// #define BYTES_PER_PAGE 512
// #define FLOATS_PER_PAGE 128
// #define FLOATS_PER_PAGE 128
// #define PAGES_PER_BLOCK 16 // for 8192 bytes / block
// #define PAGES_PER_BLOCK 16 // for 8192 bytes / block
#define LUT_SIZE 2048
//const float __attribute__((__aligned__(BYTES_PER_PAGE))) lut[LUT_SIZE] = {};
//const float __attribute__((__aligned__(BYTES_PER_PAGE))) lut[LUT_SIZE] = {};
//const void* page_ptr;
//const void* page_ptr;
//static float buffer[FLOATS_PER_PAGE];
//static uint32_t bi;
//FlashClass flashClass((const uint8_t*)lut, BYTES_PER_PAGE); // try w/ constructor values ?
#define BYTES_PER_BLOCK 8192
#define FLOATS_PER_BLOCK 2048
typedef
struct
{
const
float
__attribute__
((
__aligned__
(
8192
)))
lut
[
16834
]
=
{};
float
f
[
LUT_SIZE
];
FlashClass
flashClass
((
const
uint8_t
*
)
lut
);
}
flts
;
typedef
struct
{
// write mechanics
float
f
[
ENCODER_COUNTS
];
const
void
*
block_ptr
;
}
flts_14b
;
flts
readbuf
;
// write buffer
static
float
buffer
[
FLOATS_PER_BLOCK
];
flts
inbuf
;
uint32_t
bfi
=
0
;
// buffer indice
uint32_t
bi
=
0
;
uint32_t
bli
=
0
;
// block indice
uint32_t
pi
=
0
;
FlashStorage
(
flash_storage_0
,
flts
);
//FlashStorage(flash_storage, flts);
FlashStorage
(
flash_storage_1
,
flts
);
FlashStorage
(
flash_storage_2
,
flts
);
FlashStorage
(
flash_storage_3
,
flts
);
FlashStorage
(
flash_storage_4
,
flts
);
FlashStorage
(
flash_storage_5
,
flts
);
FlashStorage
(
flash_storage_6
,
flts
);
FlashStorage
(
flash_storage_7
,
flts
);
void
flash_write_init
(
void
){
void
flash_write_init
(
void
){
bi
=
0
;
block_ptr
=
(
const
uint8_t
*
)
lut
;
pi
=
0
;
bfi
=
0
;
bli
=
0
;
}
}
void
flash_write_page
(
void
){
void
flash_write_page
(
void
){
sysError
(
"erasing"
);
flashClass
.
erase
(
block_ptr
,
BYTES_PER_BLOCK
);
sysError
(
"writing"
);
sysError
(
"writing"
);
switch
(
pi
){
flashClass
.
write
(
block_ptr
,
(
const
uint8_t
*
)
buffer
,
BYTES_PER_BLOCK
);
case
0
:
flash_storage_0
.
write
(
inbuf
);
sysError
(
"wrote brick 0"
);
break
;
case
1
:
flash_storage_1
.
write
(
inbuf
);
sysError
(
"wrote brick 1"
);
break
;
case
2
:
flash_storage_2
.
write
(
inbuf
);
sysError
(
"wrote brick 2"
);
break
;
case
3
:
flash_storage_3
.
write
(
inbuf
);
sysError
(
"wrote brick 3"
);
break
;
case
4
:
flash_storage_4
.
write
(
inbuf
);
sysError
(
"wrote brick 4"
);
break
;
case
5
:
flash_storage_5
.
write
(
inbuf
);
sysError
(
"wrote brick 5"
);
break
;
case
6
:
flash_storage_6
.
write
(
inbuf
);
sysError
(
"wrote brick 6"
);
break
;
case
7
:
flash_storage_7
.
write
(
inbuf
);
sysError
(
"wrote brick 7"
);
break
;
default:
sysError
(
"oob page write"
);
break
;
}
// end switch
pi
++
;
delay
(
100
);
delay
(
100
);
}
}
void
flash_write_value
(
float
val
){
void
flash_write_value
(
float
val
){
in
buf
.
f
[
bi
++
]
=
val
;
buff
er
[
b
f
i
++
]
=
val
;
if
(
bi
>=
LUT_SIZE
){
if
(
b
f
i
>=
FLOATS_PER_BLOCK
){
flash_write_page
();
flash_write_page
();
bi
=
0
;
b
f
i
=
0
;
}
}
}
}
void
Step_CL
::
print_table
(
void
){
void
Step_CL
::
print_table
(
void
){
sysError
(
"reading 0"
);
sysError
(
"reading from lut"
);
inbuf
=
flash_storage_0
.
read
();
for
(
uint32_t
i
=
0
;
i
<
ENCODER_COUNTS
;
i
++
){
for
(
uint16_t
e
=
0
;
e
<
LUT_SIZE
;
e
++
){
float
ra
=
lut
[
i
];
sysError
(
String
(
inbuf
.
f
[
e
]));
sysError
(
String
(
ra
));
delay
(
2
);
}
sysError
(
"reading 1"
);
inbuf
=
flash_storage_1
.
read
();
for
(
uint16_t
e
=
0
;
e
<
LUT_SIZE
;
e
++
){
sysError
(
String
(
inbuf
.
f
[
e
]));
delay
(
2
);
}
sysError
(
"reading 2"
);
inbuf
=
flash_storage_2
.
read
();
for
(
uint16_t
e
=
0
;
e
<
LUT_SIZE
;
e
++
){
sysError
(
String
(
inbuf
.
f
[
e
]));
delay
(
5
);
}
sysError
(
"reading 3"
);
inbuf
=
flash_storage_3
.
read
();
for
(
uint16_t
e
=
0
;
e
<
LUT_SIZE
;
e
++
){
sysError
(
String
(
inbuf
.
f
[
e
]));
delay
(
5
);
delay
(
5
);
}
}
}
}
...
@@ -168,7 +105,7 @@ void Step_CL::print_table(void){
...
@@ -168,7 +105,7 @@ void Step_CL::print_table(void){
// the calib routine
// the calib routine
boolean
Step_CL
::
calibrate
(
void
){
boolean
Step_CL
::
calibrate
(
void
){
flash_write_init
();
flash_write_init
();
for
(
uint32_t
i
=
0
;
i
<
ENCODER_COUNTS
;
i
++
){
for
(
uint32_t
i
=
0
;
i
<
FLOATS_PER_BLOCK
;
i
++
){
flash_write_value
(
i
*
1.1
F
);
flash_write_value
(
i
*
1.1
F
);
}
}
return
true
;
return
true
;
...
...
firmware/cl-step-controller/src/utils/FlashStorage.cpp
View file @
e61c79df
...
@@ -47,18 +47,15 @@ static inline uint32_t read_unaligned_uint32(const void *data){
...
@@ -47,18 +47,15 @@ static inline uint32_t read_unaligned_uint32(const void *data){
// Invalidate all CMCC cache entries if CMCC cache is enabled.
// Invalidate all CMCC cache entries if CMCC cache is enabled.
static
void
invalidate_CMCC_cache
(){
static
void
invalidate_CMCC_cache
(){
/*
if
(
CMCC
->
SR
.
bit
.
CSTS
)
{
// CR -> SR
if
(
CMCC
->
SR
.
bit
.
CSTS
)
{
// CR -> SR
CMCC
->
CTRL
.
bit
.
CEN
=
0
;
CMCC
->
CTRL
.
bit
.
CEN
=
0
;
while
(
CMCC
->
SR
.
bit
.
CSTS
)
{}
while
(
CMCC
->
SR
.
bit
.
CSTS
)
{}
CMCC
->
MAINT0
.
bit
.
INVALL
=
1
;
CMCC
->
MAINT0
.
bit
.
INVALL
=
1
;
CMCC
->
CTRL
.
bit
.
CEN
=
1
;
CMCC
->
CTRL
.
bit
.
CEN
=
1
;
}
}
*/
}
}
void
FlashClass
::
write
(
const
volatile
void
*
flash_ptr
,
const
void
*
data
,
uint32_t
size
){
void
FlashClass
::
write
(
const
volatile
void
*
flash_ptr
,
const
void
*
data
,
uint32_t
size
){
/*
// Calculate data boundaries
// Calculate data boundaries
size
=
(
size
+
3
)
/
4
;
size
=
(
size
+
3
)
/
4
;
volatile
uint32_t
*
dst_addr
=
(
volatile
uint32_t
*
)
flash_ptr
;
volatile
uint32_t
*
dst_addr
=
(
volatile
uint32_t
*
)
flash_ptr
;
...
@@ -97,11 +94,9 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_
...
@@ -97,11 +94,9 @@ void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_
NVMCTRL
->
CTRLA
.
bit
.
CACHEDIS0
=
original_CACHEDIS0
;
NVMCTRL
->
CTRLA
.
bit
.
CACHEDIS0
=
original_CACHEDIS0
;
NVMCTRL
->
CTRLA
.
bit
.
CACHEDIS1
=
original_CACHEDIS1
;
NVMCTRL
->
CTRLA
.
bit
.
CACHEDIS1
=
original_CACHEDIS1
;
}
}
*/
}
}
void
FlashClass
::
erase
(
const
volatile
void
*
flash_ptr
,
uint32_t
size
){
void
FlashClass
::
erase
(
const
volatile
void
*
flash_ptr
,
uint32_t
size
){
/*
const
uint8_t
*
ptr
=
(
const
uint8_t
*
)
flash_ptr
;
const
uint8_t
*
ptr
=
(
const
uint8_t
*
)
flash_ptr
;
while
(
size
>
ROW_SIZE
)
{
while
(
size
>
ROW_SIZE
)
{
erase
(
ptr
);
erase
(
ptr
);
...
@@ -109,17 +104,14 @@ void FlashClass::erase(const volatile void *flash_ptr, uint32_t size){
...
@@ -109,17 +104,14 @@ void FlashClass::erase(const volatile void *flash_ptr, uint32_t size){
size
-=
ROW_SIZE
;
size
-=
ROW_SIZE
;
}
}
erase
(
ptr
);
erase
(
ptr
);
*/
}
}
void
FlashClass
::
erase
(
const
volatile
void
*
flash_ptr
){
void
FlashClass
::
erase
(
const
volatile
void
*
flash_ptr
){
/*
sysError
(
"erase 0x"
+
String
((
uint32_t
)
flash_ptr
));
sysError
(
"erase 0x"
+
String
((
uint32_t
)
flash_ptr
));
NVMCTRL
->
ADDR
.
reg
=
((
uint32_t
)
flash_ptr
);
NVMCTRL
->
ADDR
.
reg
=
((
uint32_t
)
flash_ptr
);
NVMCTRL
->
CTRLB
.
reg
=
NVMCTRL_CTRLB_CMDEX_KEY
|
NVMCTRL_CTRLB_CMD_EB
;
NVMCTRL
->
CTRLB
.
reg
=
NVMCTRL_CTRLB_CMDEX_KEY
|
NVMCTRL_CTRLB_CMD_EB
;
while
(
!
NVMCTRL
->
INTFLAG
.
bit
.
DONE
)
{
}
while
(
!
NVMCTRL
->
INTFLAG
.
bit
.
DONE
)
{
}
invalidate_CMCC_cache
();
invalidate_CMCC_cache
();
*/
}
}
void
FlashClass
::
read
(
const
volatile
void
*
flash_ptr
,
void
*
data
,
uint32_t
size
){
void
FlashClass
::
read
(
const
volatile
void
*
flash_ptr
,
void
*
data
,
uint32_t
size
){
...
...
log/cl-step-control-log.md
View file @
e61c79df
...
@@ -897,5 +897,7 @@ Suspect ROW_SIZE something is up,
...
@@ -897,5 +897,7 @@ Suspect ROW_SIZE something is up,
OK this is crazy, I have every fn in the class commented out, and the thing still locks up.
OK this is crazy, I have every fn in the class commented out, and the thing still locks up.
So, tried my way around that, I have honestly no idea what is going on here. I'm going to try writing from the base class again.
-
neil suggests watching the power rails, flash req
-
neil suggests watching the power rails, flash req
-
nuclear option is asking neil to chat w/ microchip contacts
-
nuclear option is asking neil to chat w/ microchip contacts
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment