Microcode SW error with an Intel 8265 / 8275 (rev 78) wireless card

The issue:

Multiple times an hour my wireless connection would drop out for a couple of seconds, then come back up. If this happened while streaming media, most often it would not be noticable because the media buffer would handle the hiccup, but during regular surfing this would lead to disconnects or unreachable pages.

Looking through the dmesg output I found plenty of tracebacks similar to this (MAC address of my router removed):

[   22.603623] iwlwifi 0000:04:00.0: Microcode SW error detected.  Restarting 0x2000000.
[   22.605114] iwlwifi 0000:04:00.0: Start IWL Error Log Dump:
[   22.606304] iwlwifi 0000:04:00.0: Status: 0x00000040, count: 6
[   22.607576] iwlwifi 0000:04:00.0: Loaded firmware version: 36.77d01142.0
[   22.608704] iwlwifi 0000:04:00.0: 0x000014FD | ADVANCED_SYSASSERT          
[   22.609791] iwlwifi 0000:04:00.0: 0x000002F0 | trm_hw_status0
[   22.610872] iwlwifi 0000:04:00.0: 0x00000000 | trm_hw_status1
[   22.611968] iwlwifi 0000:04:00.0: 0x000248EC | branchlink2
[   22.613058] iwlwifi 0000:04:00.0: 0x0003A862 | interruptlink1
[   22.614170] iwlwifi 0000:04:00.0: 0x00000000 | interruptlink2
[   22.615272] iwlwifi 0000:04:00.0: 0x00000082 | data1
[   22.616343] iwlwifi 0000:04:00.0: 0xDEADBEEF | data2
[   22.617448] iwlwifi 0000:04:00.0: 0xDEADBEEF | data3
[   22.618475] iwlwifi 0000:04:00.0: 0x0009505C | beacon time
[   22.619232] iwlwifi 0000:04:00.0: 0x00378063 | tsf low
[   22.620219] iwlwifi 0000:04:00.0: 0x00000000 | tsf hi
[   22.621186] iwlwifi 0000:04:00.0: 0x00000000 | time gp1
[   22.622329] iwlwifi 0000:04:00.0: 0x00378064 | time gp2
[   22.623512] iwlwifi 0000:04:00.0: 0x00000001 | uCode revision type
[   22.624557] iwlwifi 0000:04:00.0: 0x00000024 | uCode version major
[   22.625464] iwlwifi 0000:04:00.0: 0x77D01142 | uCode version minor
[   22.626252] iwlwifi 0000:04:00.0: 0x00000230 | hw version
[   22.626792] iwlwifi 0000:04:00.0: 0x00C89000 | board version
[   22.627331] iwlwifi 0000:04:00.0: 0x003D0108 | hcmd
[   22.627883] iwlwifi 0000:04:00.0: 0x00022080 | isr0
[   22.628434] iwlwifi 0000:04:00.0: 0x00000000 | isr1
[   22.628989] iwlwifi 0000:04:00.0: 0x08201802 | isr2
[   22.629538] iwlwifi 0000:04:00.0: 0x00400080 | isr3
[   22.630588] iwlwifi 0000:04:00.0: 0x00000000 | isr4
[   22.631341] iwlwifi 0000:04:00.0: 0x003C019F | last cmd Id
[   22.631846] iwlwifi 0000:04:00.0: 0x00000000 | wait_event
[   22.632347] iwlwifi 0000:04:00.0: 0x0000D5E7 | l2p_control
[   22.632844] iwlwifi 0000:04:00.0: 0x00000000 | l2p_duration
[   22.633334] iwlwifi 0000:04:00.0: 0x00000000 | l2p_mhvalid
[   22.633835] iwlwifi 0000:04:00.0: 0x00000000 | l2p_addr_match
[   22.634745] iwlwifi 0000:04:00.0: 0x0000008F | lmpm_pmg_sel
[   22.635664] iwlwifi 0000:04:00.0: 0x08081421 | timestamp
[   22.636676] iwlwifi 0000:04:00.0: 0x00004050 | flow_handler
[   22.637518] iwlwifi 0000:04:00.0: Start IWL Error Log Dump:
[   22.638372] iwlwifi 0000:04:00.0: Status: 0x00000040, count: 7
[   22.638861] iwlwifi 0000:04:00.0: 0x00000070 | NMI_INTERRUPT_LMAC_FATAL
[   22.639341] iwlwifi 0000:04:00.0: 0x00000000 | umac branchlink1
[   22.639813] iwlwifi 0000:04:00.0: 0xC0086948 | umac branchlink2
[   22.640278] iwlwifi 0000:04:00.0: 0xC0083B0C | umac interruptlink1
[   22.640745] iwlwifi 0000:04:00.0: 0xC0083B0C | umac interruptlink2
[   22.641211] iwlwifi 0000:04:00.0: 0x00000800 | umac data1
[   22.641693] iwlwifi 0000:04:00.0: 0xC0083B0C | umac data2
[   22.642655] iwlwifi 0000:04:00.0: 0xDEADBEEF | umac data3
[   22.643476] iwlwifi 0000:04:00.0: 0x00000024 | umac major
[   22.644376] iwlwifi 0000:04:00.0: 0x77D01142 | umac minor
[   22.645316] iwlwifi 0000:04:00.0: 0xC088628C | frame pointer
[   22.646226] iwlwifi 0000:04:00.0: 0xC088628C | stack pointer
[   22.647072] iwlwifi 0000:04:00.0: 0x003D0108 | last host cmd
[   22.647786] iwlwifi 0000:04:00.0: 0x00000000 | isr status reg
[   22.648611] iwlwifi 0000:04:00.0: Fseq Registers:
[   22.649236] iwlwifi 0000:04:00.0: 0xE5A33CD7 | FSEQ_ERROR_CODE
[   22.649769] iwlwifi 0000:04:00.0: 0x356D75C8 | FSEQ_TOP_INIT_VERSION
[   22.650294] iwlwifi 0000:04:00.0: 0x2408A24F | FSEQ_CNVIO_INIT_VERSION
[   22.650818] iwlwifi 0000:04:00.0: 0x0000A10B | FSEQ_OTP_VERSION
[   22.651341] iwlwifi 0000:04:00.0: 0x7D82B21C | FSEQ_TOP_CONTENT_VERSION
[   22.651867] iwlwifi 0000:04:00.0: 0xBADED74E | FSEQ_ALIVE_TOKEN
[   22.652391] iwlwifi 0000:04:00.0: 0x21AF7C59 | FSEQ_CNVI_ID
[   22.652914] iwlwifi 0000:04:00.0: 0x32D8E512 | FSEQ_CNVR_ID
[   22.653434] iwlwifi 0000:04:00.0: 0x00000010 | CNVI_AUX_MISC_CHIP
[   22.653957] iwlwifi 0000:04:00.0: 0x0BADCAFE | CNVR_AUX_MISC_CHIP
[   22.654477] iwlwifi 0000:04:00.0: 0x0BADCAFE | CNVR_SCU_SD_REGS_SD_REG_DIG_DCDC_VTRIM
[   22.654998] iwlwifi 0000:04:00.0: 0x0BADCAFE | CNVR_SCU_SD_REGS_SD_REG_ACTIVE_VDIG_MIRROR
[   22.655522] iwlwifi 0000:04:00.0: Collecting data: trigger 2 fired.
[   22.655526] ieee80211 phy0: Hardware restart was requested
[   22.655589] iwlwifi 0000:04:00.0: iwlwifi transaction failed, dumping registers
[   22.656168] iwlwifi 0000:04:00.0: iwlwifi device config registers:
[   22.657016] iwlwifi 0000:04:00.0: 00000000: 24fd8086 00100406 02800078 00000000 dc000004 00000000 00000000 00000000
[   22.657511] iwlwifi 0000:04:00.0: 00000020: 00000000 00000000 00000000 10108086 00000000 000000c8 00000000 000001ff
[   22.658012] iwlwifi 0000:04:00.0: 00000040: 00020010 10008ec0 00190c10 0045e811 10110142 00000000 00000000 00000000
[   22.658509] iwlwifi 0000:04:00.0: 00000060: 00000000 00080812 00000405 00000000 00010001 00000000 00000000 00000000
[   22.659021] iwlwifi 0000:04:00.0: 00000080: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   22.659511] iwlwifi 0000:04:00.0: 000000a0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   22.659999] iwlwifi 0000:04:00.0: 000000c0: 00000000 00000000 c823d001 0d000000 00814005 fee00318 00000000 00000000
[   22.660490] iwlwifi 0000:04:00.0: 000000e0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   22.660984] iwlwifi 0000:04:00.0: 00000100: 14010001 00000000 00000000 00462031 00000000 00002000 00000000 00000000
[   22.661487] iwlwifi 0000:04:00.0: 00000120: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[   22.661988] iwlwifi 0000:04:00.0: 00000140: 14c10003 ff77ed1d 00e18cff 15410018 10031003 0001001e 00481e1f 40a0000f
[   22.662500] iwlwifi 0000:04:00.0: iwlwifi device memory mapped registers:
[   22.663171] iwlwifi 0000:04:00.0: 00000000: 00c89000 00000040 00000000 ba00008b 00000000 00000000 00000010 00000000
[   22.663712] iwlwifi 0000:04:00.0: 00000020: 00000000 08040005 00000230 d55555d5 d55555d5 d55555d5 80008040 041f0042
[   22.664380] iwlwifi 0000:04:00.0: iwlwifi device AER capability structure:
[   22.665072] iwlwifi 0000:04:00.0: 00000000: 14010001 00000000 00000000 00462031 00000000 00002000 00000000 00000000
[   22.665660] iwlwifi 0000:04:00.0: 00000020: 00000000 00000000 00000000
[   22.666231] iwlwifi 0000:04:00.0: iwlwifi parent port (0000:00:1c.6) config registers:
[   22.666902] iwlwifi 0000:00:1c.6: 00000000: 9d168086 00100407 060400f1 00810000 00000000 00000000 00040400 200000f0
///
[   22.677074] iwlwifi 0000:00:1c.6: 00000200: 2201001e 00b0281f 40a0280f
[   22.677731] iwlwifi 0000:04:00.0: iwlwifi root port (0000:00:1c.6) AER cap structure:
[   22.678391] iwlwifi 0000:00:1c.6: 00000000: 14010001 00000000 00010000 00060011 00000000 00002000 00000000 00000000
[   22.679058] iwlwifi 0000:00:1c.6: 00000020: 00000000 00000000 00000000 00000000 00000000 00000000
[   22.679724] iwlwifi 0000:04:00.0: FW error in SYNC CMD PHY_CONTEXT_CMD
[   22.680398] CPU: 2 PID: 1328 Comm: wpa_supplicant Tainted: G           OE     5.4.0-89-generic #100-Ubuntu
[   22.680399] Hardware name: LENOVO 20H9CT01WW/20H9CT01WW, BIOS N1VET56W (1.46 ) 05/17/2021
[   22.680400] Call Trace:
[   22.680405]  dump_stack+0x6d/0x8b
[   22.680415]  iwl_pcie_send_hcmd_sync+0x382/0x390 [iwlwifi]
[   22.680418]  ? wait_woken+0x80/0x80
[   22.680424]  iwl_trans_pcie_send_hcmd+0x34/0xf0 [iwlwifi]
[   22.680430]  iwl_trans_send_cmd+0x55/0xc0 [iwlwifi]
[   22.680438]  iwl_mvm_send_cmd+0x1f/0x40 [iwlmvm]
[   22.680443]  iwl_mvm_send_cmd_pdu+0x51/0x70 [iwlmvm]
[   22.680448]  iwl_mvm_phy_ctxt_apply.constprop.0+0x173/0x240 [iwlmvm]
[   22.680453]  iwl_mvm_phy_ctxt_changed+0x58/0xb0 [iwlmvm]
[   22.680458]  iwl_mvm_change_chanctx+0x10a/0x140 [iwlmvm]
[   22.680477]  ieee80211_recalc_chanctx_min_def+0x1ee/0x340 [mac80211]
[   22.680490]  ieee80211_assign_vif_chanctx+0x21c/0x420 [mac80211]
[   22.680502]  ieee80211_vif_use_channel+0x17b/0x290 [mac80211]
[   22.680514]  ieee80211_prep_channel+0x2be/0x500 [mac80211]
[   22.680524]  ieee80211_prep_connection+0x25f/0x430 [mac80211]
[   22.680536]  ieee80211_mgd_auth+0x19d/0x3d0 [mac80211]
[   22.680548]  ieee80211_auth+0x18/0x20 [mac80211]  Restarting 0x2000000.
[   22.680567]  cfg80211_mlme_auth+0x104/0x210 [cfg80211]
[   22.680579]  nl80211_authenticate+0x284/0x2e0 [cfg80211]
[   22.680582]  genl_family_rcv_msg+0x1b9/0x470
[   22.680584]  ? try_to_wake_up+0x224/0x6a0
[   22.680585]  genl_rcv_msg+0x4c/0xa0
[   22.680587]  ? _cond_resched+0x19/0x30
[   22.680588]  ? genl_family_rcv_msg+0x470/0x470
[   22.680590]  netlink_rcv_skb+0x50/0x120
[   22.680591]  genl_rcv+0x29/0x40
[   22.680592]  netlink_unicast+0x187/0x220
[   22.680593]  netlink_sendmsg+0x222/0x3e0
[   22.680596]  sock_sendmsg+0x65/0x70
[   22.680597]  ____sys_sendmsg+0x212/0x280
[   22.680599]  ___sys_sendmsg+0x88/0xd0
[   22.680600]  ? sock_do_ioctl+0x47/0x140
[   22.680602]  ? __check_object_size+0x4d/0x150
[   22.680605]  ? _copy_to_user+0x2c/0x30
[   22.680606]  ? sock_ioctl+0x24f/0x3c0
[   22.680607]  ? __sys_sendto+0x113/0x190
[   22.680609]  ? __cgroup_bpf_run_filter_setsockopt+0xae/0x2d0
[   22.680611]  ? _cond_resched+0x19/0x30
[   22.680613]  ? aa_sk_perm+0x43/0x170
[   22.680614]  __sys_sendmsg+0x5c/0xa0
[   22.680615]  __x64_sys_sendmsg+0x1f/0x30
[   22.680617]  do_syscall_64+0x57/0x190
[   22.680619]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[   22.680620] RIP: 0033:0x7fe9e8042747
[   22.680622] Code: 64 89 02 48 c7 c0 ff ff ff ff eb bb 0f 1f 80 00 00 00 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 2e 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 51 c3 48 83 ec 28 89 54 24 1c 48 89 74 24 10
[   22.680623] RSP: 002b:00007ffd6dbe3fe8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
[   22.680624] RAX: ffffffffffffffda RBX: 0000558a3dd79700 RCX: 00007fe9e8042747
[   22.680624] RDX: 0000000000000000 RSI: 00007ffd6dbe4020 RDI: 0000000000000006
[   22.680625] RBP: 0000558a3ddcb680 R08: 0000000000000004 R09: 00007fe9e810ab80
[   22.680626] R10: 00007ffd6dbe40f4 R11: 0000000000000246 R12: 0000558a3dd79610
[   22.680626] R13: 00007ffd6dbe4020 R14: 00007ffd6dbe40f4 R15: 0000558a3ddca1b0
[   22.680629] iwlwifi 0000:04:00.0: PHY ctxt cmd error. ret=-5
[   23.196499] iwlwifi 0000:04:00.0: Failed to send MAC context (action:2): -5
[   23.197142] iwlwifi 0000:04:00.0: failed to update MAC 00:e1:8c:77:ed:1d
[   23.198713] iwlwifi 0000:04:00.0: Failed to send MAC context (action:2): -5
[   23.199797] iwlwifi 0000:04:00.0: failed to update MAC 00:e1:8c:77:ed:1d
[   23.200775] wlp4s0: failed to insert STA entry for the AP (error -5)
[   23.200778] iwlwifi 0000:04:00.0: Failed to send MAC context (action:2): -5
[   23.201753] iwlwifi 0000:04:00.0: failed to update MAC 00:e1:8c:77:ed:1d
[   23.203618] iwlwifi 0000:04:00.0: Failed to send quota: -5
[   23.204815] iwlwifi 0000:04:00.0: Failed to send binding (action:3): -5
[   23.206750] iwlwifi 0000:04:00.0: Failed to send MAC context (action:2): -5
[   23.207986] iwlwifi 0000:04:00.0: failed to update MAC 00:e1:8c:77:ed:1d
[   23.209208] iwlwifi 0000:04:00.0: PHY ctxt cmd error. ret=-5
[   23.230555] iwlwifi 0000:04:00.0: Applying debug destination EXTERNAL_DRAM
[   23.362536] iwlwifi 0000:04:00.0: Applying debug destination EXTERNAL_DRAM
[   23.428963] iwlwifi 0000:04:00.0: FW already configured (0) - re-configuring
[   23.559711] wlp4s0: authenticate with [[edited]]
[   23.564136] wlp4s0: send auth to [[edited]] (try 1/3)
[   23.569273] wlp4s0: authenticated
[   23.573418] wlp4s0: associate with [[edited]] (try 1/3)
[   23.575706] wlp4s0: RX AssocResp from [[edited]] (capab=0x431 status=0 aid=1)
[   23.577894] wlp4s0: associated
[   23.651524] IPv6: ADDRCONF(NETDEV_CHANGE): wlp4s0: link becomes ready

