Quantcast
Channel: 懒得折腾
Viewing all 764 articles
Browse latest View live

Making a simple AM Radio

$
0
0

Making a simple AM Radio

Follow articleChelseaBack13 Apr 2015221

title

First experiences with radio frequency circuits.

All the other projects I have made so far have been digital and microcontroller based, with the one exception to this being the Nutclough amplifier, which was assembled from a kit. The big difference in this project is that unlike the other ones which I have built from scratch it is an analogue RF circuit.

We already had some TA7642 AM receiver ICs in the workshop and some PP3 battery clips to hand, so I wanted to use both of these components in my circuit. Since I had never built any analogue circuits before I wanted to keep this fairly simple so would use an external test audio amplifier for testing.

title

After doing a bit of research it became apparent that a very important part of the radio is a tuned circuit, which can be tuned to a particular frequency in order to select the radio station desired. This can be made from an inductor and a variable capacitor connected in series or parallel.

I began looking for examples of circuits for the TA7642 and the majority used either a 1.5v or 3v supply. I occasionally found ones which used a 9v battery, however most of these seemed to incorporate built in amplifiers. After a bit more searching I finally found one which did not.


title

This circuit consists of:

– 1 x 9v battery
– 1 x 10k resistor
– 1 x 1k resistor
– 1 x 100k resistor
– 2 x 1n4148 diode
– 1 x .01uf capacitor
– 1 x .1uf capacitor
– 1 x 470uf+ capacitor
– 1 x 1uf+ capacitor
– 1 x TA7642 IC
– 1 x ferrite coil antenna
– 1 x variable capacitor
– 1 x test amplifier
– 1 x switch

title


I decided not to include a switch, as I could just remove the battery, so I removed the switch from the schematic. The ferrite coil antenna which I had had both a long wave and a medium wave coil on separate formers on the ferrite rod, each coil consisted of a longer coil and a shorter coil too. So there were four coils in total.

I began connecting the components as above in the schematic, using a breadboard. When I powered up the circuit I could hear a muffled radio station, but when I adjusted the capacitor nothing changed and it should have done.

I checked the layout against the schematic again and then powered up the circuit to find the same result. I then checked the values of all the resistors and capacitors for errors, here I found I had accidentally used a 100 ohm resistor instead of 100k. I replaced this and powered up the circuit once more hoping this would resolve the problem, but again it didn’t.


title

When I initially began looking at tuned circuits many of them only used a single coil of one length. So I then wound my own ferrite antenna using enamel wire and I attempted wiring my circuit with this.

title

The circuit didn’t work with this coil, so I tried again using the original medium wave coil, but this time not using the shorter winding. Instead by connecting the longer winding and variable capacitor in parallel and directly in circuit. 

title

When the circuit was powered up this time it surprisingly worked! Varying the capacitance tuned the circuit and the radio was now quite clear to listen to.

title

I’m still unsure as to why the radio circuit didn’t work the first time and I will look into this further to try understand what went wrong.

Another fun project as I learn more about electronics!


How to Make PCB at Home

$
0
0

How to Make PCB at Home

Last Updated on December 5, 2019 by Swagatam 19 Comments

In this post we comprehensively learn a step wise process of making small DIY PCBs at home through minimum effort and maximum precision.

DIY Step-wise Procedures

It basically involves the following crucial steps:

  1. Cutting copper clad laminate into proper size.
  2. Punching indentations for drilling holes for the component leads, as per the schematic.
  3. Drawing pads around the indentations with etch resist paint, and linking the pads through tracks using etch resist paint.
  4. Immersing the painted board in ferric chloride solution, until the chemical eats away the exposed copper, leaving the painted layout sections intact.
  5. Drying the board and scrubbing out the etch resist paint from the tracks and the pads.
  6. Drilling holes on the indentations.
  7. Polishing the finished board with fine emery paper.
  8. Using the ready PCB for assembly and soldering the parts.

Now let’s discuss the above steps in details. The first step in PCB production would be to acquire the essential resources and items. We are going to focus on all those things that are fundamental.

Materials Needed for Making PCB

To start the process we will first gather all the vital ingredients or materials required for the PCB making. The following fundamental things will be needed for the production

  • Copper Clad Laminate
  • Ferric Chloride Solution
  • Etch Resist Chemical or paint.
  • Painting brush or Pen
  • Container for etching the PCB
  • Drill Machine and Drill Bit.
  • Etchant Remover
  • Scouring pad, Kitchen Paper

Copper Clad Laminate

copper clad laminate

The most basic item will be the copper clad for making the printed circuit board alone, and you will find a variety of these.

The base (insulating) stuff is generally either fibreglass or SRBP (sheet resin bonded paper), and the latter is usually the more affordable option.

However, fibreglass has become the widely used both with commercial and recreational consumers as it is equipped with a couple of positive aspects.

The first is basically that it is tougher and for that reason less susceptible to bending and breaking than SRBP. The improved durability is additionally very helpful for boards that bear weighty parts for example transformers.

An additional benefit is that fibreglass is translucent and thus typically allows us to view the copper paths through the top (component) area of the board which is often worthwhile when examining and fault-finding.

Having said that, the standard of SRBP boards is more than satisfactory for many requirements. Marketing campaigns usually make reference to board as 1mm, 1.6mm, etc., and this is actually refering to the thickness of the base material.

Board Thickness

Naturally the thicker (about 1.6 to 2mm) boards tend to be more robust compared to slimmer (about 1mm) models, however the heavier quality boards are only crucial for large PCBs, or where weighty parts will likely be installed on the board.

For the majority of applications the thickness of the board is actually of little consequence.

Occasionally copper laminate board will likely be chosen as one ounce quality, or possibly two ounce quality, which appertains to the weight of the copper on one square foot of board.

Most circuits deal with just quite low currents, and regular one ounce board is just about all that’s needed. In reality one ounce board is frequently satisfactory even for circuits involving formidable currents.

The Etch Resist Paint

The etch resist is subsequently taken off to expose the copper tracks and pads.

Whichever paint that is able to keep the etchant away from the copper layout during the etching process can be employed as the resist.

etch resist paint

I personally prefer using nail enamels or nail polish, any cheap brand can be used and will work great as an etch resist.

Properties of Etch Resist

Professionally, probably the most widely used resists are waterproof paints and inks. Water soluble varieties are definitely not fit for purpose simply because these an get dissolved and washed off in the etching solution.

A paint or ink that dries quickly is more advantageous because it eliminates the need to wait for a long time before the board could be etched.

Even the more basic printed circuit patterns appear to have a large quantity of thin copper tracks within a relatively compact area of board nowadays, and a paint brush competent at creating extremely fine lines becomes necessary.

Drawing the Track Layout

etch resist pen

A simple solution would be to utilize an worn-out fibre-tip pen in paint brush manner, which can help develop outstanding final results although it might not look like quite a exquisite means to fix the issue. An easier way of implementing the resist is to use one of the commercially available etch resist pens which can be easily bought from any electronic part dealer.

Any kind of pen that uses a spirit based ink and a sharp point should be workable with this application. In case you are uncertain regarding the appropriateness of a pen you can easily pull out a few traces over a discarded copper laminate board then etch the board to verify if the ink maintains the etchant away correctly.

An additional type of resist are the rub-down etch resistant transfers which are available from several component merchants and which often can provide truly outstanding and specialized outcomes as demonstrated in the following example.

making track layout on copper clad

Actually you may find that there are lots of chemicals that can be applied as the etchant, but the majority of these are hazardous for some reason or another and are not likely suited to home designed boards.

The Etchant

The etchant is a chemical which reacts with the exposed copper area of the copper laminate and breaks it down from the board. It is used for taking off the copper regions on the board which are not painted by the etch resist and the areas which do not contribute to the track layouts and pads.

ferric chloride as PCB etchant

The etchant typically employed for home developed boards is ferric chloride, and while this is less hazardous compared to the majority of the choices, it is nevertheless a chemical that needs to be implemented with caution.

This should hence always be rinsed off quickly with running tap water in case you spill any on your skin. Make sure you don’t store ferric chloride in metallic containers, since this chemical is reactive to metals and make the metal porous and cause leakages.

As ferric chloride is toxic (and in in the course of many uses progressively gets transformed into copper chloride which is likewise extremely poisonous) it must obviously be stored far from foodstuff and utensils etc.

Types of Ferric Chloride

Ferric chloride can be obtained in a range of different forms. Probably the most handy type to have is a ready to use solution of the chemical. Many component suppliers market it in such liquid form; typically in 250ml containers and in a concentrated form.

You must dilute it a bit prior to use, as per the given guideline on the bottle. It may not require a great deal of dilution, and a 250ml bottle normally allows only 500ml or a litre after diluting it with water.

ferric chloride crystals

Some companies may provide the ferric chloride as crystals, also known as “Ferric Chloride Rock” sometimes. This label is very suitable since in this form it certainly looks like pieces of yellow rock rather then tiny nice crystals, which is pretty much rock solid.

In this type ferric chloride is normally available in 500gm packages, which is enough to generate one litre of etching solution.

You can as well get this in bigger packages, but since 500gm is enough to etch a seriously great number of regular size boards and may easily survive even an diligent constructor a very long time it is most likely not rewarding getting bigger than 500gm pack altogether.

How to Create Ferric Chloride Solution

In crystaline condition ferric chloride is not going to dissolve easily in particular, however when it is stirred steadily it may sooner or later break down completely, and with constant mixing it may melt fairly quickly.

Last but not least, ferric chloride can be acquired in anhydrous form, which basically signifies it’s genuine ferric chloride with virtually no water material. It will possess a slight degree of water in its crystalline form as an aside.

What actually causes this type of ferric chloride so hard to work with is the heating effect that is generated when it is mixed with water. Even if you begin with cooled water it can quickly become quite hot to a level at which the container turns very warm to touch, posing a danger of melting for plastic containers.

One more concern is that of having the chemical to dissolve adequately and create a decent etching formulation. For whatever reason you may find yourself ending up with a large quantity of chemical that will never break down, and also solution which appears like ferric chloride but has very little if any etching potential.

That is why cool water (ideally refrigerated or with ice) must be employed. It is additionally possible that there might be a tiny amount of chemical that won’t melt, which can either be strained from the liquid, or as it does not appear to impede etching it could simply be left in the solution.

Drill Bit Size

The next important ingredient for manufacturing PCB at home is the drill bit, which is required for drilling holes on the PCB for the component leads.

The typical diameter for component lead holes is 1mm, though a number of components like preset resistors, big electrolytic capacitors, etc. demand a bit bigger diameter. A hole diameter of about 1.4mm is appropriate for these kinds of components.

PCB drill bit

Typically, it is recommended to use a diameter of under 1mm for semiconductors and a number of other components that have thinner leads. 0.7mm or 0.8mm appear to be acceptable diameter for these components.

In case you have access to high quality drill bits they must be pretty tough.

However drill bits of around 0.7mm to 1.4mm in diameter may be quite weak and should be handled relatively carefully.

If they are maintained with downwards straight vertical pressure it may be fine, but if the orientation is not maintained at right angles to the board a proper hole won’t be created which is quite possible that the drill bit will break in two.

You have to for that reason take realistic care while drilling holes using such drill bits, and preferably the machine should be used with a adjustable stand as shown below.

PCB drill machine

We have so far discussed the key things which are necessary while making a printed circuit board, and there may be some other probabilities and ends which might be essential.

These are typically basic domestic objects though, and these will be unveiled as we advance with the etching course of action. You will find many different methods for manufacturing a printed circuit board.

Despite the fact that all of them are fundamentally the identical and the major dissimilarities are just the sequence through which the different measures along the way are performed.

We are going to hence begin by taking into consideration one approach of manufacturing a board, after which a couple of alternate techniques will be explained.

Getting Started with PCB Making

The very first step would be to check with the book or magazine where the printed circuit is presented in order to get the right dimensions of the board.

You might generally have a circuit schematic, a component overlay diagram, and the printed circuit track pattern reproduced in actual size, as given in the following 3 figures respectively.

track layout schematic

The size of the printed circuit should be available in the text or the schematic, however in many instances it will be required to consider the proportions through the real size copper track pattern.

Mark the boundary of the finalized board on the copper side of the laminate board, then pull an additional set of lines approximately 2mm or so on the outer side of the previous marking.

By cautiously cutting between these outlines you should be able to generate a section of board with decent precision and straight edges with minimum issues.

The sides of the board could be smoothed using a small flat file, and with fibre glass board that eliminates the abrasive ends which can be undesirable.

Be aware that the markings should be done on the copper side of the board and sawn from the same side to prevent peeling of the copper while cutting the board. Therefore, make sure to cut, or drill the board always from the copper side, and not from the laminate side

The next step would be to draw the positions of the holes for the components, and wherever suitable, the fitting holes for the board mounting.

The quick method to get this done is to clamp the schematic drawing over the board on the copper track, by accurately aligning the drawing and the board edges.

Then, with a bradawl or similar pointed tool carefully and accurately marking through the schematic onto the board by punching small indentations in the copper.

It is not necessarily essential to mark the board by punching with a pointed tool, and an alternate way is to simply align and stick the drawing to the board using cello tape, and then drill down through the drawing which now itself acts like drilling markers.

Painting the Tracks with Etch Resist

After the board is trimmed to size and all holes drilled, the next task is to paint the board with the etch resist. This basically involves cleansing the board as extensively as you can.

Special cleaning blocks can be obtained from the market and these apparently perform quite nicely. Copper laminate boards may generally show some oxide and corrosion on top of the copper surface, and it is very important to remove this or else this may prevent the board from getting properly etched.

Hence, it is recommended to make use of a reasonably powerful cleaning agent which will perfectly eliminate all oxide, dirt and corrosion from the copper surface.

After the board has been comprehensively washed and the copper layer appears glistening throughout, rinse the board beneath warm water to get rid of any remnants of the cleanser or oily ingredient. At this point make sure not to touch the copper surface, which might otherwise cause greasy finger marks and slow down the etching process.

Next, take the etch resist paint to pull copper pads round the holes drilled for the components leads.

After the pads are drawn with etch resist, it’s time to paint the copper tracks so that they link up the pads as per the circuit design. Always make sure to keep your hands away from the copper surface while doing this. Begin from the board one edge and proceed systematically towards the other edge, instead of doing it randomly (which might likely result in mistakes)

For Complex PCB Designs

Several contemporary printed circuit designs can be extremely sophisticated and challenging to replicate.

drawing tracks on complex PCBs

While designing a board of this kind it is recommended work with a printed circuit resist pen (or a appropriate alternative) with an even finer nib. In places that may have many narrow, tightly packed parallel tracks, you must take the help of a ruler to allow fine straight lines to be sketched.

If you see the tracks or pads merging with each other, wait for the resist to dry up and then make use of a compass point or other sharp pointed to scratch away the excess overlapping resist.

As soon as the resist has dried out and the PCB is inspected, the next task is to submerge the board in the etchant solution until eventually all the exposed copper has been taken off.

How PCB Etching Happens

Essentially what goes on in the course of etching is that the copper takes the place of the iron in the ferric chloride to form copper chloride, while the iron gets precipitated.

In the beginning etching process happens pretty fast and could take only a few minutes, but as the ferric chloride progressively gets transformed into copper chloride the etching action steadily becomes sluggish, and after several boards are etched it can be observed that the etching time is rather prolonged, or not getting accomplished at all.

In that case the etchant will need to replaced with new batch of ferric chloride solution. As you will notice that Ferric chloride has a red-yellow color while copper chloride is blue in color, so when you find the etching solution slowly getting towards more greenish, will indicate that the chemical is nearing the finish of its working life.

While etching the board at home in a small dish make sure the copper side of the board is facing up and the process is carried out in a non-metallic dish having adequate size.

You may want to add a decent cover on top and periodically remove the cover to check the outcome until etching is over. A main problem with this method is that an iron and copper chloride layer tends to develop on top of the board which may significantly prolong the etching time. This may be countered by carefully rocking the dish from time to time to displace off this layer so that the etching speeds up.

Using Special Containers for Etching

You may actually find it rather easy to set up a container in order to enable the PCB close to a vertical position with the copper side of the board facing downwards.

In this situation etching process happens really fast since iron precipitate is unable to develop a layer and tends to fall downwards away from the board. This ensures that the etching is not hampered. Still , periodic agitation of the board and etchant can help to knock off any small suppressing coating that may develop, enabling even faster etching.

DIY PCB etching vessel

Figure above shows a few easy options for accomplishing this. In Figure (a) a curved dish is employed which ensures that the board is maintained in place through the four corners, and does not come in contact with the dish at any other points.

The technique demonstrated in (b) a good choice for bigger PCBs which may necessitate a rather huge dish to enable the procedure. The container has to be pretty sizeable, anything similar to a classic instant coffee jar would work.

A great deal of etchant will probably be required so as to practically fill up the jar. This might look a bit pricey at first, however the etchant will certainly last proportionately more time compared to a smaller quantity.

Alternatively, a lesser amount of etchant can be diluted with higher amount of water, but this could considerably decelerate etching and is not advisable.

For substantially large boards the only functional method of etching the board could be to employ a big flat dish (like a photographic dish) with the copper side facing upwards. Frequent agitation may be accustomed to speed up the etching time.

Etching will be seen happening faster on areas of where there are smaller regions of open copper, and will take a lot longer on areas of the board where there are relatively wider areas of open copper. Etching also takes place more quickly round the perimeters of the board.

A method which usually works more effectively and is typically far easier in practice is displayed above. Here a pair of wooden or plastic rods are put down the entire length of the dish, on opposite sides. These are relatively longer than the dish to allow them to rest on top. The board is then hung from the rods supported on a couple of wire pieces, one at each end of the board.

Just a single wire is demonstrated in Figure for better understanding. If copper wire is used make sure it is a super Enameled copper wire having a thickness of 18 SWG. The wires are attached to the rods simply by turning the ends round the diameter of the rod once or twice.

After Etching is Over

When etching appears to be complete, you must thoroughly examine the board to make sure that there are no pockets of open copper left, and look for parts of the board where the copper tracks and pads are closely drawn (for example groupings of IC pads).

After you have confirmed that etching is totally accomplished, keep the board vertically over the etching solution for some moments to allow the dripping etchant elope the board, and then wipe the board using a piece of tissue paper or rag.

