Skip to content

Commit 6841f4a

Browse files
Ganesh RamachandranGanesh Ramachandran
authored andcommitted
Added new features to TMPM3HQ
1 parent 608e4c2 commit 6841f4a

File tree

14 files changed

+1886
-67
lines changed

14 files changed

+1886
-67
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* mbed Microcontroller Library
2+
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include <stdbool.h>
18+
#include "crc_api.h"
19+
#include "device.h"
20+
21+
#ifdef DEVICE_CRC
22+
23+
static uint32_t final_xor;
24+
25+
bool hal_crc_is_supported(const crc_mbed_config_t *config)
26+
{
27+
if (config == NULL) {
28+
return false;
29+
}
30+
// Currently supported only CRC16_CCITT polynomial.
31+
if (config->polynomial != POLY_16BIT_CCITT) {
32+
return false;
33+
}
34+
35+
if (config->width != 16) {
36+
return false;
37+
}
38+
// Not support for reflect_in and reflect_out.
39+
if ((config->reflect_in == true) || (config->reflect_out == true)) {
40+
return false;
41+
}
42+
43+
return true;
44+
}
45+
46+
void hal_crc_compute_partial_start(const crc_mbed_config_t *config)
47+
{
48+
TSB_CG_FSYSENB_IPENB20 = 1;
49+
50+
// Intial Value as initial_xor
51+
TSB_CRC->CLC = config->initial_xor;
52+
final_xor = config->final_xor;
53+
54+
// Data width setting CRC data width is 8 bits.
55+
// Form setting CRC form is CRC16.
56+
TSB_CRC->TYP = 0x01;
57+
}
58+
59+
void hal_crc_compute_partial(const uint8_t *data, const size_t size)
60+
{
61+
if (data && size) {
62+
uint32_t index = 0U;
63+
for(index = 0U; index < size; index++) {
64+
TSB_CRC->DIN = data[index];
65+
}
66+
}
67+
}
68+
69+
uint32_t hal_crc_get_result(void)
70+
{
71+
uint32_t result;
72+
73+
// Note: Please read [CRCCLC] twice and use the result of the 2nd time
74+
result = TSB_CRC->CLC;
75+
result = TSB_CRC->CLC ^ final_xor;
76+
77+
return (result);
78+
}
79+
#endif // DEVICE_CRC

targets/TARGET_TOSHIBA/TARGET_TMPM3HQ/device.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#ifndef MBED_DEVICE_H
1717
#define MBED_DEVICE_H
1818

19-
#define DEVICE_ID_LENGTH 32
19+
#define DEVICE_ID_LENGTH 32
20+
#define TRANSACTION_QUEUE_SIZE_SPI 4
2021

2122
#include "objects.h"
2223

targets/TARGET_TOSHIBA/TARGET_TMPM3HQ/device/TOOLCHAIN_ARM_STD/tmpm3hqfdfg.sct

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ LR_IROM1 MBED_APP_START MBED_APP_SIZE
4040

4141
RW_IRAM1 0x200002D8 (0x10000 - 0x2D8 - Stack_Size)
4242
{
43+
tmpm3hq_fc.o (+RO)
4344
.ANY (+RW, +ZI)
4445
}
4546

46-
ARM_LIB_STACK (0x200002D8+0x10000) EMPTY -Stack_Size { ; stack
47+
ARM_LIB_STACK (0x20000000+0x10000) EMPTY -Stack_Size { ; stack
4748
}
4849
}

targets/TARGET_TOSHIBA/TARGET_TMPM3HQ/device/TOOLCHAIN_GCC_ARM/tmpm3hqfdfg.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ SECTIONS
109109
__data_start__ = .;
110110
*(vtable)
111111
*(.data*)
112-
112+
*(.ram_func*)
113113
. = ALIGN(4);
114114
/* preinit data */
115115
PROVIDE_HIDDEN (__preinit_array_start = .);

targets/TARGET_TOSHIBA/TARGET_TMPM3HQ/device/TOOLCHAIN_IAR/tmpm3hqfdfg.icf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };
3737
initialize by copy { readwrite };
3838
do not initialize { section .noinit };
3939

40+
initialize by copy { section RAMCODE };
41+
42+
/* Place both in a block */
43+
define block RamCode { section RAMCODE };
44+
define block RamCodeInit { section RAMCODE_init };
45+
46+
/* Place them in ROM and RAM */
47+
place in ROM_region { block RamCodeInit };
48+
place in RAM_region { block RamCode };
4049
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
4150

4251
place in ROM_region { readonly };
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/* mbed Microcontroller Library
2+
* (C)Copyright TOSHIBA ELECTRONIC DEVICES & STORAGE CORPORATION 2018 All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "flash_api.h"
18+
#include "mbed_critical.h"
19+
#include "tmpm3hq_fc.h"
20+
21+
#define PROGRAM_WRITE_MAX (16U) // Page program could be written 16 bytes/4 words once
22+
#define SECTOR_SIZE (0x8000) // 32KB each sectors or block
23+
#define FLASH_CHIP_SIZE (0x00080000) // Flash chip size is 512KByte
24+
#define MASK_CHIP_ID_FROM_ADD (0x00FFFFFFUL)
25+
26+
#define SUCCESS (0U)
27+
#define FAIL (-1)
28+
// IHOSC1EN
29+
#define CGOSCCR_IHOSC1EN_MASK ((uint32_t)0x00000001) // IHOSC1EN :Mask
30+
#define CGOSCCR_IHOSC1EN_RW_DISABLE ((uint32_t)0x00000000) // IHOSC1EN :[R/W] :Disable
31+
#define CGOSCCR_IHOSC1EN_RW_ENABLE ((uint32_t)0x00000001) // IHOSC1EN :[R/W] :Enable
32+
33+
static void internal_hosc_enable(void);
34+
35+
int32_t flash_init(flash_t *obj)
36+
{
37+
obj->flash_inited = 0;
38+
obj->flash_inited = 1;
39+
internal_hosc_enable(); // Internal HOSC enable
40+
return 0;
41+
}
42+
43+
int32_t flash_free(flash_t *obj)
44+
{
45+
obj->flash_inited = 0;
46+
47+
return 0;
48+
}
49+
50+
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
51+
{
52+
int status = FAIL;
53+
54+
if (obj->flash_inited == 0) {
55+
flash_init(obj);
56+
}
57+
58+
// We need to prevent flash accesses during erase operation
59+
core_util_critical_section_enter();
60+
61+
if (TXZ_SUCCESS == fc_erase_block_code_flash((uint32_t*)FC_CODE_FLASH_ADDRESS_TOP, (uint32_t*)address)) {
62+
status = SUCCESS;
63+
} else {
64+
// Do nothing
65+
}
66+
67+
core_util_critical_section_exit();
68+
69+
return status;
70+
}
71+
72+
int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data, uint32_t size)
73+
{
74+
int status = SUCCESS;
75+
76+
address &= MASK_CHIP_ID_FROM_ADD;
77+
78+
// We need to prevent flash accesses during program operation
79+
core_util_critical_section_enter();
80+
81+
if (TXZ_SUCCESS == fc_write_code_flash((uint32_t*)data, (uint32_t*)address, size)) {
82+
// Do nothing
83+
} else {
84+
status = FAIL;
85+
}
86+
87+
core_util_critical_section_exit();
88+
89+
return status;
90+
}
91+
92+
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
93+
{
94+
if ((address >= FC_CODE_FLASH_ADDRESS_TOP) && (address < (FC_CODE_FLASH_ADDRESS_TOP + FLASH_CHIP_SIZE))) {
95+
return SECTOR_SIZE;
96+
} else {
97+
// Do nothing
98+
}
99+
100+
return MBED_FLASH_INVALID_SIZE;
101+
}
102+
103+
uint32_t flash_get_page_size(const flash_t *obj)
104+
{
105+
return PROGRAM_WRITE_MAX;
106+
}
107+
108+
uint32_t flash_get_start_address(const flash_t *obj)
109+
{
110+
return FC_CODE_FLASH_ADDRESS_TOP;
111+
}
112+
113+
uint32_t flash_get_size(const flash_t *obj)
114+
{
115+
return FLASH_CHIP_SIZE;
116+
}
117+
118+
static void internal_hosc_enable(void)
119+
{
120+
uint32_t work;
121+
work = (uint32_t)(TSB_CG->OSCCR & ~CGOSCCR_IHOSC1EN_MASK);
122+
TSB_CG->OSCCR = (uint32_t)(work | CGOSCCR_IHOSC1EN_RW_ENABLE);
123+
}
124+
125+
uint8_t flash_get_erase_value(const flash_t *obj)
126+
{
127+
(void)obj;
128+
129+
return 0xFF;
130+
}

0 commit comments

Comments
 (0)