Clearly there is an issue with the combination of settings, microcode and hardware that needs to be fixed.

Hardware/firmware

I’m running 5.4.0-89-generic on a Thinkpad T570 with an Intel 8265 / 8275 rev 78 and microcode 36.77d01142.0

lspci -k shows:

04:00.0 Network controller: Intel Corporation Wireless 8265 / 8275 (rev 78)
	Subsystem: Intel Corporation Dual Band Wireless-AC 8265
	Kernel driver in use: iwlwifi
	Kernel modules: iwlwifi

dmesg | grep firmware returns:

[    5.011501] iwlwifi 0000:04:00.0: loaded firmware version 36.77d01142.0 op_mode iwlmvm
[    5.120851] iwlwifi 0000:04:00.0: Allocated 0x00400000 bytes for firmware monitor.

Solution

Reading through forums, one notices this is not uncommon with the Intel iwlwifi modules.

I found a lot of options to handle this, including:

  • Reverting to older microcode by moving the current out of /usr/lib/firmware/ and reverting to an older version. For me this would be going back to v34, then v31 and so on until the issue was gone (not ideal)
  • Going through the upstream and see if newer versions where available upstream (not the case atm)
  • Sending a polite email to linuxwifi@intel.com hoping to get some support (not likely)
  • Get another card (limited to the hw options that Lenovo permits with my default BIOS, and *that* card might also have issues)
  • Changing the module parameters hoping to get improvement.

