New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards: ikea-tradfri: add support #8047

Merged
merged 2 commits into from Nov 21, 2017

Conversation

@basilfx
Copy link
Member

basilfx commented Nov 15, 2017

Last week I found out that the IKEA TRÅDFRI lighting products and accessories use the Silicon Labs EZR32MG1P microcontroller. Let it be a coincidence that the Thunderboard Sense (#7929) which was merged this week, uses the same CPU!

Now if we look into their line of products, it happens that they use the same CPU module in all(?) of their products: here, here and here. Nonetheless, you can isolate them from the product, and use them for your own ideas, or leave them in and flash a custom firmware.

The MCU is a ARM Cortex M4 with 256 kB of flash. It's quite packed (including hardware crypto), flexible pin mapping and has an integrated radio which supports Thread, ZigBee Light Link and more.

It won't surprise me if people buy the cheapest light available (the GU-10 I used costed me 6,99 euro) and upgrade, hack or repurpose them. Let RIOT-OS be one of the first to support them :-)

This PR is a quick port to this new platform. I have more information on the module over here and a demonstration video here. For flashing you need to connect a JTAG/SWD compatible debugger, but I can flash it the exact same way as the Thunderboard Sense when I use SEGGER JLink. You do not even have to remove the module.

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 15, 2017

This will void the warranty of your IKEA product.

@miri64

This comment has been minimized.

Copy link
Member

miri64 commented Nov 15, 2017

Is there a radio on-board (and do we support it already)?

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 15, 2017

It has a radio on-board, but we don't support it yet. But now I have more motivation to do so :-)

It would be a nice product/board for demo purposes.

@miri64

This comment has been minimized.

Copy link
Member

miri64 commented Nov 15, 2017

It would be a nice product/board for demo purposes.

Yes definitely! I've been waiting for hacks like this basically since day one of my contribution (but never found the time to do it myself 😞).

@kYc0o

This comment has been minimized.

Copy link
Contributor

kYc0o commented Nov 15, 2017

Eeeexcelleeeent!!! I was thinking about these products since I was aware of them, but I'm glad you also investigated them!

I'll try to grab some and hack them with RIOT.

@kYc0o kYc0o assigned kYc0o and haukepetersen and unassigned haukepetersen Nov 15, 2017

@miri64

This comment has been minimized.

Copy link
Member

miri64 commented Nov 15, 2017

I guess I have to guess I have to go to IKEA again (damn it I was saving up for a new PC!!1! 😜)

@haukepetersen

This comment has been minimized.

Copy link
Contributor

haukepetersen commented Nov 16, 2017

Awesome!!! My wife will be sooo happy that I am now motivated to go to ikea (besides the usual hot-dog motivation) :-)

Will review do a review right away.

* @{
*/
#define LED0_PIN GPIO_PIN(PA, 1)
#define LED1_PIN GPIO_PIN(PB, 13)

This comment has been minimized.

@haukepetersen

haukepetersen Nov 16, 2017

Contributor

From your video I take that this pin is connected to the FET switching the actual light, right? So what is LED0 connected to?

This comment has been minimized.

@basilfx

basilfx Nov 17, 2017

Author Member

I have to think about this, and see what is useful. In my case, PA1 was also soldered, but I don't know what it does (haven't traced it properly).

Since the same board is used in different light bulbs or accessories, I had this idea of defining different pins on an additional compiler flag. E.g. IKEA_PRODUCT=ligthbulb or something like that.

This comment has been minimized.

@haukepetersen

haukepetersen Nov 17, 2017

Contributor

I see. So I guess lets leave it for now and see what further reverse engineering brings...

This comment has been minimized.

@basilfx

basilfx Nov 17, 2017

Author Member

After closer inspection, it seems that PA1 is only connected for fixing the PCB. It leads to a dead end (missing resistor).

This comment has been minimized.

@asmaps

asmaps Nov 17, 2017