As an aside, this is a wise decision to maintain a piece of kitchen paper nearby throughout the etching process to ensure that remnants of etching solution could be wiped from the tweezers or gloves whenever needed. The board must be then carefully washed in water to launder away any final leftover traces of etching solution.

Removing the Resist

Finally at the end, the resist sticking on the copper has to be eliminated, that might otherwise seriously impede the soldering process on the copper pads. You can acquire any standard resist remover, and this may be in the form of a light spirit that will break down the majority of paints and inks.

scouring pads

It may be also feasible to obtain printed circuit polishing blocks that happen to be likewise well suited for scrubbing of the resist. One more technique is to try using a scouring pad or powder, and this is basically among the most straightforward activities of printed circuit production which should certainly not present any kind of challenges.

To enable the final assembly of the components on the ready PCB with perfect soldering and absolutely no “dry” joints, the copper tracks and pads must be polished to a glossy finishing before the soldering of the components can be actually commenced.

Over to You

As explained above, apparently making PCB at home looks pretty simple, and it is just a matter of a few hours to create outstanding professional grade PCBs using ready made DIY materials from the market. That said, the process may require some caution and precision for achieving the desired results, so that the intended circuit project is accomplished successfully.

If you have any doubts regarding the topic, please let us now through the comments below, we’ll be most happy to help!

Programming the GD32V Longan Nano

$
0
0

Programming the GD32V Longan Nano

Thu, Dec 3, 2020

Plasma on GD32V

RISC-V is gaining traction and some development boards have already popped up. One of them is the widely available Sipeed Longan Nano. Written information is a bit sparse at the moment. Let’s try to fix this with a quick writeup on wiring and programming the board. If you just want to see what the board can do here is a video instead.

Nuclei SDK

For programming a GD32V series SoC best choice at the moment is the Nuclei SDK. It seems to be well maintained, exceptionally well structured and is quite easy to learn. Developing is done with your favourite text editor.

The SDK supports three different real time operating systems: FreeRTOS, UCOSII and RT-Thread. Since Longan Nano has only 32kB SRAM you might want to stay baremetal instead.

Nuclei SDK does support Longan Nano out of the box. Basic hello world and the Makefile would look like this.

#include <stdio.h>

void main(void)
{
    printf("Hello world\r\n");
}

TARGET = firmware
NUCLEI_SDK_ROOT = ../nuclei-sdk
SRCDIRS = .

include $(NUCLEI_SDK_ROOT)/Build/Makefile.base

You would compile and upload it with the following commands.

$ make SOC=gd32vf103 BOARD=gd32vf103c_longan_nano all
$ make SOC=gd32vf103 BOARD=gd32vf103c_longan_nano upload

The SDK will take care of basic things such use redirecting STDOUT to USART. This is where the Sipeed USB-JTAG/TTL RISC-V Debugger really pays off. In addition to the JTAG interface it also acts as an USB to TTL converter.

$ screen /dev/ttyUSB1 115200

Nuclei SDK Build Time: Nov 14 2020, 23:17:41
Download Mode: FLASHXIP
CPU Frequency 108540000 Hz
Hello world

Uploading with the Sipeed RISC-V debugger

To make both JTAG and serial interface work you need to connect all pins except NC (duh!) between the debugger and Longan Nano. If nitpicking second ground is also optional. Longan Nano RST is pin number 7 on the left side of the USB socket.

Wiring GD32V with Sipeed debugger
DebuggerLongan Nano
GNDGND
RXDT0
TXDR0
NC
GNDGND (optional)
TDIJTDI
RSTRST
TMSJTMS
TDOJTDO
TCKJTCK

When flashing you also need to connect the USB-C socket to provide power. When using Nuclei SDK you can flash the firmware with make.

$ make SOC=gd32vf103 BOARD=gd32vf103c_longan_nano upload

Wiring GD32V with J-Link
DebuggerLongan Nano
VREF3v3
GNDGND
TDIJTDI
RSTRST
TMSJTMS
TDOJTDO
TCKJTCK

You can also use SEGGER J-Link Commander to upload the firmware. The command line utility requires the firmare to be in hex format.

$ riscv-nuclei-elf-objcopy firmware.elf -O ihex firmware.hex

You can connect to Longan Nano’s JTAG interface automatically with the following.

$ JLinkExe -device GD32VF103VBT6 -speed 4000 -if JTAG \
  -jtagconf -1,-1 -autoconnect 1

SEGGER J-Link Commander V6.86e (Compiled Oct 16 2020 18:21:57)
DLL version V6.86e, compiled Oct 16 2020 18:21:45

...

J-Link>

To upload a new firmware manually, first halt the CPU and load the firmware.hex from above. Reset the core and peripherals. Set the program counter to 0x08000000 and finally enable the CPU and exit the command line utility.

J-Link>halt
J-Link>loadfile firmware.hex
J-Link>r
J-Link>setPC 0x08000000
J-Link>go
J-Link>q

If the new firmware does no run automatically you might need to powercycle the board.

While manually poking the internals might be fun it gets bothersome in the long run. You can also put the above commands to an external file and pass it to JLinkExe to do all of the above automatically.

$ cat upload.jlink
halt
loadfile firmware.hex
r
setPC 0x08000000
go
q

$ JLinkExe -device GD32VF103VBT6 -speed 4000 -if JTAG \
  -jtagconf -1,-1 -autoconnect 1 -CommanderScript upload.jlink

Uploading via USB

If you don’t have an external debugger it is also possible to upload via USB. At the time of writing you need to use latest dfu-util built from source.

$ git clone git://git.code.sf.net/p/dfu-util/dfu-util
$ cd dfu-util
$ ./autogen.sh
$ ./configure --prefix=/opt/dfu-util
$ make -j8 install

Then add /opt/dfu-util/bin to your $PATH and you should be able to flash the firmware via USB.

$ make SOC=gd32vf103 BOARD=gd32vf103c_longan_nano bin
$ dfu-util -d 28e9:0189 -a 0 --dfuse-address 0x08000000:leave -D firmware.bin

Before running dfu-util you need to put the board to download mode. Do this by holding down the BOOT and RESET buttons and then release the BOOT button to enter download mode.

Hello World on Screen

For graphics programming you could use HAGL. As the name implies HAGL is a hardware agnostic graphics library. To make it work with Longan Nano you also need a HAGL GD32V HAL

$ cd lib
$ git clone git@github.com:tuupola/hagl.git
$ git clone git@github.com:tuupola/hagl_gd32v_mipi.git hagl_hal

Add both dependencies to the project Makefile.

TARGET = firmware
NUCLEI_SDK_ROOT = ../nuclei-sdk
SRCDIRS = . lib/hagl/src lib/hagl_hal/src
INCDIRS = . lib/hagl/include lib/hagl_hal/include

include $(NUCLEI_SDK_ROOT)/Build/Makefile.base

With all this in place you can create a flashing RGB Hello world!

#include <nuclei_sdk_hal.h>
#include <hagl_hal.h>
#include <hagl.h>
#include <font6x9.h>

void main()
{
    color_t red = hagl_color(255, 0, 0);
    color_t green = hagl_color(0, 255, 0);
    color_t blue = hagl_color(0, 0, 255);

    hagl_init();
    hagl_clear_screen();

    while (1) {
        hagl_put_text(L"Hello world!", 48, 32, red, font6x9);
        delay_1ms(100);

        hagl_put_text(L"Hello world!", 48, 32, green, font6x9);
        delay_1ms(100);

        hagl_put_text(L"Hello world!", 48, 32, blue, font6x9);
        delay_1ms(100);
    };
}

Animations on screen

For testing purpose lets assume we have three functions to initialise, animate and render bouncing balls on the screen.

balls_init();
balls_animate();
balls_render();

You can find the actual implementation in GitHub. With above functions we can implement the main loop.

#include <hagl_hal.h>
#include <hagl.h>

void main()
{
    hagl_init();
    balls_init();

    while (1) {
        balls_animate();
        hagl_clear_screen();
        balls_render();
    };
}

Bouncing balls with GD32V

Writing directly to display is fine for unanimated content. However above code will have a horrible flicker. Problem can be fixed by enabling double buffering in hte Makefile.

COMMON_FLAGS += -DHAGL_HAL_USE_DOUBLE_BUFFER

With double buffering enabled we also need to flush the contents from back buffer to display ie. front buffer. Here I also add some delay to slow down the animation.

#include <nuclei_sdk_hal.h>
#include <hagl_hal.h>
#include <hagl.h>

void main()
{
    hagl_init();
    balls_init();

    while (1) {
        balls_animate();
        hagl_clear_screen();
        balls_render();

        hagl_flush();
        delay_1ms(30);
    };
}

This is very naive approach and you need to manually adjust the delay to avoid tearing. It would be better to implement an fps limiter and flush the contents, for example 30 times per second.

Even though the Longan Nano is not the fastest and has only 32kB of memory the Nuclei SDK makes it pleasant to work with. Despite being tiny you can still do interesting stuff such as old school demo effects with it.https://player.vimeo.com/video/486801605

Additional reading

Posted in

ElectronicsGD32VHAGL

Notes

$
0
0

Randomness via an ADC

A much higher level of randomness can be obtained by observing some aspect of the real physical world, and capturing a noisy signal (“noise” == “random” in physics … sort of).

With an ADC, this is easy to do: leave one ADC input pin floating, and measure its analog voltage. The least-significant bit will be the noisiest, always fluctuating due to electrical noise, e.g. the omni-present thermal brownian motion. If we repeat this 32 times and keep only the lower bit, we should get nicely random results:

ADC<0> adc;
PinA<0> floatingPin;

uint32_t randomNumber () {
    uint32_t r = 0;
    for (int i = 0; i < 32; ++i)
        r = (r << 1) | (adc.read(floatingPin) & 1);
    return r;
}

https://jeelabs.org/2018/random-numbers/

alias pru='pio run -t upload'
[env:bluepill]
platform = ststm32
board = bluepill_f103c8
framework = stm32cube
upload_protocol = blackmagic
upload_port = /dev/cu.usbmodemE0C2C5A7
lib_deps = jeeh
pio device monitor --quiet -b 115200 -p /dev/cu.usbmodem469
picocom -q -b 115200 --imap lfcrlf /dev/cu.usbmodem469

https://jeelabs.org/2018/getting-started-bp/

https://github.com/gd32v-rust/gd32vf103-example

https://how2electronics.com/interfacing-ds18b20-temperature-sensor-with-stm32/

NeuG, a True Random Number Generator Implementation

$
0
0

NeuG, a True Random Number Generator Implementation

NeuG is an implementatio of True Random Number Generator, based on the sampling noise of ADCs (A/D converters).

It runs on STM32F103, and it outputs random bits at the rate of more than 80 kB/sec (kB = 1000-byte). The interface is USB, and it behaves as a device of communication device class. In GNU/Linux, it runs as /dev/ttyACM0. Note that tty discipline settings should be “raw”.

It is a true RNG, with SHA-256 conditioning component.

The Git repository

Please visit The Git Repository of NeuG.

Structure of NeuG

Here is a figure of the circuit.

NeuG 1.0.3
                                        Signal sources

                             /|<---+--- [ Analog input Vref ]
               16           | |<-+-|--- [ Analog input Temperature Sensor ]
            +---/-[ADC1] <==| |  | |
            |               | |<-+ |
     +-+    |                \|<---+
     | |<---+                |
+----| |          MUX CTL >--+
|    | |<---+
|    +-+    |                /|
|           |  16           | |<------- [ Analog input 0 ] (pull up to Vdd)
|           +---/-[ADC2] <==| |
|                           | |<------- [ Analog input 1 ] (pull up to Vdd)
|                            \|
|                            |
|                 MUX CTL >--+
|
+------------------+         <============ (*1)
                   |
                   / 32
                   |
                   | Put 4 times to output 32-bit
                   V
           [ CRC-32 filter ]
                   |
                   |           Put 35 times to output 1120-bit
                   +---------------------------------+         <====== (*2)
                                                     |
                                                     / 32
                                                     |
                                                     V
                                             [ Entropy Buffer ]
                                                     |
           +--------------+                          |
           |              |                          |
           | Conditioning |            1120          |
           | Component    |<------------/------------+
           |              |
     +-----|  Hash_df     |
     |     |    by        |
     |     |  SHA-256     |
     |     |              |  128
     |     |              |<--/--+
     |     +--------------+      |
     |                           |
     +---------------------------+
     |
     / 256
     |
     v
Random Number Output <========== (*3)

STM32F103 has two built-in A/D converters. NeuG uses A/D converters’ outputs as entropy sources. It is considered noise of quantization error, plus noise from power supply, etc.

We chose four analog input sources of: built-in voltage reference, temperature sensor and two analog inputs which are pull-up to Vdd.

Note that those signal sources are arbitrary and doesn’t matter. It is sampling itself, which gives us the entropy.

By a single sampling of two channels, we get 32-bit (not all 32-bit is valid, as a A/D converter resolution is 12-bit only). We take four sampling of combinations: (Vref, IN0), (Temp, IN1), (Vref, IN1), and (Temp, IN0). Those 32-bit * 4 is fed into CRC32 filter.

We use STM32F103’s CRC32 calculation unit as a kind of filter. We put output of A/D converters into CRC32 calculation unit, four times, to get 4-byte output. This is done because computation of SHA-256 is expensive if the sequence is too long.

Output of CRC32 filter is collected 35 times, and it becomes 1120-bit (32 * 35). This is the noise source bits.

We put this 1120-bit and half of previous output (128-bit) to conditioning component.

Conditioning Component is implemented by Hash_df function which is composed by SHA-256. Since the noise source is not “white”, signal is whiten by this Conditioning Component.

A Little History of NeuG

NeuG 1.0.3

Upgrade of Chopstx and Fraucheky.

NeuG 1.0.2

Upgrade of Chopstx. Firmware upgrade process change.

NeuG 1.0.1

Upgrade of Chopstx and Fraucheky. Optimization change.

NeuG 1.0

Chopstx’s bug fix for interrupt handling, introducing Fraucheky, the GNU GPL container.

NeuG 0.11

Use its own thread library, Chopstx. Improve the speed by tweaking health tests.

NeuG 0.06

Use its own USB stack (same as newer Gnuk).

NeuG 0.05

Improve speed of SHA256 hash function. As a whole, the speed of random number generation increases 2%.

NeuG 0.04

Improve speed when NeuG device is connected to full-speed hub. If it’s not full-size frame (== 64-byte), full-speed host submits a frame to device once per 1ms frame.

Run health tests for CRC-32 filtered output mode, too. It results slower generation speed for the mode though.

NeuG 0.03

In September 2012, Seth Schoen kindly informed me about the draft of NIST SP 800-90B.

It requires a device to have certified “conditioning component” to be full entropy source.

Thus, my journey to seek good “conditioning component” finished at this point. I decided to use hash_df function by SHA-256 for “conditioning component”.

I concentrate other points than conditioning component, such as use of ADC2, to get more performance.

NeuG 0.02

I was not satisfied about the performance of NeuG 0.01 and was not sure the quality of its output (although I tested the output of NeuG 0.01 by Dieharder 3.31 and NIST STS 2.1.1 extensively).

I played a bit with NeuG after release of Gnuk 1.0, and replaced NeuG’s component from CRC16 buffer to the WELL RNG structure in NeuG 0.02, as it looked better.

NeuG 0.01 and Gnuk 1.0

Then, I implemented NeuG 0.01 which uses CRC16 buffer to whiten noise source.

Gnuk (as of version 1.0) uses the routine of NeuG 0.01.

Initial Idea of NeuG

While developing Gnuk, I need good random number generator. Gnuk needs good random number generator for data encryption key to encrypt private keys (of RSA).

Early days, Gnuk didn’t have random number generator, and it required random bits to be stored into its flash ROM. It required its user to put output of /dev/random into there.

Then I got an idea (Initial Idea of TRNG implementation) while playing with STM32F103.

FRITZING IS STILL FREE! (HOW TO BUILD FROM SOURCE)

$
0
0

FRITZING IS STILL FREE! (HOW TO BUILD FROM SOURCE)

Want the latest version of Fritzing for free? This tutorial will teach you how to build the latest version of Fritzing from source code, which is still freely available from Github.

So what is building Fritzing from source anyway? Fritzing used to be a free to download community driven project but at some stage they introduced an enforced donation for downloading the appliction.

However the source code still remains available to download at no cost, so we can use some freely available tools to turn the source code into a working application. Fritzing can still be free!

Prerequisite

Setting up the tools for building Fritzing can be a little bit challenging but we will walk through it step-by-step. Once you have completed the first build, you will be able to quickly build new versions in the future so it is worth spending the time.

In order to build Fritzing you are going to need the latest version of Qt Creator. You can download it for free using the online installer.

  • Windows users choose MinGW or msvcXX OpenGL and the latest version of Visual Studio. The latter is recommended in the official build guide.
  • Mac users choose clang 64-bit

Windows users will also need Visual Studio for building Fritzing.

Download source code and dependencies

Whilst you download Qt Creator we can prepare the other required files. Go ahead and create a fresh directory called fritzing in a memorable location on your hard drive. I will be using Mac terminal, Windows users should use their native file structure (e.g. c:/fritzing)

mkdir ~/fritzing
cd ~/fritzing

Download Fritzing source

Now we need to download the Fritzing source code from Github. You can either download the .zip file from the Fritzing Github or use the command line with the git command if you have it installed.

Download the Fritzing app and extract it to your newly created Fritzing folder. Alternatively use the git command from within the fritzing folder.

git clone https://github.com/fritzing/fritzing-app

Download the Fritzing parts library and extract it to your newly created fritzing folder. Alternatively use the git command from within the fritzing folder.

git clone https://github.com/fritzing/fritzing-parts

If you go the route of downloading and extracting the .zip files, go ahead and rename the folders to fritzing-app and fritzing-parts.

Download dependencies

Now that we have the source code we need to download some additional dependencies.

Install Boost

Go ahead and download the latest version of Boost and extract it into your fritzing directory.

Mac users will probably want to download the .tar.gz version and Windows users will probably want to download the .zip version. However either will be ok so long as you have the tools to extract them.

Install cmake

Mac

If you don’t already have Homebrew installed, go ahead and open terminal and enter the following command.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

We can then use Homebrew install cmake with the following command.