I opted to go through the last option, and try to limit the amount of changes to what was strictly necessary.

I started by following a recommendation from the Archlinux forum, I created /etc/modprobe.d/iwlwifi.conf (can be any name, as long as it ends in .conf) with the following contents:

options iwlwifi 11n_disable=1 swcrypto=0 bt_coex_active=0 power_save=0
options iwlmvm power_scheme=1 
options iwlwifi d0i3_disable=1 
options iwlwifi uapsd_disable=1 
options iwlwifi lar_disable=1

After a reboot, the issue did not reappear.

However going over dmesg, I found that one of the options (d0i3_disable=1) was not valid, and I set out to reduce the options to the ones (or combination) required to solve the issue.

The current (working) contents of my .conf file:

options iwlwifi 11n_disable=1 swcrypto=0 bt_coex_active=0 power_save=0

Hope this saves someone some time.

pCloud sync issue

I had this crappy issue with with the pCloud Linux (AppImage) client (version linux-x64-prod-v1.9.7).It would get stuck syncing a “Local sync” folder, where Preferences screen as well as the CLI would hang at a certain amount of files and size to be uploaded.


Having no logs to go by (and less than useful technical support on their end), it took me quite a while to find the issue. In the end I found the database where I found some clues as to what was wrong.


The database is called “data.db”, a file in your “~/.pcloud” folder. It is a SQLite database, so install sqlitebrowser to open it, then execute


