Skip to content

Commit 7a9d4dd

Browse files
committed
bugfixes STW81200
1 parent 9dfafe6 commit 7a9d4dd

File tree

13 files changed

+214
-24
lines changed

13 files changed

+214
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include "STW81200.hpp"
2+
#include "FreeRTOS.h"
3+
#include "task.h"
4+
5+
#define LOG_LEVEL LOG_LEVEL_DEBUG
6+
#define LOG_MODULE "STW81200"
7+
#include "Log.h"
8+
9+
bool STW81200::Init() {
10+
setLE(false);
11+
setHW_PD(false);
12+
setPD_RF1(false);
13+
14+
writeRegister(Reg::ST9, 0x00);
15+
16+
return true;
17+
}
18+
19+
void STW81200::writeRegister(uint32_t address, uint64_t data) {
20+
writeRegister((Reg) address, data);
21+
}
22+
23+
uint64_t STW81200::readRegister(uint32_t address) {
24+
return readRegister((Reg) address);
25+
}
26+
27+
void STW81200::writeRegister(Reg reg, uint64_t data) {
28+
uint8_t send[4];
29+
data &= 0x07FFFFFF;
30+
send[0] = (int) reg << 3;
31+
send[0] |= data >> 24;
32+
send[1] = (data >> 16) & 0xFF;
33+
send[2] = (data >> 8) & 0xFF;
34+
send[3] = (data >> 0) & 0xFF;
35+
HAL_SPI_Transmit(spi, send, sizeof(send), 100);
36+
setLE(true);
37+
setLE(false);
38+
}
39+
40+
uint64_t STW81200::readRegister(Reg reg) {
41+
uint8_t send[4];
42+
uint8_t recv[4];
43+
send[0] = 0x80 | (int) reg << 3;
44+
send[1] = 0x00;
45+
send[2] = 0x00;
46+
send[3] = 0x00;
47+
HAL_SPI_TransmitReceive(spi, send, recv, sizeof(send), 100);
48+
setLE(true);
49+
setLE(false);
50+
uint64_t data = recv[0] & 0x07;
51+
data <<= 8;
52+
data |= recv[1];
53+
data <<= 8;
54+
data |= recv[2];
55+
data <<= 8;
56+
data |= recv[3];
57+
return data;
58+
}
59+
60+
void STW81200::setLE(bool p) {
61+
if(!LE) {
62+
return;
63+
}
64+
if(p) {
65+
LE->BSRR = LEpin;
66+
} else {
67+
LE->BSRR = LEpin << 16;
68+
}
69+
}
70+
71+
void STW81200::setHW_PD(bool p) {
72+
if(!HW_PD) {
73+
return;
74+
}
75+
if(p) {
76+
HW_PD->BSRR = HW_PDpin;
77+
} else {
78+
HW_PD->BSRR = HW_PDpin << 16;
79+
}
80+
}
81+
82+
void STW81200::setPD_RF1(bool p) {
83+
if(!PD_RF1) {
84+
return;
85+
}
86+
if(p) {
87+
PD_RF1->BSRR = PD_RF1pin;
88+
} else {
89+
PD_RF1->BSRR = PD_RF1pin << 16;
90+
}
91+
}
92+
93+
94+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
3+
#include "stm.hpp"
4+
#include "RegisterDevice.hpp"
5+
6+
class STW81200 : public RegisterDevice {
7+
public:
8+
constexpr STW81200(const char *name, SPI_HandleTypeDef *spi, GPIO_TypeDef *LE,
9+
uint16_t LEpin, GPIO_TypeDef *HW_PD = nullptr,
10+
uint16_t HW_PDpin = 0, GPIO_TypeDef *PD_RF1 = nullptr,
11+
uint16_t PD_RF1pin = 0):
12+
RegisterDevice("STW81200", name),
13+
spi(spi),
14+
LE(LE),
15+
HW_PD(HW_PD),
16+
PD_RF1(PD_RF1),
17+
LEpin(LEpin),
18+
HW_PDpin(HW_PDpin),
19+
PD_RF1pin(PD_RF1pin)
20+
{};
21+
22+
bool Init();
23+
24+
void writeRegister(uint32_t address, uint64_t data) override;
25+
uint64_t readRegister(uint32_t address) override;
26+
27+
enum class Reg : uint8_t {
28+
ST0 = 0x00,
29+
ST1 = 0x01,
30+
ST2 = 0x02,
31+
ST3 = 0x03,
32+
ST4 = 0x04,
33+
ST5 = 0x05,
34+
ST6 = 0x06,
35+
ST7 = 0x07,
36+
ST8 = 0x08,
37+
ST9 = 0x09,
38+
ST10 = 0x0A,
39+
ST11 = 0x0B,
40+
};
41+
private:
42+
void setLE(bool p);
43+
void setHW_PD(bool p);
44+
void setPD_RF1(bool p);
45+
void setReset(bool p);
46+
void updateRegisters();
47+
void writeRegister(Reg reg, uint64_t data);
48+
uint64_t readRegister(Reg reg);
49+
SPI_HandleTypeDef *spi;
50+
GPIO_TypeDef *LE, *HW_PD, *PD_RF1;
51+
uint16_t LEpin, HW_PDpin, PD_RF1pin;
52+
};
53+