brew install cmake
Windows

Windows users should download the precompiled binaries from the official website.

Install libgit2

Go ahead and download version 0.28.x of libgit2 from the Github releases page. Extract it into your fritzing directory and change the folder name to libgit2.

We will need to build libgit2 using cmake so go ahead and enter the following commands, substituting your chosen path for the fritzing folder.

cd ~/fritzing/libgit2
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=OFF ..
cmake --build .

Running Fritzing

Now that we have downloaded all of the dependencies, you should have a folder containing the following.

  • fritzing-app directory
  • fritzing-parts directory
  • libgit2 directory
  • boost_x_x_x directory

Setup Qt Creator

Once you have installed Qt Creator, go ahead and open fritzing-app/phoenix.pro located in the fritzing-app directory.

Open Fritzing in Qt Creator

This file will open in Qt Creator studio. If everything is configured correctly you should see some messages that state that libgit2 and boost have been found. Go ahead and click projects from the left-hand menu.

Add the first run command line argument

Next click run from the left-hand menu. We need to enter the following command line arguments, replacing the path for the path that you have chosen to locate the folders.

-f "/path/to/fritzing-app/" -parts "/path/to/fritzing-parts/" -db "/path/to/fritzing-parts/parts.db"

Once you have entered the command line argument go ahead and click the run button at the bottom of the left-hand menu. It will take a moment to build and then the Fritzing app should load for the first time. Awesome!

Add the subsequent command line argument

Once you are on the main Fritzing screen, go ahead and close the app. Then change the command line argument to the following.

-f "/path/to/fritzing-app/" -parts "/path/to/fritzing-parts/"

Qt Creator is now configured so you can go ahead and save the project. You can continue to use Fritzing via Qt Creator, however it is also possible to build an app.

Building Fritzing

Now we are ready to build a binary for Fritzing. This will give us a nice executable application that will run without the need for Qt Creator.

Build for Windows

Windows users will need to install Visual Studio in order to build Fritzing.

First we need to locate the file release_fritzing.bat stored in the fritzing-app/tools folder. Go ahead and open it your favorite text editor, Notepad will suffice if you don’t have a code editor.

You may or may not need to change the QTBIN directory for 64-bit builds. This directory should contain the qmake.exe file. If you edit the file path go ahead and save the file.

Next we need to open up a Visual Studio command prompt. This can be found on the Start menu under All Programs > Microsoft Visual Studio > Visual Studio Tools > Developer Command Prompt.

Simply drag and drop the release_fritzing.bat on to the command prompt and allow the compilation to occur, it may take a while. On completion you will have your very own completely free and fully functioning Fritzing program named fritzing.<version>.pc.zip and located in the releases folder. Awesome!

Build for Mac

Go ahead and open fritzing-app/phoenix.pro with your favorite text editor. Locate the line CONFIG += x86_64 and make sure the x86 ppc is commented out (it should have a # symbol before it like in the screenshot). If you need to amend it go ahead and save it afterwards.

Next we need to check the path in the deploy_fritzing_mac.sh file located in fritzing-app/tools. Go ahead and open it in your favorite text editor and check that the QTBIN path contains the qmake file. Change the path if necessary and save the file.

Now simply run the script to build Fritzing. You can do this from the terminal with the following command, using the path that you chose.

~/fritzing/fritzing-app/tools/deploy_fritzing_mac.sh

Once the script has finished building Fritzing, you should find the Fritzing app located in /fritzing/deploy-app. Awesome!

Conclusion

It takes a little work to setup the necessary tools for building Fritzing, however once you have successfully been able to build the app you will have your very own Fritzing binary, free to use forever!

If you ran into problems then it might be worth donating to the project as it is only a small amount that they ask for, and download the pre-compiled version.

Now that you have Fritzing installed, why not go check out some of my other awesome ArduinoESP device or Raspberry Pi tutorials!

Black Magic Probe (BMP) on Bluepill

$
0
0

Black magic probe (BMP) on Bluepill (STM32F103C8 Minimum System Development Board)

2019-04-05 15:00 | tags: STM32STM32F103C8bluepillbmpblack-magic-probearduinolibopencm3

Why I decided to write this?

I was recommended to use black magic probe (BMP) to flash / debug STM32 chips by friends from base48 hackersapce, so I searched the internet and found that there are several articles describing this procedure, such as:

And here is the github of black magic probe

Looks simple: get sources, compile, flash, but it was not so easy and straightforward as it seemed, here are some of the problems I experienced:

  • as a BMP I was using a clone of STM32F103C8T6: a CS32F103C8T6; I was unable to flash it with ST-LINK
  • when I make ST-LINK able to flash it I found that BMP compiled is >64kB and these chips refuses to flash more than 64kB (real STM32F103C8T6 are reported to be 128kB even datasheet says 64kB) – tried with ST-LINK and also tried to flash DFU first and then use it to flash the rest – both failed as 64kB reached
  • I wanted to use swlink pins already soldered on the bluepill board, so you dont need to solder anything to be able to use BMP as a debugger, but all articles were talking about different pins (PA5, PB14 instead of PA13, PA14)
  • my STM becomes locked showing 0kB of flash, I was unable to erase it or flash it – unlock via openOCD fixed this
  • articles above reccomends you to flash dfu bootloader first (blackmagic_dfu.bin), then connect bluepill via USB and flash the rest (blackmagic.bin) using dfu-util – this was not possible as dfu-util detected that firmware is bigger than reported flash size and refused to start flashing – see Announced versus available Flash size on F103

This article assumes that you have build tools for STM32 already installed, also as git, st-link utility (st-flash), etc…

CS32F103C8T6 clone

The problem why ST-LINK refuses to flash is the fact that this clone is reporting different coreid (0x2ba01477 instead of 0x1ba01477), you can fix this by change of STM32VL_CORE_ID constant in ST-LINK sources (include/stm32.h) and recompile, but even if you supply –flash=0x20000 parametter to force 128kB flash it starts flashing but fail at about 60-70% – it seems that this chip have 64kB of flash only.

Also I had problems to run Arduino LiquidCrystal_PCF8574 library example on this chip – the LCD was never properly initialized, it flashed on reset of bluepill (so there was some communication happening), but never showed any text – I suspect timing problems.

Some reading about STM32 clones:

Fortunatelly I have only 2 such boards using this CS chip and about 10 others with STM chip (bought from different chinesse seller, not sure they are 100% genuie but at least works), so I decided to stop wasting time trying to use this CS clone as it is reported as unreliable and I took different bluepill with STM chip.

If you modified the ST-LINK sources to be able to flash CS chip don’t forget to revert changes and recompile, otherwise it will refuse to flash “real” STM chips.

How to unlock chip showing 0 flash size

In case you bluepill wiil become locked and refuse to erase / flash, try these steps to unlock it:

  • install openocd (sudo apt install openocd)
  • move the BOOT0 jumper to position “1”
  • connect locked bluepill to ST-LINK (3V3 to 3V3, SWIO to SWIO, SWCLK to SWCLK, GND to GND)
  • connect ST-LINK to PC
  • run following commnd:
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c "init" -c "halt" -c "stm32f1x unlock 0" -c "shutdown"

Expected result:

Open On-Chip Debugger 0.9.0 (2018-01-24-01:05)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v4 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.279947
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0xa1000000 pc: 0x1ffff3b6 msp: 0x200000c4
Info : device id = 0x20036410
Info : flash size = 64kbytes
target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x200000c4
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.
shutdown command invoked
  • disconnect power for a short time or press reset button on the bluepill
  • don’t forget to move the BOOT0 jumper back to “0” position

Black magic probe for bluepill

  • connect the bluepill to the ST-LINK (3V3 to 3V3, SWIO to SWIO, SWCLK to SWCLK, GND to GND)
  • connect ST-LINK to the PC
  • execute following sequence – please note the “PROBE_HOST=swlink” which is not a typo – as amost all articles recommend you to use “PROBE_HOST=stlink” (with “t”), but the “swlink” option cause that the SWIO / SWCLK pins are mapped to the default SWIO / SWCLK pins which are already soldered on the blupill board by default – so you don’t need to solder pins to be able to use debugger, and this also makes life easier as these pins are already labeled as SWIO / SWCLK (also swlink is recommended option for bluepill in blackmagic wiki, dunno why all others ignore this)
$ git clone https://github.com/blacksphere/blackmagic.git
... progress of git ...

$ cd blackmagic

$ make PROBE_HOST=swlink
... progress of make ...

$ ll | grep blackmagic
-rwxrwxr-x  1 buger buger 1030380 dub  5 10:04 blackmagic*
-rwxrwxr-x  1 buger buger   73244 dub  5 10:04 blackmagic.bin*
-rwxrwxr-x  1 buger buger  345604 dub  5 10:04 blackmagic_dfu*
-rwxrwxr-x  1 buger buger    7348 dub  5 10:04 blackmagic_dfu.bin*
-rw-rw-r--  1 buger buger   20727 dub  5 10:04 blackmagic_dfu.hex

$ st-flash erase
st-flash 1.5.1-22-g4ff515e-dirty
2019-04-05T10:11:45 INFO usb.c: -- exit_dfu_mode
2019-04-05T10:11:45 INFO common.c: Loading device parameters....
2019-04-05T10:11:45 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-04-05T10:11:45 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
Mass erasing

$ st-flash write blackmagic_dfu.bin 0x8000000
st-flash 1.5.1-22-g4ff515e-dirty
2019-04-05T10:16:09 INFO common.c: Loading device parameters....
2019-04-05T10:16:09 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-04-05T10:16:09 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
2019-04-05T10:16:09 INFO common.c: Attempting to write 7348 (0x1cb4) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x08001c00 erased
2019-04-05T10:16:10 INFO common.c: Finished erasing 8 pages of 1024 (0x400) bytes
2019-04-05T10:16:10 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2019-04-05T10:16:10 INFO flash_loader.c: Successfully loaded flash loader in sram
  8/8 pages written
2019-04-05T10:16:10 INFO common.c: Starting verification of write complete
2019-04-05T10:16:10 INFO common.c: Flash written and verified! jolly good!

$ st-flash --flash=0x20000 write blackmagic.bin 0x8002000
st-flash 1.5.1-22-g4ff515e-dirty
2019-04-05T10:33:21 INFO common.c: Loading device parameters....
2019-04-05T10:33:21 INFO common.c: Device connected is: F1 Medium-density device, id 0x20036410
2019-04-05T10:33:21 INFO common.c: SRAM size: 0x5000 bytes (20 KiB), Flash: 0x10000 bytes (64 KiB) in pages of 1024 bytes
Forcing flash size: --flash=0x00020000
2019-04-05T10:33:21 INFO common.c: Attempting to write 73244 (0x11e1c) bytes to stm32 address: 134225920 (0x8002000)
Flash page at addr: 0x08013c00 erased
2019-04-05T10:33:23 INFO common.c: Finished erasing 72 pages of 1024 (0x400) bytes
2019-04-05T10:33:23 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2019-04-05T10:33:23 INFO flash_loader.c: Successfully loaded flash loader in sram
 72/72 pages written
2019-04-05T10:33:27 INFO common.c: Starting verification of write complete
2019-04-05T10:33:29 INFO common.c: Flash written and verified! jolly good!

Try to switch BOOT0 jumper to “1” in case that ST-LINK refuse to communicate with the bluepill.

Test it!

  • make sure both BOOT jumpers are in 0 position
  • disconnect ST-LINK
  • conenct bluepill to the PC using uUSB cable
  • use lsusb command to check that USB device “ID 1d50:6018 OpenMoko, Inc” is present
  • check that two serial ports are created /dev/ttyACM0 (for debugging) and /dev/ttyACM1 (for serial)
  • now you have your own BMP!

Try to flash blink from Arduino to another bluepill

  • connect second bluepill to your BMP (5V to 5V, SWIO to SWIO, SWCLK to SWCLK, GND to GND)
  • install / open Arduino and make sure that “Generic STM32F103C series” board is selected
  • open blink exmple (“File” -> “Examples” -> “Basics” -> “Blink”)
  • menu “Tools” -> “Upload method” -> “BMP”
  • menu “Tools” -> “Port” -> “/dev/ttyACM0”
  • upload the sketch, output in arduino should look like
Sketch uses 17044 bytes (26%) of program storage space. Maximum is 65536 bytes.
Global variables use 2576 bytes (12%) of dynamic memory, leaving 17904 bytes for local variables. Maximum is 20480 bytes.
Target voltage: ABSENT!
Available Targets:
No. Att Driver
 1      STM32F1 medium density
  • blink should be running = LED blinking

Flash oved gdb and run the code

  • connect second bluepill to your BMP (5V to 5V, SWIO to SWIO, SWCLK to SWCLK, GND to GND)
  • compile miniblink example from libopencm3 and run gdb
$ git clone https://github.com/libopencm3/libopencm3-miniblink
Cloning into 'libopencm3-miniblink'...
remote: Enumerating objects: 154, done.
remote: Total 154 (delta 0), reused 0 (delta 0), pack-reused 154
Receiving objects: 100% (154/154), 26.15 KiB | 0 bytes/s, done.
Resolving deltas: 100% (89/89), done.
Checking connectivity... done.

$ cd libopencm3-miniblink/

$ make
... progress of make ...

$ cd bin/stm32

$ ll | grep bluepill
-rwxrwxr-x 1 buger buger   1040 dub  5 11:31 bluepill.bin*
-rwxrwxr-x 1 buger buger 213272 dub  5 11:31 bluepill.elf*
-rw-rw-r-- 1 buger buger   2976 dub  5 11:31 bluepill.hex

$ arm-none-eabi-gdb -ex "target extended-remote /dev/ttyACM0"
GNU gdb (7.10-1ubuntu3+9) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Remote debugging using /dev/ttyACM0
(gdb) 
  • in gdb try to scan for the connected target:
(gdb) monitor swdp_scan
Target voltage: ABSENT!
Available Targets:
No. Att Driver
 1      STM32F1 medium density
  • attach the target
(gdb) attach 1
Attaching to Remote target
0x08000176 in ?? ()
  • load the debug binary
(gdb) file bluepill.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from bluepill.elf...done.
  • flash it into target and verify
(gdb) load
Loading section .text, size 0x410 lma 0x8000000
Start address 0x800037c, load size 1040
Transfer rate: 6 KB/sec, 520 bytes/write.
(gdb) compare-sections
Section .text, range 0x8000000 -- 0x8000410: matched.
  • run the blink!
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/jdrozd/temp/bmpa/libopencm3-miniblink/bin/stm32/bluepill.elf 
  • use CTRL+C to stop the program
^C
Program received signal SIGINT, Interrupt.
main () at template_stm32.c:19
19              __asm__("nop");
... led stops blinking now ...
  • continue the program
(gdb) continue
Continuing.
... led continues to blink again ...
  • use help command, “Useful GDB commands” from blackmagic wiki and google to find out more gdb commands
  • use quit command to quit gdb

Test the BMP serial

  • connect second bluepill to your BMP (5V to 5V, SWIO to SWIO, SWCLK to SWCLK, GND to GND)
  • connect also PB6 of BMP to PA10 of the second bluepill (TX-RX)
  • connact also PB7 of BMP to PA9 of the second bluepill (RX-TX)
  • we will use libopencm3-examples, lets prepare them
$ git clone https://github.com/libopencm3/libopencm3-examples.git
... progress of git ...

$ cd libopencm3-examples/

$ git submodule init
Submodule 'libopencm3' (https://github.com/libopencm3/libopencm3.git) registered for path 'libopencm3'

$ git submodule update
Cloning into 'libopencm3'...
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 25049 (delta 0), reused 0 (delta 0), pack-reused 25048
Receiving objects: 100% (25049/25049), 5.49 MiB | 2.11 MiB/s, done.
Resolving deltas: 100% (16441/16441), done.
Checking connectivity... done.
Submodule path 'libopencm3': checked out 'ff9664389bfb560145aa3b36ad8368900c57c3d8'

$ make
... progress of make, very long ...

$ cd examples/stm32/f1/stm32-h103/usart_printf/
  • open file usart_printf.c in text editor
  • search for “usart_set_baudrate(USART1, 230400);” and replace 230400 with 9600
  • replace all “GPIO12” with “GPIO13”
  • save the file and close text editor
$ make clean
$ make
... progress of make, very quick ...

$ arm-none-eabi-gdb -ex "target extended-remote /dev/ttyACM0"
GNU gdb (7.10-1ubuntu3+9) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Remote debugging using /dev/ttyACM0
0x08000588 in ?? ()

(gdb) file usart_printf.elf 
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from usart_printf.elf...done.

(gdb) attach 1
A program is being debugged already.  Kill it? (y or n) y
Attaching to program: /home/jdrozd/projects/stm32f103/libopencm3-examples/examples/stm32/f1/stm32-h103/usart_printf/usart_printf.elf, Remote target
0x080005c6 in reset_handler () at ../../cm3/vector.c:67
67      for (src = &_data_loadaddr, dest = &_data;

(gdb) load
Loading section .text, size 0x5de8 lma 0x8000000
Loading section .ARM.exidx, size 0x8 lma 0x8005de8
Loading section .data, size 0x8ac lma 0x8005df0
Start address 0x80005c0, load size 26268
Transfer rate: 17 KB/sec, 905 bytes/write.

(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/jdrozd/projects/stm32f103/libopencm3-examples/examples/stm32/f1/stm32-h103/usart_printf/usart_printf.elf
  • now the LED on the target should blink quicky
  • open new terminal (keep the terminal with gdb opened in background)
  • execute command “screen /dev/ttyACM1 9600” in the new terminal, you should see incomming “Hello world!” messages with some increasing numbers, like thoose:
Hello World! 4121 41.209091 41.210000
Hello World! 4122 41.219090 41.220000
Hello World! 4123 41.229088 41.230000
  • switch back to gdb terminal and press CTRL-C
  • the LED should stop blinking and “Hello world” messagess should stop also
  • type “continue” and press enter in gdb terminal – LED blinks and messages should start again, notice that numbers in the messages are NOT counting from 0 again but continues from where the program was interrupted

Used SW / HW / Links:

Rust on STM32F103 Blue Pill with Probe-run tooling

$
0
0

quick start

circuit4u

circuit4uDec 5, 2020·2 min read

Image for post

Rust embedded software tooling is always an interesting alternative to MCU vendor specific IDE software, such as those provided by TI, Microchip, STM32, Nordic, etc.

With the advent of probe-rs and subsequently probe-run software, Rust for embedded coding can take a different path from openocd + gdb, and it is getting more convenient.

There are already lots of cortex-m quick-start guides, especially of STM32F103 “Blue Pill”. Unfortunately, Rust library such as stm32f1xx_hal is changing fast. For example, the Timer now is initiated differently from the past.

Here is my latest try get it up and running:

  1. get hardware: STM32F103C8T6 module + ST-link (v2) debugger
  2. setup software: follow this link or stm32f1xx_hal (link) and use cargo install probe-run (link) instead of cargo install cargo-flash

3. git clone the source code from this repository: https://cgit.pinealservo.com/BluePill_Rust/blue_pill_base

change runner in .cargo/config to

runner = "probe-run --chip stm32f103c8"

4. In a terminal window, type

cargo run --bin blue_pill_base --release

That’s it. You should now see LED flashing and debugging message in the terminal window.

Useful References

STM32 Blue Pill pinout diagram (link)

Old way with openocd + gdb (link)

New way with probe-run (link)

Rust embedded GPIO model (link)

Rust software/hardware notes (link)


OpenOCD Notes

$
0
0

OpenOCD server

Start the openocd server in one command window. See the previous post Using OpenOCD to flash ARM Cortex M3.

#daemon configuration ################################################
telnet_port 4444
gdb_port 3333

#interface configuration #############################################
#
# Olimex ARM-USB-OCD-H
#
# http://www.olimex.com/dev/arm-usb-ocd-h.html
#
source [find interface/ftdi/olimex-arm-usb-ocd-h.cfg]

#board configuration #################################################

# Olimex STM32-H103 eval board
# http://olimex.com/dev/stm32-h103.html
source [find board/olimex_stm32_h103.cfg]

gdb_memory_map enable
$ openocd -f openocd.cfg

Flashing

We flash test_program.bin onto the ARM Cortex M3 using OpenOcd.

Connect to the openocd server using telnet in another command window

$ telnet localhost 4444

Halt execution of target in case it is running

reset halt

Erase content on flash

stm32f1x mass_erase 0

Flash test_program.bin

flash write_bank 0 test_program.bin 0

Run program but halt directly so that we can control the execution via the debugger (gdb)

reset halt

Debugging

Run gdb using our test program and connect to the openocd server on port 3333. We use the GDB TUI (Text User Interface) as described in Use GDB on an ARM assembly program.

gdb-multiarch -tui --eval-command="target remote localhost:3333" test_program.elf 

Display register values in GDB

(gdb) layout regs

Set a break point at the beginning of the main() function in test_program.c.

(gdb) hbreak main
Hardware assisted breakpoint 1 at 0x7c: file test_program.c, line 7.
(gdb) c
Continuing.

Breakpoint 1, main () at test_program.c:7

Inspect the values of ab and sum before executing sum = a + b.

(gdb) x 0x00000098
0x98 <a>:       0x00000007
(gdb) x 0x20000000
0x20000000 <b>: 0x00000008
(gdb) x 0x20000004
0x20000004 <sum>:       0x00000000

Execute sum = a + b using the GDB step command (section 5.2 in GDB manual) and inspect sum variable again.

(gdb) s
(gdb) x 0x20000004
0x20000004 <sum>:       0x0000000f

The sum variable now equals 0x0F (15) which is correct.

House Renovation

一次说清Refinance是什么鬼

$
0
0

房地产投资基础知识】一次说清Refinance是什么鬼

hongyuincanada楼主 2018-01-28我在多套房贷款经验分享讲座里提到了一个理财思路:Purchase ,Hold, REfinance and SEll,即,PHRESE投资法,不必太在意每套投资房是否有正现金流,通过买入+持有+refinance+继续持有+继续refinance + 最终卖出的投资模式,提高资金使用效率,提高回报率。这里面的Refinance一词成了本周多套房部落微信群里问的最多的问题。是啊,如果做不了Refinance,这个理财人生规划不成立了。到底Refinance是个什么鬼?像“按揭”一样,Refinance这个词的中文也来自于中国香港,被称为“加按”。
加按的意思就是此时此刻,用现在的房价和收入,重新做一遍房贷,把已有的房贷用新的房贷替换掉。只是房价涨了,借款人没有收入是没法加按的。如果想持续加按,即,每5-6年加按一次,必须保持良好收入水平。现在到了no income no mortgage的年代,房贷是稀缺资源,只借给财务能力最强的人,各家银行都在收回给新移民、非居民的优惠券,道理很简单,在加拿大要获得稀缺资源,先交税。如果想咨询加按的具体事宜,先告诉我你收入多少,所有人的房子都增值了,这个我知道,但没收入就是无法从房子里拿钱。 以前的文章里提到过,自住房的债务是坏债务,在我眼里,自住房的按揭贷款属于消费信贷,是家庭透支未来收入,提前消费欠下的债,需要用税后收入来偿还。自住房债务越大,申请新贷款的能力越低。自住房贷款,尽量不要做加按,除非家里有其他应急的事情需要从房子里取钱。对于自住房贷款,我的建议是在一个银行一口气付清,不用转银行,不用加按,付清时重新评估,做加按,做成一条信用额度/HELOC即可,这条信用额度也轻易不要用。对于投资房,我的看法完全不同,投资房贷款属于家庭商业贷款,而不是消费贷款,借钱是为了累积个人资产,获取租金收入,以及资本利得,贷款越多自有资金使用效率越高,只要有可能就加按加按一次资金使用效率就提升一次。总结一下,自住房一辈子只加按一次,最后做出一条信用额度备用就行了;投资房只要能通过加按将初始本金收回时就值得做。 关于加按我遇到最头痛的问题是:“加按和HELOC是一回事吗?”拜托,加按是个动词,意思是申请重做贷款。HELOC是个名词,Home equity line of credit是以房子做抵押的信用额度,您说能一样吗?当加按时,就是重做贷款,借款人可以选择把新的贷款做成按揭贷款、mortgage,或信用额度(HELOC),或信用额度加按揭贷款的组合。我总在想Refinance 和HELOC长得很像吗?咋总有人问我同样奇葩的问题呢?如果原来的房贷产品做成了按揭贷款/mortgage,趁着加按的机会可以改为带信用额度/HELOC的房屋贷款产品,或相反操作。总之,以前的贷款没能满足现在的需要,或现在有了新的需求,都有机会通过加按洗心革面从头再来。 加按对于地产投资者来说,是个宝贵的把还款期拉长到30年的机会。如果原房贷只是续约/renew,那么还款期/amortization只能越来越短。还款期决定了月供大小,月供越小,以后申请其他贷款就越容易,因此地产投资者,尤其是多套房投资者需要做的一件事就是经常把还款期拉回30年,为继续投资做好准备。续约/renew指在原银行续签贷款合同加按可以去任何银行做。续约不看收入,只看以往还款记录。有朋友给我打电话张口就问我续约的利率,可惜不是我们银行的贷款,我回答不了。再重复一遍,续约是renew,加按是refinance虽然长得像,也不能弄混啊。 转银行,指switch/transfer,香港同胞称之为“转按”。把原来的按揭贷款/mortgage余额原封不动地转到另一家银行,不增减金额,不改变房贷产品。如果原银行的原贷款是带信用额度的,无法转,只能做加按到其他银行。 加按的费用不高,通常包括评估费和律师费。评估费大约300元。律师的工作大多数情况可以通过产权保险公司来完成。如果不增减借款人名字,没有特殊的法律上的要求,银行通常建议借款人使用产权保险公司来完成重新注册抵押这一过程,费用比聘用律师便宜很多。一笔100万以下的加按,产权保险公司收费470元左右,而律师收费要1000元以上了。 加按时除了看收入,还要评估房价,如果是自住房用MPAC的估价,且贷款比例不超过这个估价的65%可以免除这个程序。投资房,都要做评估的。 无论自住房还是投资房,加按取出的资金如果用于再投资,其利息支出是可以抵税的。再投资,包括作为购买投资房的首付款,投资股票或共同基金等不是只有资本利得回报的投资品。如果用于加速偿还自住房贷款,投资TSFA,囤地,或消费等没有投资收入的用途,这部分资金的利息不能抵税。具体税务规定,建议大家与自己的会计师深入讨论。 约瑟夫.熊比特在他的《经济发展理论》中这样描述信贷:贷款是银行赋予企业家的购买能力。对于地产投资者来说,投资地产就是在进行以套利为目的的商业行为,地产投资者就是企业家,最终目的是资本回报率最大化,手段之一是加速资金周转速度,而加按就是不可或缺的,与银行为交易对手的套利行为,同时也是加速资金转速的商业行为。如果不加按,原来投入的资金难以取回,随着贷款本金的不断下降,杠杆比例越来越低,资金使用效率越来越差。加按就是银行在风险评估之后,决定授予地产投资人更多更强的购买力。套现出来的资金是有成本的,但再投资的收益率高于税后利息成本就会有利。例如,加按取出的资金利率3.3%,个人税率33.3%,税后的实际资金成本是2.2%,再投资的收益率只要高于2.2%就是有利可图的。 在加拿大,从房权中贷款出来是受鼓励的。政府机构,消费者保护局FCAC专门出版了电子手册指导消费者如何从房子里取出资金。 加按,对房价和收入都有要求,银行负责风险评估,以免过度借贷,只批准有足够偿付能力的借款人加按。多套房地产投资者如果希望完成PHRESE投资,即, 买入+持有+refinance+继续持有+继续refinance + 最终卖出的过程,要保持良好信用记录,足够高的收入,以及相当低的坏债务。本文中提到的一些暗语,例如“好债务”“坏债务”请阅读本公众号以往的文章。写完这一篇,我们又多了一个暗语“加按”。
下一篇我们详细介绍PHRESE投资理念和注意事项。

讲座视频连接 https://www.youtube.com/watch?feature=youtu.be&v=jrKyvtCoSnE&from=groupmessage&isappinstalled=0&app=desktop

年底了,加速还贷还是投资?【王红雨谈地产投资】

hongyuincanada楼主 2018-12-24

每到年底,银行房贷提前还款额度使用的期限到期前,大家都会考虑手中的资金是该提前还贷,买RRSP或TFSA,亦或做其他金融资产投资呢?这个问题在年底前,一定要做个决定了。

提前偿还按揭贷款,节省下来的利息不用上税,而投资收益是要上税的,除非是在TFSA账户中投资。自住房的利息支出不能抵税,除非能够证明重新从自住房中取出的资金用于投资。这些税务上的考虑,凸显了提前还款的优势。那么银行允许的提前还款额度就很重要了。房贷提前还款额度的大小标志着贷款合同的灵活度,对于浮动利率贷款来说,提前还款额度非常重要。A银行每日历年提前还款额度是20%,B银行每12个月允许提前偿还10%,2017年7月11日生效的两个贷款合同,到2018年7月11日,A和B 两个银行提前还款的额度差了30%,这期间央行加息了4次,从0.5%加到了1.5%,B银行的客户只能提前偿还本金的10%,而A银行的客户可以提前偿还40%。如果客户选择了B银行且是浮动利率,眼看着加息,即使有足够的现金用于提前还款,也无能为力。大多数银行,还款额度的使用,以日历年为界的,每年的12月31日就是截至日了,未使用的额度不能转入下一个日历年。

新的利率环境下,加速还款还是做其他投资,更容易选择了:利率涨了之后,提前还贷节省的利息更多了,所以提前还款收益比以往更大。当然,我说的都是自住房,投资房不必加速还款。加拿大有1542万套私产住房,其中有600万套房产上有按揭贷款,61%的房产上根本没有贷款。有贷款的房产,平均贷款金额为20.33万,谁拖了平均值的后腿,特别是自住房金额高于21万的家庭,都应该采取提前还款的方式降低贷款金额。很多华人不相信这个数字,加拿大人怎么可能只有这么少的债务呢?不相信这些数字的人都是近10年来的新移民吧,房贷余额太高是因为你来晚了。自住房不还清,不能退休,退了休也得想办法继续还,何不尽早还完呢?很多还清了自住房的客户告诉我,还清自住房贷款那天,有可以安心退休的赶脚。一句话,自住房债务是你自己的事,没还清之前,不用担心手里的现金无处安放,因为自住房债务早晚要付清,付不清,无法退休。

很多人“不舍得”加速偿还自住房按揭贷款的一个理由是,要留些现金做地产投资的首付款。这种顾虑是多余的,自住房贷款太多,根本批不了投资房贷款。自住房的所有开支,包括按揭贷款的月供,地税,取暖费,公寓管理费,都属于消费债务,就是我以前文章中提到的“坏债务”,当申请投资房贷款时,所有消费贷款的月供都会被考虑进去,当借款人无力支持“坏债务”时,银行不会批准投资房贷款。有志于做地产投资的朋友,首要任务也是加速偿还自住房贷款。这到底是什么原因,一篇文章根本说不清,网上有个视频,是我与大鹏地产公司举办的联合讲座,播放为2小时23分钟,看完之后这辈子就不会被房贷问题所困了。视频连接。抱歉啊视频在油管上,大陆的朋友看不到。

债务管理,在很多家庭里没有被纳入财务计划之内,想换自住房了,去银行问问能不能贷到款,自己筹划一下首付款,就行动了。其实,债务的管理更需要计划和安排。在实际工作中,我遇到很多房贷“植物人”:现在住在A房子里,房贷已经付清了,手里有些积蓄,打算换个自住房房,于是借了家庭收入的5倍的房贷,加上手里的现金买了新的自住房B。住进B之后,发现需要给A 房产加按,到银行一问,不行了,原因是自住房B的贷款属于消费贷款,已借到极限,A房已经转作了出租房,家庭收入无法支持对出租房加按。于是,这个家庭就变成了房贷“植物人”,无法移动,眼睁睁看着投资房里的净房权无法取出,失去了资金周转,以及进一步投资的可能性。正确的做法应该是:谋定而后动,先把自己住的房加按,加到最大极限,取出尽量多的房权做购买B房的首付,B房作为自住房,按揭贷款的余额要永远保持最低。凡是自住房贷款金额最多,投资房贷款很少的家庭,都是缺乏债务管理常识或债务安排失误的家庭,属于姿势不对,应该起来重睡。房贷的计划失误,可以毁了一个人一生的财务规划,一笔房贷做错了,可能一辈子受穷。

如果自住房已经还清,或提前还款额度已经用尽,可以考虑投资有税务优惠的金融资产,例如,RRSP,TFSA等。每个家庭的选择不一样,有的家庭财技高超,投资收益颇丰,应该优先选择TFSA;有些家庭缺乏财务知识,但收入很高,需要优先选择RRSP。如果这些有税务优惠的项目都用尽了,可以考虑投资其他金融产品,例如,加息趋势明显的情况下,可以投资浮动利率的债券或优先股。最后,实在不想投资金融产品,可以加速偿还投资房按揭贷款。

提醒大家一下,RRSP缴存时,如果没有现金,可以申请RRSP loan,但是近期有买房贷款计划的朋友需要知道,RRSP loan的每100元月供,会降低2.5万借款能力。

年底,手头现金的使用优先顺序为:加速偿还自住房按揭贷款,投资RRSP,TFSA,投资其他金融资产,加速偿还投资房按揭贷款。退休前,我们需要实现三个目标:夫妻互保100万人寿保险,拥有一套没有房贷的自住房,200万金融资产。第一个目标最容易实现,但依然有人连人寿保险都不买。总之,每个人的现金都是有限的,面对三个财务目标,你的钱不可能无处安放。

拥有多套投资房,实现提早退休和财务自由—-是众多房产投资者的终极目标。也有不少朋友说拥有和管理一套出租房已是不容易的事情,拥有和管理多套投资房一定是难上加难,实际情况是如何哪?为了深入浅出的讲明白这个议题,让我们从多套房投资者必须满足的三个条件说起:

一,稳定而且连续的家庭年收入:

大家都知道买房子的要诀是“Location,location,location”, 那么成功拿到房屋贷款的要诀就是”income,income,income”,故想要成为多套房的投资人,保持稳定的收入是第一要任,那您一定会问:需要保持多少稳定的收入才能考虑投资多套地产哪?渥太华2018年的平均成交房价在35万左右,而因投入产出率高而受广大房产投资者青睐的房产的价格主要集中在30万到50万之间的房产,我们取40万作为一个标准价格,30% 的首付–12万,您需要贷款28万,而按照目前银行的贷款审批标准—单笔贷款金额是年收入的5倍,故您需要至少有5.6万加元的年收入,银行才考虑贷给您28万的贷款。

故总而言之,“有收入,才有房贷!”要想快速拥有多套投资房,您需要满足的第一个条件就是:稳定而且连续的家庭年收入至少在5.6万以上。(注:这里的家庭年收入都是指税前收入)。

2-3.png

 二,尽可能少的家庭坏债务:

债务由好债务和坏债务之分,我们的目标就是帮大家扛起尽可能多的好债务,丢掉尽可能多的坏债务:

好债务—-有别人帮着扛的债务就是好债务,主要是指投资房的按揭贷款,因为有租客在帮着还贷款,所以是好债务。好债务不但不会影响贷款人的贷款额度,反而会帮助借款人拿到更大的贷款金额,这一点对多套房投资人尤其重要—因为单笔房贷的最大金额与收入和坏债务直接相关,而多套房贷款的总金额是与收入和好债务两个因素相关。这也是我们可以帮助大家快速拥有多套投资房的要诀之一。

坏债务—-自己扛的债务都是坏债务,这些债务都需要用自己的税后收入来偿还,常见的坏债务包括:自住房贷款月供,自住房的地税月供,自住房公寓管理费月供,每月自住房取暖费;以及所有消费贷款的月供,包括汽车贷款月供,学生贷款月供,以及信用卡消费额的3%。

每100元坏债务的月供,大约降低借款能力2.5万(这就是400元的车贷会让您的贷款额度下降10万的原因)。故要想快速拥有多套投资房,除了努力提高收入,第二就是尽快减少自己的坏债务!

2-4.png

 三,来源清晰的首付款:

银行规定,对于所有以投资为目的的房屋贷款,首付款比例最低20%,故投资房产之前,准备至少20%的首付款也是必不可少的前提条件。买房前至少提前一个月将钱转入加拿大的银行户口,以便银行可以确认这笔大额入账的清晰来源。

这里有一点需要那些目前已经拥有一套自住房的地产投资人注意—–

现有房产refinance套现的资金可以合理合法地用于下一套房子的首付款!

2-5.png

准备好上面的三个条件,我们就来具体地讲讲如何拥有多套投资房:

 PHRESE多套地产投资法:买入/Purchase,持有/Hold,加按/Refinance,继续持有,继续加按,最终卖出/Sell.

这里首先解释一下“加按/Refinance”这一个专业术语—中文翻译成“加按”—就是指此时此刻,用现在的房价和收入,重新做一遍房贷,把已有的房贷用新的房贷替换掉。加按就是从房产中将以前投入到房子中的钱以及增值的部分拿出来,一方面,通过加按,可以把资金杠杆加大,把还款期拉回25年或更长,使被房子占压的资金重新流动起来,从而实现提高资金周转率和杠杆效用;另一方面,通过加按取出的钱可以做进一步的投资,产生更大的复利效应。请大家记住:贷款越多,自有资金的使用效率越高,只要有可能就加按,加按一次资金使用效率就提升一次。

2-6.png

 这里需要注意一点:您现有的房子的价格涨了,但如果您现在没有收入,是不能完成加按的!也就是说:如果想持续加按,即,每5-6年加按一次,必须保持良好收入水平!

 讲完“加按/Refinance “,我们就可以顺畅地为大家介绍PHRESE多套地产投资法啦,为便于大家理解和实际操作,我们仍然使用案例讲解法:

2-7.png

 投资人老王,家庭年收入一直稳定在6万以上,2013年以35万的价格购入(Purchase)一套单车库新独立屋A用于出租,首付7万,贷款28万,每年的租金恰好可以支付每年的贷款月供、地税和简单的维护,持有(Hold) 5年,2018年,房子的市场价格涨到40万,老王到银行申请加按(Refinance),重新贷款80%—32万,老王计划对这套房子A继续持有,5年后继续加按;同时用重新贷到的32万,减去房子A目前剩余的23万贷款,实际到手9万,作为首付买进一套50万左右的投资房B,并开始重复买入/Purchase,持有/Hold,加按/Refinance,继续持有,继续加按这一过程,这样坚持下去,不断将买进的每一个房子按期加按,用每次加按取出的钱去买C,D,E,F.G,H………..即可。退休的时候,老王可能拥有十套投资房,卖掉其中的3套,套现的钱用于加速偿还其余7套投资房的本金,并主动降低月供,让这7套房产生正现金流,安全退休。

2-8.png

 通过上面这个例子,大家都对PHRESE多套地产投资法都有了一个直观的认识,这里再重点重复和强调几点:

1,如果您现在有一套基本还清贷款的自住房,请注意:现有房产refinance套现的资金可以合理合法地用于下一套房子的首付款,务必好好利用!

2,保持工作收入,即,一定要有地产投资以外的稳定收入,主要是用于加按时银行贷款申请;

3,保持自住房贷款最低,如果自住房已没有贷款,就可以大踏步地做地产投资啦。

4,PHRESE多套地产投资法:买入/Purchase,持有/Hold,加按/Refinance,继续持有,继续加按,最终卖出/Sell,多套房投资理论和实践,其实非常简单,只要不犯错误,家庭收入6万,35岁开始使用这个方法,65岁退休时拥有10套投资房,完全有可能。但简单并不是容易,这需要投资者坚定的投资信念和坚持不懈的努力!

千万次的问: 投资CONDO,还是HOUSE

$
0
0

千万次的问: 投资CONDO,还是HOUSE

阅读量:133  

疫情期间,房东和房客都经历了一次考验。我的朋友圈和客户群的很多房东们,都有过在疫情期间换租客的体验。

租客遇到财务困难是普遍现象,但是租客处理交租问题的态度却迥然不同:有人拒不交租金,因为疫情期间法院停止了驱逐欠租人;有些租客负担不了租金,主动提出搬出与家人和朋友合住;有人与房东协商适当降低租金,疫情后补交。

房东遇到拒不付租金的情况,在疫情期间是无能为力的;遇到换租客的情况,新租客的租金低于原租金的情况比较普遍。有人慨叹,遴选租客应该小心、再小心,千万不要遇到一有困难就不付租金的人。我个人认为,租客的财务能力与房东选择的房产有关,如果房东选择了能分租的房产,且把房子分组给几个财务能力最弱的家庭,疫情期间肯定遇到很大问题。选择租客,就是选择能帮助房东扛住房贷的家庭,买投资房的时候,目标就是选择分租给财务实力弱的家庭,遇到疫情这样的压力测试,这种投资思路的弊端立刻兑现。

我在5月和6月的多次讲座和访谈中都坚定认为,多伦多的房地产市场将会出现:房价稳健,交易量V型反转的走势,5月和6月就是市场底部。其实任何一个客观,并躬身入局的人都能做出这种预测,疫情让所有人都意识到,家,才是最后的庇护所,家里所有人在疫情之下,都退守回家里的时候,居住条件到底好不好,只有自己最清楚,要不要租更大空间的房子,要不要买房,很快就能做出一个明确的判断。进入7月份以来,买家已经平复心绪,打算入场,买CONDO 还是买HOUSE作为投资房的话题,又被提了出来。

我在YouTube 上6集视频讲座《为了平衡一生的收入我们被迫投资》中讲过了我的看法:地产投资的合作伙伴分两类:参与者和服务者。参与者包括,你自己+银行+租客;服务者包括,地产经纪,保险顾问,法律顾问等。地产投资者与服务者的关系是利益共同体,需要每次结清服务费;地产投资者和参与者的关系是事业共同体,需要长期不断接触、磨合,打交道,共同完成投资大业。租客,是地产投资的参与者,是投资人的事业共同体,在地产投资中发挥着和银行一样的作用。能选到什么样的租客,最重要的决定性因素是投资人选择了什么样的房子。财务能力最差的租客,都住在所谓的“价值洼地”地区,本来财务能力就弱,而且不在乎社会认同感,欠租了也不搬走;追求体面生活的租客,不可能与其他家庭合租在一个屋檐下,遇到财务困难也会主动搬走,最多是给房东添一点儿换租客的麻烦,而不是欠租。

选择投资CONDO 还是HOUSE,有很多考量因素,但最好不要打分租HOUSE的主意,因为这是地产投资的一个死胡同,进去就出不来了。

01 CONDO 管理费上涨影响其房价上涨吗?

我们拿2020年6月的最新数据看一下,多伦多独立屋HOUSE成交价112.7万,镇屋成交价78.6万,CONDO 成交价63.2万;10年前的2010年6月,多伦多独立屋HOUSE成交价54.3万,镇屋成交价36.5万,CONDO成交价30.8万。独立HOUSE,镇屋TH和CONDO 的涨幅分别是107.5%,115.3%,105.2%。大家可以请地产经纪,将任何一个月的成交价与10年前的成交价做个对比,结论都是一样的:每10年,HOUSE和CONDO 的涨幅是一样的,无论投资哪一种类型的房产,多伦多的房价都是每10年翻一倍,CONDO管理费涨跌不影响CONDO的升值潜力。

多伦多的CONDO,从2010年开始到2016年,每年涨幅不到4%,远远落后于非CONDO的其他房产,从2016年开始补涨直到2020年,补回来了应有的涨幅。2010年到2016年期间,很多人看到CONDO涨幅远低于其他类房产,于是产生了怀疑:是不是CONDO 管理费涨得太高,影响了涨幅呢?正如我们看到的,把CONDO某一时期涨幅不大,归因于管理费是错误的,补涨的这4年里,再也没有人嫌管理费涨得快了。其实,管理费的涨幅和地税差不多,大家把CONDO管理费视作为地税就可以。

CONDO管理费中,包括了一些生活费用。因为管理费是房东支付,等于房东帮助房客支付了一些生活费用,因此CONDO的租金比同样居住房面积的HOUSE高。HOUSE投资者,作为房东,通常只是支付地税,水电气等全部费用,都是由租客来支付,因此租金比同样面积的CONDO更低。换句话说,CONDO房东支付的管理费,已经从租金中得到了补偿。CONDO投资者需要承担管理费和地税,但由于CONDO的占地面积小,所以地税很低,管理费一部分被视作地税,一部分被打入租金,CONDO投资者的心情就能平衡很多。行为经济有个定义叫做“心理账户” mental accounting,指人们把费用和开销在心里进行分类,便于计算得失,结果导致了只见树木不见森林的结果。管理费加地税就是CONDO投资者的成本,租金已经体现了这个成本,可很多人偏偏在心理账户上单独把管理费又重新计算了一遍,这属于重复计算成本。管理费和地税,其实都是租客通过租金支付的,而且在报税的时候这两项费用都能抵减租金收入,让房东在税务上二次获利。

02 笨蛋,上车最重要

躬身入局到地产投资的人,不会有“是不是CONDO管理费太高影响房价了”之类的问题。提出莫须有问题的人,都是地产投资的旁观者。有读者在我文章后面留言“你怎么避而不谈REFINANCE贷款利率高不高的问题?”这有什么可谈的呢?你去做REFINANCE就知道利率高不高了。如果利率高得不值得做,就不要做了,大多数REFINANCE还有罚款呢,利息和罚款都是获取新资金的成本,高不高要看你拿钱去做的投资回报率是否足够高。只有在行动上什么都不做的人,才会问一些行动派完全想象不到的问题。任何投资都一样,坐而论道和躬身入局的两组人,生活在不同的世界里,没法有效沟通。我通常把沟通成本太高的人,直接从生活中删除。另外,伸手党永远不感谢任何人做的任何事,不必解答他们提出的怪问题。

《黑天鹅》的作者塔勒布,写的另外一本书的中文书名是《非对称风险》,英文名是Skin in The Game,根据这本书的内容,我觉得中文书名应该改为《躬身入局》。当你在一个游戏中用自己的皮肤来测量温度时,才会有切肤之痛或爽肤之快,置身游戏之外,不承担任何损益的人,无法获得真正的知识和经验。回顾我来多伦多10年多的投资历程,各类损失和遗憾不胜枚举,但这些学费交的太值了,让我的皮肤/skin充分领略了投资这个游戏/game的冷暖,试错成本就是投资损失,能力边界就是通过试错拓展出来的,但试错需要勇气和行动,需要躬身入局。网上有一段话,应该是一位躬身入局的人写的“不要羡慕那些比你好的人,别人只是每一分钟都在做你不敢做的事,吃了你不想吃的苦,说了你不好意思说的话,认识了你没有勇气认识的人,坚持了你放弃的事情。”把这段实践者的总结送给大家共勉:不要做个只会抖机灵、动嘴巴的“精明人”;自崩“精明人”的人设,做个敢于行动、尝试和犯错,相信实践出真知的“笨蛋”吧。

按照国家银行的可负担能力计算方法,多伦多CONDO的偿债率是37%,多伦多非CONDO房产的偿债率是61%。“偿债率GDSR”,就是指每月房产相关债务与收入的比值,偿债率越高说明房子的债务越重,银行在评估借款人能否获得贷款的时候,GDSR设置为39%,低于39%获批,高于39%获拒。从国家银行偿债能力报告上看,绝大多数买CONDO的申请人都会获批贷款。

房地产投资最重要的是走出第一步。只有躬身入局,才不会大战风车,被想象中的问题吓倒。CONDO是房地产投资的入门级物业,希望开始地产投资的读者,最好从投资CONDO开始。

03 人聚财聚,贵者生存

房地产是红酒,不仅贵,更要看原产地——《金牌投资人》。

追求房地产投资回报的努力中,很多人都忘了房地产的最大特点location,location,location。地点之所以重要,就是因为房子的增值潜力来自于稀缺性。为什么会有CONDO 这种房产形式呢?就是因为某个地点很稀缺,同时太多人想住在这里,土地有限而天空无限才会有CONDO这种物业。建在人口稀疏地区的CONDO没有投资价值,以多伦多为例,STEELS以北的CONDO投资价值大打折扣,大家记住一点,投资CONDO,就找人多的地方,不拥挤的地方不要去。

永远不要因为价格牺牲了地点。同样的价格,要选最拥挤的地方投资。有人拿CONDO和HOUSE投资对比,60万在市中心只能买CONDO,在远郊能买HOUSE,如果选择买HOUSE,就是因为价格牺牲地点。房地产是红酒,本来就是高品质,不能买便宜货,图便宜是自欺。

大多伦多与上海面积相当,大多伦多人口620万,上海人口2430万,同样的面积,多伦多人口相当分散。人口如果不是拼命向一个地方集中,房价是上不去的。就像堆沙丘一样,同样的面积,沙子越多沙丘越高;同样的面积,人口越多,房价越贵。大多数CONDO都建在人口密度最大的地方,天然为投资者选好了LOCATION。多伦多CONDO的每尺价格就是人口密度的标尺,很多人觉得目前的CONDO价格太高,那是因为以后的价格更高,多伦多目前的人口密度太低,还有很大的浓缩潜力。

04 CONDO 还是HOUSE?

投资CONDO好还是投资HOUSE好?这个问题我已经被问了千百次。从实际生活中看,同时能负担CONDO和HOUSE债务的家庭,处于选择两难境地的人并不多。即使借款能力很强,我个人也建议把鸡蛋放在两个个篮子里。例如,首付足够买一个HOUSE做投资房,也可以做两套CONDO的首付款,那么买两个CONDO出租,更能够分散空置的风险,毕竟两套房子同时空置比一套房子空置的风险少了一半。

对于多套房投资者来说,管理房产所花的时间和精力会成为一个瓶颈。有10套CONDO同时还能保持全职工作的家庭我见过,但拥有10套HOUSE投资房,还能全职上班的人我还没有见过。保持全职工作的收入,非常重要,一旦成为全职房东,再想加按房产,几乎是不可能的。如果房产无法加按,等于自断资本来源,没法从房子里再提取资本用于其他投资。李笑来在他写的几本书里都提到了一个非常关键的定义“场外赚钱能力”,投资股票要有股市以外的赚钱能力,投资房地产更要有房地产以外的赚钱能力。举个例子,疫情期间,租客遇到还款困难,房东无法采取激烈的手段驱逐,房东有租金收入的时候,投资房的债务是好债务,一旦没有了租金收入,投资房贷款立刻变成了坏债务,需要用自己的税后收入去填补租金损失,此时的场外赚钱能力成了救命稻草。如果房东早早主动放弃了场外赚钱能力,完全靠投资收益养活自己,投资收益一旦中断,自己又没有场外赚钱能力,可能会被迫卖房。这就形成的塔勒布经常提起的“肥尾效应”Fat tail,即,极端不可能发生的事情真的发生了,从而摧毁了整个投资组合,以前赚的钱,一次赔进去。躬身入局就会发现,持有CONDO和HOUSE,房东所花费的管理时间和精力是完全不一样的,投资HOUSE所花的时间和精力太多,经常导致投资人放弃持有多套房的奋斗目标。能同时持有多套房,还能维持场外赚钱能力的方式,就是选择花费管理精力和时间更少的房产,CONDO。

为什么说投资了HOUSE又进行分租的投资方式,属于死胡同呢?首先,大多伦多地区99%的社区都是ONE FAMILY ZONING的社区,即,一家庭社区,分租给多个家庭不符合ZONING 的区化要求,只有多伦多下城的老城区很小的区域才有合法的可分租HOUSE。不符合区化要求的房产,大多不符合防火要求,有些房东申请了消防局的许可,其实火灾隐患还是比租给一个家庭大很多。如实向保险公司披露分租的事实,很多保险公司拒保,这样肥尾风险就是变成了全烧掉还没有赔偿的黑天鹅式灾难。找到承保高风险的保险公司,投资成本就提高了。其次,商业银行拒绝给分租的,不符合区化要求的房产加按,投资者自断资本循环回路,即使保持场外赚钱能力,房子不符合银行要求也无法让资本周转起来。再说一遍,银行和租客是地产投资的参与者,地产投资事业能否顺利进行,不顾忌其他两个参与者的情况和要求,终将失败,太任性只顾自己利益,最后的结果好不了。买了HOUSE就想方设法分租,有人看到这么做现金流不错,把工作还给辞了,完全切断了资本再循环的渠道,丧失了场外赚钱能力,继续投资只能去寻找投资的合作伙伴。讲英语的地产投资俱乐部里,大批这样的投资者,自己已进入死胡同,靠别人拉一把继续投资,这种joint venture 的做法在华人社区没有市场。

05 CONDO和HOUSE的投资组合

疫情给CONDO出租市场带来了很大冲击,尤其是国际留学生集中的楼宇,空置现象很普遍,租金也在持续走低。租房市场能否出现反转,完全仰仗疫情控制的进程,以及加拿大政府何时取消非居民入境限制。目前,非居民是无法在7月31号之前入境加拿大的,因此多伦多CONDO市场还要再坚持一段痛苦的时间。

房子的内生性价值取决于租金的折现。租金2500的房产,按照25年折现,价值为2500元X300月=75万。如果租金降到2200则内在价值会跌到2200元X300月=66万。如果CONDO租金一蹶不振,房价会受到很大影响;如果租房市场疫情后出现V型反转,则房价不会受到影响,只是疫情期间租到房子的人获得了实惠。

2010年至2016年,CONDO租金比持有成本高,属于房价被严重低估状态,因此期间入手CONDO的投资者现在笑的很开心,但也有房东在这6年中耐不住寂寞把房子卖了。2016到2020年间,持有成本超过了租金,年轻人租房住更节省开支,因此租客有增无减,支持了CONDO 投资者,同时也让新加入CONDO投资的人觉得持有成本偏高,比较吃力。

CONDO最近4年的价格上涨,有力地支持了HOUSE未来几年的发力反弹,40万买的CONDO,60万卖掉,拿20万做首付换HOUSE很爽。2020年将成为一个分水岭,CONDO租房市场的空置率会提高,价格涨幅回落,租金比持有成本低,更多人租而不是买;受疫情影响而长期失业的人会推迟首次置业的时间,造成交量减少的卖方市场局面。

投资者面前有两个选择:1.趁着CONDO价格平稳,继续买入;2.HOUSE市场回暖在即,炒热门股,买HOUSE。我个人的建议是:1.必须坚持地点优先原则;2.早买,能买到什么买什么;3.先投资容易管理的物业,积累起经验之后再加大难度。

如果目标是10套投资房,建议先买5套CONDO,边实践边学习。说到学习,我听说有学习班可以在课堂上学习房地产投资,这是在陆地上学游泳,扔到水里就现原形了。即使想交学费,也要交给市场,而不是学校。对于长期投资来说,市场变化不重要,有人看着房地产市场的K线寻找买房时机,我看还不如去庙里烧香管用呢。即使能够抄到低,也只是安全边际比同辈人大一点儿,但不可能比早5年买的人更有优势。

结语:股票投资,是一个选股游戏。房地产投资,不是选房游戏,而是一个借钱投资的游戏。存钱投资的钱途,一片黑暗,无风险收益率已跌到1%以下,加上风险溢价4%,存钱投资的收益在5%左右。房地产投资的综合收益率在15%左右,借款比例越大、自有资金比例越小的情况下,收益率随杠杆比例增加。最重要的是,按揭贷款利率近似于通胀率,因此实际利率趋近于0,借钱投资已成为低利率环境下当代人必须掌握的投资技能。房子,只是借款的载体。《穷爸爸富爸爸》系列丛书中,作者罗伯特清崎从未介绍过如何选择房产,因为房子不重要,借款才重要,能够满足选到好租客,满足银行对抵押品的基本要求即可。借钱投资的根本是借到低利率的贷款,而这种贷款最好的载体就是房子。租金不仅帮助偿还利息,同时也在偿还本金。房地产投资者,把房子只当做收租的工具还不够,还应该尊重和保护银行的抵押品,不要非法改建分租,破坏抵押物的品相,否则就会损毁房子用于再融资的功能。什么时候地产投资者的眼中,把房子只看成是抵押物,什么时候就不会再纠结投资CONDO还是HOUSE了。有人纠结投资CONDO还是HOUSE,一纠结就是10年,其实就是不敢躬身入局,无他。

葛剑雄

$
0
0

葛剑雄今天 00:38 来自 微博 weibo.com我知道这几天网上骂我的文字不少,但都是躲在暗处或他们自以为安全的角落里用只有他们自己知道的名字,甚至公然造谣污蔑,我一律不予理睬,也不会上他们的当,增加他们的点击量。再说,其中有些人连基本的逻辑关系都不讲,有的连再明白不过的话都故意不懂,回应他们纯属浪费时间。我也从来不上微信,看公众号,也不知道那些地方还有什么不同的文字。友人转来杨争光先生的大作,我才得知还有如此认真的公开批评,要再不回应那就太不尊重杨先生,太失礼了。
不过,读完杨先生的大作,却大失所望。如果杨先生真的看过听过我在西安交大的完整讲座,以杨先生这样一位大作家的敏锐洞察力和精准的表达能力,何至于对我说的大白话产生那么大的误解,作出如此脱离事实的判断。
首先,我究竟说了什么?无非是这几层意思:中国古代的历史、尤其是正史、官史,都是为了维护当代当朝的政治合法性;当代的历史自然是为了肯定执政党的政治合法性,在中国的特殊情况下,“历史的选择“具有特别重要的意义,所以近代史就是政治,反对历史虚无主义也是政治,而不是所谓”学术“。官方对近代史的解释是一根完整的证据链,其中任何一个环节都不容抽掉或脱节。学术研究仍应坚持真理,实事求是。但在成果发表时要将国家利益放在首位,如不利可在内部说,或直接报告当局。”宣传有纪律,学术无禁区。“
请问我的话哪里说错了?哪一点不是事实?哪一点是我个人的观点?哪一点是我的发明?哪里是在向当局献媚?我的确说了,在中国,《宪法》规定了执政党的领导地位,所以如反对执政党就是最大的违法。讲近代史不是学术问题,而是证明执政党合法性的政治。我说这番话,意在告诫青年人、天真的读书人不要以为近代史是学术,可以自由讨论。网络、媒体都属宣传,要守“纪律”,课堂也要守纪律。只有这样才能获得学术的“无禁区”。
如果杨先生认为这些话本身是错的,那应该直接批评呀!我不过是个解释者、说明者,至多只是个按教材讲的教师呀!譬如“历史选择说”,难道杨先生不知道是什么时候、为什么、怎样提出的吗?如果不赞成,为什么不直接批评?当然杨先生有保持沉默的自由,我也理解杨先生为了安全适可而止的智慧,但我只是将这层纸捅破了就成了善变,成了失节,成了无耻,成了杨先生的讥讽和批评的对象,这公平吗?
我变了吗?这些话我并非第一次说,至少已经说了五六年了。在网上传的另一篇就是当初在岳麓书院讲的,我在高校、图书馆、论坛讲过几十次了,基本内容和观点都没有变过,今后也不会变。我一直主张,在学术上要坚持自己的观点,但没有必要也不应该触犯政治的底线,更不应走极端。如果想搞政治,就堂堂正正搞,不要打着学术的旗号,更不要混在学术界累及他人。请杨先生扪心自问,难道你不是一样吗?

深度挖掘借款力 王红雨

$
0
0

认知盲点 在资本主义社会中,钱的主要作用是用来投资的,不仅仅是用来消费的 投资的两个工具,复利和杠杆中,在利率高的时候复利作用大,利率低的时候杠杆作用大 一分耕耘一分收获是无产阶级和农业/工业社会的思维,不适合资本主义和信息社会;没有被税过的收入,不能作为杠杆 对房价的恐惧,让一些人只看到现在,看不到未来,用自己的收入衡量别人的买房能力。房价是关键的少数人决定的。 房子是用来住的:自住或租给别人住 房价不会永远上涨,是的,谁也不可能活到永远 年轻人买不起房,就是因为你们买了太多投资房。嫉妒是七宗罪之一,现在披上了“社会正义”的外衣 “我把房子卖了,已经落袋为安,就等房价下跌再买进”。这是卖错了时机的人对认知失调的自我辩护。 技术盲点 存款多,没工作,收入不上税,生活来源在海外….根本没有打算或没有能力在加拿大扎根的人,很难获得房贷。 房贷压力测试B20,是针对每套房产,而不是一个家庭的总计贷款金额。贷款余额有500万的家庭,不一定年收入有100万,更有可能是年收入12万,每个房子贷款50万,总计10套投资房 A银行说你不能再贷款了,可以试试B银行。压力测试B20没有对租金如何使用做出明确规定,所以每个银行算法不一样 银行要求的收入需要具备两个要素:verifiable and sustainable,不满足的申请人会被拒之门外。全职工作改成自雇不到2年,基本上被所有银行拒绝 地产投资是与银行合伙买房,银行出80%资金的条件是,买银行接受的房产。Rooming house, student home,居住面积太小的房产,有hotel 成分的CONDO,都有可能被拒绝 不同银行对借款能力的评估 B20压力测试:用5.25%做测试利率, 偿债比例44%/39%,而实际利率1.5%,压力测试是防止加息后无法负担房贷的情况发生,效果是低收入人群难以获得贷款。通过压力测试的人才能享受低利率的奖励。 压力测试让人群分化为:能拿到资本的和不能拿到资本的;房东还是房客;有产还是无产;先富起来还是后富起来 对于首次置业者来说,所有银行执行一模一样的B20 为凭传统收入无法贷款的人群设计的不同“项目” 对于已经有了一套房产的家庭来说,每个银行运用B20的政策不一样: 为凭传统收入无法贷款的人群设计的不同“项目” 租金收入使用的比例和方法:从50%到100%;直接扎差还是直接算收入和负债;算现金流还是算总体负债能力 武当:现金流派,每月收入与债务的比为1.25以上就会获批,即使自住房债务高,也能申请到投资房贷款。自住房债务大的家庭,地产投资起步比较早,但投资房贷款的LTV比较低,通常在65%。这些银行的人在做讲座的时候拼命强调:买有现金流的房产。 少林:看申请的总体偿债能力,不看现金流,将已有的投资房租金收入与其债务一一对应地扎差,扎差时已有投资房的租金收入算85%到100%,如果目标房产是投资房,租金收入算50%-80%。 江湖传言,先在XX银行申请贷款,后在YY银行申请贷款。不是这样。 现金流/武当派,在自住房贷款较多时就可以开始贷款买到投资房,起步较早,但首付比例太大,杠杆效率低。 整体债务派/少林派,要求自住房债务较低,不要求现金流,主要看employment income是否足够用,坏债务少的家庭首付低至20%。 先在武当派申请到投资房贷款的家庭,待自住房债务等坏债务降低后,通过加按到少林派,可以提取大量现金用作更多投资房首付。 10套投资房的投资者,最终会达到:自住房很早还清,债务都集中在投资房上,投资房贷款都集中在少林派。 没有被使用的HELOC也算债务,是武当派的死穴。 HELOC的功能 现金储备 利率调节器 降低罚款 首付款来源 建议:不要为了多申请一笔贷款而取消现有的HELOC 提高借款能力要做的家庭作业 房地产投资是一种修行:减少坏债务,推迟满足感的过程。 坏债务:自住房贷款,度假屋房贷,(给父母\子女住)不收租金房产的贷款;汽车贷款,学生贷款,个人享乐和消费的贷款,都是坏债务 加速还清坏债务,收父母/子女的租金 打算投资房产,资金用于加速偿还自住房贷款,优于投资RRSP/TFSA 有租金的房贷,属于好债务。收父母子女的租金可以低于市场租金,净租金收入为0即可。 不收父母子女租金,A和B 两处房产都算作自住房,买C房作为投资房时的TDSR计算: (每月A房债务+B房债务+C房债务)/(工作收入+80%的C房租金收入) 收父母子女租金,A房是自住房,B房是投资房,买C房作为投资房时的TDSR计算: (每月A房债务+C房债务)/(工作收入+80%的C房租金收入-B房每月债务与85%租金的差) 坏债务全部放在分子上,好债务与租金扎差后放在分母上 提高借款能力操作手册 自住房贷款金额的公式是年收入的5倍,“搬家”可以将现有房产变为投资房。 换自住房之前,加按原有自住房,目的是让新自住房贷款金额最小化。A换到B之前加按A,B换到C之前加按B,保持自住房贷款最小化 确定C为今生不渝的自住房之后,所有自有资金用于加速偿还自住房贷款,无情地推迟任何省税策略。 借助外力施猛药强力去坏债务 退休的必备条件:自住房没有债务,保留一条大金额的HELOC,不要使用

把银行当做朋友

$
0
0

把银行当做朋友

阅读量:285  

转王老师文章

银行,是经济的心脏,资金从银行泵出泵入,承担着信用中介的功能。银行的传统业务包括:支付,存款,汇款和贷款。作为普通消费者我们日常使用的功能大多是支付、汇款和存款功能,贷款并不经常发生。华人使用信用卡的支付功能较多,并不怎么使用信用卡的借贷功能。然而,银行的所有服务功能中,只有贷款才会帮助普通人实现家庭财富的跃迁,让财富积累快人一步。银行的贷款对于家庭来说是一种虚拟资本,而生活在资本主义国家的人,没有资本就只能将自己的时间出售给资本,即,打工的人;有资本,哪怕是虚拟资本,也能使自己有机会改姓资,成为社会中的主导阶级,即,被打工的人供养的人。

想让银行成为自己的朋友,并获取虚拟资本,实现家庭财富跃迁,首先要了解银行,其次要保持敬畏,最重要的是善用各类贷款工具。

01 银行的爸爸和妈妈

要想把银行当做朋友,就需要了解银行。从按揭贷款业务来讲,银行的爸爸是OSFI,即,银行监管当局,房贷政策B20 的作者,制定了首付超过20%的房贷政策;银行的妈妈是CMHC,既可以为首付不足20%的借款人担保,又收购银行的按揭贷款,套现给银行,类似于美国两房的功能。

B20大家再熟悉不过了,就是压力测试政策嘛。按照压力测试的要求,借款人首付不低于20%的情况下,银行需要使用最低5.19%的利率来计算借款人的偿债能力,即使借款人的实际利率还不到3%。银行的爸爸OSFI就是严管银行房贷操作的监管机构。

CMHC妈妈则恩威并施,首付不到20%的借款人,妈妈负责担保;商业银行做好的贷款可以随时卖给妈妈,换取现金,继续做贷款。金融风暴过后,美元三轮QE把钱撒向了华尔街的资本市场,于是股市一直繁荣至今;人民币四万亿给了国营企业,私营老板把厂子卖了去买房了;加拿大是怎么从金融风暴中熬过来的呢?加拿大的救市资金是通过CMHC直接放水给商业银行的,商业银行拿到这笔资金之后做了更多房贷。2008年底开始的Insured Mortgage Purchase Program,就是鼓励银行把房贷卖给CMHC,属于加拿大版的量化宽松政策QE,不过资金不是投放到股市,而是房地产。很多人不明白为什么加拿大的房地产从2009年一路高歌到2017年,媒体和议员还借机误导公众去谴责非居民,其真实的原因是:政府直管的国企CMHC,放款给商业银行做更多贷款,推升交易量——现金给了卖房子的人,夯实有房一族的财富阶层地位,贷款给了买房的人,给了无房者提升财富阶层的机会。不了解银行和加拿大房产金融体制的人,如果在2009到2017年没有买房,而是投资了加拿大的股票,则白白错失了家庭财富跃迁的机会。现在回头看,很多祥林嫂的肠子都悔青了。不了解银行,不了解加拿大的房贷金融体系,不和银行交朋友,还得继续后悔下去。

Chart, line chart

Description automatically generated

2016年11月起,CMHC停止收购投资房按揭贷款,只收购自住房按揭贷款,市场资金一下就被收紧了。这条新闻在华人社区没有被报道,说明有用的、专业的主流媒体的新闻,华人社区的小编根本看不懂,华人社区对加拿大房贷金融体制,以及银行的了解还很少,政策的东风借不上,也就找不到投资的风口。亡羊补牢,为时未晚,学习和了解现行房贷政策,可以帮大家从现在开始建立起健康、长效的房地产投资组合。

02 加拿大银行在房贷政策上的武当和少林两派

低利率的环境下,银行的理财顾问是没法帮客户小钱赚大钱的,能保值、跑赢通胀就完成任务了。低利率年代,是以建立房贷资产包为核心的投资战略,因为存钱不合理,只有借钱买资产才是顺势而为。

投资房贷款审批的政策,银行分武当和少林两派。武当派,要看投资房是否有现金流,即,按照商业贷款审批的原则审核民用物业的按揭贷款。按照武当派的原则,大多伦多地区的房贷比例基本上都低于房价的65%,所以投资房杠杆低,但即使自住房贷款大一些也可以借到投资房贷款。少林派,则是看借款人全部的收入和债务,不苛求每一套投资房是否有现金流,因此,整体债务低的家庭,例如,自住房已经还清的家庭,每套投资房都可以借到房价的80%。

银行的不同流派让借款人有了更多选择,总之,作为借款人,应该多多亲近各个银行,把政策搞搞清楚。没有贷款支持,地产投资根本搞不起来。懂得地产投资的人,就是了解和利用银行政策最娴熟的人,无他。

各家银行对投资房按揭贷款政策相同的地方是,一共不能超过10套投资房,在任何一家银行的贷款笔数不超过5笔,投资房超过10套,贷款申请人就会被定义为“real estate operator职业地产投资者”,按照商业贷款的审批流程和利率来批复。对于投资房的按揭贷款政策,各家银行规定各不相同,主要区别在于如何计算投资房的租金。

Diagram

Description automatically generated

03 租金收入的不同看法

银行的爸爸虽然把B20标准定得非常高冷,但有一项内容没有做具体规定,任由商业银行去发挥,那就是租金收入怎么算。在计算偿债能力TDSR的时候,投资房的债务,以及投资房的租金收入该如何计算决定了偿债能力的大小,即,能否符合TDSR小于44%的要求。有两种截然不同的计算投资房债务和租金收入的方法:A 投资房债务算100%,租金算50%到80%;B 投资房债务因为有租金收入做抵消,不算做为债务,每月的债务金额100%与租金收入的85%到90%相抵消,如果结果是负数就从家庭收入中减除,如果是正数就加在家庭收入上。不同的银行用的方法不同,而且即使是同一个银行对不同类型的投资房使用的公式也不一样。举个例子,甲银行规定,如果要申请贷款的房产是投资房,就使用A方法,对于申请人已有的投资房计算债务时使用B方法。甲乙丙丁戊,5家银行使用不同的组合,则算法多达25种之多,借款人不懵就怪了。

不同的银行对租金收入的确定也不一样,上面说的租金只用80%是因为银行认为有20%的空置率,不同银行对空置率有自己的看法,没有统一规定限制。有些银行一定要看到报税的租金收入文件T776,有些银行接受租约作为确定租金的文件,还有些银行只接受评估师提供的公允租金市场价。

这些不确定性和分歧让地产投资者头痛不已。但也说明了一点,就是水库论坛版主欧神在《中产阶级如何保护自己的财富》一书中再三强调的:用80%的时间找房贷,用20%的时间找房子。

04 对银行保持敬畏才能交下银行这个朋友

银行要求申请人偿债能力达到每月的债务低于每月收入的44%,否则贷款批不了。因此,与银行交朋友,首先要做一个交税大户,应纳税收入太低了不行。

为了达到偿债能力要求,消费类债务太大,会造成每月债务比例高于44%。因此,消费类债务,例如,自住房债务,汽车贷款,学生贷款,不能太大。与银行谋投资房贷款,需要推迟满足感,减少消费类坏债务。

银行只借款给信誉好的客户,因此信用记录必须良好,所谓的良好就是借钱按时偿还,没有不良记录。借贷方面的良民,才能与银行交朋友。

房贷的抵押物是房产,因此房产必须符合银行的要求。居住面积太小,银行不喜欢。房子有非法改动,银行不借钱。房子有非法用途,例如,大麻屋,群租/rooming house,银行不借钱。民用住宅才可以申请按揭贷款/residential mortgage,房子有商业用途,例如,上居下铺,申请不到按揭贷款。

05 善用银行的债务管理工具

从上面的银行偏好来看,贷款买投资房,是一个减少消费类坏债务,增加应纳税收入的一场修行。修行到自住房付清,贷款都在投资房上,由租客来承担债务,最终实现用租金的被动收入,取代工薪类的主动收入的一个正果。收入,要靠借款人自己努力,而债务的管理需要借助银行的工具。银行债务管理工具箱的两大工具是:

加按/Refinance:这是最有力的债务重组工具。自住房可以通过加按把还款期拉回到30年,减少月供,增加投资房贷款能力。投资房可以通过加按套现,提取现金做下一套投资房的首付,实现下一套投资房零首付。加按过程中还可以实现去掉原有的借款人,或增加新的借款人。加按可以新增一个信用额度,或去掉原有的信用额度。总之,加按是一个重头再来的机会,把以往的错误纠正过来,并将僵死和沉淀的财富以资本的形式提取出来,从而加速资金周转。

信用额度/HELOC可循环使用的房贷产品,可以向信用卡一样不断地将已经偿还了的本金,再拿出来用,也是个增加资金周转速度的工具。

Diagram

Description automatically generated

06 无法使用银行杠杆的那些人

无法使用银行杠杆的人,主要有两个特征:1.收入低,报税少;2.破坏银行抵押品。

过去10年,银行的父母不断要求银行收紧房贷政策,银行也自发地改变了一些贷款政策。例如,已往,小业主,公司成立3年以内,个人收入低的情况下,首付35%,可以通过Stated Income program,获得房贷,目前,这个项目被所有银行都取消了,因为所谓的stated income 其实就是未来收入,或假收入,无法证实。以往,给新移民和非居民的贷款政策过于宽松,现在银行坚决杜绝了给出示海外收入买投资房的机会,只能购买自住房,而且海外收入的验证方式也越来越严格和严肃,基本上排出了利用新移民政策投资房地产的可能性,新移民政策只适用于自住房贷款。总之,银行对未报税的收入容忍度越来越低。不过,各家银行在最近两年对高净值资产客户的贷款审批可以出现了优惠性倾斜,高净值申请人可以加按已有房产,也可以贷款买投资房。

非法改建,非法分租,就是在主动破坏银行的抵押品——房产。银行不会给主动搞破坏的借款人加按。

总结:把银行当作朋友,可以借助银行的贷款获取虚拟资本,冲破阶级固化,成为有产阶级。交银行这个朋友,要么有稳定收入,要么有高净值资产,并保持良好的信用记录。交上朋友之后,需要保持尊重和敬畏,并通过实践学习债务管理工具的用法,最终达到消灭消费债务等坏债务,建立以房贷和房地产为核心的资产包,用被动收入,替代主动收入。

最近重新启动了油tube的帐户,并上传了长达54分钟的一段讲解房贷政策的视频。更多视频还在整理和制作当中,欢迎订阅我的视频频道。

很多来了加拿大多年的华人移民对加拿大的银行体制,特别是房贷金融体制知之甚少,请将这篇基础知识的文章与你的亲朋好友分享,谢谢。


财商的自我开悟

$
0
0

财商的自我开悟 (第100篇文章)

Written by 王红雨在加拿大Posted on 04/16/2020

这是“王红雨在加拿大”公众号第100篇文章。在过去2年里,我把自己的所思所想,以每周一篇文章的方式与各位订阅读者进行了分享。写第一篇《我看到的房贷本质》时,我给自己定下一个标准:只写可以沉淀下来的,知识性的文章,请各位读者去检验一下,两年前的第一篇文章中的内容和观点,今天是否依然正确,是否经得起时间的检验。人生三不朽包括立功、立德、立言。以“立言”的标准写每一篇文章,是我对个人修养的要求。

为什么要写这些将投资心得开源的文章呢?有人说是软广告呗,有人说是偶然得手之后就嘚瑟呗,这两个原因或多或少都有。可我写着写着发现,“分享”的确是一件非常快乐的事,而且是一种高级快乐。读者呢?读着读着,还真有人对财商开悟了。有了读者的正反馈,我的快乐又升级了一小步。我特别能理解开悟了财商之后的那种“爽”所带来的高级愉悦。我第一次读到“自住房不是你的资产”的时候非常愤怒,那时候我32岁,在哈尔滨有一套房子,当时的人民币存款也就5位数,那套房子值6位数,是我最大的资产了,你说不是资产就不是资产了?羞辱谁呢?直到45岁,才明白只有出租房才是资产,自住房是负债。开悟了这个道理之后,才觉得以前的我是上辈子的自己。如果我在32岁的时候就能读懂那句要命的话,鄙人的财商就早死早超生了。坚持写这个公众号,就是希望素不相识的读者,越早明白这句话越好——“自住房不是你的资产”,早日实现财商的自我开悟吧。

01 失败的移民人生是不了解资本的秘密

移民加拿大的华人中,很多人生活得并不幸福,也有人一无所获地又回流了。人生百年,青壮年时期这么折腾个来回儿,难道是来人间吃苦受难的吗?要移民,就100%连人带心都移过来,把他乡做故乡,把异国当祖国,了解加拿大,融入加拿大,努力寻找适合自己的舞台。网上有无数后悔自己移民他乡的文章,包括移民来加拿大的华人写的,“移民还不如不移民”是常见的一种牢骚。最有范儿的一种遗憾是,如果不移民,早在北上广深买了房,现在身价千万人民币了。10年前,央视播音员义正词严说要打压房价的时候,你真的敢在北上广深买房吗?算你穿越了,你买了房,现在能卖出1千万,折成加元再移民加拿大,能汇过来吗?好,再一次蒜你狠,你汇过来了,一共200万加元对吧,这就是成功人生了?过去10年里,一个普通工薪家庭就可以在加拿大贷款买5+套房子,稳稳地赚了200万加元房屋净值,而且还可以继续收租,房价还在继续涨。中国过去10的房地产井喷,一去不复返了,而在加拿大投资房地产的机会却依然天天有,年年有,BUT 这些机会只给懂得“资本的秘密”的人。我在《家庭财富跃迁的秘密》一文中向读者介绍了这个资本的秘密,如果还有人没有向着家庭财富跃迁的正确道路努力,那就是暴殄天物,糟蹋加拿大的资源啊,早点回流我看也行。

加拿大已经过了高速发展的时期,财富增量很小,因此在加拿大创业,创造财富,赚到钱的机会微乎其微。加拿大的存量财富巨大,但需要使用工具才能撬动存量财富。存量财富的争夺是最血腥和激烈的,年青一代或新移民无法从既得利益者手里分一杯羹的情况下,一个火星就能燃爆一个火药桶,曾经是东方之珠又怎样?加拿大有高福利支撑,穷人饿不死,因此发生无产者革命的可能性在全球最低,工薪族和中产阶级可以从容地布局,攫取存量财富。投资移民,将中国的存款转移的加拿大之后,可以利用银行的高净值资产贷款项目购买投资房。技术移民,如果是双职工,非常适合投资房地产,每套房最多可以借到年收入的5倍,银行看的是每套房的借款能力,不是总的负债,这对中产工薪阶层建立自己的房地产投资组合是非常有利的,最多可以持有10套民用物业。推荐再读《工薪族要不要投资房地产》《中产阶级与地产投资的缘分》《如何平衡一生的收入是中产的底层焦虑》《有多少穷爸爸需要补课》《西瓜是芝麻的2万倍咋还捡芝麻?》《扛着高额房债还能快乐吗?》《整天工作的人没时间赚钱》

02 被收入和税收困住的想象力

加拿大是福利国家,税率高,因此很多人为了避税,错失了取得金融杠杆的机会。攒钱快,还是借钱快?答案很清楚,但道理都懂,咋还过不好这一生呢?一是因为恐惧的边界决定了人生的边界;二是因为节税的先后顺序弄颠倒了。

借钱消费,透支未来,是坏债务;借钱投资,是用OPMother peoples money)积累财富,是好债务,是杠杆。读了以往99篇文章的读者应该能分清债务和杠杆了。有些人恐惧的边界设在只要借钱就害怕的点上,那就没法借钱投资了,其他再说什么都没用了。拓展阅读:《会借钱算不算是一种本事》《行动的勇气》《如果经济衰退还能投资房地产吗》

高税收,才能保证高福利,高福利是为了保证整个国家最贫困的人口不造反。交税,既是义务也是为自己获取存量财富创造条件。银行批准贷款的时候看收入,应纳税收入少,银行不会批准杠杆,没有金融杠杆是撬不动存量财富的。拓展阅读:《税多了不痒才能债多了不愁》《细说杠杆的功与过》《我能想到最浪漫的事:贷得最多,税得最少》《报多少税才能借到房贷》

有一次我看到朋友圈里的一则广告,出售一个经营了10年的移民咨询公司,要价16万。假设有人买了这个生意,以16万元成交,那么卖这个生意的老板获得了16万的收入,平摊到过去10年中,每年增加收入1.6万。借款能力是年收入的5倍,这位老板在过去10年如果每年多给自己发1.6万工资,每年就可以多借款8万房贷,生意开始的前两年就能多借款16万,而10年前多伦多独立屋平均房价36.5万,CONDO 平均房价22.7万,这位老板在过去10年至少少买了一个condo。多伦多还存在大量的,根本不值得做的生意,家庭作坊式的小企业经营N年之后,售价极低,或根本没人买,经营过程中因为节税不舍得给自己发工资,最后的结果不仅没有个人资产投资,生意又艰难且惨淡,出售困难。如果这个例子中的老板是10年前花了16万从其他人手里买的生意,而经营期间为了节税,不舍得给自己发工资,也就无法贷款买房,这10年的人生都虚度了。

贷款买了投资房之后,投资房的开支,包括贷款利息都是能抵税的。很多小企业主,把节税努力的方向搞错了。我的个人看法供大家参考:如果能做成一个大企业,且能卖个高价钱,可以把自己的时间和精力all in,采取所有个人节税的方法,勒紧自己的裤腰带,把公司的财务报告做好看些,申请商业贷款,发展自己的企业,或买些仓库;如果发展不起来,公司的收入应该尽量多地分配到个人,虽然个人税率比公司税高,但税交了之后银行就认可了收入,就可以借到年收入的5倍买房了,买下10套投资房,想退休了,如果生意只值16万,直接干脆关了算了,回家数房产证吧。努力创造个人收入,不要心疼报税,多报税才能从银行取得杠杆,购入房产,因为投资房的所有开销都可以抵税。提高收入多报税在先,购入投资房并节税在后,这才是在加拿大的聪明活法。有很多华人小企业主,每年给自己发2万元工资,节税是不是狠了点儿?银行怎么看你呢?哦,你在企业里的价值就是每年2万元,我们怎么敢借款给你?我看了太多这么想不开的同胞,很痛心,希望他们早日能明白过来。

创业,在任何国家都是艰辛的,不仅辛苦还承担风险,理当获得风险溢价和超额利润,而我在加拿大看到的华人创业者并非如此,很多人的日子过得还不如打工族。最让人捉急的是很多小企业主的财商太感人,就知道心痛交的税,肉眼看不见的机会成本,就权当不存在了。

延伸阅读:《你投资的是真正的资产吗?》《房贷申请途中的杀手排行榜》《识破生活中的财富幻觉》《变穷的18种办法》《投资理财极简课程表》

03 地产投资是一场债务管理的修行

收入减开支等于储蓄,储蓄多了就可以开始投资。投资是为了平衡一生的消费,其实也是平衡一生的收入。投资,需要使用工具,复利和杠杆这两个工具你会用哪个?因为我不会用复利,所以侧重给大家介绍杠杆怎么用。

美国的穷人不会用杠杆,贷款经纪找到他们之后把杠杆塞给了他们,因为银行要赚贷款利息,华尔街需要这些贷款当饲料加工次贷饼干喂给全世界。对于不会用杠杆的人,债务并不是礼物,而是潘多拉的盒子。房价下跌之后,这些穷人输的最惨,首付、房子、工作,全没了,美国梦成了噩梦。我写了很多分析次贷成因和结果的文章,就是想让读者知道,如何使用杠杆,克服对使用杠杆的恐惧心理。

超前消费欠下的债,是用自己税后收入偿还的,例如,自住房贷款,汽车贷款,学生贷款,信用卡债务等等,这些债务是坏债务,要尽一切努力尽快消灭掉,因为有坏债务的家庭,财务非常脆弱。投资房的贷款是租客在负担,且用于投资的费用可以抵税,包括借款利息,地税,公寓管理费,等等,即使有负现金流,也是首付款的分期付款,贷款比例是房价80%的情况下,多伦多公寓CONDO 的净租金回报在目前利率3%的情况下,也是正收益。自己还钱的是债务,别人替你还钱的是杠杆,这一点一定要分清。不懂得债务的特性,是不能轻易用杠杆的。如果分不清债务和杠杆,推荐重读:《房债是魔鬼还是天使》《你的房贷和其他加拿大人比是不是太多了》《如何快速偿还自住房贷款》《细说杠杆的功与过》

有投资多套目标的朋友,最大的敌人是自住房贷款,最好的朋友是稳定的收入。自住房贷款,其实就是人生最大奢侈品贷款,金额越大,财务状况越脆弱,想贷款投资就非常难。每月100元坏债务,减少借款能力2.5万,每月100月收入增加借款能力6千,坏债务和收入不等式说明,减少债务是最有效的提高借款能力的方法。“债务收入不等式”是由于银行要求每月的债务与每月的收入相比,要小于44%造成的。提高收入不仅要多交税,效果还比减少债务差。建议所有家庭,把提前、加速偿还自住房贷款,预设为优先级最高的理财方案。债务与收入的关系,推荐重读:房地产投资的套路》《是什么阻挡了你的多套房投资大计》《地产投资者众生相》《投资楼花还是二手房?》《地产投资最重要的事》《地产投资开始的地方》《房地产投资中的政治和经济学》《地产交易中冲动的惩罚》《如何计算房地产投资回报率》

04 城市房地产投资的特点

城市房地产的特点是,人聚财聚,贵者生存。房价越贵,租金越高的城市,越是吸引新移民。城市化的后期,就是大城市圈化,中小城市向超大城市再移民。以上特点都被多伦多占了。多伦多人口和房地产的特点,以及贷款政策、政府调控政策的影响,见下面几篇文章:《房产是家庭财富的分水岭吗?》《多伦多房价摔了一跤损失1.35亿988笔交易受影响》《土地供应决定着多伦多房价》《城市里的高楼还值得投资吗》《加拿大的人口与住房》《加拿大老人住房状况及房贷解决方案》《加拿大房屋类型与人口结构》《大多伦多地产大数据分析》《谁忽悠了多伦多房价》《当多伦多遇到地产投资者》《多伦多房价居高不下的原因找到了》《房地产投资中正现金流的利弊》《多伦多租房难怎么破》《租房和买房到底能差多少》

05 如何使用杠杆

有志于多套房投资的朋友会发现,地产投资的前3套房子的首付是自己攒的,从第四套开始,就可以加按原有投资房取出现金了。前三套投资房是推石头上山,后面的投资房是推石头下山,山顶上可以做加按,银行提供石头。告别西西弗式的生存方式,就要借助山上的石头,而不是总要自己推石头山上。银行的工具箱有充足的工具促成此事,可偏偏大多数人止步于3套房产了。啥原因呢?在以往的99篇文章中找吧。

延伸阅读:

《向巴菲特学习地产投资》《一次说清Refinance是什么鬼》《地产投资中的现金流和流动性难题怎么破?》《房地产周期有哪些特点?》《房价为啥涨的快跌的慢?》HELOC的属性与应用》《把银行当做朋友》《华人对加拿大信用记录和分数的误解》《房贷续约的十个建议》《买楼花需要注意些什么》《房贷的高压政策值得表扬吗?》《成熟的买房者应如何看待房贷政策和利率》《选择房贷利率的四项基本原则》。

06 怎么才算是“开悟”了?

很多人给“开悟”下定义,我最欢的定义是埃克哈特·托利说的“开悟意味着超越思维”,当然,这里的“思维”是自己的思维。自己超越自己的思维,根本就是没有可能的,需要借助外力。托利在《当下的力量》里讲了这样一个故事:曾经,有一位乞丐在路边坐了三十多年。一天,一位陌生人经过。这位乞丐机械地举起他的旧棒球帽,喃喃地说:“给点儿吧。”陌生人说:“我没有任何东西可以给你。”然后他问:“你坐着的是什么?”乞丐回答说:“什么都没有,只是一个旧箱子而已,自从我有记忆以来,我就一直坐在它上面。”陌生人问:“你曾经打开过箱子吗?”“没有。”乞丐说:“有什么用?里面什么都没有。”陌生人坚持:“打开箱子看一看。”乞丐这才试着打开箱子。这时令人意想不到的事情发生了,乞丐充满了惊奇与狂喜:箱子里装满了金子。我在没有读懂《穷爸爸富爸爸》里说的“你的自住房不是你的资产之前,做了40多年乞丐,现在看到其他乞丐很捉急。如果有一天你对自己的朋友说,“你知道吗?我以前一直以为自住房是我的资产,现在我才知道,自住房是负债。”那一刻,你的财商已经自我开悟了。如果发现你的朋友无法理解你,请把我曾经讲给你的故事,讲给下一位乞丐听。乞丐,自己发现不了身下的木箱,需要陌生人的点拨,罗伯特清崎是我的陌生人,我是你的陌生人,你可能是下一位乞丐的陌生人。让智慧和财富在陌生人之间温暖地传递吧,让世界上更多乞丐早日能发下自己身下的宝藏。

延伸阅读:《经济衰退的成因及其应对方法》《如何轻松拥有悲惨的一生》《没钱与从众是两处硬伤》《真假富人》《投资开始的地方》《只有两个鸡蛋,怎么放到十个篮子里》《如果经济衰退还能投资房地产吗》

07 100篇文章写完之后呢?

我给自己定的目标是写100篇公众号文章,把关于债务的私产经济学基础内容,以及房地产投资的硬核知识介绍完。下一步是要专心建一个多伦多本地的财商读书会。不求读多少书,但求读透那些深刻影响我们当下生活的智慧宝典。知识,是前人留给我们的财富,怎么用到当下,用到生活中,指导我们的日常生活和投资,还需要我们当代人活学活用。

我有个自己的政治理想:帮助第一代华人移民狠挖资本主义墙角,让更多人在加拿大持有多套房。亚当斯密的《道德情操论》里有一个观点:任何国家和社会,无论怎么文明进化,可以没有肤色的黑白之分,但一定会有贫富之别;“嫌贫爱富”维护了所有社会的等级和秩序。托马斯·索维尔在《美国种族简史》中有一个统计,以美国人平均收入100为标尺,华人的收入是112,黑人是62,即使黑人群体要求的政治权利很高,但经济收入并没有同步增加。在加拿大,民主够用就行,财富越多越好,因为这里同样嫌贫爱富

德不孤,必有邻。这个小众的的公众号,自创建以来,已经有7000+的读者订阅。2020年,我会每两周更新一篇,把更多精力花在财商读书群的互动上。这个读书群服务的是多伦多本地,与我志同道合,努力挖资本主义墙角,决心利用金融杠杆持有多套房产的朋友。读书群的入群条件稍后公布。

植入广告:2020年,2021年,2022年和2023年要交割的楼花,现在可以申请贷款了,一次批复,到交房时放款。冬天我们不忙,有时间处理这些房地产交易的期货交易。

这篇文章当做圣诞礼物送给大家,“收藏”,做个以往文章的索引吧。祝各位读者圣诞快乐,新年进步。

红雨

2019年12月25号

房从0到N之路

$
0
0

投资房从0到N之路

中国人:人为财死鸟为食亡;仓廪实则知礼节,衣食足则知荣辱;让生于有余,争起于不足;人富而仁义附焉;天下攘攘,皆为利往,夫千乘之王,万家之侯,百室之君,尚犹患贫,而况匹夫编户之民乎。”

新教徒的资本主义精神:系统地,理性地追求合法收入和资产,积累超过自身生活基本需求的财富,不虚度时光,不奢侈浪费。

把工作/job当成天职/calling,不劳动,不得食,春种秋收,不贪婪,不浪费,不嫉妒——经济理性主义者,本能地利己,在交换中追求利益最大化,符合所处社会的伦理,使用合法的工具和流程。

债务管理能力,决定了获取房产的能力

利率是债务的成本,利率的不确定性,是地产投资的挑战

地产投资是一项小生意,需要管理,其中房产和租客的管理是难点

每个家庭的负债能力靠银行来评估 TDSR是标准的衡量标准,total debt service ratio,每月家庭债务/每月家庭收入,小于44% 评估方法非常保守,用5.25%的利率计算目标房产的贷款月供,如果能通过44%指标,则会获得1.5%利率的奖励

家庭间的财富差距,是由通过压力测试的能力决定的 “不同人之间的价值不能作为一个整体进行加总计算”——米塞斯。“同样,不同人之间的债务也不能作为一个整体进行加总计算”——王红雨 自住房,年收入的5倍 投资房,年收入的5倍,减自住房余额,最多10套投资房 保持稳定可验证收入 自住房没有达到理想居住条件时,用换自住房,保留原自住房的方式投资,途径就是搬家,买新自住房之前加按原自住房贷款 确定理想自住房之后,尽快加速偿还自住房贷款,牺牲RRSP,TFSA投资机会 对于收入的要求就两条:连续,可验证。Sustainable and verifiable 受雇改自雇,毁3年 收入藏在自己的公司里,无法证明个人收入,IT contractor, 地产经纪注册PREC 明明是加拿大税务居民,不把海外收入在加拿大税局申报 对房产的要求:必须是合法的residential property 面积太小影响流动性 非法分租,非法加建,租给多名学生, Not livable,只有一个卫生间且在装修,只有一个厨房且在装修 有酒店成分的CONDO,有农场成分的house 自住房,年收入的5倍 (每套)投资房,年收入的5倍,减自住房余额,最多10套投资房 一个目标两条路 借钱投资已成为趋势,房产是家庭NO1资产,多一套房就超过一个家庭的财富,所以要确定多套房投资的家庭投资目标 两条路:1.通过换自住房,留住原自住房,积累多套房;2.还清自住房,每套投资房借到最大值 中低收入,单身家庭,只有一个人工作的家庭,选择不断买自住房,留原自住房做投资房的方式积累房产。技术动作: 凑首套房首付,而不是攒 换自住房之前加按现自住房,取出最大限度的现金做首付。每次换自住房之前,都要加按现自住房 中高收入家庭,自住房已不需要改善的家庭 用足全力加速还清自住房贷款,推迟满足感,推迟一切避税诱惑,每年把用于投资RRSP/TFSA的资金都用于加速偿还自住房贷款 采取“暴力”方式还清自住房贷款。《房奴翻身把歌唱|一夜还清自住房贷款是怎么做到的》——公众号《王红雨在加拿大》;视频《深度挖掘借款力》youtube 《王红雨》频道 新教伦理:工作是天职/calling,在尘世中努力工作,并积累财富,以此为凭被上帝拣选。华人的经济理性与基督教伦理暗合:不努力工作和不努力积累财富不会被天选。 房地产是NO.1家庭财富,如果在努力工作的同时无法兼顾学习金融资产投资技术,那就不用学了,买房就行。 加拿大人口净流入是趋势;全世界进入低利率是趋势;过多货币追逐有限资产是趋势。通过地产投资保全资产,趋势不可逆 所有人的平均负债水平没有任何意义,银行是评估家庭负债能力的裁判。 让能借到款的人先富起来 只要在加拿大有足够的报税收入,任何人都可以做地产投资。通过B20测试,是技术问题;要不要投资是决策问题。

gem install 时权限问题的修正

$
0
0

2020 10 月 22 日

gem install 时权限问题的修正

进行 gem install 时,如果报如下权限错误:

$ gem install jekyll bundler
gem install jekyll bundler
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

可尝试下面这些解决方式。

--user-install

根据这个回答,似乎加上 --user-install 参数就可以修正:

gem install name_of_gem --user-install

修正 PATH

如果实测发现仍然不行:

$ gem install jekyll bundler --user-install
WARNING:  You don't have /Users/wayongliu/.gem/ruby/2.6.0/bin in your PATH,
	  gem executables will not run.
Building native extensions. This could take a while...
ERROR:  Error installing jekyll:
	ERROR: Failed to build gem native extension.
…

不过这里的错误信息提示变了,和 PATH 有关,于是根据这个回答,修正一个 PATH:

$ PATH="`ruby -e 'puts Gem.user_dir'`/bin:$PATH"

fish 环境使用如下命令:

$ set PATH "`ruby -e 'puts Gem.user_dir'`/bin:$PATH"

或者添加如下命令到 shell 配置文件中:

set -gx PATH ~/.gem/ruby/2.6.0/bin $PATH

重装 Ruby

如果仍然不行,可以尝试使用 brew 重装 Ruby,抛弃 mac 自带的版本。安装过程输出的信息会有如下提示:

By default, binaries installed by gem will be placed into:
  /usr/local/lib/ruby/gems/2.7.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH run:
  echo 'set -g fish_user_paths "/usr/local/opt/ruby/bin" $fish_user_paths' >> ~/.config/fish/config.fish

For compilers to find ruby you may need to set:
  set -gx LDFLAGS "-L/usr/local/opt/ruby/lib"
  set -gx CPPFLAGS "-I/usr/local/opt/ruby/include"

For pkg-config to find ruby you may need to set:
  set -gx PKG_CONFIG_PATH "/usr/local/opt/ruby/lib/pkgconfig"

根据提示,添加相应脚本的 shell 的配置中。

echo 'set -g fish_user_paths "/usr/local/opt/ruby/bin" $fish_user_paths' >> ~/.config/fish/config.fish

刷新配置:

$ source ~/.config/fish/fish.config

然后再执行 gem 安装相关的命令,应该就解决了。

$ gem install --user-install bundler jekyll
Fetching public_suffix-4.0.6.gem
Fetching i18n-1.8.5.gem
Fetching eventmachine-1.2.7.gem
Fetching http_parser.rb-0.6.0.gem
Fetching colorator-1.1.0.gem
Fetching addressable-2.7.0.gem
Fetching concurrent-ruby-1.1.7.gem
Fetching em-websocket-0.5.2.gem
…

检查安装:

$ jekyll -v                                                                                                  
jekyll 4.1.1

如果报 jekyll 命令找不到,检查 shell 配置中是 PATH 是否配置正确,见上面步骤。

以上。

how do i set up in Linux CLI?

$
0
0

On Ubuntu 20, here’s what I do:

This is for the suprnova pool, you can change the address below if you want another pool / no pool.

git clone https://github.com/WyvernTKC/cpuminer-gr-avx2

sudo apt-get update

sudo apt-get install -y libgmp3-dev automake zlib1g-dev libcurl4-openssl-dev libnuma-dev libssl-dev

cd cpuminer-gr-avx2

./autogen.sh

CFLAGS=”-O3 -march=native -Wall -lnuma” ./configure –with-curl

make -j4

sudo ./cpuminer -a gr -o stratum+tcp://stratum.us-la1.suprnova.cc:6273 -u [your-worker-id] -p [yourpass]

硅谷王川:去中心化的流动性黑洞,和区块链第一法则 

$
0
0

1/ 流动性,就是钱的一种文邹邹的说法。它还包含了另外一个层面的含义,就是资产可以迅速 (最好是几分钟,不要等几个月甚至几年, 黄花菜都凉了)从一种状态流动变迁到另外一种状态(俗称“变现”),而在流动前后资产的价值没有较大的打折损耗。

2/ 流动性对于企业家和投资者都是一个刚需。没有流动性的资产,其价格往往是虚假而无法验证的。号称资产过亿的企业家,如果没有流动性,实际可能是下个月都无法付房租的穷光蛋。号称回报若干倍的基金,如果没有流动性,实际可能只是个自欺欺人的骗局。

3/ 传统上流动性的产生需要很多中介机构, 会计师,律师, 分析师,投资银行家,风险投资家,交易所等等。监管机构也是少不了的。这给流动性的产生,增加了很多成本障碍,和时间上的延迟。

4/ 这种障碍对于小企业和创业者是个头疼的问题,只有获得流动性的支持才能做大,而没有做大之前,很难获得流动性。很多外表光鲜的企业,无非是在流动性的获取上有着某种垄断的优势而已, 但内在业务和管理水平其实可能一塌糊涂。这种现状让很多企业家把精力本末倒置,主要放在获取流动性的折腾上,而不是专注技术和业务本身。

5/ 区块链行业,中心化的交易所(centralized exchange, 以下简称 cex ) 过去几年在流动性的控制上占据了一个重要的位置。大的cex,因为可以给某个 token 带来巨大的流动性,直到2020年初, 都有底气为想上市者开出超过百万美元的要价。

6/ 但 cex 的各种问题也是人尽皆知:除了高额的上市费用外,有些 cex 还存在伪造夸大交易量,恶意操纵价格波动导致加杠杆的交易者被迫平仓割肉,财务透明度不够创始人突然跑路,钱包安全性,个人隐私信息可能被盗,等等问题。

7/ Uniswap 作为目前以太坊上最大的去中心化交易所 (decentralized exchange, 下简称 dex ) ,2018年十一月开始在以太坊的主网上运营。其创始人 Hayden Adams, 原为西门子的机械工程师,这是他大学毕业后的第一份工作。2017年六月他被西门子解雇后转而进入区块链行业, 将近一年时间都是靠自己的微薄积蓄苦苦挣扎,直到2018年七月他的项目获得以太坊基金会的资助。

8/ Uniswap 属于所谓的“自动做市商”(Automated Market Makers) , 通过智能合约让交易者自动置换资产,同时收取 0.3%的交易费用分享给流动性提供者,也称流动性挖矿。智能合约的优点是完全自动化,无需 cex 繁琐的注册手续.但对流动性挖矿者目前也存在合约安全性和所谓“非永久性亏损” (impermanent loss) 之类的风险,在此暂不细表。

9/ 今年五月开始 Uniswap 上的交易量有了迅猛的增长,八月十号,其单日交易量达到四点二亿美元,第一次超过(2012年就成立了的) Coinbase 的交易量 (三点四八亿美元)。目前 Uniswap 整体交易量在所有各类区块链交易所中排名第四。

10/ Uniswap 上锁定的数字资产在今年八月初时还只有一亿多美元,从八月二十八号开始突然爆炸式增长,截止到十月六号,已经锁定了二十二亿美元的数字资产,锁定资金量在整个DeFi(去中心化金融)生态中占比接近 22%。

11/ 为什么 uniswap 的交易量获得如此突破?原因有几个:一是很多原来只能先交钱再通过 cex 才能上市交易的 token, 马上可以通过 uniswap 公开自由交易。DeFi 的很多创新带来的 token, 第一时间上 uniswap 交易,抢了 cex 的生意,进而倒逼后者突然放下身段,不收钱了,也要跟着上。

12/ 二是流动性的增加进入一个良性循环。参与交易者越多,流动性挖矿者获得的收益越多,交易损耗越小,进而吸引更多的流动性。

13/ 第三个原因是 DeFi 生态的“可组合性”(composability)。Uniswap 的自动交易的智能合约,就像乐高积木一样,可以很方便地被其它新应用在链上直接调用,对于开发者而言是个非常自然简单的选择。

14/ 然而八月底,以太坊上横空杀出一个项目叫做 Sushiswap. 它只是把 Uniswap 的代码拷贝了一下,但是许诺给流动性提供者更多的利益分成。

15/ Sushiswap 的创始人,一个人单枪匹马,两周之内就集聚了价值约三万八千个以太坊 (超过一千三百万美元)的 token fund 套现。尽管他操作过于草率,一度被社区指责为要卷款逃跑的骗子, 但最后套现的以太坊还是被归还给社区。而sushiswap 一度劫持了 uniswap 的超过三分之二的流动性,并暴露出后者的短板。正是因为这场风波,才给 uniswap 项目方更大压力,迅速推出 UNI token 分享给社区。

16/ 像 sushiswap 一类的操作并不复杂,只是把前人的代码复制了一下,但在设计上给社区分享让利更多,主要通过推特 / Github / Discord 等社区渠道宣传,很容易吸引新的流量和用户。花几个月学习 solidity 的人应当都有能力开发类似的应用。

17/ 现在开始,世界各地,从瑞士到马耳他,从塞舌尔到新加坡, 从旧金山到多伦多,会有更多一无所有的年轻开发者每天晚上进行这样震耳欲聋的心灵拷问:

和尚摸得,为什么我摸不得?

18/ 别人可以 fork uniswap 搞 sushiswap, 我为什么不能用我的智力去改进其它 protocol, 给用户分享更多利益,然后直接利用去中心化的流动性,筹集一个开发者基金给自己生活用,哪怕一年套现 5-10%也可以过得很好,这样不用再低三下四地去找工作或者向 VC 融资?

19/ 而实际上大部分雇主和 VC 只是有流动性渠道的优势而已,其它方面哪点比我强?

20/ 我如果可以直接依靠开发能力在链上迅速获得资金,为什么要浪费时间和这些人在线下纠缠? 他们还能增加什么样的价值?

21/ 至于有人抱怨以太坊上 gas 费用太高了会影响 dex 的发展,这种论调其实不新鲜。可以回顾一下 2017年下半年比特币网络上的争论,在2017年底比特币链上的转币费用一度超过一百美元,各种骂声不断,现在早已烟消云散。

22/ 著名生物学家 Leslie Orgel 曾有生物学的 Orgel 第一法则:

“当任何自发进程过于缓慢或者低效时,总会有一个蛋白质进化出来加速进程或者提高它的效率。”

我也发明一个“王川区块链第一法则”:

当任何自发公链的费用过高或者速度过慢时,总会有新技术涌现出来降低交易费用或者提高交易速度”。

23/ 以太坊扩容的解决方案,除了下面两三年的 sharding, eth2.0, 短期内还会有 zk-rollup, optimistic rollup 的解决方案, 总有一款将会适合你。

24/ 有多少人一年前预测到 uniswap 的交易量能够达到所有交易所中排名第四?有多少人预测得到 sushiswap 一夜之间可以劫持其三分之二流量?又有多少人预料得到 uniswap 又很快卷土重来,锁定资产的金额重新创新高?如果这些无法预料,又怎能预料 dex 领域未来涌现的创新,在自动做市交易的算法和社区管理规则的继续改进,不会带来我们无法想象的更大惊喜呢?

25/ 去中心化的流动性创新,是区块链技术发展的一条主线,导致交易摩擦,交易费用不断下降,交易的选择和方式越来越多。Uniswap 号称明年要推出的 v3 第三版要比现在的 v2 强一百倍,但不排除还会有别的竞争者捷足先登。

26/ 有了源源不断的去中心化流动性,就会吸引源源不断的开发者,创造源源不断的新应用。新应用带来更高的效率和收益分享给投资者,则会进一步吸引更多的流动性和新包装的资产上链。

27/ 有了新的更高效的应用,会有更多投资者问自己:“嗯,这个链上的新应用可以有价值好几倍的数字资产抵押,风险低,可以获得不错的收益,总比放在银行里零利率强。银行从来不给我们储户送股票,这个应用还给我们免费送 token, 为什么不投一点?”

28/ 会有更多借贷者问自己:“嗯,我用数字资产抵押,可以获得比别的渠道利率更低的资金,手续简单,随时还随时借出,为什么不?”

29/ 直到有一天,传统金融的一些从业者说,“不对,我的那些客户怎么都到区块链上去借贷和储蓄了,我也要资产和业务上链!”

30/ 这, 就是一个将席卷全球的去中心化的流动性黑洞。它将以开放,高效和透明的优点不断吸入一波又一波的新的流动性。

31/ 如果既得利益者要忽视 DeFi 里面涌现的各种技术革新的话,台词和借口都有现成的:监管风险,智能合约风险,骗子跑路风险,等等。全球每天外汇交易额就有六万亿美元,是 uniswap 目前日交易量的两到三万倍,还有四个数量级的差距需要追赶,实在不入传统金融从业者的法眼。

32/ 但 uniswap 从零到两亿美元的日交易量,只花了两年的时间。作为一种完全无需许可的创新,区块链市场去中心化的交易规模,未来没有理由不超过外汇市场。

33/ 如果传统金融从业者,还没有因去中心化流动性黑洞的到来,而开始颤抖的话,不用急,他们不会等太久的。

(作者简介:王川,投资人,现居加州硅谷。本文转自其公众号“硅谷王川”。)

Viewing all 764 articles
Browse latest View live