sqlitebrowser ~/.pcloud/data.db


The “browse data” tab allows you to check the contents of the tables. The “localfolder” table turned out to be what I was looking for. It contains a list of all files that should be synced, with their id, folder, parentfolder, inode …

Contents of the localfolder table.


I noticed that no inode, timestamps or deviceid were given starting at a certain id. That looked interesting. The filename contained an “*” (asterisk) in the filename which doesn’t feel right. I can’t imagine I would have created such a filename intentionally.
So where is this file? The screenshot above shows that it has a folderid of 871638551. Lets search for this id in the most logical table, called “folder”.Using the “Execute SQL” tab we can quickly search for it.

select * from folder where id == 871638551;

and hit CTRL + ENTER.

Result of the SQL query (in the middle)


This returned a row with the name of the file, but a parentfolderid of 288744716. This shows me a row with the folder name that contains the file. You can go up all the way by searching for the parentfolderid of each folder (or write a simple Python script for this), but for me this was enough to show me that the issue was an autogenerated file created by Calibre.


I went online, logged in to my pcloud account, deleted the file, restarted the pcloud client and a couple of minutes later everything was synced. Problem solved.

Finished downloading!

Add warning and tip macros to TiddlyWiki

I am a *very* big fan of TiddlyWiki. I use it to document just about anything I figure out while working on projects, setting up systems, … Anything I would otherwise quickly forget. It makes it easier to add structure to random tidbits of information, and forcing myself to document while I work on something helps to stay focused on a certain goal.

I noticed some of the “official documentation” Tiddlers had options to emphasize tips and (more importantly) warnings, such as these:

While there seems to be an endless list of special tricks one can do with a TiddlyWiki, this was something that seemed really useful so I decided I needed to find out how to recreate them…

Add the macros and stylesheets

In the examples below, replace “Deevee” with any other folder name where you want to gather your own custom macros and stylesheets…

  • Create a new tiddler, name it $:/Deevee/macros
  • Add the tag $:/tags/Macro
  • Past in the following contents:
\define .tip(_) <div class="doc-icon-block"><div class="doc-block-icon">{{$:/core/images/tip}}</div>$_$</div> 
\define .warning(_) <div class="doc-icon-block"><div class="doc-block-icon">{{$:/core/images/warning}}</div>$_$</div>
  • Create another tiddler, name it $:/Deevee/styles
  • add the tag $:/tags/Stylesheet
  • paste in the following contents:
.doc-icon-block {
	border-left: 2px solid <<colour code-border>>;
	margin-left: 3em;
	padding-left: 0.6em;
	position: relative;
}

.doc-block-icon {
	position: absolute;
	left: -3em;
	top: 0.2em;
}

Using the macros

Simply use:

<<.tip “your text”>>

<<.warning “your text”>>

Setting up Visual Studio Code for Python development (on Linux)

The following is a brief guide to reinstalling/setting up Visual Studio Code (VSC) on a new Linux system. The main use is Python development. As such, it is very brief and mostly for my own documentation.

Install VSC

sudo snap install --classic code

Install Python packages

! DO THIS OUTSIDE OF AN ACTIVE VIRTUAL ENVIRONMENT !

  • linting (flake8): python -m pip install pyflakes pycodestyle mccabe flake8
  • Refactoring (rope): python -m pip install rope
  • Formatting (Yapf): python -m pip install yapf
  • Type checking (mypy): python -m pip install -U mypy --user
  • Flake8 Bugbear: python -m pip install flake8-bugbear, then check if installed with flake8 --version (should include flake8-bugbear)
  • Sphinx/RST support: python -m pip install doc8 rstcheck sphinx-autobuild
  • Snooty languageserver: python -m pip install snooty-lextudio

Install and configure plugins

Select interpreter

Add

"python.pythonPath": "/usr/bin/python3",

to $HOME/.config/Code/User/settings.json

Set up linting

List of possible linters and how to configure them

Open user settings and

  • set Python > linting: flake8 path, to C:\Python39\Scripts\flake8.exe
  • Add max-line-length=99 to Python > Linting: Flake8 Args
  • Enable flake8

or add

    "python.linting.flake8Path": "C:\\Python39\\Scripts\\flake8.exe",
    "python.linting.flake8Args": [
        "max-line-length=99"
    ],
    "python.linting.flake8Enabled": true,

to %APPDATA%\Code\User\settings.json (Windows) or $HOME/.config/Code/User/settings.json (Linux)

MyPy:

  • Install package

python -m pip install -U mypy --user

  • Enable
    "python.linting.mypyEnabled": true,
    "python.linting.mypyArgs": [],
    "python.analysis.typeCheckingMode" :"basic",
    "python.linting.mypyPath": "C:\\Users\\dieterv\\AppData\\Roaming\\Python\\Python39\\Scripts\\mypy.exe",

to ~/.config/Code/User/settings.json

more mypy info

Autodocstring

Add the following to your settings.json

"autoDocstring.docstringFormat": "google",
"autoDocstring.guessTypes": true,
"autoDocstring.generateDocstringOnEnter": true,
"autoDocstring.includeExtendedSummary": true,
"autoDocstring.quoteStyle": "\"\"\"",

Home Server – setting up ZFS (revisited)

Finally, after two years of renovations and two children, I am revisiting the idea of a small home server. I don’t expect it to do much:

  • Media server
  • File backup
  • Some docker containers
  • Grafana
  • Possibly pfSense or another firewall

Whenever I’m accessing a remote system (even when using SSH in my internal network) I prefer to start a TMUX session. That way, if I get disconnected (for instance) during the middle of a package upgrade, that process just continues and I can reconnect at a later time without issues (if tmux is not yet installed or you’re not using it yet, I highly recommend reading up on it and taking a bit of time to get used to the basic concepts. I used this quickstart a couple of years ago).

tmux new -s sessionname

Install the required zfs package:

sudo apt update && sudo apt install zfsutils-linux

Then find out which drives you want to use:

sudo fdisk -l

In my case, I wanted to use the two 1.8GB drives (/dev/sdb and /dev/sdc) in a mirror configuration. I don’t have a hundred movies to fill a drive, most space will be taken up by photos and system images.

sudo zpool create mypool mirror /dev/sdb /dev/sdc

Check the pool status to verify that it is as intended:

zpool status

The pool automatically gets mounted on /mypool with root:root as owner. I changed the owner/group to my own user

sudo chown <user>:<user> /mypool/ (replace <user>)

Using MicroPython (PyBoard V1.1) with Visual Studio Code

Warning

This still isn’t working as I think it should. Especially the linting and autocomplete still doesn’t work (leaving only the PyMakr module which works partly, in fact). For example: “import pyb” still does not add autocompletion when typing something like “s = pyb.<CTRL + SPACE>”. Most likely this is because I used a combinations of tools that shouldn’t be used together. Need to spend more time on this…

Intro

I’ve recently started using a PyBoard for a project that I am working on. Writing code in an IDE, saving the files, then manually copying them to the board to test them gets tedious rather quickly. If you’re using Visual Studio Code, there are options to do almost everything from within the IDE itself. Getting things to work as they should took a bit of effort and headscratching. What I needed to do is documented below.
Links to the sources of my information is at the bottom.

Install libraries/addon

  • pip install --upgrade pip --user
  • pip install --upgrade micropy-cli --user
  • pip install micropy-cli[create_stubs]
  • pip install rshell --upgrade
  • To prevent “Source directory /pyboard/stubs does not exist.” after creation open pybwrapper.py, change line 63 from
    pyb_path = f"{self.pyb_root}{_path}"
to:
    pyb_path = f"/flash/{_path}"

and save the file.

  • Inside VSC, install the Pymakr plugin
  • Install node.js (see link below, and reboot afterwards)

Create the stub yourself…

(This did not work properly for me. See below for another option.)

  • Connect the PyBoard over USB
  • Find out the serial port number (represented from here on by comXX)
  • Run
    micropy stubs create comXX

    (replace XX by com port number) -> this takes a couple of minutes

  • the result will be copied to ~/.micropy/stubs (in my case in a sub directory “pyboard-1.13.0”

…Or get them from someone else

I got mine from Josverl on Github. See his read.me for more information as well.

  • Pick a directory that will hold the files. Clone the repo:
    git clone git@github.com:Josverl/micropython-stubs.git
  • create a symlink in your project folder:

    mklink /d all-stubs <directory holding the stubs>
  • create a settings.json file in your project folder containing (change the references to the stubs you need, in the desired order):
{
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.languageServer": "Microsoft",
    "python.jediEnabled": false,
    "python.autoComplete.extraPaths": [
         "all-stubs/cpython_core",
         "all-stubs/pyboard_1_13_95",
         "all-stubs/mpy_1_13-nightly_frozen/GENERIC",
         "all-stubs/cpython_pyboard"
     ],
     "python.autoComplete.typeshedPaths": [
          "all-stubs/cpython_core",
         "all-stubs/pyboard_1_13_95",
          "all-stubs/mpy_1_13-nightly_frozen/GENERIC",
          "all-stubs/cpython_pyboard"
     ],
     "python.analysis.typeshedPaths": [
          "all-stubs/cpython_core",
          "all-stubs/pyboard_1_13_95",
          "all-stubs/mpy_1_13-nightly_frozen/GENERIC",
         "all-stubs/cpython_pyboard"
    ]
}
  • Copy the .pylintrc file from the sample folder and adapt the init-hook line to reflect the chosen folders (in last step):
[MASTER]
init-hook='import sys;sys.path[1:1] = ["all-stubs/cpython_core", "all-stubs/pyboard_1_13_95", "all-stubs/mpy_1_13-nightly_frozen/GENERIC", "all-stubs/cpython_pyboard",];'
  • Restart VSC:
Developer: Reload Window

Set up your project (in VSC terminal, with project open)

  • To check that your stub (config file for your board) has been installed run
    micropy stubs list 
  • If not, run
    micropy stubs add <path to stub> 

    (where the path is the directory that contains the info.json file.)

  • run
    micropy init <project name>
  • Select what to generate (‘a’ selects all)
  • select which stub to use (the one you just created)
  • A subdirectory will created with <project name> you just specified
  • Open the pymakr.conf file in the subdirectory <project name>. Change
    "address":"192.168.4.1" 

    to your comXX. To do this system wide for Pymakr, open the command palette (CTRL+SHIFT+P) and select/type “Pymakr > Global settings”

  • In the same config file, I had to set “auto_connect”: false to resolve some vague
    "> Failed to connect (Error: Port is not open). Click here to try again." 

    errors when connecting to the board. Setting this to “true” the following behavior: “ignores any ‘address’ setting and automatically connects to the top item in the serial port list”

  • See here for more explanation on the other options

Using the combination

  • To add package dependencies to your project:
    micropy install <PACKAGE_NAMES>
  • Functionality in the Pymakr addon can be used by opening the command palette (CTRL+SHIFT+P) and typing Pymakr. There are options to (dis)connect, run the current file, up/download the whole project, get the FW version,…
  • Note the new terminal “Pymakr Console”:
    Pymakr console
  • And the “Pymakr toolbar”:
    Pymakr toolbar

Shortcuts (from the Pymakr addon info)

ctrl-shift-c : (Re)connect
ctrl-shift-g : Global settings
ctrl-shift-s : Synchronize project
ctrl-shift-r : Run current file
ctrl-shift-enter : Run current Line

References

Ikea Välgjord (Electrolux dishwasher, HYGIENISK/SKINANDE ) error 50

See the edits below the text for two more possible causes I’ve encountered with this machine, both causing the same error.

Our Ikea Välgjord dishwasher stopped working last night. When switched on, it would take a minute or so, then begin beeping (three times, then about two seconds of silence). When opened, the display showed error code 50, and the bottom LED blinked.

The manual shows error codes 10, 20 and 30 but no 50.

I found the needed information on this (Dutch) site. Error 50 might mean that the pump is somehow obstructed, possibly by a shard of a plate or (in my case) a large piece of [insert some unrecognizable piece of food here].

The solution took maybe 15 minutes, possible less than a phone call to customer support would have taken. You need:

  • Torx 20 screwdriver
  • Philips screwdriver
  • Some rags
  • Ideally a shopvac that can be used to get the water out. Otherwise: a sponge…

Steps:

  1. Unplug the dishwasher. Seriously. Didn’t do it. Regretted that. (see below)
  2. Get as much of the water as possible out. Remove the filter from the bottom inside the dishwasher, then drain the water. Shopvac if possible, otherwise enjoy yourself with the sponge.
  3. Remove the wooden front panel: open the dishwasher. On each side of the door you’ll find a small grey plastic cover plate. Pop these off. Open the door about halfway until you can see a bolt through one of the holes. This is a torx 20. Remove these. The bottom of the front panel will come loose, so while you do this, hold the bottom of the panel up. Then slide it upwards to clear it from the dishwasher door. Try not to look at all the grime and dirt.
  4. Under the door, on the bottom front of the dishwasher, remove the four philips screws. Take off the metal cover.
  5. At the right side you’ll see the pump, rather small. It has two blue wires coming out of a connector on the side. Remember the orientation of the pump.2
  6. The pump can be removed by rotating it and pulling it backwards towards you. If there’s still water in the dishwasher (you probably cannot get everything out), water will wash out into the plastic drain pan. The float at the back will detect a water leak and the pump impeller will begin to rotate even if the dishwasher is switched off.

    The pump that you’re holding in your hand.

    In the tiny space underneath the dishwasher.

    With cables around it.

    So, you really might want to unplug the dishwasher from the start.1

  7. Remove the obstruction.
  8. Reverse the above.
  9. Fill the dishwasher filter hole with water (if you start the dishwasher without water, it will display the same error after a little while).
  10. Try it out.

<EDIT> (20 Jan 2019): I’ve successfully done this twice, but this time, there wasn’t any debris in the pump. I haven’t found any other pieces of food anywhere else. After a couple of tries without finding any obvious cause for the problem, the dishwasher started working again. Since the dishwasher is still within warranty (Ikea gives five years of warranty) and you shouldn’t have to do these kind of “repairs” with a new appliance anyway, we asked for a technician which will come over next week. Maybe he has some tips…
</EDIT>

<EDIT2> (24 March 2019) Completely forgot to follow up on the EDIT above. The technician found a bad seal in the washer motor and replaced it under warantee. He told me that it wasn’t something that happened a lot, but enough for him to have seen it before (as a repair technician).
Two weeks later, the washing machine gave the same error. The second technician (another one) found that one of the hose clamps on reservoir on the side of the machine was badly placed and replaced it. Likely, the machine would leak some water, go into alarm mode, get unplugged, would dry after a couple of hours and work again for a short while.
We’ve had no more issues since then, which is about two months ago.

 

So, in addition to “something in the pump” as below, you might want to check for small amounts/droplets of water under the machine in the plastic sump. It might be as simple as a hose clamp…
</EDIT2>

Hytera PD365 programming

I recently acquired a second-hand Hytera PD365 DMR radio.

Hours of trying to program the radio learned me that this is a bit of an odd one out in the Hytera range of radios. I spent *a lot* of time trying to connect it to my computer to read out the memory and program it. I found a lot of information spread out on the internet, but lots of it is not applicable to the PD365. You’ll find remarks such as “There’s a different driver for the PD365.” but which one to use isn’t marked. There might be a page dedicated to the PD365, but I haven’t found it.

I’m not claiming all of this is 100% correct and this is certainly not a definite “user guide to the Hytera PD365”, but there are a few things I learned that might save someone a bit (lot) of time.

First off a some info on my specific handheld, which might be important:

  • Frequency range: 430-470MHz
  • FW version: A1.02.09.001
  • Baseband version: V2.01.03P8

Things I found out:

  • There’s different versions of the PD365, covering different frequency ranges. Codeplugs cannot be interchanged between these two versions. (thanks to ON5LUC for pointing that out)
  • To program the device, you’ll need CPS (customer programming software) from Hytera. You’ll find that you can download it on a few sites. However, the versions you’ll find easily don’t work with the PD365. For this specific hand-held, version V8.06.01.010 and others in the v8 range will not work. You’ll need a version in the v2, such as V2.05.03.002.EM5
  • Getting the programming cable to work: I lost a lot of time trying to connect to the PD365. Since I found different drivers for the programming cable (without any explanation on what’s the difference and when to use which), and even batch files to remove previous versions of drivers, I figured there was a driver issue on my computer. Trying on another one had the same result. And another one. I kept trying to get Windows 10 to use the drivers that I found mentioned on different websites instead of using generic Prolific drivers. However, the CPS didn’t indicate any available port to connect to.
    After all, this wasn’t necessary. After installing and using the v2 CPS program, I could select the serial port that was assigned to the programming cable using the Prolific drivers (currently using version 3.8.25.0).
  • Reading the configuration from the hand-held instantly worked after connecting the hand-held to the programming cable and using the correct CPS. After making changes and trying to write to the hand-held, I had some more issues. The hand-held would display an error message, and the software would display a message box. After clicking OK in the message box, the software would force close without any further messages.
  • Upgrading the FW: there is a v1.06.01.001 FW version available. To use it, install the software package. Then disconnect the radio from the USB cable and remove the battery. Press the button under the PTT button (the round one), and place the battery. The red LED will blink. After about 3-5 seconds the LED will light solid. Release the button. The display on the HT is blank. Connect the USB cable. Start the software, select the correct COM port and click upgrade. The process takes a couple of minutes during which the software informs you multiple times that different phases of the upgrade are finished. Just wait. “Updating the firmware chip, please wait…” takes a long time and it might seem like something is wrong.
    Just wait. If all goes well, the process will end with ”
    However, the first time I tried this, the process ended with an error message after upgrading the FW chip (“Update the firmware chip failed”, the progress bar was at 72% at that time). However, after powering the radio on, the new fw seemed to be installed. Baseband version is now at V2.01.03P8_A.
    I tried the process again with the same result.
  • After upgrading I could write from the CPS software to the radio. The radio restarts after successful programming.

 

Current status

I’ve managed to program the local analogue repeater so that I can use it. I have not yet managed to get the DMR to work, probably most likely because I haven’t spent enough time learning about the DMR network and how it should be configured. Still, I expect the radio to work and that I will manage to get it configured properly.

 

Some useful links (some in Dutch):

https://www.hamdigitaal.nl/2015/03/firmware-upgrade-en-codeplug-bijwerken-pd365/
https://hytera782.blogspot.com/2015/08/hytera-pd-365-firmware-upload.html
https://manxrepeaters.com/index.php/digital-mobile-radio-dmr/articles-user-guides-and-help/user-guides-and-help/programming-a-new-hytera-radio
http://www.zendamateur.com/viewtopic.php?f=16&t=18207

 

HP 8640B Signal generator. Part 1: initial state

IMG_7088_cr

I recently acquired a HP 8640B signal generator. A quick summary of the specs shows why this is an interesting piece of equipment:

  • 500kHz to 512 MHz (option 2 adds a doubler, extending the range to 1.024 GHz)
  • Available power range is -145dBm to +19 dBm, withing +0.5dB across the full frequency range
  • Extremely low phase noise (less then -130 dBc at 450 MHz, 20kHz from the carrier)
  • Fine tuning (when in locked mode): >+/-20ppm
  • Integrated counter, switchable between the internal generator and an external input
  • FM and AM modulation
  • Beautifully engineered (but that’s just an opinion)

The retail price in the mid seventies was around 12.000 USD.

My unit has the frequency doubler (Option 2), and a serial number starting with 1522U, meaning it was produced in 1975 (add the first two digits to 1960), week 22 in England. As far as I know this is probably in a factory in Erskine, Schotland.

And obviously it doesn’t work as it should. At first sight, the apparent issues are:

  • The unit has cracked gears (which is a common issue)
  • Intermittent power rail faillures
  • Counter shows all zeros (seems to work with external signals when the -5.2v rail comes on)
  • No output power on the front connector
  • “Reduce FM vernier” is lit

At least, the display shows something, and there are some lights. More lights = better.

IMG_7122

It needs cosmetic work as well: there is flash corrosion all over the metal parts, and some kind of brown gooey residue. One of the modulation dials has a broken knob. Plastic has yellowed, the vinyl needs work. The list goes on.

First issues to be solved (apart from cleaning while waiting for components):

  • Fix -5.2V power rail (A18U1 needs to be replaced)
  • Replace burned diode on the A12 Rectifier board, possibly using an external rectifier placed on a custom made board
  • Zener diode A20VR3 (+44.6V LED) seems to have been burned, or is at least moving in that direction

After those issues have been solved, the RF path can be checked.

The following sources of information have been of great help so far:

  • The people at the great Yahoo HP/Agilent Test Equipment newsgroup
  • Various blog posts, I will list them where apropriate
  • The US Army TM 9-4935-601-14-7&P “PATRIOT AIR DEFENSE GUIDED MISSILE SYSTEM” Operator, organizational, direct support and general support maintenance manual

HP 8711A: modifications, tweaks, refurbishing

I recently acquired a fairly well preserved HP 8711A network analyser. As sold, this is an economy model, offering only scalar measurements (although vector information can be acquired through the HP-IB bus).

Conversion

What makes this unit interesting, is that the hardware is the same as the never released 8712A, which has vector capabilities. Some changes in the bootrom allow the user to “convert” the unit, making it behave like a full fledged VNA.

Credits for this rom modifcation go to Massimo Porzio (IK1IZA). As far as I know, he is the one who took the time to figure this out. I also found a lot of information on the site of Michal Lewczuk (SP2XDM).

Before doing anything, a backup of the correction constants was made to disk.

Unit boot screen as received:

20160927_173814

I used the TL866 USB High Performance Programmer which can be bought online for around €40. Download the software while you wait for the package to arrive, download speed reminded me of the late nineties…

The bootrom with attached label (on the A1 CPU board, removal of the CRT/PSU module is necessary):

20161006_211100

Contents of the ROM at address 0x1FFA0 prior to modifications:

eeprom-before

After modifications:

eeprom

New bootscreen (SRL and fault location enabled as well):

20161114_171152

Smith chart as proof of vector capabilities:

20161114_171232

CRT realignment and brightness setting

Some adjustments on the CRT were done:

  • When looking from a normal viewing angle with the unit placed on the desk, the alignment of the options on the right of the screen seems “off” when compared to the location of soft buttons next to them.
  • The screen was rather dim.
  • Sizing of the display compared to the cutout in the front panel could be enlarged.

I marked the locations of the front panel cutout and the top and bottom buttons on the CRT:

20161031_091501

After disassembling the CRT/PSU module and attaching the PSU to the back, followed by some creative cabling, the unit was powered on while leaving access to the alignment potmeters:

20161031_094911

The positions of the potmeters before adjustment were marked:

20161031_093910

After adjusting the height/width and brightness, the screen looked much better.

Power supply patch

According to a ECN from HP, units with serials between A00000 and 3325A00941 need a 3W, 680Ω resistor between pin 9 and 16 on J5 in the power supply.

Before:

20161107_212030

Resistor added and pcb cleaned:

20161107_212732

Speaker “modification”

The A models of this network analyser had an issue where noise would get into the audio circuit, causing a high pitched, squeeling noise. When used in a silent environment this was really bothersome, so I first tried replacing the speaker by a version with a slightly different resonant frequency.

This didn’t help enough, so I ended up with this ugly (but fully working) solution:

20161031_103828

Cleaning and restoring the unit

A lot of time was spend cleaning and restoring the unit, as to give it as much of its original appearance as possible.

  • The inside of the case was cleaned, connectors on the backplane (which are notorious for causing problems with this model) were cleaned using a combination of MEK, IPA, soda, warm water, patience and lots of love.
  • Front panel and keypad were cleaned, and the yellowing of the plastic due to age and UV was reversed through the use of high concentration hydrogen peroxide. Dents, holes and cuts were fixed.
  • The vinyl was cleaned, restored and treated.
  • Internals of the disk drive were cleaned.

Documenting this is worth a separate post.