tool78: fix entry sequence, so it should be ready for testing on real hw
This commit is contained in:
parent
c9f81731bb
commit
3c1b4d88aa
|
@ -1,2 +1,2 @@
|
|||
build/
|
||||
build*/
|
||||
dat/
|
||||
|
|
15
src/main.c
15
src/main.c
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <hardware/gpio.h>
|
||||
#include <pico/stdlib.h>
|
||||
|
@ -9,6 +10,7 @@
|
|||
#include "tap.h"
|
||||
#include "msp430dbg.h"
|
||||
#include "tool78_hw.h"
|
||||
#include "tool78_cmds.h"
|
||||
|
||||
void piotest(void);
|
||||
|
||||
|
@ -175,9 +177,20 @@ static void tool78_testtest() {
|
|||
}
|
||||
}
|
||||
|
||||
static void tool78_prototest() {
|
||||
tool78_silicon_sig_t sig;
|
||||
memset(&sig, 0, sizeof sig);
|
||||
enum tool78_stat st = tool78_init(&tool78_hw_rl78_uart1, &sig);
|
||||
printf("result: 0x%02x. sig:\n", st);
|
||||
for (size_t i = 0; i < sizeof(struct tool78_silicon_sig_78k0); ++i)
|
||||
printf("0x%02x ", ((const uint8_t*)&sig)[i]);
|
||||
printf("%c", '\n');
|
||||
}
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
tool78_testtest();
|
||||
//tool78_testtest();
|
||||
tool78_prototest();
|
||||
//piotest();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ loop:
|
|||
% c-sdk {
|
||||
|
||||
#include <hardware/clocks.h>
|
||||
#include <hardware/structs/iobank0.h>
|
||||
|
||||
static inline void tool78_uart_tx_program_init(PIO pio, uint sm, uint offset,
|
||||
uint pin, uint baudrate, bool en) {
|
||||
|
@ -46,11 +47,17 @@ static inline void tool78_uart_tx_program_init(PIO pio, uint sm, uint offset,
|
|||
// * drive output low, always
|
||||
// * use pin direction setting to send data
|
||||
// * default to hiZ/pullup after initc
|
||||
gpio_set_function(pin, GPIO_FUNC_SIO); // also sets input/output enables properly
|
||||
pio_sm_set_pins_with_mask(pio, sm, 0u << pin, 1u << pin);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, false); // pin is input by default (i.e. pullup)
|
||||
pio_gpio_init(pio, pin);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); // pin is output by default EXCEPT negated to input! (i.e. pullup)
|
||||
gpio_pull_up(pin);
|
||||
gpio_set_oeover(pin, GPIO_OVERRIDE_INVERT); // see note in PIO code
|
||||
//gpio_set_oeover(pin, GPIO_OVERRIDE_INVERT); // see note in PIO code
|
||||
//pio_gpio_init(pio, pin);
|
||||
// we need to perform the above two at once to avoid a spurious glitch
|
||||
// where the line goes low for a few cycles
|
||||
iobank0_hw->io[pin].ctrl
|
||||
= (((pio==pio0)?GPIO_FUNC_PIO0:GPIO_FUNC_PIO1) << IO_BANK0_GPIO0_CTRL_FUNCSEL_LSB)
|
||||
| (GPIO_OVERRIDE_INVERT << IO_BANK0_GPIO0_CTRL_OEOVER_LSB);
|
||||
|
||||
pio_sm_config c = tool78_uart_tx_program_get_default_config(offset);
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pico/time.h>
|
||||
|
@ -248,10 +249,13 @@ static enum tool78_stat tool78_wait_status(struct tool78_hw* hw, int l, int time
|
|||
|
||||
enum tool78_stat tool78_do_reset(struct tool78_hw* hw) {
|
||||
enum tool78_stat st = tool78_cmd_send(hw, tool78_cmd_reset, 0, NULL);
|
||||
printf("send st=%02x\n", st);
|
||||
if (st != tool78_stat_ack) return st;
|
||||
|
||||
st = tool78_wait_status(hw, 1, tWT0); // aka tCS1
|
||||
printf("wait st=%02x\n", st);
|
||||
if (st != tool78_stat_ack) return st;
|
||||
printf("reset cmd sent\n");
|
||||
|
||||
return st;
|
||||
}
|
||||
|
@ -701,14 +705,18 @@ enum tool78_stat tool78_init(struct tool78_hw* hw, tool78_silicon_sig_t* sig) {
|
|||
enum tool78_stat st;
|
||||
for (size_t i = 0; i < 16; ++i) {
|
||||
if (!hw->init()) return tool78_stat_fatal_hw_error;
|
||||
printf("init %zu ok\n", i);
|
||||
|
||||
st = tool78_do_reset(hw);
|
||||
printf("done reset st=0x%02x\n", st);
|
||||
if (st == tool78_stat_timeout_error) {
|
||||
hw->deinit();
|
||||
continue;
|
||||
}
|
||||
return st;
|
||||
break;
|
||||
}
|
||||
if (st != tool78_stat_ack) return st;
|
||||
printf("hw inited\n");
|
||||
|
||||
st = tool78_do_generic_baudrate(hw);
|
||||
if (st != tool78_stat_ack) return st;
|
||||
|
|
|
@ -58,7 +58,7 @@ static bool t78k0_spi_init(void) {
|
|||
vars.bitswap = false;
|
||||
|
||||
// extclk between 2 and 20 MHz
|
||||
tool78_entryseq_78k0(tool78k0_spi);
|
||||
tool78_entryseq_78k0(tool78_entry_78k0_spi);
|
||||
|
||||
tool78_spi_program_init(PINOUT_TOOL78_PIO, vars.smrx, vars.rxoff,
|
||||
PINOUT_TOOL78_78K0_CLOCK, PINOUT_TOOL78_78K0_TXMOSI,
|
||||
|
|
|
@ -22,7 +22,7 @@ static bool t78k0_uart2_init(void) {
|
|||
vars.bitswap = true;
|
||||
|
||||
// extclk between 2 and 20 MHz
|
||||
tool78_entryseq_78k0(tool78k0_uart2);
|
||||
tool78_entryseq_78k0(tool78_entry_78k0_uart2);
|
||||
|
||||
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,
|
||||
PINOUT_TOOL78_78K0_TXMOSI, 9600, true);
|
||||
|
|
|
@ -28,7 +28,7 @@ static bool t78k0_uart2_extclk_init(void) {
|
|||
pwm_init(pwm_gpio_to_slice_num(PINOUT_TOOL78_78K0_CLOCK), &pc, true);
|
||||
gpio_set_function(PINOUT_TOOL78_78K0_CLOCK, GPIO_FUNC_PWM);
|
||||
|
||||
tool78_entryseq_78k0(tool78k0_uart2_extclk);
|
||||
tool78_entryseq_78k0(tool78_entry_78k0_uart2_extclk);
|
||||
|
||||
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,
|
||||
PINOUT_TOOL78_78K0_TXMOSI, 9600, true);
|
||||
|
|
|
@ -25,10 +25,10 @@ static bool t78k0r_uart1_init(void) {
|
|||
|
||||
tool78_entryseq_78k0r(tool78_entry_78k0r_uart1);
|
||||
|
||||
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,
|
||||
PINOUT_TOOL78_78K0R_TOOL0, 9600, true);
|
||||
tool78_uart_rx_program_init(PINOUT_TOOL78_PIO, vars.smrx, vars.rxoff,
|
||||
PINOUT_TOOL78_78K0R_TOOL0, 9600, true);
|
||||
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,
|
||||
PINOUT_TOOL78_78K0R_TOOL0, 9600, true);
|
||||
|
||||
// wait for 0x00 "READY" byte
|
||||
uint8_t byte = 0xff;
|
||||
|
|
|
@ -23,10 +23,10 @@ static bool trl78_uart1_init(void) {
|
|||
|
||||
tool78_entryseq_rl78(tool78_entry_rl78_uart1);
|
||||
|
||||
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,
|
||||
PINOUT_TOOL78_RL78_TOOL0, 115200, true);
|
||||
tool78_uart_rx_program_init(PINOUT_TOOL78_PIO, vars.smrx, vars.rxoff,
|
||||
PINOUT_TOOL78_RL78_TOOL0, 115200, true);
|
||||
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,
|
||||
PINOUT_TOOL78_RL78_TOOL0, 115200, true);
|
||||
|
||||
uint8_t byte = (uint8_t)tool78_entry_rl78_uart1;
|
||||
trl78_uart1_send(1, &byte, -1);
|
||||
|
|
Loading…
Reference in New Issue