Maybe it's connected in the more expensive versions? The versions that can change the white color between warm and cold (not only brightness) have 2 different LED-types for this - cold whites and warm whites. So there's probably one color on each connector?

This comment has been minimized.

@basilfx

basilfx Nov 18, 2017

Author Member

That is definitely possible. In other teardowns you can see that more pins are connected.

@haukepetersen
Copy link
Contributor

haukepetersen left a comment

One tiny remark, else looking great!

.dev = USART1,
.mosi_pin = GPIO_PIN(PD, 15),
.miso_pin = GPIO_PIN(PD, 14),
.clk_pin = GPIO_PIN(PD, 13),

This comment has been minimized.

@haukepetersen

haukepetersen Nov 16, 2017

Contributor

Is there anything connected to these pins (or rather: are they accessible)? If not, we might just want to skip the SPI configuration all together for this board?!

This comment has been minimized.

@basilfx

basilfx Nov 17, 2017

Author Member

There is an additional SPI flash that we might want to access.

This comment has been minimized.

@haukepetersen

haukepetersen Nov 17, 2017

Contributor

Alright, so never mind.

This comment has been minimized.

@basilfx

basilfx Nov 17, 2017

Author Member

I'm not 100% sure, but based on reading the JEDEC ID and Product Identification, it seems that a 2Mbit flash by Integrated Silicon Solution Inc. (part number IS25LQ020B) is used.

@kaibeckmann

This comment has been minimized.

Copy link

kaibeckmann commented Nov 17, 2017

Hey thats cool!

Based on your work I started with the radio driver and support for the Silicon Labs Dev-boards. It is still work in progress and based on the RIOT version from February, but could be a starting point to get RIOT on light bulbs :)

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 17, 2017

@kaibeckmann That's cool! I can help you if you want!

I am also working on another PR which will improve support for EFM32, based on feedback by @haukepetersen. Hope to create a PR this weekend.

In the mean time, I have updated https://github.com/basilfx/TRADFRI-Hacking and added some work-in-progress schematics and PCB designs for development. I first need another trip to IKEA!

@kaibeckmann

This comment has been minimized.

Copy link

kaibeckmann commented Nov 17, 2017

@basilfx Yeah that could speed things up!
Regarding the EFM32 support: I ran in some issues with the radio stuff there. I'll try to sum it up and send you a mail. Furthermore, I started to put the gecko-sdk in an package. At the moment I only pull the radio driver blob from it and use the header files for the RAIL-API. Maybe that could be a used for the rest of the emlib-stuff as well?

@haukepetersen
Copy link
Contributor

haukepetersen left a comment

My concerns are addressed -> ACK ACK ACK

@haukepetersen

This comment has been minimized.

Copy link
Contributor

haukepetersen commented Nov 17, 2017

@kaspar030 I know you won't like the duplicated code in this PR either, but I'd say we merge this anyway and wait for the results of #8058 and clean-up/unify around the EFM32-based boards once a structure is decided.

@kYc0o

This comment has been minimized.

Copy link
Contributor

kYc0o commented Nov 17, 2017

@basilfx is there a way to backup the existing firmware? (in case of we want to come back to the default behaviour).

@kYc0o

This comment has been minimized.

Copy link
Contributor

kYc0o commented Nov 17, 2017

Just FYI, there are efforts to communicate with these things using aiocoap, you might be interested in this issue.

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 17, 2017

@kYc0o Yes, I've managed to backup a copy of the firmware. I haven't tried to flash it back, but I will try that tonight (just went to IKEA to buy some more lights).

@kYc0o

This comment has been minimized.

Copy link
Contributor

kYc0o commented Nov 17, 2017

There is this effort too.

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 17, 2017

I can confirm that the light will still work after downloading the binary (256 kB), erasing the chip, and then uploading the binary again (including power cycling). I did have to re-pair the light bulb, but I think that is not due to flashing. It even defaulted to last brightness.