Software/HelperTools/SynthEvalBoard/Application/Hardware.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "AD9913.hpp"
66
#include "Si5332.hpp"
7+
#include "STW81200.hpp"
78
#include "main.h"
89

910
extern I2C_HandleTypeDef hi2c1;
@@ -16,13 +17,21 @@ static AD9913 ad9913 = AD9913("AD9913", &hspi2, AD9913_CS_GPIO_Port,
1617
AD9913_MRESET_GPIO_Port, AD9913_MRESET_Pin, AD9913_PWR_DWN_GPIO_Port,
1718
AD9913_PWR_DWN_Pin);
1819

20+
21+
static STW81200 stw81200 = STW81200("STW81200", &hspi1, STW_LE_GPIO_Port,
22+
STW_LE_Pin, STW_HW_PD_GPIO_Port, STW_HW_PD_Pin, STW_PD_RF1_GPIO_Port,
23+
STW_PD_RF1_Pin);
24+
1925
bool HW::Init() {
2026
if(!ad9913.Init()) {
2127
return false;
2228
}
2329
if(!si5332.Init()) {
2430
return false;
2531
}
32+
if(!stw81200.Init()) {
33+
return false;
34+
}
2635
return true;
2736
}
2837

Software/HelperTools/SynthEvalBoard/Application/Hardware.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace HW {
66

7-
static constexpr uint8_t registerDevices = 2;
7+
static constexpr uint8_t registerDevices = 3;
88

99
static constexpr Protocol::DeviceInfo Info = {
1010
.ProtocolVersion = Protocol::Version,

Software/HelperTools/SynthEvalBoard/Src/stm32l4xx_hal_msp.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,20 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
169169
PA6 ------> SPI1_MISO
170170
PA7 ------> SPI1_MOSI
171171
*/
172-
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
172+
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
173173
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
174174
GPIO_InitStruct.Pull = GPIO_NOPULL;
175175
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
176176
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
177177
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
178178

179+
GPIO_InitStruct.Pin = GPIO_PIN_6;
180+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
181+
GPIO_InitStruct.Pull = GPIO_PULLUP;
182+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
183+
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
184+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
185+
179186
/* USER CODE BEGIN SPI1_MspInit 1 */
180187

181188
/* USER CODE END SPI1_MspInit 1 */

Software/HelperTools/SynthEvalBoard/SynthEvalBoard.ioc

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ PA4.Signal=GPIO_Output
105105
PA5.Locked=true
106106
PA5.Mode=Full_Duplex_Master
107107
PA5.Signal=SPI1_SCK
108+
PA6.GPIOParameters=GPIO_PuPd
109+
PA6.GPIO_PuPd=GPIO_PULLUP
108110
PA6.Locked=true
109111
PA6.Mode=Full_Duplex_Master
110112
PA6.Signal=SPI1_MISO

Software/PC_Application/Device/RegisterAccess/rawregisterdialog.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ RawRegisterDialog::RawRegisterDialog(Device *dev, QWidget *parent) :
3131
// trigger extraction of device information, this will trigger the receivedDirectRegisterInfo slot which will further populate the dialog
3232
dev->SendCommandWithoutPayload(Protocol::PacketType::RequestDirectRegisterInfo);
3333

34+
connect(ui->reload, &QPushButton::clicked, [=](){
35+
devices[ui->tabs->currentIndex()]->reloadRegisters();
36+
});
37+
3438
connect(ui->buttonBox->button(QDialogButtonBox::Save), &QPushButton::clicked, [=](){
3539
auto filename = QFileDialog::getSaveFileName(this, "Save register settigns", "", "Raw register file (*.regs)", nullptr, QFileDialog::DontUseNativeDialog);
3640
if(filename.length() > 0) {

Software/PC_Application/Device/RegisterAccess/rawregisterdialog.ui

+25-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,31 @@
2525
</widget>
2626
</item>
2727
<item>
28-
<widget class="QDialogButtonBox" name="buttonBox">
29-
<property name="orientation">
30-
<enum>Qt::Horizontal</enum>
31-
</property>
32-
<property name="standardButtons">
33-
<set>QDialogButtonBox::Open|QDialogButtonBox::Save</set>
34-
</property>
35-
</widget>
28+
<layout class="QHBoxLayout" name="horizontalLayout">
29+
<item>
30+
<widget class="QPushButton" name="reload">
31+
<property name="text">
32+
<string>Reload Registers</string>
33+
</property>
34+
<property name="icon">
35+
<iconset theme="view-refresh"/>
36+
</property>
37+
</widget>
38+
</item>
39+
<item>
40+
<widget class="QDialogButtonBox" name="buttonBox">
41+
<property name="orientation">
42+
<enum>Qt::Horizontal</enum>
43+
</property>
44+
<property name="standardButtons">
45+
<set>QDialogButtonBox::Open|QDialogButtonBox::Save</set>
46+
</property>
47+
<property name="centerButtons">
48+
<bool>false</bool>
49+
</property>
50+
</widget>
51+
</item>
52+
</layout>
3653
</item>
3754
</layout>
3855
</widget>

Software/PC_Application/Device/RegisterAccess/registerdevice.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ RegisterDevice *RegisterDevice::create(Device *dev, int number, QString partnumb
2525
regdev->name = name;
2626

2727
// read initial register content
28-
Protocol::PacketInfo p;
29-
p.type = Protocol::PacketType::DirectRegisterRead;
30-
p.directRegRead.device = number;
31-
for(unsigned int i=0;i<regdev->regs.size();i++) {
32-
p.directRegRead.address = regdev->regs[i]->getAddress();
33-
dev->SendPacket(p);
34-
}
28+
regdev->reloadRegisters();
3529
}
3630
return regdev;
3731
}
@@ -60,6 +54,17 @@ QString RegisterDevice::getName() const
6054
return name;
6155
}
6256

57+
void RegisterDevice::reloadRegisters()
58+
{
59+
Protocol::PacketInfo p;
60+
p.type = Protocol::PacketType::DirectRegisterRead;
61+
p.directRegRead.device = number;
62+
for(unsigned int i=0;i<regs.size();i++) {
63+
p.directRegRead.address = regs[i]->getAddress();
64+
dev->SendPacket(p);
65+
}
66+
}
67+
6368
void RegisterDevice::addPossibleInputs(RegisterDevice *inputDevice)
6469
{
6570
for(auto o : inputDevice->outputs) {

Software/PC_Application/Device/RegisterAccess/registerdevice.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class RegisterDevice : public Savable
1919
QWidget *getWidget() const;
2020
QString getPartnumber() const;
2121
QString getName() const;
22+
void reloadRegisters();
2223

2324
virtual void addPossibleInputs(RegisterDevice *inputDevice);
2425

Software/PC_Application/Device/RegisterAccess/si5332.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ SI5332::SI5332()
446446
switch(sel0->currentIndex()) {
447447
case 0: group = ui->freqPLLref->value(); break;
448448
case 1: group = ui->freqPLLref->value() / ui->PDIV_DIV->value(); break;
449-
case 2: group = ui->ref->value();
449+
case 2: group = ui->ref->value(); break;
450450
case 3: group = 0; // CLKIN_3, not available at this part
451451
}
452452
break;

Software/PC_Application/Device/RegisterAccess/stw81200.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ STW81200::STW81200()
1717
addRegister(new Register("ST8", 8, 26));
1818
addRegister(new Register("ST9", 9, 26));
1919
addRegister(new Register("ST10", 10, 26));
20+
addRegister(new Register("ST11", 11, 26));
2021

2122
ui = new Ui::STW81200Widget;
2223
ui->setupUi(widget);
@@ -44,9 +45,6 @@ STW81200::STW81200()
4445
regs[3]->assignUI(ui->PFD_DEL_MODE, 15, 2);
4546
regs[3]->assignUI(ui->REF_PATH_SEL, 13, 2);
4647
regs[3]->assignUI(ui->R, 0, 12);
47-
regs[3]->assignUI(ui->RF1_OUT_PD, 24, true);
48-
regs[3]->assignUI(ui->RF1_DIV_SEL, 21, 3);
49-
regs[3]->assignUI(ui->frac, 0, 21);
5048

5149
regs[4]->assignUI(ui->RF_OUT_PWR, 23, 2);
5250
regs[4]->assignUI(ui->VCO_2V5_MODE, 22);
@@ -90,7 +88,7 @@ STW81200::STW81200()
9088
regs[7]->assignUI(ui->LD_SDO_SEL, 21, 2);
9189
regs[7]->assignUI(ui->CYCLE_SLIP_EN, 19);
9290
regs[7]->assignUI(ui->FSTLCK_EN, 18);
93-
regs[7]->assignUI(ui->CP_SEL, 13, 5);
91+
regs[7]->assignUI(ui->CP_SEL_FL, 13, 5);
9492
regs[7]->assignUI(ui->FSTLCK_CNT, 0, 13);
9593

9694
regs[8]->assignUI(ui->PD_RF2_DISABLE, 26);
@@ -103,7 +101,7 @@ STW81200::STW81200()
103101
regs[8]->assignUI(ui->REG_VCO_PD, 6);
104102
regs[8]->assignUI(ui->REG_VCO_VOUT, 4, 2);
105103
regs[8]->assignUI(ui->REG_VCO_4V5_PD, 2);
106-
regs[8]->assignUI(ui->REG_VCO_4V5_OCP, 0, 2);
104+
regs[8]->assignUI(ui->REG_VCO_4V5_VOUT, 0, 2);
107105

108106
regs[10]->assignUI(ui->REG_DIG_STARTUP, 17);
109107
regs[10]->assignUI(ui->REG_REF_STARTUP, 16);

Software/PC_Application/Device/RegisterAccess/stw81200widget.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@
990990
</widget>
991991
</item>
992992
<item>
993-
<widget class="QComboBox" name="REG_VC_4V5_VOUT">
993+
<widget class="QComboBox" name="REG_VCO_4V5_VOUT">
994994
<item>
995995
<property name="text">
996996
<string>5.0V</string>

0 commit comments

Comments
 (0)