img_0983

@miri64

This comment has been minimized.

Copy link
Member

miri64 commented Nov 17, 2017

Nobody dares to merge this awesome feature?

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 17, 2017

I have a small fix for the SPI pins. I have confirmed that it works, because I can read the SPI chip.

@basilfx basilfx force-pushed the basilfx:feature/ikea-tradfri branch from ec2bba9 to d710676 Nov 17, 2017

@kYc0o

This comment has been minimized.

Copy link
Contributor

kYc0o commented Nov 17, 2017

Nobody dares to merge this awesome feature?

It was maybe acked too fast 😉

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 17, 2017

@kYc0o

This comment has been minimized.

Copy link
Contributor

kYc0o commented Nov 17, 2017

Waaaaao!!! Congrats! 😃

@miri64

This comment has been minimized.

Copy link
Member

miri64 commented Nov 18, 2017

Whoopwhoop \o/

@miri64

This comment has been minimized.

Copy link
Member

miri64 commented Nov 18, 2017

Nobody dares to merge this awesome feature?

It was maybe acked too fast 😉

Can you point me to the comment where this is stated? I couldn't find it. (and why wasn't the review dismissed then 😉?)

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 18, 2017

If somebody wants to re-ACK my last commit (d710676), than I will squash, rebase and commit when Murdock agrees!

@kYc0o

This comment has been minimized.

Copy link
Contributor

kYc0o commented Nov 19, 2017

Can you point me to the comment where this is stated? I couldn't find it. (and why wasn't the review dismissed then 😉?)

I didn't mean too fast in the sense of "bad-acked" but in the sense that several changes came just after it was acked which can also belong to this PR. We could have merged this as it was acked (since it was OK to ack it, everything worked as expected and the comments were addressed), and the modifications and improvements which came afterwards would have been part of another PR.

Thus, nothing to dismiss, nothing to complain, just a personal impression. Waiting a bit more before merge it gave us other features and better understanding.

MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 262144
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 31744

This comment has been minimized.

@kYc0o

kYc0o Nov 20, 2017

Contributor

What happened with the remaining 1K of RAM?

This comment has been minimized.

@basilfx

basilfx Nov 20, 2017

Author Member

If I recall correctly, 1 KiB is reserved for the (proprietary) radio (driver). However, I've double-checked with the Gecko SDK, but that number is correct :-)

This comment has been minimized.

@kYc0o

kYc0o Nov 20, 2017

Contributor

Ok. I suppose that is managed internally since I don't see any specific instruction in the ld you cite on which they make use of the last 1K of RAM. Though it looks a bit strange but if it works let's continue this way.


MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 262144

This comment has been minimized.

@gebart

gebart Nov 20, 2017

Member

262144 can be written as 256K to make it a little bit more friendly

This comment has been minimized.

@basilfx

basilfx Nov 20, 2017

Author Member

I can change that, but I have another PR coming up that will use the default Cortex-M linker scripts :-)

@haukepetersen

This comment has been minimized.

Copy link
Contributor

haukepetersen commented Nov 20, 2017

re-ACK your SPI fix -> please squash and I will be happy to press the big green button :-)

@basilfx basilfx force-pushed the basilfx:feature/ikea-tradfri branch from d710676 to c51948c Nov 20, 2017

@basilfx

This comment has been minimized.

Copy link
Member Author

basilfx commented Nov 21, 2017

@haukepetersen Go ahead :-)

@haukepetersen

This comment has been minimized.

Copy link
Contributor

haukepetersen commented Nov 21, 2017

My pleasure! -> go

@haukepetersen haukepetersen merged commit e5083ab into RIOT-OS:master Nov 21, 2017

2 checks passed

Murdock The build succeeded. runtime: 5m:29s
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@miri64

This comment has been minimized.

Copy link
Member

miri64 commented Nov 21, 2017

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment